Skip to content

Commit

Permalink
Revert "Inner hashing of value in state trie (runtime versioning). (p…
Browse files Browse the repository at this point in the history
…aritytech#9732)"

This reverts commit b03e8bc.
  • Loading branch information
librelois committed Feb 5, 2022
1 parent 1d2fe38 commit 7a6dc6e
Show file tree
Hide file tree
Showing 78 changed files with 773 additions and 1,805 deletions.
30 changes: 9 additions & 21 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion bin/node-template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
state_version: 1,
};

/// This determines the average expected block time that we are targeting.
Expand Down
5 changes: 3 additions & 2 deletions bin/node/bench/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::{collections::HashMap, sync::Arc};

use kvdb::KeyValueDB;
use node_primitives::Hash;
use sp_trie::{trie_types::TrieDBMutV1, TrieMut};
use sp_trie::{trie_types::TrieDBMut, TrieMut};

use crate::simple_trie::SimpleTrie;

Expand All @@ -43,7 +43,8 @@ pub fn generate_trie(
);
let mut trie = SimpleTrie { db, overlay: &mut overlay };
{
let mut trie_db = TrieDBMutV1::<crate::simple_trie::Hasher>::new(&mut trie, &mut root);
let mut trie_db = TrieDBMut::new(&mut trie, &mut root);

for (key, value) in key_values {
trie_db.insert(&key, &value).expect("trie insertion failed");
}
Expand Down
6 changes: 3 additions & 3 deletions bin/node/bench/src/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use kvdb::KeyValueDB;
use lazy_static::lazy_static;
use rand::Rng;
use sp_state_machine::Backend as _;
use sp_trie::{trie_types::TrieDBMutV1, TrieMut as _};
use sp_trie::{trie_types::TrieDBMut, TrieMut as _};
use std::{borrow::Cow, collections::HashMap, sync::Arc};

use node_primitives::Hash;
Expand Down Expand Up @@ -286,8 +286,8 @@ impl core::Benchmark for TrieWriteBenchmark {

let mut overlay = HashMap::new();
let mut trie = SimpleTrie { db: kvdb.clone(), overlay: &mut overlay };
let mut trie_db_mut = TrieDBMutV1::from_existing(&mut trie, &mut new_root)
.expect("Failed to create TrieDBMut");
let mut trie_db_mut =
TrieDBMut::from_existing(&mut trie, &mut new_root).expect("Failed to create TrieDBMut");

for (warmup_key, warmup_value) in self.warmup_keys.iter() {
let value = trie_db_mut
Expand Down
4 changes: 2 additions & 2 deletions bin/node/executor/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ fn construct_block<E: Externalities>(
parent_hash: Hash,
extrinsics: Vec<CheckedExtrinsic>,
) -> (Vec<u8>, Hash) {
use sp_trie::{LayoutV0, TrieConfiguration};
use sp_trie::{trie_types::Layout, TrieConfiguration};

// sign extrinsics.
let extrinsics = extrinsics.into_iter().map(sign).collect::<Vec<_>>();

// calculate the header fields that we can.
let extrinsics_root =
LayoutV0::<BlakeTwo256>::ordered_trie_root(extrinsics.iter().map(Encode::encode))
Layout::<BlakeTwo256>::ordered_trie_root(extrinsics.iter().map(Encode::encode))
.to_fixed_bytes()
.into();

Expand Down
2 changes: 1 addition & 1 deletion bin/node/executor/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub fn construct_block(
extrinsics: Vec<CheckedExtrinsic>,
babe_slot: Slot,
) -> (Vec<u8>, Hash) {
use sp_trie::{LayoutV1 as Layout, TrieConfiguration};
use sp_trie::{trie_types::Layout, TrieConfiguration};

// sign extrinsics.
let extrinsics = extrinsics.into_iter().map(sign).collect::<Vec<_>>();
Expand Down
1 change: 0 additions & 1 deletion bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
state_version: 1,
};

/// The BABE epoch configuration at genesis.
Expand Down
9 changes: 2 additions & 7 deletions client/api/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use sp_core::offchain::OffchainStorage;
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, HashFor, NumberFor},
Justification, Justifications, StateVersion, Storage,
Justification, Justifications, Storage,
};
use sp_state_machine::{
ChildStorageCollection, IndexOperation, OffchainChangesCollection, StorageCollection,
Expand Down Expand Up @@ -178,15 +178,10 @@ pub trait BlockImportOperation<Block: BlockT> {
&mut self,
storage: Storage,
commit: bool,
state_version: StateVersion,
) -> sp_blockchain::Result<Block::Hash>;

/// Inject storage data into the database replacing any existing data.
fn reset_storage(
&mut self,
storage: Storage,
state_version: StateVersion,
) -> sp_blockchain::Result<Block::Hash>;
fn reset_storage(&mut self, storage: Storage) -> sp_blockchain::Result<Block::Hash>;

/// Set storage changes.
fn update_storage(
Expand Down
4 changes: 2 additions & 2 deletions client/api/src/call_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//! A method call executor interface.

use codec::{Decode, Encode};
use sc_executor::{RuntimeVersion, RuntimeVersionOf};
use sc_executor::RuntimeVersion;
use sp_core::NativeOrEncoded;
use sp_externalities::Extensions;
use sp_runtime::{generic::BlockId, traits::Block as BlockT};
Expand All @@ -42,7 +42,7 @@ pub trait ExecutorProvider<Block: BlockT> {
}

/// Method call executor.
pub trait CallExecutor<B: BlockT>: RuntimeVersionOf {
pub trait CallExecutor<B: BlockT> {
/// Externalities error type.
type Error: sp_state_machine::Error;

Expand Down
15 changes: 4 additions & 11 deletions client/api/src/in_mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use sp_core::{
use sp_runtime::{
generic::BlockId,
traits::{Block as BlockT, HashFor, Header as HeaderT, NumberFor, Zero},
Justification, Justifications, StateVersion, Storage,
Justification, Justifications, Storage,
};
use sp_state_machine::{
Backend as StateBackend, ChildStorageCollection, InMemoryBackend, IndexOperation,
Expand Down Expand Up @@ -506,7 +506,6 @@ where
&mut self,
storage: Storage,
commit: bool,
state_version: StateVersion,
) -> sp_blockchain::Result<Block::Hash> {
check_genesis_storage(&storage)?;

Expand All @@ -520,7 +519,6 @@ where
let (root, transaction) = self.old_state.full_storage_root(
storage.top.iter().map(|(k, v)| (k.as_ref(), Some(v.as_ref()))),
child_delta,
state_version,
);

if commit {
Expand Down Expand Up @@ -568,17 +566,12 @@ where
&mut self,
storage: Storage,
commit: bool,
state_version: StateVersion,
) -> sp_blockchain::Result<Block::Hash> {
self.apply_storage(storage, commit, state_version)
self.apply_storage(storage, commit)
}

fn reset_storage(
&mut self,
storage: Storage,
state_version: StateVersion,
) -> sp_blockchain::Result<Block::Hash> {
self.apply_storage(storage, true, state_version)
fn reset_storage(&mut self, storage: Storage) -> sp_blockchain::Result<Block::Hash> {
self.apply_storage(storage, true)
}

fn insert_aux<I>(&mut self, ops: I) -> sp_blockchain::Result<()>
Expand Down
1 change: 0 additions & 1 deletion client/block-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ where
header.extrinsics_root().clone(),
HashFor::<Block>::ordered_trie_root(
self.extrinsics.iter().map(Encode::encode).collect(),
sp_runtime::StateVersion::V0,
),
);

Expand Down
13 changes: 4 additions & 9 deletions client/db/src/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use sp_core::{
};
use sp_runtime::{
traits::{Block as BlockT, HashFor},
StateVersion, Storage,
Storage,
};
use sp_state_machine::{
backend::Backend as StateBackend, ChildStorageCollection, DBValue, ProofRecorder,
Expand Down Expand Up @@ -73,7 +73,6 @@ impl<Block: BlockT> sp_state_machine::Storage<HashFor<Block>> for StorageDb<Bloc
}
}
}

/// State that manages the backend database reference. Allows runtime to control the database.
pub struct BenchmarkingState<B: BlockT> {
root: Cell<B::Hash>,
Expand Down Expand Up @@ -106,10 +105,9 @@ impl<B: BlockT> BenchmarkingState<B> {
record_proof: bool,
enable_tracking: bool,
) -> Result<Self, String> {
let state_version = sp_runtime::StateVersion::default();
let mut root = B::Hash::default();
let mut mdb = MemoryDB::<HashFor<B>>::default();
sp_state_machine::TrieDBMutV1::<HashFor<B>>::new(&mut mdb, &mut root);
sp_state_machine::TrieDBMut::<HashFor<B>>::new(&mut mdb, &mut root);

let mut state = BenchmarkingState {
state: RefCell::new(None),
Expand Down Expand Up @@ -140,7 +138,6 @@ impl<B: BlockT> BenchmarkingState<B> {
state.state.borrow_mut().as_mut().unwrap().full_storage_root(
genesis.top.iter().map(|(k, v)| (k.as_ref(), Some(v.as_ref()))),
child_delta,
state_version,
);
state.genesis = transaction.clone().drain();
state.genesis_root = root.clone();
Expand Down Expand Up @@ -418,30 +415,28 @@ impl<B: BlockT> StateBackend<HashFor<B>> for BenchmarkingState<B> {
fn storage_root<'a>(
&self,
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
state_version: StateVersion,
) -> (B::Hash, Self::Transaction)
where
B::Hash: Ord,
{
self.state
.borrow()
.as_ref()
.map_or(Default::default(), |s| s.storage_root(delta, state_version))
.map_or(Default::default(), |s| s.storage_root(delta))
}

fn child_storage_root<'a>(
&self,
child_info: &ChildInfo,
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
state_version: StateVersion,
) -> (B::Hash, bool, Self::Transaction)
where
B::Hash: Ord,
{
self.state
.borrow()
.as_ref()
.map_or(Default::default(), |s| s.child_storage_root(child_info, delta, state_version))
.map_or(Default::default(), |s| s.child_storage_root(child_info, delta))
}

fn pairs(&self) -> Vec<(Vec<u8>, Vec<u8>)> {
Expand Down
Loading

0 comments on commit 7a6dc6e

Please sign in to comment.