mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 01:47:55 +00:00
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:
@@ -25,11 +25,11 @@ use sc_executor::{sp_wasm_interface::HostFunctions, WasmExecutor};
|
||||
use serde::de::DeserializeOwned;
|
||||
use sp_core::H256;
|
||||
use sp_inherents::{InherentData, InherentDataProvider};
|
||||
use sp_io::TestExternalities;
|
||||
use sp_runtime::{
|
||||
traits::{Header, NumberFor, One},
|
||||
traits::{HashingFor, Header, NumberFor, One},
|
||||
Digest,
|
||||
};
|
||||
use sp_state_machine::TestExternalities;
|
||||
use std::{fmt::Debug, str::FromStr};
|
||||
use substrate_rpc_client::{ws_client, ChainApi};
|
||||
|
||||
@@ -92,8 +92,8 @@ where
|
||||
}
|
||||
|
||||
/// Call `method` with `data` and return the result. `externalities` will not change.
|
||||
async fn dry_run<T: Decode, Block: BlockT, HostFns: HostFunctions>(
|
||||
externalities: &TestExternalities,
|
||||
fn dry_run<T: Decode, Block: BlockT, HostFns: HostFunctions>(
|
||||
externalities: &TestExternalities<HashingFor<Block>>,
|
||||
executor: &WasmExecutor<HostFns>,
|
||||
method: &'static str,
|
||||
data: &[u8],
|
||||
@@ -111,7 +111,7 @@ async fn dry_run<T: Decode, Block: BlockT, HostFns: HostFunctions>(
|
||||
|
||||
/// Call `method` with `data` and actually save storage changes to `externalities`.
|
||||
async fn run<Block: BlockT, HostFns: HostFunctions>(
|
||||
externalities: &mut TestExternalities,
|
||||
externalities: &mut TestExternalities<HashingFor<Block>>,
|
||||
executor: &WasmExecutor<HostFns>,
|
||||
method: &'static str,
|
||||
data: &[u8],
|
||||
@@ -124,11 +124,8 @@ async fn run<Block: BlockT, HostFns: HostFunctions>(
|
||||
full_extensions(executor.clone()),
|
||||
)?;
|
||||
|
||||
let storage_changes = changes.drain_storage_changes(
|
||||
&externalities.backend,
|
||||
&mut Default::default(),
|
||||
externalities.state_version,
|
||||
)?;
|
||||
let storage_changes =
|
||||
changes.drain_storage_changes(&externalities.backend, externalities.state_version)?;
|
||||
|
||||
externalities
|
||||
.backend
|
||||
@@ -143,7 +140,7 @@ async fn next_empty_block<
|
||||
HostFns: HostFunctions,
|
||||
BBIP: BlockBuildingInfoProvider<Block, Option<(InherentData, Digest)>>,
|
||||
>(
|
||||
externalities: &mut TestExternalities,
|
||||
externalities: &mut TestExternalities<HashingFor<Block>>,
|
||||
executor: &WasmExecutor<HostFns>,
|
||||
parent_height: NumberFor<Block>,
|
||||
parent_hash: Block::Hash,
|
||||
@@ -182,8 +179,7 @@ async fn next_empty_block<
|
||||
executor,
|
||||
"BlockBuilder_inherent_extrinsics",
|
||||
&inherent_data.encode(),
|
||||
)
|
||||
.await?;
|
||||
)?;
|
||||
}
|
||||
|
||||
for xt in &extrinsics {
|
||||
@@ -196,8 +192,7 @@ async fn next_empty_block<
|
||||
executor,
|
||||
"BlockBuilder_finalize_block",
|
||||
&[0u8; 0],
|
||||
)
|
||||
.await?;
|
||||
)?;
|
||||
|
||||
run::<Block, _>(externalities, executor, "BlockBuilder_finalize_block", &[0u8; 0]).await?;
|
||||
|
||||
|
||||
@@ -177,7 +177,6 @@ where
|
||||
let storage_changes = changes
|
||||
.drain_storage_changes(
|
||||
&state_ext.backend,
|
||||
&mut Default::default(),
|
||||
// Note that in case a block contains a runtime upgrade, state version could
|
||||
// potentially be incorrect here, this is very niche and would only result in
|
||||
// unaligned roots, so this use case is ignored for now.
|
||||
|
||||
@@ -28,7 +28,6 @@ use crate::block_building_info::BlockBuildingInfoProvider;
|
||||
use parity_scale_codec::Decode;
|
||||
use remote_externalities::{
|
||||
Builder, Mode, OfflineConfig, OnlineConfig, RemoteExternalities, SnapshotConfig,
|
||||
TestExternalities,
|
||||
};
|
||||
use sc_cli::{
|
||||
execution_method_from_cli, CliConfiguration, RuntimeVersion, WasmExecutionMethod,
|
||||
@@ -38,7 +37,6 @@ use sc_cli::{
|
||||
use sc_executor::{
|
||||
sp_wasm_interface::HostFunctions, HeapAllocStrategy, WasmExecutor, DEFAULT_HEAP_ALLOC_STRATEGY,
|
||||
};
|
||||
use sp_api::HashT;
|
||||
use sp_core::{
|
||||
hexdisplay::HexDisplay,
|
||||
offchain::{
|
||||
@@ -53,10 +51,12 @@ use sp_externalities::Extensions;
|
||||
use sp_inherents::InherentData;
|
||||
use sp_keystore::{testing::MemoryKeystore, KeystoreExt};
|
||||
use sp_runtime::{
|
||||
traits::{BlakeTwo256, Block as BlockT, NumberFor},
|
||||
traits::{BlakeTwo256, Block as BlockT, Hash as HashT, HashingFor, NumberFor},
|
||||
DeserializeOwned, Digest,
|
||||
};
|
||||
use sp_state_machine::{CompactProof, OverlayedChanges, StateMachine, TrieBackendBuilder};
|
||||
use sp_state_machine::{
|
||||
CompactProof, OverlayedChanges, StateMachine, TestExternalities, TrieBackendBuilder,
|
||||
};
|
||||
use sp_version::StateVersion;
|
||||
use std::{fmt::Debug, path::PathBuf, str::FromStr};
|
||||
|
||||
@@ -514,7 +514,7 @@ pub(crate) fn build_executor<H: HostFunctions>(shared: &SharedParams) -> WasmExe
|
||||
/// Ensure that the given `ext` is compiled with `try-runtime`
|
||||
fn ensure_try_runtime<Block: BlockT, HostFns: HostFunctions>(
|
||||
executor: &WasmExecutor<HostFns>,
|
||||
ext: &mut TestExternalities,
|
||||
ext: &mut TestExternalities<HashingFor<Block>>,
|
||||
) -> bool {
|
||||
use sp_api::RuntimeApiInfo;
|
||||
let final_code = ext
|
||||
@@ -532,12 +532,12 @@ fn ensure_try_runtime<Block: BlockT, HostFns: HostFunctions>(
|
||||
/// Execute the given `method` and `data` on top of `ext`, returning the results (encoded) and the
|
||||
/// state `changes`.
|
||||
pub(crate) fn state_machine_call<Block: BlockT, HostFns: HostFunctions>(
|
||||
ext: &TestExternalities,
|
||||
ext: &TestExternalities<HashingFor<Block>>,
|
||||
executor: &WasmExecutor<HostFns>,
|
||||
method: &'static str,
|
||||
data: &[u8],
|
||||
mut extensions: Extensions,
|
||||
) -> sc_cli::Result<(OverlayedChanges, Vec<u8>)> {
|
||||
) -> sc_cli::Result<(OverlayedChanges<HashingFor<Block>>, Vec<u8>)> {
|
||||
let mut changes = Default::default();
|
||||
let encoded_results = StateMachine::new(
|
||||
&ext.backend,
|
||||
@@ -561,13 +561,13 @@ pub(crate) fn state_machine_call<Block: BlockT, HostFns: HostFunctions>(
|
||||
///
|
||||
/// Make sure [`LOG_TARGET`] is enabled in logging.
|
||||
pub(crate) fn state_machine_call_with_proof<Block: BlockT, HostFns: HostFunctions>(
|
||||
ext: &TestExternalities,
|
||||
ext: &TestExternalities<HashingFor<Block>>,
|
||||
executor: &WasmExecutor<HostFns>,
|
||||
method: &'static str,
|
||||
data: &[u8],
|
||||
mut extensions: Extensions,
|
||||
maybe_export_proof: Option<PathBuf>,
|
||||
) -> sc_cli::Result<(OverlayedChanges, Vec<u8>)> {
|
||||
) -> sc_cli::Result<(OverlayedChanges<HashingFor<Block>>, Vec<u8>)> {
|
||||
use parity_scale_codec::Encode;
|
||||
|
||||
let mut changes = Default::default();
|
||||
@@ -624,7 +624,7 @@ pub(crate) fn state_machine_call_with_proof<Block: BlockT, HostFns: HostFunction
|
||||
let proof_size = proof.encoded_size();
|
||||
let compact_proof = proof
|
||||
.clone()
|
||||
.into_compact_proof::<sp_runtime::traits::BlakeTwo256>(pre_root)
|
||||
.into_compact_proof::<HashingFor<Block>>(pre_root)
|
||||
.map_err(|e| {
|
||||
log::error!(target: LOG_TARGET, "failed to generate compact proof {}: {:?}", method, e);
|
||||
e
|
||||
|
||||
Reference in New Issue
Block a user