mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 00:01:09 +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:
@@ -380,7 +380,7 @@ where
|
||||
<TCl as ProvideRuntimeApi<TBl>>::Api: sp_api::Metadata<TBl>
|
||||
+ sp_transaction_pool::runtime_api::TaggedTransactionQueue<TBl>
|
||||
+ sp_session::SessionKeys<TBl>
|
||||
+ sp_api::ApiExt<TBl, StateBackend = TBackend::State>,
|
||||
+ sp_api::ApiExt<TBl>,
|
||||
TBl: BlockT,
|
||||
TBl::Hash: Unpin,
|
||||
TBl::Header: Unpin,
|
||||
|
||||
@@ -21,10 +21,13 @@ use sc_client_api::{
|
||||
backend, call_executor::CallExecutor, execution_extensions::ExecutionExtensions, HeaderBackend,
|
||||
};
|
||||
use sc_executor::{RuntimeVersion, RuntimeVersionOf};
|
||||
use sp_api::{ProofRecorder, StorageTransactionCache};
|
||||
use sp_api::ProofRecorder;
|
||||
use sp_core::traits::{CallContext, CodeExecutor, RuntimeCode};
|
||||
use sp_externalities::Extensions;
|
||||
use sp_runtime::{generic::BlockId, traits::Block as BlockT};
|
||||
use sp_runtime::{
|
||||
generic::BlockId,
|
||||
traits::{Block as BlockT, HashingFor},
|
||||
};
|
||||
use sp_state_machine::{backend::AsTrieBackend, Ext, OverlayedChanges, StateMachine, StorageProof};
|
||||
use std::{cell::RefCell, sync::Arc};
|
||||
|
||||
@@ -119,8 +122,7 @@ where
|
||||
) -> sp_blockchain::Result<RuntimeVersion> {
|
||||
let mut overlay = OverlayedChanges::default();
|
||||
|
||||
let mut cache = StorageTransactionCache::<Block, B::State>::default();
|
||||
let mut ext = Ext::new(&mut overlay, &mut cache, state, None);
|
||||
let mut ext = Ext::new(&mut overlay, state, None);
|
||||
|
||||
self.executor
|
||||
.runtime_version(&mut ext, code)
|
||||
@@ -197,14 +199,11 @@ where
|
||||
at_hash: Block::Hash,
|
||||
method: &str,
|
||||
call_data: &[u8],
|
||||
changes: &RefCell<OverlayedChanges>,
|
||||
storage_transaction_cache: Option<&RefCell<StorageTransactionCache<Block, B::State>>>,
|
||||
changes: &RefCell<OverlayedChanges<HashingFor<Block>>>,
|
||||
recorder: &Option<ProofRecorder<Block>>,
|
||||
call_context: CallContext,
|
||||
extensions: &RefCell<Extensions>,
|
||||
) -> Result<Vec<u8>, sp_blockchain::Error> {
|
||||
let mut storage_transaction_cache = storage_transaction_cache.map(|c| c.borrow_mut());
|
||||
|
||||
let state = self.backend.state_at(at_hash)?;
|
||||
|
||||
let changes = &mut *changes.borrow_mut();
|
||||
@@ -237,7 +236,6 @@ where
|
||||
&runtime_code,
|
||||
call_context,
|
||||
)
|
||||
.with_storage_transaction_cache(storage_transaction_cache.as_deref_mut())
|
||||
.set_parent_hash(at_hash);
|
||||
state_machine.execute()
|
||||
},
|
||||
@@ -252,7 +250,6 @@ where
|
||||
&runtime_code,
|
||||
call_context,
|
||||
)
|
||||
.with_storage_transaction_cache(storage_transaction_cache.as_deref_mut())
|
||||
.set_parent_hash(at_hash);
|
||||
state_machine.execute()
|
||||
},
|
||||
|
||||
@@ -148,9 +148,9 @@ impl<H> PrePostHeader<H> {
|
||||
}
|
||||
}
|
||||
|
||||
enum PrepareStorageChangesResult<B: backend::Backend<Block>, Block: BlockT> {
|
||||
enum PrepareStorageChangesResult<Block: BlockT> {
|
||||
Discard(ImportResult),
|
||||
Import(Option<sc_consensus::StorageChanges<Block, backend::TransactionFor<B, Block>>>),
|
||||
Import(Option<sc_consensus::StorageChanges<Block>>),
|
||||
}
|
||||
|
||||
/// Create an instance of in-memory client.
|
||||
@@ -489,15 +489,12 @@ where
|
||||
fn apply_block(
|
||||
&self,
|
||||
operation: &mut ClientImportOperation<Block, B>,
|
||||
import_block: BlockImportParams<Block, backend::TransactionFor<B, Block>>,
|
||||
storage_changes: Option<
|
||||
sc_consensus::StorageChanges<Block, backend::TransactionFor<B, Block>>,
|
||||
>,
|
||||
import_block: BlockImportParams<Block>,
|
||||
storage_changes: Option<sc_consensus::StorageChanges<Block>>,
|
||||
) -> sp_blockchain::Result<ImportResult>
|
||||
where
|
||||
Self: ProvideRuntimeApi<Block>,
|
||||
<Self as ProvideRuntimeApi<Block>>::Api:
|
||||
CoreApi<Block> + ApiExt<Block, StateBackend = B::State>,
|
||||
<Self as ProvideRuntimeApi<Block>>::Api: CoreApi<Block> + ApiExt<Block>,
|
||||
{
|
||||
let BlockImportParams {
|
||||
origin,
|
||||
@@ -580,9 +577,7 @@ where
|
||||
justifications: Option<Justifications>,
|
||||
body: Option<Vec<Block::Extrinsic>>,
|
||||
indexed_body: Option<Vec<Vec<u8>>>,
|
||||
storage_changes: Option<
|
||||
sc_consensus::StorageChanges<Block, backend::TransactionFor<B, Block>>,
|
||||
>,
|
||||
storage_changes: Option<sc_consensus::StorageChanges<Block>>,
|
||||
finalized: bool,
|
||||
aux: Vec<(Vec<u8>, Option<Vec<u8>>)>,
|
||||
fork_choice: ForkChoiceStrategy,
|
||||
@@ -590,8 +585,7 @@ where
|
||||
) -> sp_blockchain::Result<ImportResult>
|
||||
where
|
||||
Self: ProvideRuntimeApi<Block>,
|
||||
<Self as ProvideRuntimeApi<Block>>::Api:
|
||||
CoreApi<Block> + ApiExt<Block, StateBackend = B::State>,
|
||||
<Self as ProvideRuntimeApi<Block>>::Api: CoreApi<Block> + ApiExt<Block>,
|
||||
{
|
||||
let parent_hash = *import_headers.post().parent_hash();
|
||||
let status = self.backend.blockchain().status(hash)?;
|
||||
@@ -830,12 +824,11 @@ where
|
||||
/// provided, the block is re-executed to get the storage changes.
|
||||
fn prepare_block_storage_changes(
|
||||
&self,
|
||||
import_block: &mut BlockImportParams<Block, backend::TransactionFor<B, Block>>,
|
||||
) -> sp_blockchain::Result<PrepareStorageChangesResult<B, Block>>
|
||||
import_block: &mut BlockImportParams<Block>,
|
||||
) -> sp_blockchain::Result<PrepareStorageChangesResult<Block>>
|
||||
where
|
||||
Self: ProvideRuntimeApi<Block>,
|
||||
<Self as ProvideRuntimeApi<Block>>::Api:
|
||||
CoreApi<Block> + ApiExt<Block, StateBackend = B::State>,
|
||||
<Self as ProvideRuntimeApi<Block>>::Api: CoreApi<Block> + ApiExt<Block>,
|
||||
{
|
||||
let parent_hash = import_block.header.parent_hash();
|
||||
let state_action = std::mem::replace(&mut import_block.state_action, StateAction::Skip);
|
||||
@@ -1418,8 +1411,7 @@ where
|
||||
E: CallExecutor<Block> + Send + Sync + 'static,
|
||||
Block: BlockT,
|
||||
Self: ChainHeaderBackend<Block> + ProvideRuntimeApi<Block>,
|
||||
<Self as ProvideRuntimeApi<Block>>::Api:
|
||||
ApiExt<Block, StateBackend = backend::StateBackendFor<B, Block>> + BlockBuilderApi<Block>,
|
||||
<Self as ProvideRuntimeApi<Block>>::Api: ApiExt<Block> + BlockBuilderApi<Block>,
|
||||
{
|
||||
fn new_block_at<R: Into<RecordProof>>(
|
||||
&self,
|
||||
@@ -1705,17 +1697,13 @@ where
|
||||
{
|
||||
type StateBackend = B::State;
|
||||
|
||||
fn call_api_at(
|
||||
&self,
|
||||
params: CallApiAtParams<Block, B::State>,
|
||||
) -> Result<Vec<u8>, sp_api::ApiError> {
|
||||
fn call_api_at(&self, params: CallApiAtParams<Block>) -> Result<Vec<u8>, sp_api::ApiError> {
|
||||
self.executor
|
||||
.contextual_call(
|
||||
params.at,
|
||||
params.function,
|
||||
¶ms.arguments,
|
||||
params.overlayed_changes,
|
||||
Some(params.storage_transaction_cache),
|
||||
params.recorder,
|
||||
params.call_context,
|
||||
params.extensions,
|
||||
@@ -1754,13 +1742,10 @@ where
|
||||
E: CallExecutor<Block> + Send + Sync,
|
||||
Block: BlockT,
|
||||
Client<B, E, Block, RA>: ProvideRuntimeApi<Block>,
|
||||
<Client<B, E, Block, RA> as ProvideRuntimeApi<Block>>::Api:
|
||||
CoreApi<Block> + ApiExt<Block, StateBackend = B::State>,
|
||||
<Client<B, E, Block, RA> as ProvideRuntimeApi<Block>>::Api: CoreApi<Block> + ApiExt<Block>,
|
||||
RA: Sync + Send,
|
||||
backend::TransactionFor<B, Block>: Send + 'static,
|
||||
{
|
||||
type Error = ConsensusError;
|
||||
type Transaction = backend::TransactionFor<B, Block>;
|
||||
|
||||
/// Import a checked and validated block. If a justification is provided in
|
||||
/// `BlockImportParams` then `finalized` *must* be true.
|
||||
@@ -1773,7 +1758,7 @@ where
|
||||
/// algorithm, don't use this function.
|
||||
async fn import_block(
|
||||
&mut self,
|
||||
mut import_block: BlockImportParams<Block, backend::TransactionFor<B, Block>>,
|
||||
mut import_block: BlockImportParams<Block>,
|
||||
) -> Result<ImportResult, Self::Error> {
|
||||
let span = tracing::span!(tracing::Level::DEBUG, "import_block");
|
||||
let _enter = span.enter();
|
||||
@@ -1867,17 +1852,14 @@ where
|
||||
E: CallExecutor<Block> + Send + Sync,
|
||||
Block: BlockT,
|
||||
Self: ProvideRuntimeApi<Block>,
|
||||
<Self as ProvideRuntimeApi<Block>>::Api:
|
||||
CoreApi<Block> + ApiExt<Block, StateBackend = B::State>,
|
||||
<Self as ProvideRuntimeApi<Block>>::Api: CoreApi<Block> + ApiExt<Block>,
|
||||
RA: Sync + Send,
|
||||
backend::TransactionFor<B, Block>: Send + 'static,
|
||||
{
|
||||
type Error = ConsensusError;
|
||||
type Transaction = backend::TransactionFor<B, Block>;
|
||||
|
||||
async fn import_block(
|
||||
&mut self,
|
||||
import_block: BlockImportParams<Block, Self::Transaction>,
|
||||
import_block: BlockImportParams<Block>,
|
||||
) -> Result<ImportResult, Self::Error> {
|
||||
(&*self).import_block(import_block).await
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user