-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Set StateBackend::Transaction
to PrefixedMemoryDB
#14612
Set StateBackend::Transaction
to PrefixedMemoryDB
#14612
Conversation
…e-transaction-cache
} | ||
} | ||
|
||
impl<H: Hasher> Clone for OverlayedChanges<H> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can't this be derived?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome cleanup
@@ -142,7 +188,7 @@ pub struct StorageChanges<Transaction, H: Hasher> { | |||
/// [`main_storage_changes`](StorageChanges::main_storage_changes) and from | |||
/// [`child_storage_changes`](StorageChanges::child_storage_changes). | |||
/// [`offchain_storage_changes`](StorageChanges::offchain_storage_changes). | |||
pub transaction: Transaction, | |||
pub transaction: PrefixedMemoryDB<H>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit. Replace PrefixedMemoryDB<H>
in the overall file with the alias BackendTransaction<H>
(import crate::backend::BackendTransaction
).
I know it's just an alias, but for sure is more explicit about the usage intent
/// Storage transactions are calculated as part of the `storage_root`. | ||
/// These transactions can be reused for importing the block into the | ||
/// storage. So, we cache them to not require a recomputation of those transactions. | ||
pub struct StorageTransactionCache<Transaction, H: Hasher> { | ||
pub struct StorageTransactionCache<H: Hasher> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub struct StorageTransactionCache<H: Hasher> { | |
struct StorageTransactionCache<H: Hasher> { |
If only used here maybe we can keep it private?
@@ -176,7 +177,7 @@ mod execution { | |||
pub type DefaultHandler<E> = fn(CallResult<E>, CallResult<E>) -> CallResult<E>; | |||
|
|||
/// Trie backend with in-memory storage. | |||
pub type InMemoryBackend<H> = TrieBackend<MemoryDB<H>, H>; | |||
pub type InMemoryBackend<H> = TrieBackend<PrefixedMemoryDB<H>, H>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really related to this PR, but since there is some overhaul in progress...
Can't we define the InMemoryBackend
in in_memory_backend.rs
(maybe as a newtype) and replace the function new_in_mem
with a new
constructor in the impl
block for that newtype?
Co-authored-by: Davide Galassi <davxy@datawok.net>
…e-transaction-cache
bot merge |
* Companion for Substrate#14612 paritytech/substrate#14612 * Remove patch * Cargo.lock * Fix * Fix compilation * Fix Fix * ... * :face_palm: * ................. * update lockfile for {"polkadot", "substrate"} * ".git/.scripts/commands/fmt/fmt.sh" --------- Co-authored-by: parity-processbot <>
* 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>
The main change this pull request doing is the removal of
Transaction
associated type fromsp_state_machine::Backend
. The transaction is then fixed toPrefixedMemoryDB
. BasicallyPrefixedMemoryDB
was always the transaction type being used in Substrate. This removes a lot of generics which simplifies the code in a lot of places. Another important change this pull request is doing is to move the so called "storage transaction cache" into theOverlayedChanges
. There is no real need to have this cache out of theOverlayedChanges
and thus, we can also simplify some things here and there.This is works towards: paritytech/polkadot-sdk#27
Downstream Code changes
TransactionFor
orStateBackend::Transaction
was used in where bounds or similar can just be removed to make the code compile again.BlockImportParams
was also changed to only take one generic argument, the block type and not anymore the transaction type as the second generic parameter.DefaultImportQueue
is also only taking one generic argument after this pr, the block type.polkadot companion: paritytech/polkadot#7536
cumulus companion: paritytech/cumulus#2923