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 13 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
10 changes: 10 additions & 0 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions bin/node-template/node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
block_announce_validator_builder: None,
finality_proof_request_builder: None,
finality_proof_provider: Some(finality_proof_provider.clone()),
sync_state_items: None,
})?;

if config.offchain_worker.enabled {
Expand Down Expand Up @@ -273,6 +274,7 @@ pub fn new_light(config: Configuration) -> Result<TaskManager, ServiceError> {
block_announce_validator_builder: None,
finality_proof_request_builder: Some(finality_proof_request_builder),
finality_proof_provider: Some(finality_proof_provider),
sync_state_items: None,
})?;

if config.offchain_worker.enabled {
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 @@ -100,17 +100,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
9 changes: 7 additions & 2 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ pub fn new_full_base(
} = new_partial(&config)?;

let (shared_voter_state, finality_proof_provider) = rpc_setup;
let (block_import, grandpa_link, babe_link) = import_setup;
let shared_authority_set = grandpa_link.shared_authority_set().clone();
let shared_epoch_changes = babe_link.epoch_changes().clone();

let (network, network_status_sinks, system_rpc_tx, network_starter) =
sc_service::build_network(sc_service::BuildNetworkParams {
Expand All @@ -192,6 +195,9 @@ pub fn new_full_base(
block_announce_validator_builder: None,
finality_proof_request_builder: None,
finality_proof_provider: Some(finality_proof_provider.clone()),
sync_state_items: Some((
shared_authority_set.clone(), shared_epoch_changes.clone(),
))
})?;

if config.offchain_worker.enabled {
Expand Down Expand Up @@ -223,8 +229,6 @@ pub fn new_full_base(
system_rpc_tx,
})?;

let (block_import, grandpa_link, babe_link) = import_setup;

(with_startup_data)(&block_import, &babe_link);

if let sc_service::config::Role::Authority { .. } = &role {
Expand Down Expand Up @@ -414,6 +418,7 @@ pub fn new_light_base(config: Configuration) -> Result<(
block_announce_validator_builder: None,
finality_proof_request_builder: Some(finality_proof_request_builder),
finality_proof_provider: Some(finality_proof_provider),
sync_state_items: None,
})?;
network_starter.start_network();

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" }
44 changes: 38 additions & 6 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 @@ -333,6 +333,13 @@ impl<G: RuntimeGenesis, E: serde::Serialize + Clone + 'static> ChainSpec<G, E> {
json::to_string_pretty(&container)
.map_err(|e| format!("Error generating spec json: {}", e))
}

/// Dump to json value
pub fn as_json_value(&self, raw: bool) -> Result<json::Value, String> {
let container = self.json_container(raw)?;
json::to_value(container)
.map_err(|e| format!("Error generating spec json: {}", e))
}
}

impl<G, E> crate::ChainSpec for ChainSpec<G, E>
Expand Down Expand Up @@ -380,6 +387,10 @@ where
ChainSpec::as_json(self, raw)
}

fn as_json_value(&self, raw: bool) -> Result<serde_json::Value, String> {
ChainSpec::as_json_value(self, raw)
}

fn as_storage_builder(&self) -> &dyn BuildStorage {
self
}
Expand All @@ -400,7 +411,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 +426,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 +455,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: 2 additions & 0 deletions client/chain-spec/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ pub trait ChainSpec: BuildStorage + Send {
fn add_boot_node(&mut self, addr: MultiaddrWithPeerId);
/// Return spec as JSON.
fn as_json(&self, raw: bool) -> Result<String, String>;
/// Return spec as JSON value.
fn as_json_value(&self, raw: bool) -> Result<serde_json::Value, String>;
expenses marked this conversation as resolved.
Show resolved Hide resolved
/// Return StorageBuilder for this spec.
fn as_storage_builder(&self) -> &dyn BuildStorage;
/// Returns a cloned `Box<dyn ChainSpec>`.
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
113 changes: 0 additions & 113 deletions client/cli/src/commands/build_sync_spec_cmd.rs

This file was deleted.

2 changes: 0 additions & 2 deletions client/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
mod build_spec_cmd;
mod build_sync_spec_cmd;
mod check_block_cmd;
mod export_blocks_cmd;
mod export_state_cmd;
Expand All @@ -37,7 +36,6 @@ pub mod utils;

pub use self::{
build_spec_cmd::BuildSpecCmd,
build_sync_spec_cmd::BuildSyncSpecCmd,
check_block_cmd::CheckBlockCmd,
export_blocks_cmd::ExportBlocksCmd,
export_state_cmd::ExportStateCmd,
Expand Down
2 changes: 1 addition & 1 deletion client/consensus/babe/src/aux_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub(crate) fn write_block_weight<H: Encode, F, R>(
}

/// Load the cumulative chain-weight associated with a block.
pub(crate) fn load_block_weight<H: Encode, B: AuxStore>(
pub fn load_block_weight<H: Encode, B: AuxStore>(
backend: &B,
block_hash: H,
) -> ClientResult<Option<BabeBlockWeight>> {
Expand Down
Loading