mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 18:07:58 +00:00
Kill the light client, CHTs and change tries. (#10080)
* Remove light client, change tries and CHTs * Update tests * fmt * Restore changes_root * Fixed benches * Cargo fmt * fmt * fmt
This commit is contained in:
@@ -23,7 +23,6 @@ use sc_service::client::genesis;
|
||||
use sp_core::{
|
||||
map,
|
||||
storage::{well_known_keys, Storage},
|
||||
ChangesTrieConfiguration,
|
||||
};
|
||||
use sp_io::hashing::{blake2_256, twox_128};
|
||||
use sp_runtime::traits::{Block as BlockT, Hash as HashT, Header as HeaderT};
|
||||
@@ -31,7 +30,6 @@ use std::collections::BTreeMap;
|
||||
|
||||
/// Configuration of a general Substrate test genesis block.
|
||||
pub struct GenesisConfig {
|
||||
changes_trie_config: Option<ChangesTrieConfiguration>,
|
||||
authorities: Vec<AuthorityId>,
|
||||
balances: Vec<(AccountId, u64)>,
|
||||
heap_pages_override: Option<u64>,
|
||||
@@ -41,7 +39,6 @@ pub struct GenesisConfig {
|
||||
|
||||
impl GenesisConfig {
|
||||
pub fn new(
|
||||
changes_trie_config: Option<ChangesTrieConfiguration>,
|
||||
authorities: Vec<AuthorityId>,
|
||||
endowed_accounts: Vec<AccountId>,
|
||||
balance: u64,
|
||||
@@ -49,7 +46,6 @@ impl GenesisConfig {
|
||||
extra_storage: Storage,
|
||||
) -> Self {
|
||||
GenesisConfig {
|
||||
changes_trie_config,
|
||||
authorities,
|
||||
balances: endowed_accounts.into_iter().map(|a| (a, balance)).collect(),
|
||||
heap_pages_override,
|
||||
@@ -77,9 +73,6 @@ impl GenesisConfig {
|
||||
.into_iter(),
|
||||
)
|
||||
.collect();
|
||||
if let Some(ref changes_trie_config) = self.changes_trie_config {
|
||||
map.insert(well_known_keys::CHANGES_TRIE_CONFIG.to_vec(), changes_trie_config.encode());
|
||||
}
|
||||
map.insert(twox_128(&b"sys:auth"[..])[..].to_vec(), self.authorities.encode());
|
||||
// Add the extra storage entries.
|
||||
map.extend(self.extra_storage.top.clone().into_iter());
|
||||
|
||||
@@ -28,7 +28,7 @@ use scale_info::TypeInfo;
|
||||
use sp_std::{marker::PhantomData, prelude::*};
|
||||
|
||||
use sp_application_crypto::{ecdsa, ed25519, sr25519, RuntimeAppPublic};
|
||||
use sp_core::{offchain::KeyTypeId, ChangesTrieConfiguration, OpaqueMetadata, RuntimeDebug};
|
||||
use sp_core::{offchain::KeyTypeId, OpaqueMetadata, RuntimeDebug};
|
||||
use sp_trie::{
|
||||
trie_types::{TrieDB, TrieDBMut},
|
||||
PrefixedMemoryDB, StorageProof,
|
||||
@@ -161,7 +161,6 @@ pub enum Extrinsic {
|
||||
},
|
||||
IncludeData(Vec<u8>),
|
||||
StorageChange(Vec<u8>, Option<Vec<u8>>),
|
||||
ChangesTrieConfigUpdate(Option<ChangesTrieConfiguration>),
|
||||
OffchainIndexSet(Vec<u8>, Vec<u8>),
|
||||
OffchainIndexClear(Vec<u8>),
|
||||
Store(Vec<u8>),
|
||||
@@ -197,8 +196,6 @@ impl BlindCheckable for Extrinsic {
|
||||
},
|
||||
Extrinsic::IncludeData(v) => Ok(Extrinsic::IncludeData(v)),
|
||||
Extrinsic::StorageChange(key, value) => Ok(Extrinsic::StorageChange(key, value)),
|
||||
Extrinsic::ChangesTrieConfigUpdate(new_config) =>
|
||||
Ok(Extrinsic::ChangesTrieConfigUpdate(new_config)),
|
||||
Extrinsic::OffchainIndexSet(key, value) => Ok(Extrinsic::OffchainIndexSet(key, value)),
|
||||
Extrinsic::OffchainIndexClear(key) => Ok(Extrinsic::OffchainIndexClear(key)),
|
||||
Extrinsic::Store(data) => Ok(Extrinsic::Store(data)),
|
||||
@@ -265,9 +262,9 @@ pub type BlockNumber = u64;
|
||||
/// Index of a transaction.
|
||||
pub type Index = u64;
|
||||
/// The item of a block digest.
|
||||
pub type DigestItem = sp_runtime::generic::DigestItem<H256>;
|
||||
pub type DigestItem = sp_runtime::generic::DigestItem;
|
||||
/// The digest of a block.
|
||||
pub type Digest = sp_runtime::generic::Digest<H256>;
|
||||
pub type Digest = sp_runtime::generic::Digest;
|
||||
/// A test block.
|
||||
pub type Block = sp_runtime::generic::Block<Header, Extrinsic>;
|
||||
/// A test block's header.
|
||||
@@ -1264,15 +1261,13 @@ fn test_witness(proof: StorageProof, root: crate::Hash) {
|
||||
let db: sp_trie::MemoryDB<crate::Hashing> = proof.into_memory_db();
|
||||
let backend = sp_state_machine::TrieBackend::<_, crate::Hashing>::new(db, root);
|
||||
let mut overlay = sp_state_machine::OverlayedChanges::default();
|
||||
let mut cache = sp_state_machine::StorageTransactionCache::<_, _, BlockNumber>::default();
|
||||
let mut cache = sp_state_machine::StorageTransactionCache::<_, _>::default();
|
||||
let mut ext = sp_state_machine::Ext::new(
|
||||
&mut overlay,
|
||||
&mut cache,
|
||||
&backend,
|
||||
#[cfg(feature = "std")]
|
||||
None,
|
||||
#[cfg(feature = "std")]
|
||||
None,
|
||||
);
|
||||
assert!(ext.storage(b"value3").is_some());
|
||||
assert!(ext.storage_root().as_slice() == &root[..]);
|
||||
|
||||
@@ -24,12 +24,8 @@ use crate::{
|
||||
use codec::{Decode, Encode, KeyedVec};
|
||||
use frame_support::{decl_module, decl_storage, storage};
|
||||
use frame_system::Config;
|
||||
use sp_core::{storage::well_known_keys, ChangesTrieConfiguration};
|
||||
use sp_io::{
|
||||
hashing::blake2_256,
|
||||
storage::{changes_root as storage_changes_root, root as storage_root},
|
||||
trie,
|
||||
};
|
||||
use sp_core::storage::well_known_keys;
|
||||
use sp_io::{hashing::blake2_256, storage::root as storage_root, trie};
|
||||
use sp_runtime::{
|
||||
generic,
|
||||
traits::Header as _,
|
||||
@@ -54,7 +50,6 @@ decl_storage! {
|
||||
Number get(fn number): Option<BlockNumber>;
|
||||
ParentHash get(fn parent_hash): Hash;
|
||||
NewAuthorities get(fn new_authorities): Option<Vec<AuthorityId>>;
|
||||
NewChangesTrieConfig get(fn new_changes_trie_config): Option<Option<ChangesTrieConfiguration>>;
|
||||
StorageDigest get(fn storage_digest): Option<Digest>;
|
||||
Authorities get(fn authorities) config(): Vec<AuthorityId>;
|
||||
}
|
||||
@@ -207,30 +202,17 @@ pub fn finalize_block() -> Header {
|
||||
let mut digest = <StorageDigest>::take().expect("StorageDigest is set by `initialize_block`");
|
||||
|
||||
let o_new_authorities = <NewAuthorities>::take();
|
||||
let new_changes_trie_config = <NewChangesTrieConfig>::take();
|
||||
|
||||
// This MUST come after all changes to storage are done. Otherwise we will fail the
|
||||
// “Storage root does not match that calculated” assertion.
|
||||
let storage_root =
|
||||
Hash::decode(&mut &storage_root()[..]).expect("`storage_root` is a valid hash");
|
||||
let storage_changes_root = storage_changes_root(&parent_hash.encode())
|
||||
.map(|r| Hash::decode(&mut &r[..]).expect("`storage_changes_root` is a valid hash"));
|
||||
|
||||
if let Some(storage_changes_root) = storage_changes_root {
|
||||
digest.push(generic::DigestItem::ChangesTrieRoot(storage_changes_root));
|
||||
}
|
||||
|
||||
if let Some(new_authorities) = o_new_authorities {
|
||||
digest.push(generic::DigestItem::Consensus(*b"aura", new_authorities.encode()));
|
||||
digest.push(generic::DigestItem::Consensus(*b"babe", new_authorities.encode()));
|
||||
}
|
||||
|
||||
if let Some(new_config) = new_changes_trie_config {
|
||||
digest.push(generic::DigestItem::ChangesTrieSignal(
|
||||
generic::ChangesTrieSignal::NewConfiguration(new_config),
|
||||
));
|
||||
}
|
||||
|
||||
Header { number, extrinsics_root, state_root: storage_root, parent_hash, digest }
|
||||
}
|
||||
|
||||
@@ -251,8 +233,6 @@ fn execute_transaction_backend(utx: &Extrinsic, extrinsic_index: u32) -> ApplyEx
|
||||
Extrinsic::IncludeData(_) => Ok(Ok(())),
|
||||
Extrinsic::StorageChange(key, value) =>
|
||||
execute_storage_change(key, value.as_ref().map(|v| &**v)),
|
||||
Extrinsic::ChangesTrieConfigUpdate(ref new_config) =>
|
||||
execute_changes_trie_config_update(new_config.clone()),
|
||||
Extrinsic::OffchainIndexSet(key, value) => {
|
||||
sp_io::offchain_index::set(&key, &value);
|
||||
Ok(Ok(()))
|
||||
@@ -311,18 +291,6 @@ fn execute_storage_change(key: &[u8], value: Option<&[u8]>) -> ApplyExtrinsicRes
|
||||
Ok(Ok(()))
|
||||
}
|
||||
|
||||
fn execute_changes_trie_config_update(
|
||||
new_config: Option<ChangesTrieConfiguration>,
|
||||
) -> ApplyExtrinsicResult {
|
||||
match new_config.clone() {
|
||||
Some(new_config) =>
|
||||
storage::unhashed::put_raw(well_known_keys::CHANGES_TRIE_CONFIG, &new_config.encode()),
|
||||
None => storage::unhashed::kill(well_known_keys::CHANGES_TRIE_CONFIG),
|
||||
}
|
||||
<NewChangesTrieConfig>::put(new_config);
|
||||
Ok(Ok(()))
|
||||
}
|
||||
|
||||
#[cfg(feature = "std")]
|
||||
fn info_expect_equal_hash(given: &Hash, expected: &Hash) {
|
||||
use sp_core::hexdisplay::HexDisplay;
|
||||
|
||||
Reference in New Issue
Block a user