-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use new consensus backend in compute node #172
Conversation
0f558ee
to
15fe047
Compare
6bf7b3a
to
e271416
Compare
e271416
to
e17159a
Compare
e17159a
to
3a5be89
Compare
3a5be89
to
9640c09
Compare
compute/src/main.rs
Outdated
None | ||
// Setup consensus backend. | ||
// TODO: Change dummy backend to get computation group from another backend. | ||
let consensus_backend = Arc::new(ekiden_consensus_dummy::DummyConsensusBackend::new(vec![ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be keyed off of the argument above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean by this? Also, you seem to have commented on something that is out of date?
compute/src/consensus.rs
Outdated
block: Block, | ||
} | ||
|
||
struct ConsensusFrontendInner { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
define this next to consensusfrontend below, without the configuration struct in-between them?
Also: this seems is defining the consensus 'client library'. why is it in compute, and not consensus?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also: this seems is defining the consensus 'client library'. why is it in compute, and not consensus?
This understanding is not correct. The consensus/*
defines the client interface (e.g., the interface that clients use to talk to the backend) and implementations of these clients (e.g. dummy backend). So this frontend is just using the client interface for a compute node specific purpose. It makes absolutely no sense to put that into consensus?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I think the core of this and a couple other one i flagged below is that the terms 'frontend' and 'backend' are context specific. I think this makes sense to me now.
compute/src/consensus.rs
Outdated
/// Start consensus frontend. | ||
/// | ||
/// Returns list of futures that should be spawned in the event loop. | ||
pub fn start(&self) -> Vec<BoxFuture<()>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this returning a vector of 3 futures? Can you join them into a single future?
Would it be cleaner to have start
take a reactor / task pool in which to insert its work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this returning a vector of 3 futures? Can you join them into a single future?
You can join them, but then they will be scheduled in the same task which would be wrong as it may cause deadlocks.
Would it be cleaner to have start take a reactor / task pool in which to insert its work?
I was thinking about this, but the problem is that the reactor is a generic term and there is no trait that would be implemented for all reactors (e.g., the gRPC reactor that we are using). We could create our own trait and implement it for all these reactors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually with futures 0.2, handling of execution has been much improved. But futures 0.2 is considered unstable and will be replaced by 0.3, so we should revisit this when 0.3 is released and other libraries start supporting it. I'll open an issue and inbetween I'll change it so that an executor is passed as an argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
compute/src/consensus.rs
Outdated
self.inner | ||
.backend | ||
.get_events() | ||
.for_each(move |event| -> BoxFuture<()> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is long enough that it would be worth refactoring the three handlers defined in it into named methods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I'll refactor it. Of course they will be functions without the self argument not instance methods as those are currently unusable in futures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
struct ConsensusFrontendInner { | ||
/// Consensus backend. | ||
backend: Arc<ConsensusBackend + Send + Sync>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be named something with consensus if it stays within compute/src/, since otherwise in the methods below i was double checking myself that it was referring to consensus versus compute.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this is in ConsensusFrontend
and it referes to the consensus backend. Is there some other backend that this could refer to? So self.backend
should be read as ConsensusFrontend -> backend
, e.g. the backend part that he frontend is talking to. To me it sounds strange if there was a consensus_backend
in consensus frontend as in this case the consensus part is duplicated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On other thought, consensus_backend may really be more clear in futures where there's no self, so if you still think this is confusing, I'll change it.
compute/src/main.rs
Outdated
@@ -87,6 +107,12 @@ fn main() { | |||
.takes_value(true) | |||
.default_value("9003"), | |||
) | |||
.arg( | |||
Arg::with_name("consensus-backend") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, currently not, I'll remove it as we will probably want some way to specify backend-specific configuration when we support multiple backends.
}) | ||
} else { | ||
eprintln!("WARNING: IAS is not configured, validation will always return an error."); | ||
// Setup key pair. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to have a config file for the binary that hold the key state and also the other identity information / parameters used to resume the same service?
It feels like we'll want the config soon enough, and then we'll have to deal with the interaction of two state files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What state do you mean, the local contract identity? That is transient and may not even be persisted, especially if we will be supporting compute nodes that run arbitrary contracts.
But I agree regarding the config file and this is something that is out of scope for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Issue for config file is in #37.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(meant the key_pair, along with configured backend and whatever else we consider as state). Sounds good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the first part of the refactor changes arguments into a giant "compute node configuration" structure. The next step would probably be to make it serializable / deserializable to TOML or something.
compute/src/worker.rs
Outdated
let (contract, identity_proof) = | ||
Self::create_contract(&config.contract_filename, ias, config.saved_identity_path); | ||
|
||
// Construct consensus client. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The worker is given a consensus frontend. why does it also talk to the consensus directly? can we route communication through the frontend to make the communication pattern a bit more constrained?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this is the old "consensus" which is actually storage. It will be removed as soon as storage lands (I am currently blocked on the storage interface which is why I did consensus first, otherwise storage was going to be first).
compute/src/worker.rs
Outdated
None | ||
}; | ||
|
||
#[cfg(not(feature = "no_diffs"))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is doing something weird. needs a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is old code, just copied from the previous worker. Will be removed with new storage.
/// Create new contract worker. | ||
pub fn new( | ||
config: WorkerConfiguration, | ||
grpc_environment: Arc<grpcio::Environment>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an awkward interface: we should give it an instantiated service at the same level as consensus_frontend below, rather than having the worker build its own grpc to consensus. Won't there be multiple nodes in the consensus committee eventually that the service should be able to fail over to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is old code and will be removed when we have storage, see my comments above.
9640c09
to
9a637f0
Compare
@willscott I've changed how the consensus frontend and worker interact, making the consensus frontend responsible for batching which makes much more sense. The interaction is now as in the following figure: I also added TODOs around things that should be removed once we switch to use the new storage backend. |
9a637f0
to
d90f085
Compare
d90f085
to
1319c30
Compare
See #163
See #40