Set StateBackend::Transaction to PrefixedMemoryDB (#14612)

* Yep

* Try to get it working everywhere

* Make `from_raw_storage` start with an empty db

* More fixes!

* Make everything compile

* Fix `child_storage_root`

* Fix after merge

* Cleanups

* Update primitives/state-machine/src/overlayed_changes/mod.rs

Co-authored-by: Davide Galassi <davxy@datawok.net>

* Review comments

* Fix issues

* Silence warning

* FMT

* Clippy

---------

Co-authored-by: Davide Galassi <davxy@datawok.net>
This commit is contained in:
Bastian Köcher
2023-08-17 12:49:38 +02:00
committed by GitHub
parent a892fa7f92
commit ecf8035da6
67 changed files with 750 additions and 1150 deletions
+5 -6
View File
@@ -32,8 +32,8 @@ use sp_runtime::{
StateVersion, Storage,
};
use sp_state_machine::{
backend::Backend as StateBackend, ChildStorageCollection, DBValue, IterArgs, StorageCollection,
StorageIterator, StorageKey, StorageValue,
backend::Backend as StateBackend, BackendTransaction, ChildStorageCollection, DBValue,
IterArgs, StorageCollection, StorageIterator, StorageKey, StorageValue,
};
use sp_trie::{
cache::{CacheSize, SharedTrieCache},
@@ -343,7 +343,6 @@ fn state_err() -> String {
impl<B: BlockT> StateBackend<HashingFor<B>> for BenchmarkingState<B> {
type Error = <DbState<B> as StateBackend<HashingFor<B>>>::Error;
type Transaction = <DbState<B> as StateBackend<HashingFor<B>>>::Transaction;
type TrieBackendStorage = <DbState<B> as StateBackend<HashingFor<B>>>::TrieBackendStorage;
type RawIter = RawIter<B>;
@@ -423,7 +422,7 @@ impl<B: BlockT> StateBackend<HashingFor<B>> for BenchmarkingState<B> {
&self,
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
state_version: StateVersion,
) -> (B::Hash, Self::Transaction) {
) -> (B::Hash, BackendTransaction<HashingFor<B>>) {
self.state
.borrow()
.as_ref()
@@ -435,7 +434,7 @@ impl<B: BlockT> StateBackend<HashingFor<B>> for BenchmarkingState<B> {
child_info: &ChildInfo,
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
state_version: StateVersion,
) -> (B::Hash, bool, Self::Transaction) {
) -> (B::Hash, bool, BackendTransaction<HashingFor<B>>) {
self.state
.borrow()
.as_ref()
@@ -460,7 +459,7 @@ impl<B: BlockT> StateBackend<HashingFor<B>> for BenchmarkingState<B> {
fn commit(
&self,
storage_root: <HashingFor<B> as Hasher>::Out,
mut transaction: Self::Transaction,
mut transaction: BackendTransaction<HashingFor<B>>,
main_storage_changes: StorageCollection,
child_storage_changes: ChildStorageCollection,
) -> Result<(), Self::Error> {
+5 -6
View File
@@ -86,9 +86,9 @@ use sp_runtime::{
};
use sp_state_machine::{
backend::{AsTrieBackend, Backend as StateBackend},
ChildStorageCollection, DBValue, IndexOperation, IterArgs, OffchainChangesCollection,
StateMachineStats, StorageCollection, StorageIterator, StorageKey, StorageValue,
UsageInfo as StateUsageInfo,
BackendTransaction, ChildStorageCollection, DBValue, IndexOperation, IterArgs,
OffchainChangesCollection, StateMachineStats, StorageCollection, StorageIterator, StorageKey,
StorageValue, UsageInfo as StateUsageInfo,
};
use sp_trie::{cache::SharedTrieCache, prefixed_key, MemoryDB, PrefixedMemoryDB};
@@ -187,7 +187,6 @@ impl<B: BlockT> StorageIterator<HashingFor<B>> for RawIter<B> {
impl<B: BlockT> StateBackend<HashingFor<B>> for RefTrackingState<B> {
type Error = <DbState<B> as StateBackend<HashingFor<B>>>::Error;
type Transaction = <DbState<B> as StateBackend<HashingFor<B>>>::Transaction;
type TrieBackendStorage = <DbState<B> as StateBackend<HashingFor<B>>>::TrieBackendStorage;
type RawIter = RawIter<B>;
@@ -243,7 +242,7 @@ impl<B: BlockT> StateBackend<HashingFor<B>> for RefTrackingState<B> {
&self,
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
state_version: StateVersion,
) -> (B::Hash, Self::Transaction) {
) -> (B::Hash, BackendTransaction<HashingFor<B>>) {
self.state.storage_root(delta, state_version)
}
@@ -252,7 +251,7 @@ impl<B: BlockT> StateBackend<HashingFor<B>> for RefTrackingState<B> {
child_info: &ChildInfo,
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
state_version: StateVersion,
) -> (B::Hash, bool, Self::Transaction) {
) -> (B::Hash, bool, BackendTransaction<HashingFor<B>>) {
self.state.child_storage_root(child_info, delta, state_version)
}
@@ -26,7 +26,7 @@ use sp_runtime::{
};
use sp_state_machine::{
backend::{AsTrieBackend, Backend as StateBackend},
IterArgs, StorageIterator, StorageKey, StorageValue, TrieBackend,
BackendTransaction, IterArgs, StorageIterator, StorageKey, StorageValue, TrieBackend,
};
use std::sync::Arc;
@@ -109,7 +109,6 @@ impl<S: StateBackend<HashingFor<B>>, B: BlockT> StateBackend<HashingFor<B>>
for RecordStatsState<S, B>
{
type Error = S::Error;
type Transaction = S::Transaction;
type TrieBackendStorage = S::TrieBackendStorage;
type RawIter = RawIter<S, B>;
@@ -173,7 +172,7 @@ impl<S: StateBackend<HashingFor<B>>, B: BlockT> StateBackend<HashingFor<B>>
&self,
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
state_version: StateVersion,
) -> (B::Hash, Self::Transaction) {
) -> (B::Hash, BackendTransaction<HashingFor<B>>) {
self.state.storage_root(delta, state_version)
}
@@ -182,7 +181,7 @@ impl<S: StateBackend<HashingFor<B>>, B: BlockT> StateBackend<HashingFor<B>>
child_info: &ChildInfo,
delta: impl Iterator<Item = (&'a [u8], Option<&'a [u8]>)>,
state_version: StateVersion,
) -> (B::Hash, bool, Self::Transaction) {
) -> (B::Hash, bool, BackendTransaction<HashingFor<B>>) {
self.state.child_storage_root(child_info, delta, state_version)
}