-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Consensus Engines Implementation: Aura #911
Conversation
990f378
to
733e826
Compare
core/client/src/error.rs
Outdated
|
||
error_chain! { | ||
links { | ||
Consenensus(consensus::Error, consensus::ErrorKind); |
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.
typo :)
core/consensus/aura/src/lib.rs
Outdated
let environ = Arc::new(DummyFactory(client.clone())); | ||
import_notifications.push( | ||
client.import_notification_stream() | ||
.take_while(|n| Ok(n.header.number() < &10)) |
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.
it may be possible for this test to pass without each node getting the others' blocks. Perhaps we could add another non-authority node to the network
43943d7
to
cad30e8
Compare
- move ImportBlock, BlockOrigin, ImportResult into shared sr-primitives - let Consensus provide and traits again - update consensus traits to latest development - implement traits on client::Client, test_client::TestClient - update RHD to use the new import_block API
core/consensus/aura/src/lib.rs
Outdated
-> Result<Option<(AuthorityId, Vec<AuthorityId>)>, C::Error> | ||
{ | ||
let hash = header.hash(); | ||
match client.authorities(&BlockId::Hash(hash)) { |
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.
Maybe using let authorities = client.authorities(&BlockId::Hash(hash))?;
would be better here?
core/consensus/aura/src/lib.rs
Outdated
Ok(dur) => Ok(dur), | ||
Err(_) => { | ||
warn!("Current time {:?} is before unix epoch. Something is wrong.", now); | ||
return Err(()) |
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.
If the error is just ()
, I would change the return type to an Option<Duration>
.
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.
And the return
can be omitted here.
core/consensus/aura/src/lib.rs
Outdated
} | ||
|
||
/// Get the slot for now. | ||
fn slot_now(slot_duration: u64) -> Result<u64, ()> { |
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.
Same here with the changing the return type to Option<u64>
.
|
||
#![cfg(feature="rhd")] | ||
//! Consensus Basics and common features | ||
#![recursion_limit="128"] |
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.
Could you please add a comment, why we need the increased recursion limit?
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.
@rphmeier !?!
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.
it was there before AFAIK -- but it can go
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.
turns out, the error_chain
definition can blow up otherwise. this is a recommendation from the rust compiler. I'll add a comment.
srml/consensus/src/lib.rs
Outdated
for i in &items { | ||
storage::unhashed::put_raw(&i.0, &i.1); | ||
} | ||
Ok(()) | ||
} | ||
|
||
/// Set the number of pages in the WebAssembly environment's heap. | ||
pub fn set_heap_pages(pages: u64) -> Result { | ||
storage::unhashed::put_raw(well_known_keys::HEAP_PAGES, &pages.encode()); |
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.
If we don't have any result in this function, we do we need to return one here?
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.
Just by looking around, how the other functions work in that file:
pub fn set_code(new: Vec<u8>) -> Result {
storage::unhashed::put_raw(well_known_keys::CODE, &new);
Ok(())
}
/// Set some items of storage.
pub fn set_storage(items: Vec<KeyValue>) -> Result {
for i in &items {
storage::unhashed::put_raw(&i.0, &i.1);
}
Ok(())
}
/// Set the number of pages in the WebAssembly environment's heap.
pub fn set_heap_pages(pages: u64) -> Result {
storage::unhashed::put_raw(well_known_keys::HEAP_PAGES, &pages.encode());
Ok(())
}
I can assume this is the current convention. Not sure, if there a better reason. @gavofyork ?
@@ -150,7 +150,7 @@ where | |||
let heap_pages = state.storage(well_known_keys::HEAP_PAGES) | |||
.map_err(|e| error::ErrorKind::Execution(Box::new(e)))? | |||
.and_then(|v| u64::decode(&mut &v[..])) | |||
.unwrap_or(8) as usize; | |||
.unwrap_or(1024) as usize; |
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 was this changed?
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.
@gavofyork can you say something about this?
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.
8 is way too low to do a chain upgrade. as i understand it, memory is unallocated until used anyway so it shouldn't cause a performance degradation?
core/client/src/client.rs
Outdated
body, | ||
finalized, | ||
_aux, // TODO: write this to DB also | ||
) = import_block.into_inner(); |
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 wonder why this uses into_inner
and not plain destruction, like:
let ImportBlock {
origin,
pre_header,
...
} = import_block;
core/consensus/aura/src/lib.rs
Outdated
Error: ::std::error::Error + Send + 'static + From<::consensus_common::Error>, | ||
{ | ||
|
||
// wait until the next full slot has started before authoring anything |
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 comment looks misplaced, doesn't it?
core/consensus/aura/src/lib.rs
Outdated
|
||
let idx = slot_num % (authorities.len() as u64); | ||
|
||
let expected_author = *authorities.get(idx as usize) |
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 do we check
assert!(idx <= usize::max_value() as u64,
"It is impossible to have a vector with length beyond the address space; qed");
in the slot_author
but not here?
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 one extra indent level)
core/network/src/sync.rs
Outdated
@@ -18,7 +18,8 @@ use std::collections::HashMap; | |||
use std::sync::Arc; | |||
use protocol::Context; | |||
use network_libp2p::{Severity, NodeIndex}; | |||
use client::{BlockStatus, BlockOrigin, ClientInfo}; | |||
use client::{BlockStatus, ClientInfo}; | |||
use consensus::{BlockOrigin}; |
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.
use consensus::{BlockOrigin}; | |
use consensus::BlockOrigin; |
core/consensus/rhd/src/lib.rs
Outdated
signature: Some((node_runtime::RawAddress::Id(local_id), signature, payload.0, Era::immortal())), | ||
function: payload.1, | ||
}; | ||
let uxt: <<C as AuthoringApi>::Block as BlockT>::Extrinsic = Decode::decode(&mut extrinsic.encode().as_slice()).expect("Encoded extrinsic is valid"); |
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.
It looks like this code is wider than 120 maximum. Can we wrap this code?
core/consensus/rhd/src/lib.rs
Outdated
=> MisbehaviorKind::BftDoubleCommit(round as u32, (h1.into(), s1.signature), (h2.into(), s2.signature)), | ||
} | ||
}; | ||
let payload = (next_index, Call::Consensus(ConsensusCall::report_misbehavior(report)), Era::immortal(), self.client.genesis_hash()); |
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.
It looks like this code is wider than 120 maximum. Can we wrap this code?
|
||
fn current_timestamp() -> u64 { | ||
time::SystemTime::now().duration_since(time::UNIX_EPOCH) | ||
.expect("now always later than unix epoch; qed") |
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 do we claim here that now
is always later than UNIX epoch but in aura code we try to handle it?
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 has been moved here from the old code base. I am not actually sure this or the other approach is really that different, after I changed the unwrap_or
to also fail now.
Bumps [h2](https://github.com/hyperium/h2) from 0.3.16 to 0.3.17. - [Release notes](https://github.com/hyperium/h2/releases) - [Changelog](https://github.com/hyperium/h2/blob/master/CHANGELOG.md) - [Commits](hyperium/h2@v0.3.16...v0.3.17) --- updated-dependencies: - dependency-name: h2 dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* add partial_fee estimation to submittable extrinsic * add integration test * make functions immune to doctest * add doc test * inline encoded_with_len, fix tests * fix test fmt * remove unused imoort * Bump h2 from 0.3.16 to 0.3.17 (paritytech#911) Bumps [h2](https://github.com/hyperium/h2) from 0.3.16 to 0.3.17. - [Release notes](https://github.com/hyperium/h2/releases) - [Changelog](https://github.com/hyperium/h2/blob/master/CHANGELOG.md) - [Commits](hyperium/h2@v0.3.16...v0.3.17) --- updated-dependencies: - dependency-name: h2 dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * call_raw returns Res: Decode * remove import * remove struct --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This PR attempts to (re-)implement the pluggable consensus engine upon #883: Aura
Updated scope, Oct 25th, 2018:
import_block
-Infrastructurenode_consensus
intosubstrate-consensus-rhd
node
And for later, following this
generalize consensus setup for node
move consensus engine out of
ImportQueue
setupgeneralize consensus infrastructure over multiple engines
move specific type implementations from node-service
clean up
struct Justification
(external_justification
->justification
;post_runtime_digest
->post_digest
)re-add
Proposer::evaluate
move
ImportQueue
intoconsensus-common
(unclear whether possible)re-activate RHD as a possible node consensus-algo
allow configuration of RHD/Aura via yaml for node