Companion PR for 'Add missing fields to the light sync state #7225' (#1801)

* Add sync_state_items

* Add SyncStateRpc

* "Update Substrate"

Co-authored-by: parity-processbot <>
This commit is contained in:
Ashley
2020-10-15 12:28:00 +02:00
committed by GitHub
parent 5ba73b5b7b
commit c7e729e07b
6 changed files with 188 additions and 184 deletions
+165 -137
View File
File diff suppressed because it is too large Load Diff
-3
View File
@@ -24,9 +24,6 @@ pub enum Subcommand {
/// Build a chain specification. /// Build a chain specification.
BuildSpec(sc_cli::BuildSpecCmd), BuildSpec(sc_cli::BuildSpecCmd),
/// Build a chain specification with a light client sync state.
BuildSyncSpec(sc_cli::BuildSyncSpecCmd),
/// Validate blocks. /// Validate blocks.
CheckBlock(sc_cli::CheckBlockCmd), CheckBlock(sc_cli::CheckBlockCmd),
-38
View File
@@ -18,7 +18,6 @@ use log::info;
use service::{IdentifyVariant, self}; use service::{IdentifyVariant, self};
use sc_cli::{SubstrateCli, Result, RuntimeVersion, Role}; use sc_cli::{SubstrateCli, Result, RuntimeVersion, Role};
use crate::cli::{Cli, Subcommand}; use crate::cli::{Cli, Subcommand};
use std::sync::Arc;
fn get_exec_name() -> Option<String> { fn get_exec_name() -> Option<String> {
std::env::current_exe() std::env::current_exe()
@@ -158,43 +157,6 @@ pub fn run() -> Result<()> {
let runner = cli.create_runner(cmd)?; let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| cmd.run(config.chain_spec, config.network)) runner.sync_run(|config| cmd.run(config.chain_spec, config.network))
}, },
Some(Subcommand::BuildSyncSpec(cmd)) => {
let runner = cli.create_runner(cmd)?;
let chain_spec = &runner.config().chain_spec;
set_default_ss58_version(chain_spec);
let authority_discovery_disabled = cli.run.authority_discovery_disabled;
let grandpa_pause = if cli.run.grandpa_pause.is_empty() {
None
} else {
Some((cli.run.grandpa_pause[0], cli.run.grandpa_pause[1]))
};
if chain_spec.is_kusama() {
info!("----------------------------");
info!("This chain is not in any way");
info!(" endorsed by the ");
info!(" KUSAMA FOUNDATION ");
info!("----------------------------");
}
runner.async_run(|config| {
let chain_spec = config.chain_spec.cloned_box();
let network_config = config.network.clone();
let service::NewFull {
task_manager,
client,
network_status_sinks,
..
} = service::build_full(
config, authority_discovery_disabled, grandpa_pause,
)?;
let client = Arc::new(client);
Ok((cmd.run(chain_spec, network_config, client, network_status_sinks), task_manager))
})
},
Some(Subcommand::CheckBlock(cmd)) => { Some(Subcommand::CheckBlock(cmd)) => {
let runner = cli.create_runner(cmd)?; let runner = cli.create_runner(cmd)?;
let chain_spec = &runner.config().chain_spec; let chain_spec = &runner.config().chain_spec;
+2
View File
@@ -234,12 +234,14 @@ fn new_partial<RuntimeApi, Executor>(config: &mut Configuration) -> Result<
let keystore = keystore_container.sync_keystore(); let keystore = keystore_container.sync_keystore();
let transaction_pool = transaction_pool.clone(); let transaction_pool = transaction_pool.clone();
let select_chain = select_chain.clone(); let select_chain = select_chain.clone();
let chain_spec = config.chain_spec.cloned_box();
move |deny_unsafe, subscription_executor| -> polkadot_rpc::RpcExtension { move |deny_unsafe, subscription_executor| -> polkadot_rpc::RpcExtension {
let deps = polkadot_rpc::FullDeps { let deps = polkadot_rpc::FullDeps {
client: client.clone(), client: client.clone(),
pool: transaction_pool.clone(), pool: transaction_pool.clone(),
select_chain: select_chain.clone(), select_chain: select_chain.clone(),
chain_spec: chain_spec.cloned_box(),
deny_unsafe, deny_unsafe,
babe: polkadot_rpc::BabeDeps { babe: polkadot_rpc::BabeDeps {
babe_config: babe_config.clone(), babe_config: babe_config.clone(),
+2
View File
@@ -14,6 +14,7 @@ sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "master
sp-api = { 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 = { git = "https://github.com/paritytech/substrate", branch = "master" }
sp-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "master" } sp-consensus-babe = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-consensus-babe = { 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"} sc-consensus-babe-rpc = { git = "https://github.com/paritytech/substrate", branch = "master"}
@@ -21,6 +22,7 @@ sc-consensus-epochs = { git = "https://github.com/paritytech/substrate", branch
sc-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-finality-grandpa = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-finality-grandpa-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } sc-finality-grandpa-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" }
sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "master"} sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "master"}
sc-sync-state-rpc = { git = "https://github.com/paritytech/substrate", branch = "master"}
txpool-api = { package = "sp-transaction-pool", git = "https://github.com/paritytech/substrate", branch = "master" } txpool-api = { package = "sp-transaction-pool", git = "https://github.com/paritytech/substrate", branch = "master" }
frame-rpc-system = { package = "substrate-frame-rpc-system", git = "https://github.com/paritytech/substrate", branch = "master" } frame-rpc-system = { package = "substrate-frame-rpc-system", git = "https://github.com/paritytech/substrate", branch = "master" }
pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" } pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate", branch = "master" }
+19 -6
View File
@@ -28,9 +28,11 @@ use sp_blockchain::{HeaderBackend, HeaderMetadata, Error as BlockChainError};
use sp_consensus::SelectChain; use sp_consensus::SelectChain;
use sp_consensus_babe::BabeApi; use sp_consensus_babe::BabeApi;
use sp_keystore::SyncCryptoStorePtr; use sp_keystore::SyncCryptoStorePtr;
use sc_client_api::AuxStore;
use sc_client_api::light::{Fetcher, RemoteBlockchain}; use sc_client_api::light::{Fetcher, RemoteBlockchain};
use sc_consensus_babe::Epoch; use sc_consensus_babe::Epoch;
use sc_finality_grandpa::FinalityProofProvider; use sc_finality_grandpa::FinalityProofProvider;
use sc_sync_state_rpc::{SyncStateRpcApi, SyncStateRpcHandler};
pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor}; pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor};
/// A type representing all RPC extensions. /// A type representing all RPC extensions.
@@ -80,6 +82,8 @@ pub struct FullDeps<C, P, SC, B> {
pub pool: Arc<P>, pub pool: Arc<P>,
/// The SelectChain Strategy /// The SelectChain Strategy
pub select_chain: SC, pub select_chain: SC,
/// A copy of the chain spec.
pub chain_spec: Box<dyn sc_chain_spec::ChainSpec>,
/// Whether to deny unsafe calls /// Whether to deny unsafe calls
pub deny_unsafe: DenyUnsafe, pub deny_unsafe: DenyUnsafe,
/// BABE specific dependencies. /// BABE specific dependencies.
@@ -90,9 +94,8 @@ pub struct FullDeps<C, P, SC, B> {
/// Instantiate all RPC extensions. /// Instantiate all RPC extensions.
pub fn create_full<C, P, SC, B>(deps: FullDeps<C, P, SC, B>) -> RpcExtension where pub fn create_full<C, P, SC, B>(deps: FullDeps<C, P, SC, B>) -> RpcExtension where
C: ProvideRuntimeApi<Block>, C: ProvideRuntimeApi<Block> + HeaderBackend<Block> + AuxStore +
C: HeaderBackend<Block> + HeaderMetadata<Block, Error=BlockChainError>, HeaderMetadata<Block, Error=BlockChainError> + Send + Sync + 'static,
C: Send + Sync + 'static,
C::Api: frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>, C::Api: frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>, C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: BabeApi<Block>, C::Api: BabeApi<Block>,
@@ -112,6 +115,7 @@ pub fn create_full<C, P, SC, B>(deps: FullDeps<C, P, SC, B>) -> RpcExtension whe
client, client,
pool, pool,
select_chain, select_chain,
chain_spec,
deny_unsafe, deny_unsafe,
babe, babe,
grandpa, grandpa,
@@ -138,8 +142,8 @@ pub fn create_full<C, P, SC, B>(deps: FullDeps<C, P, SC, B>) -> RpcExtension whe
io.extend_with( io.extend_with(
sc_consensus_babe_rpc::BabeApi::to_delegate( sc_consensus_babe_rpc::BabeApi::to_delegate(
BabeRpcHandler::new( BabeRpcHandler::new(
client, client.clone(),
shared_epoch_changes, shared_epoch_changes.clone(),
keystore, keystore,
babe_config, babe_config,
select_chain, select_chain,
@@ -149,13 +153,22 @@ pub fn create_full<C, P, SC, B>(deps: FullDeps<C, P, SC, B>) -> RpcExtension whe
); );
io.extend_with( io.extend_with(
GrandpaApi::to_delegate(GrandpaRpcHandler::new( GrandpaApi::to_delegate(GrandpaRpcHandler::new(
shared_authority_set, shared_authority_set.clone(),
shared_voter_state, shared_voter_state,
justification_stream, justification_stream,
subscription_executor, subscription_executor,
finality_provider, finality_provider,
)) ))
); );
io.extend_with(
SyncStateRpcApi::to_delegate(SyncStateRpcHandler::new(
chain_spec,
client,
shared_authority_set,
shared_epoch_changes,
deny_unsafe,
))
);
io io
} }