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

Generalize the Consensus Infrastructure #883

Merged
merged 8 commits into from
Oct 16, 2018
Merged

Conversation

gnunicorn
Copy link
Contributor

@gnunicorn gnunicorn commented Oct 5, 2018

In our efforts to allow pluggable consensus engines in substrate, this PR attempts to generalize consensus messages over the network, blocks and the client.

  • Generalize NetworkMessages for Consensus as an opaque Vec<u8>
  • Generalize Justification as a Consensus-specific opaque Vec<u8>
  • Generalize ConsensusGossip over any consensus internal information
  • Remove all rhododendron-dependencies (and everything bft:*) from core, sr-* and the srml
  • Restructure Import-Procedure as described in Pluggable Consensus: Import Queue #784
  • disable current rhd-code-base; make it all compile

@gnunicorn gnunicorn added the A3-in_progress Pull request is in progress. No review needed at this stage. label Oct 5, 2018
@gavofyork
Copy link
Member

because GRANDPA and AURA have a higher priority at the moment, we might post-pone fixing rhd for later and merge this after the restructure itself finished, breaking consensus for node on master...

tht's fine - bbq birch will be decommissioned as soon as shaft(grandpa)/aura are operational.

@gnunicorn gnunicorn force-pushed the ben-consensus-restructure branch from 404c543 to bfb31c0 Compare October 8, 2018 14:28
@gnunicorn
Copy link
Contributor Author

gnunicorn commented Oct 8, 2018

Updated the comment to reflect the latest design and process decisions, specifically:

  • fix block-import for cli by providing allow substrate/node to provide a specialization to decide on consensus engines
  • drop attempt to fix RHD; instead disable and focus on getting CI pass without it for now

Previously, this also attempted to, but won't be part of this

  • Re-activate rhododendron (substrate-consensus-rhd)*
    • simplify message handling by directly supporting for parity-codec
    • move MisbehaviourCheck into rhd-crate (as it is rhd specific)
    • refactor rhodendron to use new ImportQueue-System
    • re-implement rhd in node
    • ensure rhd-messages are backwards-compatible
  • Move all common consensus into a shared substrate-consensus-common-crate
    • OfflineTracker
    • Generic Consensus Service (from node)

}

#[cfg(any(test, feature = "test-helpers"))]
unsafe impl Send for PassThroughVerifier {}
Copy link
Contributor

Choose a reason for hiding this comment

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

PassThroughVerifier stores only a bool -- are these necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nope. this stems from a previous version, where it stored more than a bool. removed.

@gnunicorn gnunicorn force-pushed the ben-consensus-restructure branch 3 times, most recently from 294d9a1 to 21d394e Compare October 12, 2018 22:47
body: Option<Vec<<Block as BlockT>::Extrinsic>>,
finalized: bool,
import_block: ImportBlock<Block>,
new_authorities: Option<Vec<AuthorityId>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

This value (named new_authorities) is actually cached under parent header Id - previously it meant 'authorities that have justified this block'. So probably rename back to authorities, since it is not necessary the new authorities set? Or the meaning has 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.

@svyatonik the meaning has changed. While you described how it was previously, all actual checks are done within the Verifier now and this only communicates the changes to import: the Block itself and optionally a new Set of Authorities - as changes of authority set will also be consensus engine driven. This is a temporary hack until we have the signaling in place, in which case this wouldn't be passed here anymore but instead a NewAuthorities-Signal will be triggered at import time instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, thanks. Then better to wait for actual Verifier implementation && see if some changes are required here (and in the authorities cache).

core/client/src/client.rs Show resolved Hide resolved
pub header: Block::Header,
/// Justification provided for this block from the outside
pub external_justification: Justification,
/// internal Justification for the block
Copy link
Member

Choose a reason for hiding this comment

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

Nitpick: Capitalize Internal.


/// Sign a BFT message with the given key.
pub fn sign_message<B: Block + Clone>(message: Message<B>, key: &ed25519::Pair, parent_hash: B::Hash) -> LocalizedMessage<B> {
// fn check_justification_signed_message<H>(
Copy link
Member

Choose a reason for hiding this comment

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

Why did you need this code entirely? If you need this code anytime in the future, you can just use git to get it back^^

@gnunicorn gnunicorn requested review from arkpar and pepyakin October 15, 2018 10:21
@gnunicorn gnunicorn changed the title [WIP] Generalize the Consensus Infrastructure Generalize the Consensus Infrastructure Oct 15, 2018
@gnunicorn gnunicorn added A0-please_review Pull request needs code review. and removed A3-in_progress Pull request is in progress. No review needed at this stage. labels Oct 15, 2018
Copy link
Contributor

@pepyakin pepyakin left a comment

Choose a reason for hiding this comment

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

Looks good! a few minor nits.

body: Option<Vec<<Block as BlockT>::Extrinsic>>,
finalized: bool,
import_block: ImportBlock<Block>,
new_authorities: Option<Vec<AuthorityId>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Stray spaces

/// A collection of type to generalise specific components over full / light client.
pub trait Components: service::Components {
/// Demo API.
type Api: 'static + AuthoringApi + Send + Sync;
type Api: 'static + Send + Sync;
Copy link
Contributor

Choose a reason for hiding this comment

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

Double space

sync.on_block_data(&mut ProtocolContext::new(&self.context_data, io), peer, request, response)
};

if let Some((origin, new_blocks)) = new_blocks {
Copy link
Contributor

Choose a reason for hiding this comment

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

Double space

}

} else {
Err("Chain Specification doesn't containg any consensus_engine name".into())
Copy link
Contributor

Choose a reason for hiding this comment

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

containgcontain?

}

} else {
Err("Chain Specification doesn't containg any consensus_engine name".into())
Copy link
Contributor

Choose a reason for hiding this comment

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

containgcontain?

receipt: None,
message_queue: None
};
// import queue handels verification and importing it into the client
Copy link
Contributor

Choose a reason for hiding this comment

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

handelshandles

@@ -71,10 +60,33 @@ pub type ChainSpec = service::ChainSpec<GenesisConfig>;
pub type ComponentClient<C> = Client<<C as Components>::Backend, <C as Components>::Executor, Block>;
pub type NetworkService = network::Service<Block, <Factory as service::ServiceFactory>::NetworkProtocol, Hash>;

/// A verifier that doesn't actually do any checks
pub struct NoneVerifier;
Copy link
Member

Choose a reason for hiding this comment

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

Using () for "null" implementations of traits by convention.

Copy link
Contributor Author

@gnunicorn gnunicorn Oct 16, 2018

Choose a reason for hiding this comment

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

Can't be done here: impl<B: BlockT> Verifier<B> for () can only be done within the crate that defines Verifier, not in node-service but in substrate-network . However we don't want to provide such a bad implementation in substrate-network.

Leaving it as is for now, as this is only temporarily to make the compiler happy and will be replaced in the next chunk of work with an actual Verifier implementation.

Copy link
Member

@gavofyork gavofyork left a comment

Choose a reason for hiding this comment

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

Minor grumble that might be nice/reasonable to address

@gnunicorn gnunicorn force-pushed the ben-consensus-restructure branch 2 times, most recently from 0e77cc7 to dc0826b Compare October 16, 2018 11:27
@gnunicorn gnunicorn merged commit 14ff8f9 into master Oct 16, 2018
@arkpar arkpar deleted the ben-consensus-restructure branch October 18, 2018 20:45
lamafab pushed a commit to lamafab/substrate that referenced this pull request Jun 16, 2020
Co-authored-by: cheme <emericchevalier.pro@gmail.com>
helin6 pushed a commit to boolnetwork/substrate that referenced this pull request Jul 25, 2023
Bumps [regex](https://github.com/rust-lang/regex) from 1.7.1 to 1.7.3.
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](rust-lang/regex@1.7.1...1.7.3)

---
updated-dependencies:
- dependency-name: regex
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

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.

6 participants