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
@@ -229,10 +229,7 @@ fn generate_runtime_api_base_structures() -> Result<TokenStream> {
pub struct RuntimeApiImpl<Block: #crate_::BlockT, C: #crate_::CallApiAt<Block> + 'static> {
call: &'static C,
transaction_depth: std::cell::RefCell<u16>,
changes: std::cell::RefCell<#crate_::OverlayedChanges>,
storage_transaction_cache: std::cell::RefCell<
#crate_::StorageTransactionCache<Block, C::StateBackend>
>,
changes: std::cell::RefCell<#crate_::OverlayedChanges<#crate_::HashingFor<Block>>>,
recorder: std::option::Option<#crate_::ProofRecorder<Block>>,
call_context: #crate_::CallContext,
extensions: std::cell::RefCell<#crate_::Extensions>,
@@ -242,8 +239,6 @@ fn generate_runtime_api_base_structures() -> Result<TokenStream> {
impl<Block: #crate_::BlockT, C: #crate_::CallApiAt<Block>> #crate_::ApiExt<Block> for
RuntimeApiImpl<Block, C>
{
type StateBackend = C::StateBackend;
fn execute_in_transaction<F: FnOnce(&Self) -> #crate_::TransactionOutcome<R>, R>(
&self,
call: F,
@@ -305,22 +300,21 @@ fn generate_runtime_api_base_structures() -> Result<TokenStream> {
})
}
fn into_storage_changes(
fn into_storage_changes<B: #crate_::StateBackend<#crate_::HashingFor<Block>>>(
&self,
backend: &Self::StateBackend,
backend: &B,
parent_hash: Block::Hash,
) -> core::result::Result<
#crate_::StorageChanges<C::StateBackend, Block>,
#crate_::StorageChanges<Block>,
String
> where Self: Sized {
let state_version = #crate_::CallApiAt::<Block>::runtime_version_at(self.call, std::clone::Clone::clone(&parent_hash))
.map(|v| #crate_::RuntimeVersion::state_version(&v))
.map_err(|e| format!("Failed to get state version: {}", e))?;
#crate_::OverlayedChanges::into_storage_changes(
std::cell::RefCell::take(&self.changes),
#crate_::OverlayedChanges::drain_storage_changes(
&mut std::cell::RefCell::borrow_mut(&self.changes),
backend,
core::cell::RefCell::take(&self.storage_transaction_cache),
state_version,
)
}
@@ -349,7 +343,6 @@ fn generate_runtime_api_base_structures() -> Result<TokenStream> {
transaction_depth: 0.into(),
changes: std::default::Default::default(),
recorder: std::default::Default::default(),
storage_transaction_cache: std::default::Default::default(),
call_context: #crate_::CallContext::Offchain,
extensions: std::default::Default::default(),
extensions_generated_for: std::default::Default::default(),
@@ -535,7 +528,6 @@ impl<'a> ApiRuntimeImplToApiRuntimeApiImpl<'a> {
function: (*fn_name)(version),
arguments: params,
overlayed_changes: &self.changes,
storage_transaction_cache: &self.storage_transaction_cache,
call_context: self.call_context,
recorder: &self.recorder,
extensions: &self.extensions,