@@ -36,16 +36,22 @@ use jsonrpsee::RpcModule;
3636use polymesh_primitives:: { AccountId , Block , BlockNumber , Hash , IdentityId , Moment , Nonce , Ticker } ;
3737use sc_client_api:: AuxStore ;
3838use 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 ;
4246pub use sc_rpc_api:: DenyUnsafe ;
4347use sc_transaction_pool_api:: TransactionPool ;
4448use sp_api:: ProvideRuntimeApi ;
49+ use sp_application_crypto:: RuntimeAppPublic ;
4550use sp_block_builder:: BlockBuilder ;
4651use sp_blockchain:: { Error as BlockChainError , HeaderBackend , HeaderMetadata } ;
4752use sp_consensus:: SelectChain ;
4853use sp_consensus_babe:: BabeApi ;
54+ use sp_consensus_beefy:: AuthorityIdBound ;
4955use 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 > >
103125where
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