Skip to content

Commit 03a8b16

Browse files
committed
Add Beefy, Beefy-MMR, MMR and StatementStore pallets.
1 parent 3bc74ac commit 03a8b16

File tree

28 files changed

+1487
-418
lines changed

28 files changed

+1487
-418
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 53 additions & 10 deletions
Large diffs are not rendered by default.

node-rpc/Cargo.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,15 @@ pallet-group-rpc = { workspace = true, default-features = false }
1717
pallet-protocol-fee-rpc = { workspace = true, default-features = false }
1818
node-rpc = { workspace = true, default-features = false }
1919

20+
mmr-gadget = { workspace = true }
21+
mmr-rpc = { workspace = true }
22+
2023
sc-chain-spec = { workspace = true }
2124
sc-client-api = { workspace = true }
2225
sc-consensus-babe = { workspace = true }
2326
sc-consensus-babe-rpc = { workspace = true }
27+
sc-consensus-beefy = { workspace = true }
28+
sc-consensus-beefy-rpc = { workspace = true }
2429
sc-consensus-grandpa = { workspace = true }
2530
sc-consensus-grandpa-rpc = { workspace = true }
2631
sc-rpc = { workspace = true }
@@ -29,11 +34,14 @@ sc-rpc-spec-v2 = { workspace = true }
2934
sc-sync-state-rpc = { workspace = true }
3035
sc-transaction-pool-api = { workspace = true }
3136
sp-api = { workspace = true, default-features = false }
37+
sp-application-crypto = { workspace = true, default-features = false }
3238
sp-block-builder = { workspace = true, default-features = false }
3339
sp-blockchain = { workspace = true, default-features = false }
3440
sp-consensus = { workspace = true, default-features = false }
3541
sp-consensus-babe = { workspace = true, default-features = false }
42+
sp-consensus-beefy = { workspace = true }
3643
sp-keystore = { workspace = true, default-features = false }
44+
sp-statement-store = { workspace = true, default-features = false }
3745
sp-runtime = { workspace = true, default-features = false }
3846
substrate-frame-rpc-system = { workspace = true, default-features = false }
3947

node-rpc/src/lib.rs

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,22 @@ use jsonrpsee::RpcModule;
3636
use polymesh_primitives::{AccountId, Block, BlockNumber, Hash, IdentityId, Moment, Nonce, Ticker};
3737
use sc_client_api::AuxStore;
3838
use sc_consensus_babe::BabeWorkerHandle;
39-
use sc_consensus_grandpa::{FinalityProofProvider, GrandpaJustificationStream};
40-
use sc_consensus_grandpa::{SharedAuthoritySet, SharedVoterState};
41-
use sc_rpc::SubscriptionTaskExecutor;
39+
use sc_consensus_beefy::communication::notification::{
40+
BeefyBestBlockStream, BeefyVersionedFinalityProofStream,
41+
};
42+
use sc_consensus_grandpa::{
43+
FinalityProofProvider, GrandpaJustificationStream, SharedAuthoritySet, SharedVoterState,
44+
};
45+
pub use sc_rpc::SubscriptionTaskExecutor;
4246
pub use sc_rpc_api::DenyUnsafe;
4347
use sc_transaction_pool_api::TransactionPool;
4448
use sp_api::ProvideRuntimeApi;
49+
use sp_application_crypto::RuntimeAppPublic;
4550
use sp_block_builder::BlockBuilder;
4651
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
4752
use sp_consensus::SelectChain;
4853
use sp_consensus_babe::BabeApi;
54+
use sp_consensus_beefy::AuthorityIdBound;
4955
use sp_keystore::KeystorePtr;
5056

5157
/// Extra dependencies for BABE.
@@ -70,8 +76,18 @@ pub struct GrandpaDeps<B> {
7076
pub finality_provider: Arc<FinalityProofProvider<B, Block>>,
7177
}
7278

79+
/// Dependencies for BEEFY
80+
pub struct BeefyDeps<AuthorityId: AuthorityIdBound> {
81+
/// Receives notifications about finality proof events from BEEFY.
82+
pub beefy_finality_proof_stream: BeefyVersionedFinalityProofStream<Block, AuthorityId>,
83+
/// Receives notifications about best block events from BEEFY.
84+
pub beefy_best_block_stream: BeefyBestBlockStream<Block>,
85+
/// Executor to drive the subscription manager in the BEEFY RPC handler.
86+
pub subscription_executor: SubscriptionTaskExecutor,
87+
}
88+
7389
/// Full client dependencies.
74-
pub struct FullDeps<C, P, SC, B> {
90+
pub struct FullDeps<C, P, SC, B, AuthorityId: AuthorityIdBound> {
7591
/// The client instance to use.
7692
pub client: Arc<C>,
7793
/// Transaction pool instance.
@@ -84,21 +100,27 @@ pub struct FullDeps<C, P, SC, B> {
84100
pub babe: BabeDeps,
85101
/// GRANDPA specific dependencies.
86102
pub grandpa: GrandpaDeps<B>,
103+
/// BEEFY specific dependencies.
104+
pub beefy: BeefyDeps<AuthorityId>,
105+
/// Shared statement store reference.
106+
pub statement_store: Arc<dyn sp_statement_store::StatementStore>,
87107
/// The backend used by the node.
88108
pub backend: Arc<B>,
89109
}
90110

91111
/// Instantiate all Full RPC extensions.
92-
pub fn create_full<C, P, SC, B>(
112+
pub fn create_full<C, P, SC, B, AuthorityId>(
93113
FullDeps {
94114
client,
95115
pool,
96116
select_chain,
97117
chain_spec,
98118
babe,
99119
grandpa,
100-
..
101-
}: FullDeps<C, P, SC, B>,
120+
beefy,
121+
statement_store,
122+
backend,
123+
}: FullDeps<C, P, SC, B, AuthorityId>,
102124
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
103125
where
104126
C: ProvideRuntimeApi<Block>
@@ -110,6 +132,7 @@ where
110132
+ Send
111133
+ 'static,
112134
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
135+
C::Api: mmr_rpc::MmrRuntimeApi<Block, <Block as sp_runtime::traits::Block>::Hash, BlockNumber>,
113136
C::Api: node_rpc::transaction_payment::TransactionPaymentRuntimeApi<Block>,
114137
C::Api: node_rpc::pips::PipsRuntimeApi<Block, AccountId>,
115138
C::Api: node_rpc::identity::IdentityRuntimeApi<Block, IdentityId, Ticker, AccountId, Moment>,
@@ -124,7 +147,10 @@ where
124147
SC: SelectChain<Block> + 'static,
125148
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
126149
B::State: sc_client_api::backend::StateBackend<sp_runtime::traits::HashingFor<Block>>,
150+
AuthorityId: AuthorityIdBound,
151+
<AuthorityId as RuntimeAppPublic>::Signature: Send + Sync,
127152
{
153+
use mmr_rpc::{Mmr, MmrApiServer};
128154
use node_rpc::{
129155
asset::{Asset, AssetApiServer},
130156
identity::{Identity, IdentityApiServer},
@@ -136,8 +162,12 @@ where
136162
use pallet_group_rpc::{Group, GroupApiServer};
137163
use pallet_protocol_fee_rpc::{ProtocolFee, ProtocolFeeApiServer};
138164
use sc_consensus_babe_rpc::{Babe, BabeApiServer};
165+
use sc_consensus_beefy_rpc::{Beefy, BeefyApiServer};
139166
use sc_consensus_grandpa_rpc::{Grandpa, GrandpaApiServer};
140-
use sc_rpc::dev::{Dev, DevApiServer};
167+
use sc_rpc::{
168+
dev::{Dev, DevApiServer},
169+
statement::StatementApiServer,
170+
};
141171
use sc_sync_state_rpc::{SyncState, SyncStateApiServer};
142172
use substrate_frame_rpc_system::{System, SystemApiServer};
143173

@@ -156,6 +186,18 @@ where
156186
} = grandpa;
157187

158188
io.merge(System::new(client.clone(), pool).into_rpc())?;
189+
// Making synchronous calls in light client freezes the browser currently,
190+
// more context: https://github.com/paritytech/substrate/pull/3480
191+
// These RPCs should use an asynchronous caller instead.
192+
io.merge(
193+
Mmr::new(
194+
client.clone(),
195+
backend
196+
.offchain_storage()
197+
.ok_or_else(|| "Backend doesn't provide an offchain storage")?,
198+
)
199+
.into_rpc(),
200+
)?;
159201
io.merge(TransactionPayment::new(client.clone()).into_rpc())?;
160202
io.merge(
161203
Babe::new(
@@ -189,6 +231,18 @@ where
189231

190232
io.merge(Dev::new(client.clone()).into_rpc())?;
191233

234+
let statement_store = sc_rpc::statement::StatementStore::new(statement_store).into_rpc();
235+
io.merge(statement_store)?;
236+
237+
io.merge(
238+
Beefy::<Block, AuthorityId>::new(
239+
beefy.beefy_finality_proof_stream,
240+
beefy.beefy_best_block_stream,
241+
beefy.subscription_executor,
242+
)?
243+
.into_rpc(),
244+
)?;
245+
192246
io.merge(Pips::new(client.clone()).into_rpc())?;
193247
io.merge(Identity::new(client.clone()).into_rpc())?;
194248
io.merge(ProtocolFee::new(client.clone()).into_rpc())?;

0 commit comments

Comments
 (0)