diff --git a/bin/node-template/node/src/rpc.rs b/bin/node-template/node/src/rpc.rs index 5650fae750..254b282936 100644 --- a/bin/node-template/node/src/rpc.rs +++ b/bin/node-template/node/src/rpc.rs @@ -41,19 +41,21 @@ pub struct BabeDeps { } /// Extra dependencies for GRANDPA -pub struct GrandpaDeps { +pub struct GrandpaDeps { /// Voting round info. pub shared_voter_state: sc_finality_grandpa::SharedVoterState, /// Authority set info. pub shared_authority_set: sc_finality_grandpa::SharedAuthoritySet, /// Receives notifications about justification events from Grandpa. pub justification_stream: sc_finality_grandpa::GrandpaJustificationStream, - /// Subscription manager to keep track of pubsub subscribers. + /// Executor to drive the subscription manager in the Grandpa RPC handler. pub subscription_executor: sc_rpc::SubscriptionTaskExecutor, + /// Finality proof provider. + pub finality_provider: Arc>, } /// Full client dependencies. -pub struct FullDeps { +pub struct FullDeps { /// The client instance to use. pub client: Arc, /// Transaction pool instance. @@ -65,7 +67,7 @@ pub struct FullDeps { /// BABE specific dependencies. pub babe: BabeDeps, /// GRANDPA specific dependencies. - pub grandpa: GrandpaDeps, + pub grandpa: GrandpaDeps, } /// Light client extra dependencies. @@ -81,7 +83,7 @@ pub struct LightDeps { } /// Instantiate all RPC extensions. -pub fn create_full(deps: FullDeps) -> RpcExtension +pub fn create_full(deps: FullDeps) -> RpcExtension where C: 'static + Send + Sync, C: ProvideRuntimeApi, @@ -96,6 +98,8 @@ where C::Api: darwinia_staking_rpc::StakingRuntimeApi, P: 'static + sp_transaction_pool::TransactionPool, SC: 'static + sp_consensus::SelectChain, + B: 'static + Send + Sync + sc_client_api::Backend, + B::State: sc_client_api::StateBackend>, { // --- substrate --- use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi}; @@ -146,6 +150,7 @@ where shared_authority_set, justification_stream, subscription_executor, + finality_provider, } = grandpa; io.extend_with(sc_finality_grandpa_rpc::GrandpaApi::to_delegate( GrandpaRpcHandler::new( @@ -153,6 +158,7 @@ where shared_voter_state, justification_stream, subscription_executor, + finality_provider, ), )); } diff --git a/bin/node-template/node/src/service.rs b/bin/node-template/node/src/service.rs index 80b4550202..3cd52f74d2 100644 --- a/bin/node-template/node/src/service.rs +++ b/bin/node-template/node/src/service.rs @@ -162,7 +162,10 @@ fn new_partial( LinkHalf, FullSelectChain>, BabeLink, ), - GrandpaSharedVoterState, + ( + GrandpaSharedVoterState, + Arc>, + ), ), >, ServiceError, @@ -216,8 +219,10 @@ where let justification_stream = grandpa_link.justification_stream(); let shared_authority_set = grandpa_link.shared_authority_set().clone(); let shared_voter_state = GrandpaSharedVoterState::empty(); + let finality_proof_provider = + GrandpaFinalityProofProvider::new_for_service(backend.clone(), client.clone()); let import_setup = (babe_import.clone(), grandpa_link, babe_link.clone()); - let rpc_setup = shared_voter_state.clone(); + let rpc_setup = (shared_voter_state.clone(), finality_proof_provider.clone()); let babe_config = babe_link.config().clone(); let shared_epoch_changes = babe_link.epoch_changes().clone(); let rpc_extensions_builder = { @@ -242,6 +247,7 @@ where shared_authority_set: shared_authority_set.clone(), justification_stream: justification_stream.clone(), subscription_executor, + finality_provider: finality_proof_provider.clone(), }, }; @@ -290,8 +296,7 @@ where other: (rpc_extensions_builder, import_setup, rpc_setup), } = new_partial::(&mut config)?; let prometheus_registry = config.prometheus_registry().cloned(); - let finality_proof_provider = - GrandpaFinalityProofProvider::new_for_service(backend.clone(), client.clone()); + let (shared_voter_state, finality_proof_provider) = rpc_setup; let (network, network_status_sinks, system_rpc_tx, network_starter) = sc_service::build_network(BuildNetworkParams { config: &config, @@ -334,7 +339,6 @@ where })?; let (block_import, link_half, babe_link) = import_setup; - let shared_voter_state = rpc_setup; if role.is_authority() { let can_author_with = CanAuthorWithNativeVersion::new(client.executor().clone());