mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 20:11:09 +00:00
Allow updating configuration of changes tries (#3201)
* DigestItem::ChangesTrieSignal * introduce changes_trie::State * introduce config activation block * ChangesTrieSignal::as_new_configuration * moved well_known_cache_keys to client * extracted DbChangesTrieStorage to separate file * change meaning of none in blockchain cache * changes trie config (FULL) cache draft * eliminating const ChangesTrieConfiguration * delay pruning * continue elimination * do not prune CT config from cache * removed redundant code * fix some TODOs * introduce ConfigurationRange * use Configuration range in build * build skewed digest * remove debug print * extracted surface iterator * key_changes works with skewed digests * fix client build * add test for NeverPrune * fix TODO * fixed some TODOs * more tests * fixing TODOs * fixed compilation * update runtime version * git rid of large tuple * too long lines * config_activation_block -> zero * obsolete TODO * removed unjustified expect * update TODOs with issue number * new CT pruning algorithm fixed cache + multiple blocks finalization track CT configuraiton on light clients support CT configuration change revert revert CT config test new CT pruning algorithm fixed cache + multiple blocks finalization track CT configuraiton on light clients support CT configuration change revert revert CT config test * BlockIdOrHeader isn't really required * removed debug leftovers + some docs * more docs * more post-merge fixes * more post-merge fixes * revertes some unnecessary changes * reverted unnecessary changes * fix compilation + unnecessary changes * (restart CI) * fix cache update when finalizing multiple blocks * fixed tests * collect_extrinsics -> set_collect_extrinsics * restore lost test * do not calculate block number twice * Update primitives/blockchain/src/error.rs Co-Authored-By: cheme <emericchevalier.pro@gmail.com> * map_err -> unwrap_or * document get_at Result * delete abandoned file * added weight for set_changes_trie_config * prefer_configs -> fail_if_disabled * Update client/api/src/backend.rs Co-Authored-By: cheme <emericchevalier.pro@gmail.com> * Update client/db/src/changes_tries_storage.rs Co-Authored-By: cheme <emericchevalier.pro@gmail.com> * CommitOperation+merge -> CommitOperations * fixed test compilation * merged two different CTRange structs * lost file * uggrade db from v0 to v1 (init CT cache + add column) * fix after merge Co-authored-by: cheme <emericchevalier.pro@gmail.com> Co-authored-by: Gavin Wood <github@gavwood.com>
This commit is contained in:
committed by
Gavin Wood
parent
45fbf09dac
commit
febf29390a
@@ -23,7 +23,7 @@ use sp_std::prelude::*;
|
||||
|
||||
use crate::ConsensusEngineId;
|
||||
use crate::codec::{Decode, Encode, Input, Error};
|
||||
use sp_core::RuntimeDebug;
|
||||
use sp_core::{ChangesTrieConfiguration, RuntimeDebug};
|
||||
|
||||
/// Generic header digest.
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode, RuntimeDebug)]
|
||||
@@ -97,10 +97,32 @@ pub enum DigestItem<Hash> {
|
||||
/// by runtimes.
|
||||
Seal(ConsensusEngineId, Vec<u8>),
|
||||
|
||||
/// Digest item that contains signal from changes tries manager to the
|
||||
/// native code.
|
||||
ChangesTrieSignal(ChangesTrieSignal),
|
||||
|
||||
/// Some other thing. Unsupported and experimental.
|
||||
Other(Vec<u8>),
|
||||
}
|
||||
|
||||
/// Available changes trie signals.
|
||||
#[derive(PartialEq, Eq, Clone, Encode, Decode)]
|
||||
#[cfg_attr(feature = "std", derive(Debug))]
|
||||
pub enum ChangesTrieSignal {
|
||||
/// New changes trie configuration is enacted, starting from **next block**.
|
||||
///
|
||||
/// The block that emits this signal will contain changes trie (CT) that covers
|
||||
/// blocks range [BEGIN; current block], where BEGIN is (order matters):
|
||||
/// - LAST_TOP_LEVEL_DIGEST_BLOCK+1 if top level digest CT has ever been created
|
||||
/// using current configuration AND the last top level digest CT has been created
|
||||
/// at block LAST_TOP_LEVEL_DIGEST_BLOCK;
|
||||
/// - LAST_CONFIGURATION_CHANGE_BLOCK+1 if there has been CT configuration change
|
||||
/// before and the last configuration change happened at block
|
||||
/// LAST_CONFIGURATION_CHANGE_BLOCK;
|
||||
/// - 1 otherwise.
|
||||
NewConfiguration(Option<ChangesTrieConfiguration>),
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
impl<Hash: Encode> serde::Serialize for DigestItem<Hash> {
|
||||
fn serialize<S>(&self, seq: S) -> Result<S::Ok, S::Error> where S: serde::Serializer {
|
||||
@@ -141,6 +163,9 @@ pub enum DigestItemRef<'a, Hash: 'a> {
|
||||
/// Put a Seal on it. This is only used by native code, and is never seen
|
||||
/// by runtimes.
|
||||
Seal(&'a ConsensusEngineId, &'a Vec<u8>),
|
||||
/// Digest item that contains signal from changes tries manager to the
|
||||
/// native code.
|
||||
ChangesTrieSignal(&'a ChangesTrieSignal),
|
||||
/// Any 'non-system' digest item, opaque to the native code.
|
||||
Other(&'a Vec<u8>),
|
||||
}
|
||||
@@ -152,11 +177,12 @@ pub enum DigestItemRef<'a, Hash: 'a> {
|
||||
#[repr(u32)]
|
||||
#[derive(Encode, Decode)]
|
||||
pub enum DigestItemType {
|
||||
Other = 0,
|
||||
ChangesTrieRoot = 2,
|
||||
PreRuntime = 6,
|
||||
Consensus = 4,
|
||||
Seal = 5,
|
||||
Other = 0,
|
||||
PreRuntime = 6,
|
||||
ChangesTrieSignal = 7,
|
||||
}
|
||||
|
||||
/// Type of a digest item that contains raw data; this also names the consensus engine ID where
|
||||
@@ -181,6 +207,7 @@ impl<Hash> DigestItem<Hash> {
|
||||
DigestItem::PreRuntime(ref v, ref s) => DigestItemRef::PreRuntime(v, s),
|
||||
DigestItem::Consensus(ref v, ref s) => DigestItemRef::Consensus(v, s),
|
||||
DigestItem::Seal(ref v, ref s) => DigestItemRef::Seal(v, s),
|
||||
DigestItem::ChangesTrieSignal(ref s) => DigestItemRef::ChangesTrieSignal(s),
|
||||
DigestItem::Other(ref v) => DigestItemRef::Other(v),
|
||||
}
|
||||
}
|
||||
@@ -205,6 +232,11 @@ impl<Hash> DigestItem<Hash> {
|
||||
self.dref().as_seal()
|
||||
}
|
||||
|
||||
/// Returns `Some` if the entry is the `ChangesTrieSignal` entry.
|
||||
pub fn as_changes_trie_signal(&self) -> Option<&ChangesTrieSignal> {
|
||||
self.dref().as_changes_trie_signal()
|
||||
}
|
||||
|
||||
/// Returns Some if `self` is a `DigestItem::Other`.
|
||||
pub fn as_other(&self) -> Option<&[u8]> {
|
||||
match *self {
|
||||
@@ -253,6 +285,9 @@ impl<Hash: Decode> Decode for DigestItem<Hash> {
|
||||
let vals: (ConsensusEngineId, Vec<u8>) = Decode::decode(input)?;
|
||||
Ok(DigestItem::Seal(vals.0, vals.1))
|
||||
},
|
||||
DigestItemType::ChangesTrieSignal => Ok(DigestItem::ChangesTrieSignal(
|
||||
Decode::decode(input)?,
|
||||
)),
|
||||
DigestItemType::Other => Ok(DigestItem::Other(
|
||||
Decode::decode(input)?,
|
||||
)),
|
||||
@@ -293,6 +328,14 @@ impl<'a, Hash> DigestItemRef<'a, Hash> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Cast this digest item into `ChangesTrieSignal`.
|
||||
pub fn as_changes_trie_signal(&self) -> Option<&'a ChangesTrieSignal> {
|
||||
match *self {
|
||||
DigestItemRef::ChangesTrieSignal(ref changes_trie_signal) => Some(changes_trie_signal),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Cast this digest item into `PreRuntime`
|
||||
pub fn as_other(&self) -> Option<&'a [u8]> {
|
||||
match *self {
|
||||
@@ -342,6 +385,10 @@ impl<'a, Hash: Encode> Encode for DigestItemRef<'a, Hash> {
|
||||
DigestItemType::PreRuntime.encode_to(&mut v);
|
||||
(val, data).encode_to(&mut v);
|
||||
},
|
||||
DigestItemRef::ChangesTrieSignal(changes_trie_signal) => {
|
||||
DigestItemType::ChangesTrieSignal.encode_to(&mut v);
|
||||
changes_trie_signal.encode_to(&mut v);
|
||||
},
|
||||
DigestItemRef::Other(val) => {
|
||||
DigestItemType::Other.encode_to(&mut v);
|
||||
val.encode_to(&mut v);
|
||||
@@ -352,6 +399,15 @@ impl<'a, Hash: Encode> Encode for DigestItemRef<'a, Hash> {
|
||||
}
|
||||
}
|
||||
|
||||
impl ChangesTrieSignal {
|
||||
/// Try to cast this signal to NewConfiguration.
|
||||
pub fn as_new_configuration(&self) -> Option<&Option<ChangesTrieConfiguration>> {
|
||||
match self {
|
||||
ChangesTrieSignal::NewConfiguration(config) => Some(config),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, Hash: Encode> codec::EncodeLike for DigestItemRef<'a, Hash> {}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -33,7 +33,7 @@ pub use self::checked_extrinsic::CheckedExtrinsic;
|
||||
pub use self::header::Header;
|
||||
pub use self::block::{Block, SignedBlock, BlockId};
|
||||
pub use self::digest::{
|
||||
Digest, DigestItem, DigestItemRef, OpaqueDigestItemId
|
||||
Digest, DigestItem, DigestItemRef, OpaqueDigestItemId, ChangesTrieSignal,
|
||||
};
|
||||
|
||||
use crate::codec::Encode;
|
||||
|
||||
Reference in New Issue
Block a user