Skip to content

Commit bcab07a

Browse files
drskalmandavxyLederstrumpfacatangiu
authored
Beefy client generic on aduthority Id (#1816)
Revived version of paritytech/substrate#13311 . Except Signature is not generic and is dictated by AuthorityId. --------- Co-authored-by: Davide Galassi <[email protected]> Co-authored-by: Robert Hambrock <[email protected]> Co-authored-by: Adrian Catangiu <[email protected]>
1 parent 4ab078d commit bcab07a

File tree

27 files changed

+660
-444
lines changed

27 files changed

+660
-444
lines changed

Cargo.lock

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

polkadot/node/service/src/lib.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ use telemetry::TelemetryWorker;
8888
#[cfg(feature = "full-node")]
8989
use telemetry::{Telemetry, TelemetryWorkerHandle};
9090

91+
use beefy_primitives::ecdsa_crypto;
9192
pub use chain_spec::{GenericChainSpec, RococoChainSpec, WestendChainSpec};
9293
pub use consensus_common::{Proposal, SelectChain};
9394
use frame_benchmarking_cli::SUBSTRATE_REFERENCE_HARDWARE;
@@ -394,8 +395,8 @@ type FullSelectChain = relay_chain_selection::SelectRelayChain<FullBackend>;
394395
type FullGrandpaBlockImport<ChainSelection = FullSelectChain> =
395396
grandpa::GrandpaBlockImport<FullBackend, Block, FullClient, ChainSelection>;
396397
#[cfg(feature = "full-node")]
397-
type FullBeefyBlockImport<InnerBlockImport> =
398-
beefy::import::BeefyBlockImport<Block, FullBackend, FullClient, InnerBlockImport>;
398+
type FullBeefyBlockImport<InnerBlockImport, AuthorityId> =
399+
beefy::import::BeefyBlockImport<Block, FullBackend, FullClient, InnerBlockImport, AuthorityId>;
399400

400401
#[cfg(feature = "full-node")]
401402
struct Basics {
@@ -486,11 +487,14 @@ fn new_partial<ChainSelection>(
486487
babe::BabeBlockImport<
487488
Block,
488489
FullClient,
489-
FullBeefyBlockImport<FullGrandpaBlockImport<ChainSelection>>,
490+
FullBeefyBlockImport<
491+
FullGrandpaBlockImport<ChainSelection>,
492+
ecdsa_crypto::AuthorityId,
493+
>,
490494
>,
491495
grandpa::LinkHalf<Block, FullClient, ChainSelection>,
492496
babe::BabeLink<Block>,
493-
beefy::BeefyVoterLinks<Block>,
497+
beefy::BeefyVoterLinks<Block, ecdsa_crypto::AuthorityId>,
494498
),
495499
grandpa::SharedVoterState,
496500
sp_consensus_babe::SlotDuration,
@@ -601,7 +605,7 @@ where
601605
subscription_executor: subscription_executor.clone(),
602606
finality_provider: finality_proof_provider.clone(),
603607
},
604-
beefy: polkadot_rpc::BeefyDeps {
608+
beefy: polkadot_rpc::BeefyDeps::<ecdsa_crypto::AuthorityId> {
605609
beefy_finality_proof_stream: beefy_rpc_links.from_voter_justif_stream.clone(),
606610
beefy_best_block_stream: beefy_rpc_links.from_voter_best_beefy_stream.clone(),
607611
subscription_executor,
@@ -1293,7 +1297,9 @@ pub fn new_full<
12931297
is_authority: role.is_authority(),
12941298
};
12951299

1296-
let gadget = beefy::start_beefy_gadget::<_, _, _, _, _, _, _>(beefy_params);
1300+
let gadget = beefy::start_beefy_gadget::<_, _, _, _, _, _, _, ecdsa_crypto::AuthorityId>(
1301+
beefy_params,
1302+
);
12971303

12981304
// BEEFY is part of consensus, if it fails we'll bring the node down with it to make sure it
12991305
// is noticed.

polkadot/rpc/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ sp-blockchain = { path = "../../substrate/primitives/blockchain" }
1717
sp-keystore = { path = "../../substrate/primitives/keystore" }
1818
sp-runtime = { path = "../../substrate/primitives/runtime" }
1919
sp-api = { path = "../../substrate/primitives/api" }
20+
sp-application-crypto = { path = "../../substrate/primitives/application-crypto" }
2021
sp-consensus = { path = "../../substrate/primitives/consensus/common" }
2122
sp-consensus-babe = { path = "../../substrate/primitives/consensus/babe" }
23+
sp-consensus-beefy = { path = "../../substrate/primitives/consensus/beefy" }
2224
sc-chain-spec = { path = "../../substrate/client/chain-spec" }
2325
sc-rpc = { path = "../../substrate/client/rpc" }
2426
sc-rpc-spec-v2 = { path = "../../substrate/client/rpc-spec-v2" }

polkadot/rpc/src/lib.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ use sc_consensus_beefy::communication::notification::{
2929
use sc_consensus_grandpa::FinalityProofProvider;
3030
pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor};
3131
use sp_api::ProvideRuntimeApi;
32+
use sp_application_crypto::RuntimeAppPublic;
3233
use sp_block_builder::BlockBuilder;
3334
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
3435
use sp_consensus::SelectChain;
3536
use sp_consensus_babe::BabeApi;
37+
use sp_consensus_beefy::AuthorityIdBound;
3638
use sp_keystore::KeystorePtr;
3739
use txpool_api::TransactionPool;
3840

@@ -62,17 +64,17 @@ pub struct GrandpaDeps<B> {
6264
}
6365

6466
/// Dependencies for BEEFY
65-
pub struct BeefyDeps {
67+
pub struct BeefyDeps<AuthorityId: AuthorityIdBound> {
6668
/// Receives notifications about finality proof events from BEEFY.
67-
pub beefy_finality_proof_stream: BeefyVersionedFinalityProofStream<Block>,
69+
pub beefy_finality_proof_stream: BeefyVersionedFinalityProofStream<Block, AuthorityId>,
6870
/// Receives notifications about best block events from BEEFY.
6971
pub beefy_best_block_stream: BeefyBestBlockStream<Block>,
7072
/// Executor to drive the subscription manager in the BEEFY RPC handler.
7173
pub subscription_executor: sc_rpc::SubscriptionTaskExecutor,
7274
}
7375

7476
/// Full client dependencies
75-
pub struct FullDeps<C, P, SC, B> {
77+
pub struct FullDeps<C, P, SC, B, AuthorityId: AuthorityIdBound> {
7678
/// The client instance to use.
7779
pub client: Arc<C>,
7880
/// Transaction pool instance.
@@ -88,14 +90,14 @@ pub struct FullDeps<C, P, SC, B> {
8890
/// GRANDPA specific dependencies.
8991
pub grandpa: GrandpaDeps<B>,
9092
/// BEEFY specific dependencies.
91-
pub beefy: BeefyDeps,
93+
pub beefy: BeefyDeps<AuthorityId>,
9294
/// Backend used by the node.
9395
pub backend: Arc<B>,
9496
}
9597

9698
/// Instantiate all RPC extensions.
97-
pub fn create_full<C, P, SC, B>(
98-
FullDeps { client, pool, select_chain, chain_spec, deny_unsafe, babe, grandpa, beefy, backend } : FullDeps<C, P, SC, B>,
99+
pub fn create_full<C, P, SC, B, AuthorityId>(
100+
FullDeps { client, pool, select_chain, chain_spec, deny_unsafe, babe, grandpa, beefy, backend } : FullDeps<C, P, SC, B, AuthorityId>,
99101
) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
100102
where
101103
C: ProvideRuntimeApi<Block>
@@ -114,6 +116,8 @@ where
114116
SC: SelectChain<Block> + 'static,
115117
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
116118
B::State: sc_client_api::StateBackend<sp_runtime::traits::HashingFor<Block>>,
119+
AuthorityId: AuthorityIdBound,
120+
<AuthorityId as RuntimeAppPublic>::Signature: Send + Sync,
117121
{
118122
use frame_rpc_system::{System, SystemApiServer};
119123
use mmr_rpc::{Mmr, MmrApiServer};
@@ -171,7 +175,7 @@ where
171175
)?;
172176

173177
io.merge(
174-
Beefy::<Block>::new(
178+
Beefy::<Block, AuthorityId>::new(
175179
beefy.beefy_finality_proof_stream,
176180
beefy.beefy_best_block_stream,
177181
beefy.subscription_executor,

substrate/bin/node/cli/src/service.rs

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@
2020

2121
//! Service implementation. Specialized wrapper over substrate service.
2222
23-
use polkadot_sdk::{sc_consensus_beefy as beefy, sc_consensus_grandpa as grandpa, *};
23+
use polkadot_sdk::{
24+
sc_consensus_beefy as beefy, sc_consensus_grandpa as grandpa,
25+
sp_consensus_beefy as beefy_primitives, *,
26+
};
2427

2528
use crate::Cli;
2629
use codec::Encode;
@@ -67,8 +70,13 @@ type FullBackend = sc_service::TFullBackend<Block>;
6770
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;
6871
type FullGrandpaBlockImport =
6972
grandpa::GrandpaBlockImport<FullBackend, Block, FullClient, FullSelectChain>;
70-
type FullBeefyBlockImport<InnerBlockImport> =
71-
beefy::import::BeefyBlockImport<Block, FullBackend, FullClient, InnerBlockImport>;
73+
type FullBeefyBlockImport<InnerBlockImport> = beefy::import::BeefyBlockImport<
74+
Block,
75+
FullBackend,
76+
FullClient,
77+
InnerBlockImport,
78+
beefy_primitives::ecdsa_crypto::AuthorityId,
79+
>;
7280

7381
/// The transaction pool type definition.
7482
pub type TransactionPool = sc_transaction_pool::FullPool<Block, FullClient>;
@@ -180,7 +188,7 @@ pub fn new_partial(
180188
>,
181189
grandpa::LinkHalf<Block, FullClient, FullSelectChain>,
182190
sc_consensus_babe::BabeLink<Block>,
183-
beefy::BeefyVoterLinks<Block>,
191+
beefy::BeefyVoterLinks<Block, beefy_primitives::ecdsa_crypto::AuthorityId>,
184192
),
185193
grandpa::SharedVoterState,
186194
Option<Telemetry>,
@@ -328,7 +336,7 @@ pub fn new_partial(
328336
subscription_executor: subscription_executor.clone(),
329337
finality_provider: finality_proof_provider.clone(),
330338
},
331-
beefy: node_rpc::BeefyDeps {
339+
beefy: node_rpc::BeefyDeps::<beefy_primitives::ecdsa_crypto::AuthorityId> {
332340
beefy_finality_proof_stream: beefy_rpc_links
333341
.from_voter_justif_stream
334342
.clone(),
@@ -683,7 +691,7 @@ pub fn new_full_base<N: NetworkBackend<Block, <Block as BlockT>::Hash>>(
683691
is_authority: role.is_authority(),
684692
};
685693

686-
let beefy_gadget = beefy::start_beefy_gadget::<_, _, _, _, _, _, _>(beefy_params);
694+
let beefy_gadget = beefy::start_beefy_gadget::<_, _, _, _, _, _, _, _>(beefy_params);
687695
// BEEFY is part of consensus, if it fails we'll bring the node down with it to make sure it
688696
// is noticed.
689697
task_manager

substrate/bin/node/rpc/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ sc-consensus-babe = { path = "../../../client/consensus/babe" }
2626
sc-consensus-babe-rpc = { path = "../../../client/consensus/babe/rpc" }
2727
sc-consensus-beefy = { path = "../../../client/consensus/beefy" }
2828
sc-consensus-beefy-rpc = { path = "../../../client/consensus/beefy/rpc" }
29+
sp-consensus-beefy = { path = "../../../primitives/consensus/beefy" }
2930
sc-consensus-grandpa = { path = "../../../client/consensus/grandpa" }
3031
sc-consensus-grandpa-rpc = { path = "../../../client/consensus/grandpa/rpc" }
3132
sc-mixnet = { path = "../../../client/mixnet" }
@@ -41,6 +42,7 @@ sp-consensus = { path = "../../../primitives/consensus/common" }
4142
sp-consensus-babe = { path = "../../../primitives/consensus/babe" }
4243
sp-keystore = { path = "../../../primitives/keystore" }
4344
sp-runtime = { path = "../../../primitives/runtime" }
45+
sp-application-crypto = { path = "../../../primitives/application-crypto" }
4446
sp-statement-store = { path = "../../../primitives/statement-store" }
4547
substrate-frame-rpc-system = { path = "../../../utils/frame/rpc/system" }
4648
substrate-state-trie-migration-rpc = { path = "../../../utils/frame/rpc/state-trie-migration-rpc" }

substrate/bin/node/rpc/src/lib.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ pub use sc_rpc::SubscriptionTaskExecutor;
4747
pub use sc_rpc_api::DenyUnsafe;
4848
use sc_transaction_pool_api::TransactionPool;
4949
use sp_api::ProvideRuntimeApi;
50+
use sp_application_crypto::RuntimeAppPublic;
5051
use sp_block_builder::BlockBuilder;
5152
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
5253
use sp_consensus::SelectChain;
5354
use sp_consensus_babe::BabeApi;
55+
use sp_consensus_beefy::AuthorityIdBound;
5456
use sp_keystore::KeystorePtr;
5557

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

7880
/// Dependencies for BEEFY
79-
pub struct BeefyDeps {
81+
pub struct BeefyDeps<AuthorityId: AuthorityIdBound> {
8082
/// Receives notifications about finality proof events from BEEFY.
81-
pub beefy_finality_proof_stream: BeefyVersionedFinalityProofStream<Block>,
83+
pub beefy_finality_proof_stream: BeefyVersionedFinalityProofStream<Block, AuthorityId>,
8284
/// Receives notifications about best block events from BEEFY.
8385
pub beefy_best_block_stream: BeefyBestBlockStream<Block>,
8486
/// Executor to drive the subscription manager in the BEEFY RPC handler.
8587
pub subscription_executor: SubscriptionTaskExecutor,
8688
}
8789

8890
/// Full client dependencies.
89-
pub struct FullDeps<C, P, SC, B> {
91+
pub struct FullDeps<C, P, SC, B, AuthorityId: AuthorityIdBound> {
9092
/// The client instance to use.
9193
pub client: Arc<C>,
9294
/// Transaction pool instance.
@@ -102,7 +104,7 @@ pub struct FullDeps<C, P, SC, B> {
102104
/// GRANDPA specific dependencies.
103105
pub grandpa: GrandpaDeps<B>,
104106
/// BEEFY specific dependencies.
105-
pub beefy: BeefyDeps,
107+
pub beefy: BeefyDeps<AuthorityId>,
106108
/// Shared statement store reference.
107109
pub statement_store: Arc<dyn sp_statement_store::StatementStore>,
108110
/// The backend used by the node.
@@ -112,7 +114,7 @@ pub struct FullDeps<C, P, SC, B> {
112114
}
113115

114116
/// Instantiate all Full RPC extensions.
115-
pub fn create_full<C, P, SC, B>(
117+
pub fn create_full<C, P, SC, B, AuthorityId>(
116118
FullDeps {
117119
client,
118120
pool,
@@ -125,7 +127,7 @@ pub fn create_full<C, P, SC, B>(
125127
statement_store,
126128
backend,
127129
mixnet_api,
128-
}: FullDeps<C, P, SC, B>,
130+
}: FullDeps<C, P, SC, B, AuthorityId>,
129131
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
130132
where
131133
C: ProvideRuntimeApi<Block>
@@ -145,6 +147,8 @@ where
145147
SC: SelectChain<Block> + 'static,
146148
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
147149
B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashingFor<Block>>,
150+
AuthorityId: AuthorityIdBound,
151+
<AuthorityId as RuntimeAppPublic>::Signature: Send + Sync,
148152
{
149153
use mmr_rpc::{Mmr, MmrApiServer};
150154
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
@@ -223,7 +227,7 @@ where
223227
}
224228

225229
io.merge(
226-
Beefy::<Block>::new(
230+
Beefy::<Block, AuthorityId>::new(
227231
beefy.beefy_finality_proof_stream,
228232
beefy.beefy_best_block_stream,
229233
beefy.subscription_executor,

substrate/client/consensus/beefy/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ sp-keystore = { path = "../../../primitives/keystore" }
4242
sp-runtime = { path = "../../../primitives/runtime" }
4343
tokio = "1.37"
4444

45-
4645
[dev-dependencies]
4746
serde = { workspace = true, default-features = true }
4847
tempfile = "3.1.0"

substrate/client/consensus/beefy/rpc/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ sp-consensus-beefy = { path = "../../../../primitives/consensus/beefy" }
2424
sc-rpc = { path = "../../../rpc" }
2525
sp-core = { path = "../../../../primitives/core" }
2626
sp-runtime = { path = "../../../../primitives/runtime" }
27+
sp-application-crypto = { path = "../../../../primitives/application-crypto" }
2728

2829
[dev-dependencies]
2930
serde_json = { workspace = true, default-features = true }

0 commit comments

Comments
 (0)