Skip to content

Commit

Permalink
Beefy client generic on aduthority Id (#1816)
Browse files Browse the repository at this point in the history
Revived version of paritytech/substrate#13311 .
Except Signature is not generic and is dictated by AuthorityId.

---------

Co-authored-by: Davide Galassi <davxy@datawok.net>
Co-authored-by: Robert Hambrock <roberthambrock@gmail.com>
Co-authored-by: Adrian Catangiu <adrian@parity.io>
  • Loading branch information
4 people authored May 30, 2024
1 parent 4ab078d commit bcab07a
Show file tree
Hide file tree
Showing 27 changed files with 660 additions and 444 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions polkadot/node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ use telemetry::TelemetryWorker;
#[cfg(feature = "full-node")]
use telemetry::{Telemetry, TelemetryWorkerHandle};

use beefy_primitives::ecdsa_crypto;
pub use chain_spec::{GenericChainSpec, RococoChainSpec, WestendChainSpec};
pub use consensus_common::{Proposal, SelectChain};
use frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE;
Expand Down Expand Up @@ -394,8 +395,8 @@ type FullSelectChain = relay_chain_selection::SelectRelayChain<FullBackend>;
type FullGrandpaBlockImport<ChainSelection = FullSelectChain> =
grandpa::GrandpaBlockImport<FullBackend, Block, FullClient, ChainSelection>;
#[cfg(feature = "full-node")]
type FullBeefyBlockImport<InnerBlockImport> =
beefy::import::BeefyBlockImport<Block, FullBackend, FullClient, InnerBlockImport>;
type FullBeefyBlockImport<InnerBlockImport, AuthorityId> =
beefy::import::BeefyBlockImport<Block, FullBackend, FullClient, InnerBlockImport, AuthorityId>;

#[cfg(feature = "full-node")]
struct Basics {
Expand Down Expand Up @@ -486,11 +487,14 @@ fn new_partial<ChainSelection>(
babe::BabeBlockImport<
Block,
FullClient,
FullBeefyBlockImport<FullGrandpaBlockImport<ChainSelection>>,
FullBeefyBlockImport<
FullGrandpaBlockImport<ChainSelection>,
ecdsa_crypto::AuthorityId,
>,
>,
grandpa::LinkHalf<Block, FullClient, ChainSelection>,
babe::BabeLink<Block>,
beefy::BeefyVoterLinks<Block>,
beefy::BeefyVoterLinks<Block, ecdsa_crypto::AuthorityId>,
),
grandpa::SharedVoterState,
sp_consensus_babe::SlotDuration,
Expand Down Expand Up @@ -601,7 +605,7 @@ where
subscription_executor: subscription_executor.clone(),
finality_provider: finality_proof_provider.clone(),
},
beefy: polkadot_rpc::BeefyDeps {
beefy: polkadot_rpc::BeefyDeps::<ecdsa_crypto::AuthorityId> {
beefy_finality_proof_stream: beefy_rpc_links.from_voter_justif_stream.clone(),
beefy_best_block_stream: beefy_rpc_links.from_voter_best_beefy_stream.clone(),
subscription_executor,
Expand Down Expand Up @@ -1293,7 +1297,9 @@ pub fn new_full<
is_authority: role.is_authority(),
};

let gadget = beefy::start_beefy_gadget::<_, _, _, _, _, _, _>(beefy_params);
let gadget = beefy::start_beefy_gadget::<_, _, _, _, _, _, _, ecdsa_crypto::AuthorityId>(
beefy_params,
);

// BEEFY is part of consensus, if it fails we'll bring the node down with it to make sure it
// is noticed.
Expand Down
2 changes: 2 additions & 0 deletions polkadot/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ sp-blockchain = { path = "../../substrate/primitives/blockchain" }
sp-keystore = { path = "../../substrate/primitives/keystore" }
sp-runtime = { path = "../../substrate/primitives/runtime" }
sp-api = { path = "../../substrate/primitives/api" }
sp-application-crypto = { path = "../../substrate/primitives/application-crypto" }
sp-consensus = { path = "../../substrate/primitives/consensus/common" }
sp-consensus-babe = { path = "../../substrate/primitives/consensus/babe" }
sp-consensus-beefy = { path = "../../substrate/primitives/consensus/beefy" }
sc-chain-spec = { path = "../../substrate/client/chain-spec" }
sc-rpc = { path = "../../substrate/client/rpc" }
sc-rpc-spec-v2 = { path = "../../substrate/client/rpc-spec-v2" }
Expand Down
18 changes: 11 additions & 7 deletions polkadot/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@ use sc_consensus_beefy::communication::notification::{
use sc_consensus_grandpa::FinalityProofProvider;
pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor};
use sp_api::ProvideRuntimeApi;
use sp_application_crypto::RuntimeAppPublic;
use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use sp_consensus::SelectChain;
use sp_consensus_babe::BabeApi;
use sp_consensus_beefy::AuthorityIdBound;
use sp_keystore::KeystorePtr;
use txpool_api::TransactionPool;

Expand Down Expand Up @@ -62,17 +64,17 @@ pub struct GrandpaDeps<B> {
}

/// Dependencies for BEEFY
pub struct BeefyDeps {
pub struct BeefyDeps<AuthorityId: AuthorityIdBound> {
/// Receives notifications about finality proof events from BEEFY.
pub beefy_finality_proof_stream: BeefyVersionedFinalityProofStream<Block>,
pub beefy_finality_proof_stream: BeefyVersionedFinalityProofStream<Block, AuthorityId>,
/// Receives notifications about best block events from BEEFY.
pub beefy_best_block_stream: BeefyBestBlockStream<Block>,
/// Executor to drive the subscription manager in the BEEFY RPC handler.
pub subscription_executor: sc_rpc::SubscriptionTaskExecutor,
}

/// Full client dependencies
pub struct FullDeps<C, P, SC, B> {
pub struct FullDeps<C, P, SC, B, AuthorityId: AuthorityIdBound> {
/// The client instance to use.
pub client: Arc<C>,
/// Transaction pool instance.
Expand All @@ -88,14 +90,14 @@ pub struct FullDeps<C, P, SC, B> {
/// GRANDPA specific dependencies.
pub grandpa: GrandpaDeps<B>,
/// BEEFY specific dependencies.
pub beefy: BeefyDeps,
pub beefy: BeefyDeps<AuthorityId>,
/// Backend used by the node.
pub backend: Arc<B>,
}

/// Instantiate all RPC extensions.
pub fn create_full<C, P, SC, B>(
FullDeps { client, pool, select_chain, chain_spec, deny_unsafe, babe, grandpa, beefy, backend } : FullDeps<C, P, SC, B>,
pub fn create_full<C, P, SC, B, AuthorityId>(
FullDeps { client, pool, select_chain, chain_spec, deny_unsafe, babe, grandpa, beefy, backend } : FullDeps<C, P, SC, B, AuthorityId>,
) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<Block>
Expand All @@ -114,6 +116,8 @@ where
SC: SelectChain<Block> + 'static,
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sc_client_api::StateBackend<sp_runtime::traits::HashingFor<Block>>,
AuthorityId: AuthorityIdBound,
<AuthorityId as RuntimeAppPublic>::Signature: Send + Sync,
{
use frame_rpc_system::{System, SystemApiServer};
use mmr_rpc::{Mmr, MmrApiServer};
Expand Down Expand Up @@ -171,7 +175,7 @@ where
)?;

io.merge(
Beefy::<Block>::new(
Beefy::<Block, AuthorityId>::new(
beefy.beefy_finality_proof_stream,
beefy.beefy_best_block_stream,
beefy.subscription_executor,
Expand Down
20 changes: 14 additions & 6 deletions substrate/bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@

//! Service implementation. Specialized wrapper over substrate service.

use polkadot_sdk::{sc_consensus_beefy as beefy, sc_consensus_grandpa as grandpa, *};
use polkadot_sdk::{
sc_consensus_beefy as beefy, sc_consensus_grandpa as grandpa,
sp_consensus_beefy as beefy_primitives, *,
};

use crate::Cli;
use codec::Encode;
Expand Down Expand Up @@ -67,8 +70,13 @@ type FullBackend = sc_service::TFullBackend<Block>;
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;
type FullGrandpaBlockImport =
grandpa::GrandpaBlockImport<FullBackend, Block, FullClient, FullSelectChain>;
type FullBeefyBlockImport<InnerBlockImport> =
beefy::import::BeefyBlockImport<Block, FullBackend, FullClient, InnerBlockImport>;
type FullBeefyBlockImport<InnerBlockImport> = beefy::import::BeefyBlockImport<
Block,
FullBackend,
FullClient,
InnerBlockImport,
beefy_primitives::ecdsa_crypto::AuthorityId,
>;

/// The transaction pool type definition.
pub type TransactionPool = sc_transaction_pool::FullPool<Block, FullClient>;
Expand Down Expand Up @@ -180,7 +188,7 @@ pub fn new_partial(
>,
grandpa::LinkHalf<Block, FullClient, FullSelectChain>,
sc_consensus_babe::BabeLink<Block>,
beefy::BeefyVoterLinks<Block>,
beefy::BeefyVoterLinks<Block, beefy_primitives::ecdsa_crypto::AuthorityId>,
),
grandpa::SharedVoterState,
Option<Telemetry>,
Expand Down Expand Up @@ -328,7 +336,7 @@ pub fn new_partial(
subscription_executor: subscription_executor.clone(),
finality_provider: finality_proof_provider.clone(),
},
beefy: node_rpc::BeefyDeps {
beefy: node_rpc::BeefyDeps::<beefy_primitives::ecdsa_crypto::AuthorityId> {
beefy_finality_proof_stream: beefy_rpc_links
.from_voter_justif_stream
.clone(),
Expand Down Expand Up @@ -683,7 +691,7 @@ pub fn new_full_base<N: NetworkBackend<Block, <Block as BlockT>::Hash>>(
is_authority: role.is_authority(),
};

let beefy_gadget = beefy::start_beefy_gadget::<_, _, _, _, _, _, _>(beefy_params);
let beefy_gadget = beefy::start_beefy_gadget::<_, _, _, _, _, _, _, _>(beefy_params);
// BEEFY is part of consensus, if it fails we'll bring the node down with it to make sure it
// is noticed.
task_manager
Expand Down
2 changes: 2 additions & 0 deletions substrate/bin/node/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ sc-consensus-babe = { path = "../../../client/consensus/babe" }
sc-consensus-babe-rpc = { path = "../../../client/consensus/babe/rpc" }
sc-consensus-beefy = { path = "../../../client/consensus/beefy" }
sc-consensus-beefy-rpc = { path = "../../../client/consensus/beefy/rpc" }
sp-consensus-beefy = { path = "../../../primitives/consensus/beefy" }
sc-consensus-grandpa = { path = "../../../client/consensus/grandpa" }
sc-consensus-grandpa-rpc = { path = "../../../client/consensus/grandpa/rpc" }
sc-mixnet = { path = "../../../client/mixnet" }
Expand All @@ -41,6 +42,7 @@ sp-consensus = { path = "../../../primitives/consensus/common" }
sp-consensus-babe = { path = "../../../primitives/consensus/babe" }
sp-keystore = { path = "../../../primitives/keystore" }
sp-runtime = { path = "../../../primitives/runtime" }
sp-application-crypto = { path = "../../../primitives/application-crypto" }
sp-statement-store = { path = "../../../primitives/statement-store" }
substrate-frame-rpc-system = { path = "../../../utils/frame/rpc/system" }
substrate-state-trie-migration-rpc = { path = "../../../utils/frame/rpc/state-trie-migration-rpc" }
18 changes: 11 additions & 7 deletions substrate/bin/node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ pub use sc_rpc::SubscriptionTaskExecutor;
pub use sc_rpc_api::DenyUnsafe;
use sc_transaction_pool_api::TransactionPool;
use sp_api::ProvideRuntimeApi;
use sp_application_crypto::RuntimeAppPublic;
use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use sp_consensus::SelectChain;
use sp_consensus_babe::BabeApi;
use sp_consensus_beefy::AuthorityIdBound;
use sp_keystore::KeystorePtr;

/// Extra dependencies for BABE.
Expand All @@ -76,17 +78,17 @@ pub struct GrandpaDeps<B> {
}

/// Dependencies for BEEFY
pub struct BeefyDeps {
pub struct BeefyDeps<AuthorityId: AuthorityIdBound> {
/// Receives notifications about finality proof events from BEEFY.
pub beefy_finality_proof_stream: BeefyVersionedFinalityProofStream<Block>,
pub beefy_finality_proof_stream: BeefyVersionedFinalityProofStream<Block, AuthorityId>,
/// Receives notifications about best block events from BEEFY.
pub beefy_best_block_stream: BeefyBestBlockStream<Block>,
/// Executor to drive the subscription manager in the BEEFY RPC handler.
pub subscription_executor: SubscriptionTaskExecutor,
}

/// Full client dependencies.
pub struct FullDeps<C, P, SC, B> {
pub struct FullDeps<C, P, SC, B, AuthorityId: AuthorityIdBound> {
/// The client instance to use.
pub client: Arc<C>,
/// Transaction pool instance.
Expand All @@ -102,7 +104,7 @@ pub struct FullDeps<C, P, SC, B> {
/// GRANDPA specific dependencies.
pub grandpa: GrandpaDeps<B>,
/// BEEFY specific dependencies.
pub beefy: BeefyDeps,
pub beefy: BeefyDeps<AuthorityId>,
/// Shared statement store reference.
pub statement_store: Arc<dyn sp_statement_store::StatementStore>,
/// The backend used by the node.
Expand All @@ -112,7 +114,7 @@ pub struct FullDeps<C, P, SC, B> {
}

/// Instantiate all Full RPC extensions.
pub fn create_full<C, P, SC, B>(
pub fn create_full<C, P, SC, B, AuthorityId>(
FullDeps {
client,
pool,
Expand All @@ -125,7 +127,7 @@ pub fn create_full<C, P, SC, B>(
statement_store,
backend,
mixnet_api,
}: FullDeps<C, P, SC, B>,
}: FullDeps<C, P, SC, B, AuthorityId>,
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<Block>
Expand All @@ -145,6 +147,8 @@ where
SC: SelectChain<Block> + 'static,
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashingFor<Block>>,
AuthorityId: AuthorityIdBound,
<AuthorityId as RuntimeAppPublic>::Signature: Send + Sync,
{
use mmr_rpc::{Mmr, MmrApiServer};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
Expand Down Expand Up @@ -223,7 +227,7 @@ where
}

io.merge(
Beefy::<Block>::new(
Beefy::<Block, AuthorityId>::new(
beefy.beefy_finality_proof_stream,
beefy.beefy_best_block_stream,
beefy.subscription_executor,
Expand Down
1 change: 0 additions & 1 deletion substrate/client/consensus/beefy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ sp-keystore = { path = "../../../primitives/keystore" }
sp-runtime = { path = "../../../primitives/runtime" }
tokio = "1.37"


[dev-dependencies]
serde = { workspace = true, default-features = true }
tempfile = "3.1.0"
Expand Down
1 change: 1 addition & 0 deletions substrate/client/consensus/beefy/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ sp-consensus-beefy = { path = "../../../../primitives/consensus/beefy" }
sc-rpc = { path = "../../../rpc" }
sp-core = { path = "../../../../primitives/core" }
sp-runtime = { path = "../../../../primitives/runtime" }
sp-application-crypto = { path = "../../../../primitives/application-crypto" }

[dev-dependencies]
serde_json = { workspace = true, default-features = true }
Expand Down
Loading

0 comments on commit bcab07a

Please sign in to comment.