Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
companion: for #6215
Browse files Browse the repository at this point in the history
  • Loading branch information
AurevoirXavier committed Oct 14, 2020
1 parent 3605990 commit 8049213
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
16 changes: 11 additions & 5 deletions bin/node-template/node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,21 @@ pub struct BabeDeps {
}

/// Extra dependencies for GRANDPA
pub struct GrandpaDeps {
pub struct GrandpaDeps<B> {
/// Voting round info.
pub shared_voter_state: sc_finality_grandpa::SharedVoterState,
/// Authority set info.
pub shared_authority_set: sc_finality_grandpa::SharedAuthoritySet<Hash, BlockNumber>,
/// Receives notifications about justification events from Grandpa.
pub justification_stream: sc_finality_grandpa::GrandpaJustificationStream<Block>,
/// 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<sc_finality_grandpa::FinalityProofProvider<B, Block>>,
}

/// Full client dependencies.
pub struct FullDeps<C, P, SC> {
pub struct FullDeps<C, P, SC, B> {
/// The client instance to use.
pub client: Arc<C>,
/// Transaction pool instance.
Expand All @@ -65,7 +67,7 @@ pub struct FullDeps<C, P, SC> {
/// BABE specific dependencies.
pub babe: BabeDeps,
/// GRANDPA specific dependencies.
pub grandpa: GrandpaDeps,
pub grandpa: GrandpaDeps<B>,
}

/// Light client extra dependencies.
Expand All @@ -81,7 +83,7 @@ pub struct LightDeps<C, F, P> {
}

/// Instantiate all RPC extensions.
pub fn create_full<C, P, SC>(deps: FullDeps<C, P, SC>) -> RpcExtension
pub fn create_full<C, P, SC, B>(deps: FullDeps<C, P, SC, B>) -> RpcExtension
where
C: 'static + Send + Sync,
C: ProvideRuntimeApi<Block>,
Expand All @@ -96,6 +98,8 @@ where
C::Api: darwinia_staking_rpc::StakingRuntimeApi<Block, AccountId, Power>,
P: 'static + sp_transaction_pool::TransactionPool,
SC: 'static + sp_consensus::SelectChain<Block>,
B: 'static + Send + Sync + sc_client_api::Backend<Block>,
B::State: sc_client_api::StateBackend<sp_runtime::traits::HashFor<Block>>,
{
// --- substrate ---
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
Expand Down Expand Up @@ -146,13 +150,15 @@ where
shared_authority_set,
justification_stream,
subscription_executor,
finality_provider,
} = grandpa;
io.extend_with(sc_finality_grandpa_rpc::GrandpaApi::to_delegate(
GrandpaRpcHandler::new(
shared_authority_set,
shared_voter_state,
justification_stream,
subscription_executor,
finality_provider,
),
));
}
Expand Down
14 changes: 9 additions & 5 deletions bin/node-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ fn new_partial<RuntimeApi, Executor>(
LinkHalf<Block, FullClient<RuntimeApi, Executor>, FullSelectChain>,
BabeLink<Block>,
),
GrandpaSharedVoterState,
(
GrandpaSharedVoterState,
Arc<GrandpaFinalityProofProvider<FullBackend, Block>>,
),
),
>,
ServiceError,
Expand Down Expand Up @@ -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 = {
Expand All @@ -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(),
},
};

Expand Down Expand Up @@ -290,8 +296,7 @@ where
other: (rpc_extensions_builder, import_setup, rpc_setup),
} = new_partial::<RuntimeApi, Executor>(&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,
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 8049213

Please sign in to comment.