Skip to content

Commit e4ff90d

Browse files
committed
Wire BEEFY into demo runtime/node
1 parent 84752d4 commit e4ff90d

File tree

12 files changed

+540
-87
lines changed

12 files changed

+540
-87
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@ pallet-scheduler = { default-features = false,
262262
pallet-preimage = { default-features = false, git = "https://github.com/input-output-hk/polkadot-sdk.git", rev = "01884a99a9507fa1f6e893e602c85e172825cea5" }
263263
pallet-parameters = { default-features = false, git = "https://github.com/input-output-hk/polkadot-sdk.git", rev = "01884a99a9507fa1f6e893e602c85e172825cea5" }
264264
sp-consensus-beefy = { default-features = false, git = "https://github.com/input-output-hk/polkadot-sdk.git", rev = "01884a99a9507fa1f6e893e602c85e172825cea5" }
265+
sc-consensus-beefy = { default-features = false, git = "https://github.com/input-output-hk/polkadot-sdk.git", rev = "01884a99a9507fa1f6e893e602c85e172825cea5" }
266+
sc-consensus-beefy-rpc = { default-features = false, git = "https://github.com/input-output-hk/polkadot-sdk.git", rev = "01884a99a9507fa1f6e893e602c85e172825cea5" }
267+
pallet-beefy = { default-features = false, git = "https://github.com/input-output-hk/polkadot-sdk.git", rev = "01884a99a9507fa1f6e893e602c85e172825cea5" }
268+
pallet-beefy-mmr = { default-features = false, git = "https://github.com/input-output-hk/polkadot-sdk.git", rev = "01884a99a9507fa1f6e893e602c85e172825cea5" }
269+
pallet-mmr = { default-features = false, git = "https://github.com/input-output-hk/polkadot-sdk.git", rev = "01884a99a9507fa1f6e893e602c85e172825cea5" }
265270

266271
raw-scripts = { git = "https://github.com/input-output-hk/partner-chains-smart-contracts.git", rev = "v8.2.0" }
267272
# local dependencies

demo/node/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ sp-consensus-aura = { workspace = true }
3838
sp-partner-chains-consensus-aura = { workspace = true }
3939
sp-consensus = { workspace = true }
4040
sc-consensus = { workspace = true }
41+
sc-consensus-beefy = { workspace = true }
42+
sc-consensus-beefy-rpc = { workspace = true }
43+
sp-consensus-beefy = { workspace = true }
4144
sc-consensus-grandpa = { workspace = true }
4245
sc-consensus-grandpa-rpc = { workspace = true }
4346
sp-consensus-grandpa = { workspace = true }

demo/node/src/chain_spec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub fn pc_create_chain_spec(config: &CreateChainSpecConfig<SessionKeys>) -> serd
4343
system: partner_chains_demo_runtime::SystemConfig::default(),
4444
balances: partner_chains_demo_runtime::BalancesConfig::default(),
4545
aura: partner_chains_demo_runtime::AuraConfig::default(),
46+
beefy: partner_chains_demo_runtime::BeefyConfig::default(),
4647
grandpa: partner_chains_demo_runtime::GrandpaConfig::default(),
4748
sudo: partner_chains_demo_runtime::SudoConfig::default(),
4849
transaction_payment: Default::default(),

demo/node/src/rpc.rs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ use partner_chains_demo_runtime::{
1717
opaque::{Block, SessionKeys},
1818
};
1919
use partner_chains_demo_runtime::{BlockNumber, BlockProducerMetadataType, CrossChainPublic, Hash};
20+
use sc_consensus_beefy::communication::notification::{
21+
BeefyBestBlockStream, BeefyVersionedFinalityProofStream,
22+
};
23+
use sc_consensus_beefy_rpc::Beefy;
2024
use sc_consensus_grandpa::{
2125
FinalityProofProvider, GrandpaJustificationStream, SharedAuthoritySet, SharedVoterState,
2226
};
@@ -28,6 +32,7 @@ use sidechain_domain::mainchain_epoch::MainchainEpochConfig;
2832
use sp_api::{CallApiAt, ProvideRuntimeApi};
2933
use sp_block_builder::BlockBuilder;
3034
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
35+
use sp_consensus_beefy::AuthorityIdBound;
3136
use sp_session_validator_management_query::SessionValidatorManagementQuery;
3237
use sp_sidechain::GetEpochDurationApi;
3338
use std::sync::Arc;
@@ -47,23 +52,35 @@ pub struct GrandpaDeps<B> {
4752
pub finality_provider: Arc<FinalityProofProvider<B, Block>>,
4853
}
4954

55+
/// Dependencies for BEEFY
56+
pub struct BeefyDeps<AuthorityId: AuthorityIdBound> {
57+
/// Receives notifications about finality proof events from BEEFY.
58+
pub beefy_finality_proof_stream: BeefyVersionedFinalityProofStream<Block, AuthorityId>,
59+
/// Receives notifications about best block events from BEEFY.
60+
pub beefy_best_block_stream: BeefyBestBlockStream<Block>,
61+
/// Executor to drive the subscription manager in the BEEFY RPC handler.
62+
pub subscription_executor: sc_rpc::SubscriptionTaskExecutor,
63+
}
64+
5065
/// Full client dependencies.
51-
pub struct FullDeps<C, P, B, T> {
66+
pub struct FullDeps<C, P, B, T, AuthorityId: AuthorityIdBound> {
5267
/// The client instance to use.
5368
pub client: Arc<C>,
5469
/// Transaction pool instance.
5570
pub pool: Arc<P>,
5671
/// GRANDPA specific dependencies.
5772
pub grandpa: GrandpaDeps<B>,
73+
/// BEEFY specific dependencies.
74+
pub beefy: BeefyDeps<AuthorityId>,
5875
/// Data sources.
5976
pub data_sources: DataSources,
6077
/// Source of system time
6178
pub time_source: Arc<T>,
6279
}
6380

6481
/// Instantiate all full RPC extensions.
65-
pub fn create_full<C, P, B, T>(
66-
deps: FullDeps<C, P, B, T>,
82+
pub fn create_full<C, P, B, T, AuthorityId: AuthorityIdBound>(
83+
deps: FullDeps<C, P, B, T, AuthorityId>,
6784
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
6885
where
6986
C: ProvideRuntimeApi<Block>,
@@ -93,10 +110,11 @@ where
93110
T: TimeSource + Send + Sync + 'static,
94111
{
95112
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
113+
use sc_consensus_beefy_rpc::BeefyApiServer;
96114
use substrate_frame_rpc_system::{System, SystemApiServer};
97115

98116
let mut module = RpcModule::new(());
99-
let FullDeps { client, pool, grandpa, data_sources, time_source } = deps;
117+
let FullDeps { client, pool, grandpa, beefy, data_sources, time_source } = deps;
100118

101119
module.merge(System::new(client.clone(), pool.clone()).into_rpc())?;
102120
module.merge(TransactionPayment::new(client.clone()).into_rpc())?;
@@ -137,6 +155,15 @@ where
137155
.into_rpc(),
138156
)?;
139157

158+
module.merge(
159+
Beefy::<Block, AuthorityId>::new(
160+
beefy.beefy_finality_proof_stream,
161+
beefy.beefy_best_block_stream,
162+
beefy.subscription_executor,
163+
)?
164+
.into_rpc(),
165+
)?;
166+
140167
// Extend this RPC with a custom API by using the following syntax.
141168
// `YourRpcStruct` should have a reference to a client, which is needed
142169
// to call into the runtime.

0 commit comments

Comments
 (0)