Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Consensus Engines Implementation: Aura #911

Merged
merged 57 commits into from
Oct 27, 2018
Merged

Consensus Engines Implementation: Aura #911

merged 57 commits into from
Oct 27, 2018

Conversation

gnunicorn
Copy link
Contributor

@gnunicorn gnunicorn commented Oct 16, 2018

This PR attempts to (re-)implement the pluggable consensus engine upon #883: Aura

Updated scope, Oct 25th, 2018:

  • Rhododendron (still disabled)
    • re-activate rhodendron, integrate it into the new network message infrastructure
    • let tests pass again
    • update RHD to use new import_block-Infrastructure
    • move node_consensus into substrate-consensus-rhd
  • Aura
    • General infrastructure of crate
    • implement as default consensus engine for node
    • implement aura block proposing and verification (without finalization)
    • add tests for network-wide handling
  • fix CI

And for later, following this

  • generalize consensus setup for node

  • move consensus engine out of ImportQueue setup

  • generalize consensus infrastructure over multiple engines

    • threading? generic handler to control engine from cli?
  • 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 into consensus-common (unclear whether possible)

  • re-activate RHD as a possible node consensus-algo

  • allow configuration of RHD/Aura via yaml for node

@gnunicorn gnunicorn added the A3-in_progress Pull request is in progress. No review needed at this stage. label Oct 16, 2018
@gnunicorn gnunicorn force-pushed the rh-aura branch 2 times, most recently from 990f378 to 733e826 Compare October 17, 2018 16:18

error_chain! {
links {
Consenensus(consensus::Error, consensus::ErrorKind);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo :)

let environ = Arc::new(DummyFactory(client.clone()));
import_notifications.push(
client.import_notification_stream()
.take_while(|n| Ok(n.header.number() < &10))
Copy link
Contributor

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

@gnunicorn gnunicorn force-pushed the rh-aura branch 2 times, most recently from 43943d7 to cad30e8 Compare October 19, 2018 15:21
rphmeier and others added 10 commits October 19, 2018 18:25
@gnunicorn gnunicorn requested review from arkpar and pepyakin October 25, 2018 15:31
@rphmeier rphmeier mentioned this pull request Oct 25, 2018
5 tasks
core/consensus/rhd/src/error.rs Outdated Show resolved Hide resolved
-> Result<Option<(AuthorityId, Vec<AuthorityId>)>, C::Error>
{
let hash = header.hash();
match client.authorities(&BlockId::Hash(hash)) {
Copy link
Member

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?

Ok(dur) => Ok(dur),
Err(_) => {
warn!("Current time {:?} is before unix epoch. Something is wrong.", now);
return Err(())
Copy link
Member

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>.

Copy link
Member

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.

}

/// Get the slot for now.
fn slot_now(slot_duration: u64) -> Result<u64, ()> {
Copy link
Member

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"]
Copy link
Member

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rphmeier !?!

Copy link
Contributor

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

Copy link
Contributor Author

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.

core/service/src/lib.rs Outdated Show resolved Hide resolved
core/state-machine/src/lib.rs Outdated Show resolved Hide resolved
core/test-client/src/client_ext.rs Outdated Show resolved Hide resolved
srml/balances/src/lib.rs Outdated Show resolved Hide resolved
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());
Copy link
Member

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?

Copy link
Contributor Author

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this changed?

Copy link
Contributor Author

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?

Copy link
Member

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?

body,
finalized,
_aux, // TODO: write this to DB also
) = import_block.into_inner();
Copy link
Contributor

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;

Error: ::std::error::Error + Send + 'static + From<::consensus_common::Error>,
{

// wait until the next full slot has started before authoring anything
Copy link
Contributor

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 Show resolved Hide resolved

let idx = slot_num % (authorities.len() as u64);

let expected_author = *authorities.get(idx as usize)
Copy link
Contributor

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?

Copy link
Member

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)

@@ -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};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
use consensus::{BlockOrigin};
use consensus::BlockOrigin;

core/network/src/test/mod.rs Show resolved Hide resolved
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");
Copy link
Contributor

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?

=> 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());
Copy link
Contributor

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")
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@gnunicorn gnunicorn merged commit 101d673 into master Oct 27, 2018
@gnunicorn gnunicorn deleted the rh-aura branch October 27, 2018 13:59
@gnunicorn gnunicorn mentioned this pull request Jan 8, 2019
lamafab pushed a commit to lamafab/substrate that referenced this pull request Jun 16, 2020
helin6 pushed a commit to boolnetwork/substrate that referenced this pull request Jul 25, 2023
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>
helin6 pushed a commit to boolnetwork/substrate that referenced this pull request Jul 25, 2023
* 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>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants