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

Companion PR for #6215 #1654

Merged
merged 8 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions node/service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@ fn new_partial<RuntimeApi, Executor>(config: &mut Configuration) -> Result<
grandpa::LinkHalf<Block, FullClient<RuntimeApi, Executor>, FullSelectChain>,
babe::BabeLink<Block>
),
grandpa::SharedVoterState,
(
grandpa::SharedVoterState,
Arc<GrandpaFinalityProofProvider<FullBackend, Block>>,
),
)
>,
Error
Expand Down Expand Up @@ -235,9 +238,11 @@ fn new_partial<RuntimeApi, Executor>(config: &mut Configuration) -> Result<
let justification_stream = grandpa_link.justification_stream();
let shared_authority_set = grandpa_link.shared_authority_set().clone();
let shared_voter_state = grandpa::SharedVoterState::empty();
let finality_proof_provider =
GrandpaFinalityProofProvider::new_for_service(backend.clone(), client.clone());

let import_setup = (block_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();
Expand All @@ -264,6 +269,7 @@ fn new_partial<RuntimeApi, Executor>(config: &mut Configuration) -> Result<
shared_authority_set: shared_authority_set.clone(),
justification_stream: justification_stream.clone(),
subscription_executor,
finality_provider: finality_proof_provider.clone(),
},
};

Expand Down Expand Up @@ -344,8 +350,7 @@ fn new_full<RuntimeApi, Executor>(

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) =
service::build_network(service::BuildNetworkParams {
Expand Down Expand Up @@ -385,8 +390,6 @@ fn new_full<RuntimeApi, Executor>(

let (block_import, link_half, babe_link) = import_setup;

let shared_voter_state = rpc_setup;

let overseer_client = client.clone();
let spawner = task_manager.spawn_handle();
let leaves: Vec<_> = select_chain.clone()
Expand Down
1 change: 1 addition & 0 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master
sp-api = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "master"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can be removed with the edits below.

sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "master"}
sc-consensus-babe-rpc = { git = "https://github.com/paritytech/substrate", branch = "master"}
Expand Down
20 changes: 14 additions & 6 deletions rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ use std::sync::Arc;
use polkadot_primitives::v0::{Block, BlockNumber, AccountId, Nonce, Balance, Hash};
use sp_api::ProvideRuntimeApi;
use txpool_api::TransactionPool;
use sp_block_builder::BlockBuilder;
use sp_blockchain::{HeaderBackend, HeaderMetadata, Error as BlockChainError};
use sp_consensus::SelectChain;
use sp_consensus_babe::BabeApi;
use sp_runtime::traits::BlakeTwo256;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
use sp_runtime::traits::BlakeTwo256;

use sc_client_api::light::{Fetcher, RemoteBlockchain};
use sc_consensus_babe::Epoch;
use sp_block_builder::BlockBuilder;
use sc_finality_grandpa::FinalityProofProvider;
pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor};

/// A type representing all RPC extensions.
Expand Down Expand Up @@ -57,19 +59,21 @@ pub struct BabeDeps {
}

/// 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<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 @@ -81,11 +85,11 @@ pub struct FullDeps<C, P, SC> {
/// BABE specific dependencies.
pub babe: BabeDeps,
/// GRANDPA specific dependencies.
pub grandpa: GrandpaDeps,
pub grandpa: GrandpaDeps<B>,
}

/// Instantiate all RPC extensions.
pub fn create_full<C, P, SC>(deps: FullDeps<C, P, SC>) -> RpcExtension where
pub fn create_full<C, P, SC, B>(deps: FullDeps<C, P, SC, B>) -> RpcExtension where
C: ProvideRuntimeApi<Block>,
C: HeaderBackend<Block> + HeaderMetadata<Block, Error=BlockChainError>,
C: Send + Sync + 'static,
Expand All @@ -95,6 +99,8 @@ pub fn create_full<C, P, SC>(deps: FullDeps<C, P, SC>) -> RpcExtension where
C::Api: BlockBuilder<Block>,
P: TransactionPool + Sync + Send + 'static,
SC: SelectChain<Block> + 'static,
B: Send + Sync + 'static + sc_client_api::Backend<Block>,
<B as sc_client_api::Backend<Block>>::State: sp_state_machine::Backend<BlakeTwo256>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
B: Send + Sync + 'static + sc_client_api::Backend<Block>,
<B as sc_client_api::Backend<Block>>::State: sp_state_machine::Backend<BlakeTwo256>,
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sp_state_machine::Backend<sp_runtime::traits::HashFor<Block>>,

{
use frame_rpc_system::{FullSystem, SystemApi};
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
Expand All @@ -120,6 +126,7 @@ pub fn create_full<C, P, SC>(deps: FullDeps<C, P, SC>) -> RpcExtension where
shared_authority_set,
justification_stream,
subscription_executor,
finality_provider,
} = grandpa;

io.extend_with(
Expand All @@ -146,6 +153,7 @@ pub fn create_full<C, P, SC>(deps: FullDeps<C, P, SC>) -> RpcExtension where
shared_voter_state,
justification_stream,
subscription_executor,
finality_provider,
))
);
io
Expand Down
15 changes: 9 additions & 6 deletions service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ pub fn new_partial<RuntimeApi, Executor>(config: &mut Configuration, test: bool)
grandpa::LinkHalf<Block, FullClient<RuntimeApi, Executor>, FullSelectChain>,
babe::BabeLink<Block>
),
grandpa::SharedVoterState,
(
grandpa::SharedVoterState,
Arc<GrandpaFinalityProofProvider<FullBackend, Block>>,
),
)
>,
Error
Expand Down Expand Up @@ -203,9 +206,11 @@ pub fn new_partial<RuntimeApi, Executor>(config: &mut Configuration, test: bool)
let justification_stream = grandpa_link.justification_stream();
let shared_authority_set = grandpa_link.shared_authority_set().clone();
let shared_voter_state = grandpa::SharedVoterState::empty();
let finality_proof_provider =
GrandpaFinalityProofProvider::new_for_service(backend.clone(), client.clone());

let import_setup = (block_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();
Expand All @@ -232,6 +237,7 @@ pub fn new_partial<RuntimeApi, Executor>(config: &mut Configuration, test: bool)
shared_authority_set: shared_authority_set.clone(),
justification_stream: justification_stream.clone(),
subscription_executor,
finality_provider: finality_proof_provider.clone(),
},
};

Expand Down Expand Up @@ -303,8 +309,7 @@ pub fn new_full<RuntimeApi, Executor>(

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) =
service::build_network(service::BuildNetworkParams {
Expand Down Expand Up @@ -345,8 +350,6 @@ pub fn new_full<RuntimeApi, Executor>(

let (block_import, link_half, babe_link) = import_setup;

let shared_voter_state = rpc_setup;

if role.is_authority() {
let proposer = consensus::ProposerFactory::new(
client.clone(),
Expand Down