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

Add missing fields to the light sync state #7225

Merged
18 commits merged into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
d3e8c97
Initial draft
expenses Sep 23, 2020
1eb1297
Add an iterator that helps us get most items
expenses Sep 28, 2020
a118cea
Merge remote-tracking branch 'origin/master' into ashley-improve-sync…
expenses Sep 28, 2020
ccfb11d
Revert changes to grandpa
expenses Sep 28, 2020
b3e8f09
Merge remote-tracking branch 'origin/master' into ashley-improve-sync…
expenses Sep 29, 2020
35a580a
Change fields to just be the grandpa authority set and babe epoch cha…
expenses Sep 29, 2020
a8f0966
Only use the fields we need from the shared authority set
expenses Sep 30, 2020
fdd282f
Switch to RPC call
expenses Oct 6, 2020
32c12ed
Merge remote-tracking branch 'origin/master' into ashley-improve-sync…
expenses Oct 6, 2020
7f28aa9
Revert "Only use the fields we need from the shared authority set"
expenses Oct 9, 2020
6e7855b
Merge remote-tracking branch 'origin/master' into ashley-improve-sync…
expenses Oct 9, 2020
81ac0ab
Add babe_finalized_block_weight from `ashley-improve-sync-state-WIP-l…
expenses Oct 9, 2020
136231b
Fix rpc test
expenses Oct 9, 2020
d94adf1
Move sync state rpc stuff into sc-sync-state-rpc
expenses Oct 12, 2020
d56cafc
Merge remote-tracking branch 'origin/master' into ashley-improve-sync…
expenses Oct 12, 2020
49f1d47
Remove as_json_value and remove unwraps from sc-sync-state-rpc
expenses Oct 12, 2020
b6af3e9
Merge remote-tracking branch 'origin/master' into ashley-improve-sync…
expenses Oct 14, 2020
750448b
Add clone_inner to SharedAuthoritySet
expenses Oct 15, 2020
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
31 changes: 29 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ members = [
"client/service",
"client/service/test",
"client/state-db",
"client/sync-state-rpc",
"client/telemetry",
"client/transaction-pool",
"client/transaction-pool/graph",
Expand Down
3 changes: 0 additions & 3 deletions bin/node/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,6 @@ pub enum Subcommand {
/// Build a chain specification.
BuildSpec(sc_cli::BuildSpecCmd),

/// Build a chain specification with a light client sync state.
BuildSyncSpec(sc_cli::BuildSyncSpecCmd),

/// Validate blocks.
CheckBlock(sc_cli::CheckBlockCmd),

Expand Down
13 changes: 1 addition & 12 deletions bin/node/cli/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use node_executor::Executor;
use node_runtime::{Block, RuntimeApi};
use sc_cli::{Result, SubstrateCli, RuntimeVersion, Role, ChainSpec};
use sc_service::PartialComponents;
use crate::service::{new_partial, new_full_base, NewFullBase};
use crate::service::new_partial;

impl SubstrateCli for Cli {
fn impl_name() -> String {
Expand Down Expand Up @@ -102,17 +102,6 @@ pub fn run() -> Result<()> {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|config| cmd.run(config.chain_spec, config.network))
},
Some(Subcommand::BuildSyncSpec(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
let chain_spec = config.chain_spec.cloned_box();
let network_config = config.network.clone();
let NewFullBase { task_manager, client, network_status_sinks, .. }
= new_full_base(config, |_, _| ())?;

Ok((cmd.run(chain_spec, network_config, client, network_status_sinks), task_manager))
})
},
Some(Subcommand::CheckBlock(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
Expand Down
2 changes: 2 additions & 0 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ pub fn new_partial(config: &Configuration) -> Result<sc_service::PartialComponen
let pool = transaction_pool.clone();
let select_chain = select_chain.clone();
let keystore = keystore_container.sync_keystore();
let chain_spec = config.chain_spec.cloned_box();

let rpc_extensions_builder = move |deny_unsafe, subscription_executor| {
let deps = node_rpc::FullDeps {
client: client.clone(),
pool: pool.clone(),
select_chain: select_chain.clone(),
chain_spec: chain_spec.cloned_box(),
deny_unsafe,
babe: node_rpc::BabeDeps {
babe_config: babe_config.clone(),
Expand Down
2 changes: 2 additions & 0 deletions bin/node/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ sc-client-api = { version = "2.0.0", path = "../../../client/api" }
sc-consensus-babe = { version = "0.8.0", path = "../../../client/consensus/babe" }
sc-consensus-babe-rpc = { version = "0.8.0", path = "../../../client/consensus/babe/rpc" }
sc-consensus-epochs = { version = "0.8.0", path = "../../../client/consensus/epochs" }
sc-chain-spec = { version = "2.0.0", path = "../../../client/chain-spec" }
sc-finality-grandpa = { version = "0.8.0", path = "../../../client/finality-grandpa" }
sc-finality-grandpa-rpc = { version = "0.8.0", path = "../../../client/finality-grandpa/rpc" }
sc-keystore = { version = "2.0.0", path = "../../../client/keystore" }
sc-rpc-api = { version = "0.8.0", path = "../../../client/rpc-api" }
sc-rpc = { version = "2.0.0", path = "../../../client/rpc" }
sc-sync-state-rpc = { version = "0.8.0", path = "../../../client/sync-state-rpc" }
sp-api = { version = "2.0.0", path = "../../../primitives/api" }
sp-block-builder = { version = "2.0.0", path = "../../../primitives/block-builder" }
sp-blockchain = { version = "2.0.0", path = "../../../primitives/blockchain" }
Expand Down
27 changes: 21 additions & 6 deletions bin/node/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ use sp_consensus::SelectChain;
use sp_consensus_babe::BabeApi;
use sc_rpc::SubscriptionTaskExecutor;
use sp_transaction_pool::TransactionPool;
use sc_client_api::AuxStore;

/// Light client extra dependencies.
pub struct LightDeps<C, F, P> {
Expand Down Expand Up @@ -94,6 +95,8 @@ pub struct FullDeps<C, P, SC, B> {
pub pool: Arc<P>,
/// The SelectChain Strategy
pub select_chain: SC,
/// A copy of the chain spec.
pub chain_spec: Box<dyn sc_chain_spec::ChainSpec>,
/// Whether to deny unsafe calls
pub deny_unsafe: DenyUnsafe,
/// BABE specific dependencies.
Expand All @@ -109,9 +112,8 @@ pub type IoHandler = jsonrpc_core::IoHandler<sc_rpc::Metadata>;
pub fn create_full<C, P, SC, B>(
deps: FullDeps<C, P, SC, B>,
) -> jsonrpc_core::IoHandler<sc_rpc_api::Metadata> where
C: ProvideRuntimeApi<Block>,
C: HeaderBackend<Block> + HeaderMetadata<Block, Error=BlockChainError> + 'static,
C: Send + Sync + 'static,
C: ProvideRuntimeApi<Block> + HeaderBackend<Block> + AuxStore +
HeaderMetadata<Block, Error=BlockChainError> + Sync + Send + 'static,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
C::Api: pallet_contracts_rpc::ContractsRuntimeApi<Block, AccountId, Balance, BlockNumber>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
Expand All @@ -131,6 +133,7 @@ pub fn create_full<C, P, SC, B>(
client,
pool,
select_chain,
chain_spec,
deny_unsafe,
babe,
grandpa,
Expand Down Expand Up @@ -164,8 +167,8 @@ pub fn create_full<C, P, SC, B>(
io.extend_with(
sc_consensus_babe_rpc::BabeApi::to_delegate(
BabeRpcHandler::new(
client,
shared_epoch_changes,
client.clone(),
shared_epoch_changes.clone(),
keystore,
babe_config,
select_chain,
Expand All @@ -176,7 +179,7 @@ pub fn create_full<C, P, SC, B>(
io.extend_with(
sc_finality_grandpa_rpc::GrandpaApi::to_delegate(
GrandpaRpcHandler::new(
shared_authority_set,
shared_authority_set.clone(),
shared_voter_state,
justification_stream,
subscription_executor,
Expand All @@ -185,6 +188,18 @@ pub fn create_full<C, P, SC, B>(
)
);

io.extend_with(
sc_sync_state_rpc::SyncStateRpcApi::to_delegate(
sc_sync_state_rpc::SyncStateRpcHandler::new(
chain_spec,
client,
shared_authority_set,
shared_epoch_changes,
deny_unsafe,
)
)
);

io
}

Expand Down
4 changes: 4 additions & 0 deletions client/chain-spec/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ sp-runtime = { version = "2.0.0", path = "../../primitives/runtime" }
sp-chain-spec = { version = "2.0.0", path = "../../primitives/chain-spec" }
sc-telemetry = { version = "2.0.0", path = "../telemetry" }
codec = { package = "parity-scale-codec", version = "1.3.4" }
sc-consensus-babe = { version = "0.8.0-rc6", path = "../consensus/babe" }
sp-consensus-babe = { version = "0.8.0-rc6", path = "../../primitives/consensus/babe" }
sc-consensus-epochs = { version = "0.8.0-rc6", path = "../consensus/epochs" }
sc-finality-grandpa = { version = "0.8.0-rc6", path = "../finality-grandpa" }
35 changes: 28 additions & 7 deletions client/chain-spec/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use serde_json as json;
use crate::{RuntimeGenesis, ChainType, extension::GetExtension, Properties};
use sc_network::config::MultiaddrWithPeerId;
use sc_telemetry::TelemetryEndpoints;
use sp_runtime::traits::Block as BlockT;
use sp_runtime::traits::{Block as BlockT, NumberFor};

enum GenesisSource<G> {
File(PathBuf),
Expand Down Expand Up @@ -264,7 +264,7 @@ impl<G, E> ChainSpec<G, E> {

/// Hardcode infomation to allow light clients to sync quickly into the chain spec.
fn set_light_sync_state(&mut self, light_sync_state: SerializableLightSyncState) {
self.client_spec.light_sync_state = Some(light_sync_state);
self.client_spec.light_sync_state = Some(light_sync_state);
}
}

Expand Down Expand Up @@ -338,7 +338,7 @@ impl<G: RuntimeGenesis, E: serde::Serialize + Clone + 'static> ChainSpec<G, E> {
impl<G, E> crate::ChainSpec for ChainSpec<G, E>
where
G: RuntimeGenesis + 'static,
E: GetExtension + serde::Serialize + Clone + Send + 'static,
E: GetExtension + serde::Serialize + Clone + Send + Sync + 'static,
{
fn boot_nodes(&self) -> &[MultiaddrWithPeerId] {
ChainSpec::boot_nodes(self)
Expand Down Expand Up @@ -400,7 +400,13 @@ where
/// Hardcoded infomation that allows light clients to sync quickly.
pub struct LightSyncState<Block: BlockT> {
/// The header of the best finalized block.
pub header: <Block as BlockT>::Header,
pub finalized_block_header: <Block as BlockT>::Header,
/// The epoch changes tree for babe.
pub babe_epoch_changes: sc_consensus_epochs::EpochChangesFor<Block, sc_consensus_babe::Epoch>,
/// The babe weight of the finalized block.
pub babe_finalized_block_weight: sp_consensus_babe::BabeBlockWeight,
/// The authority set for grandpa.
pub grandpa_authority_set: sc_finality_grandpa::AuthoritySet<<Block as BlockT>::Hash, NumberFor<Block>>,
}

impl<Block: BlockT> LightSyncState<Block> {
Expand All @@ -409,14 +415,26 @@ impl<Block: BlockT> LightSyncState<Block> {
use codec::Encode;

SerializableLightSyncState {
header: StorageData(self.header.encode()),
finalized_block_header: StorageData(self.finalized_block_header.encode()),
babe_epoch_changes:
StorageData(self.babe_epoch_changes.encode()),
babe_finalized_block_weight:
self.babe_finalized_block_weight,
grandpa_authority_set:
StorageData(self.grandpa_authority_set.encode()),
}
}

/// Convert from a `SerializableLightSyncState`.
pub fn from_serializable(serialized: &SerializableLightSyncState) -> Result<Self, codec::Error> {
Ok(Self {
header: codec::Decode::decode(&mut &serialized.header.0[..])?,
finalized_block_header: codec::Decode::decode(&mut &serialized.finalized_block_header.0[..])?,
babe_epoch_changes:
codec::Decode::decode(&mut &serialized.babe_epoch_changes.0[..])?,
babe_finalized_block_weight:
serialized.babe_finalized_block_weight,
grandpa_authority_set:
codec::Decode::decode(&mut &serialized.grandpa_authority_set.0[..])?,
})
}
}
Expand All @@ -426,7 +444,10 @@ impl<Block: BlockT> LightSyncState<Block> {
#[serde(rename_all = "camelCase")]
#[serde(deny_unknown_fields)]
pub struct SerializableLightSyncState {
header: StorageData,
finalized_block_header: StorageData,
babe_epoch_changes: StorageData,
babe_finalized_block_weight: sp_consensus_babe::BabeBlockWeight,
grandpa_authority_set: StorageData,
}

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion client/chain-spec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub trait RuntimeGenesis: Serialize + DeserializeOwned + BuildStorage {}
impl<T: Serialize + DeserializeOwned + BuildStorage> RuntimeGenesis for T {}

/// Common interface of a chain specification.
pub trait ChainSpec: BuildStorage + Send {
pub trait ChainSpec: BuildStorage + Send + Sync {
/// Spec name.
fn name(&self) -> &str;
/// Spec id.
Expand Down
3 changes: 3 additions & 0 deletions client/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ sp-state-machine = { version = "0.8.0", path = "../../primitives/state-machine"
sc-telemetry = { version = "2.0.0", path = "../telemetry" }
substrate-prometheus-endpoint = { path = "../../utils/prometheus" , version = "0.8.0"}
sp-keyring = { version = "2.0.0", path = "../../primitives/keyring" }
sc-consensus-babe = { version = "0.8.0", path = "../consensus/babe" }
sc-consensus-epochs = { version = "0.8.0", path = "../consensus/epochs" }
sc-finality-grandpa = { version = "0.8.0", path = "../finality-grandpa" }
names = "0.11.0"
structopt = "0.3.8"
sc-tracing = { version = "2.0.0", path = "../tracing" }
Expand Down
Loading