Add missing fields to the light sync state (#7225)

* Initial draft

* Add an iterator that helps us get most items

* Revert changes to grandpa

* Change fields to just be the grandpa authority set and babe epoch changes

* Only use the fields we need from the shared authority set

* Switch to RPC call

* Revert "Only use the fields we need from the shared authority set"

This reverts commit 6ede87b0c5fe53f251d7cb45951006a7dc8f9b83.

* Add babe_finalized_block_weight from `ashley-improve-sync-state-WIP-loading`

* Fix rpc test

* Move sync state rpc stuff into sc-sync-state-rpc

* Remove as_json_value and remove unwraps from sc-sync-state-rpc

* Add clone_inner to SharedAuthoritySet
This commit is contained in:
Ashley
2020-10-15 12:10:43 +02:00
committed by GitHub
parent a297e447f2
commit d1ef8507d7
22 changed files with 263 additions and 195 deletions
+28 -7
View File
@@ -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),
@@ -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);
}
}
@@ -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)
@@ -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> {
@@ -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[..])?,
})
}
}
@@ -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)]