Skip to content

Commit e4e4ee3

Browse files
committed
Integrate BEEFY into PC
1 parent d56de71 commit e4e4ee3

File tree

11 files changed

+569
-13
lines changed

11 files changed

+569
-13
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,10 @@ frame-system-rpc-runtime-api = { default-features = false, git = "https://github
194194
frame-try-runtime = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
195195
pallet-aura = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
196196
pallet-balances = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
197+
pallet-beefy = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
198+
pallet-beefy-mmr = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
197199
pallet-grandpa = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
200+
pallet-mmr = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
198201
pallet-session = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
199202
pallet-sudo = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
200203
pallet-timestamp = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
@@ -209,6 +212,8 @@ sc-client-api = { default-features = false, git = "https://github.com/paritytech
209212
sc-client-db = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
210213
sc-consensus = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
211214
sc-consensus-aura = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
215+
sc-consensus-beefy = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
216+
sc-consensus-beefy-rpc = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
212217
sc-consensus-grandpa = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
213218
sc-consensus-grandpa-rpc = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
214219
sc-executor = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
@@ -229,6 +234,7 @@ sp-block-builder = { default-features = false, git = "https://github.com/parityt
229234
sp-blockchain = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
230235
sp-consensus = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
231236
sp-consensus-aura = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
237+
sp-consensus-beefy = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
232238
sp-consensus-grandpa = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
233239
sp-consensus-slots = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }
234240
sp-core = { default-features = false, git = "https://github.com/paritytech/polkadot-sdk.git", tag = "polkadot-stable2503-2" }

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/rpc.rs

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ use partner_chains_demo_runtime::{
2020
opaque::{Block, SessionKeys},
2121
};
2222
use partner_chains_demo_runtime::{BlockNumber, BlockProducerMetadataType, CrossChainPublic, Hash};
23+
use sc_consensus_beefy::communication::notification::{
24+
BeefyBestBlockStream, BeefyVersionedFinalityProofStream,
25+
};
26+
use sc_consensus_beefy_rpc::Beefy;
2327
use sc_consensus_grandpa::{
2428
FinalityProofProvider, GrandpaJustificationStream, SharedAuthoritySet, SharedVoterState,
2529
};
@@ -31,6 +35,7 @@ use sidechain_domain::mainchain_epoch::MainchainEpochConfig;
3135
use sp_api::ProvideRuntimeApi;
3236
use sp_block_builder::BlockBuilder;
3337
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
38+
use sp_consensus_beefy::AuthorityIdBound;
3439
use sp_session_validator_management_query::SessionValidatorManagementQuery;
3540
use std::sync::Arc;
3641
use time_source::TimeSource;
@@ -49,23 +54,35 @@ pub struct GrandpaDeps<B> {
4954
pub finality_provider: Arc<FinalityProofProvider<B, Block>>,
5055
}
5156

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

6683
/// Instantiate all full RPC extensions.
67-
pub fn create_full<C, P, B, T>(
68-
deps: FullDeps<C, P, B, T>,
84+
pub fn create_full<C, P, B, T, AuthorityId: AuthorityIdBound>(
85+
deps: FullDeps<C, P, B, T, AuthorityId>,
6986
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
7087
where
7188
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)