mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 09:21:05 +00:00
Offchain execution extensions (#4145)
* Pass Extensions instead of individual objects. * Move TransactionPool to a separate ExternalitiesExtension. * Fix compilation.? * Clean up. * Refactor testing utilities. * Add docs, fix tests. * Fix doctest. * Fix formatting and add some logs. * Add some docs. * Remove unused files.
This commit is contained in:
committed by
Gavin Wood
parent
f000392cc0
commit
86b6ac5571
@@ -21,8 +21,9 @@ use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use parking_lot::{RwLock, Mutex};
|
||||
|
||||
use sr_primitives::{generic::BlockId, Justification, StorageOverlay, ChildrenStorageOverlay};
|
||||
use state_machine::{Backend as StateBackend, TrieBackend, backend::InMemory as InMemoryState, ChangesTrieTransaction};
|
||||
use primitives::offchain::storage::InMemOffchainStorage;
|
||||
use sr_primitives::{generic::BlockId, Justification, StorageOverlay, ChildrenStorageOverlay};
|
||||
use sr_primitives::traits::{Block as BlockT, NumberFor, Zero, Header};
|
||||
use crate::in_mem::{self, check_genesis_storage};
|
||||
use client_api::{
|
||||
@@ -37,9 +38,8 @@ use client_api::{
|
||||
Error as ClientError, Result as ClientResult
|
||||
},
|
||||
light::Storage as BlockchainStorage,
|
||||
InMemOffchainStorage,
|
||||
};
|
||||
use crate::light::blockchain::{Blockchain};
|
||||
use crate::light::blockchain::Blockchain;
|
||||
use hash_db::Hasher;
|
||||
use trie::MemoryDB;
|
||||
|
||||
|
||||
@@ -22,12 +22,13 @@ use std::{
|
||||
|
||||
use codec::{Encode, Decode};
|
||||
use primitives::{
|
||||
offchain::OffchainExt, H256, Blake2Hasher, convert_hash, NativeOrEncoded,
|
||||
H256, Blake2Hasher, convert_hash, NativeOrEncoded,
|
||||
traits::CodeExecutor,
|
||||
};
|
||||
use sr_primitives::{
|
||||
generic::BlockId, traits::{One, Block as BlockT, Header as HeaderT, NumberFor},
|
||||
};
|
||||
use externalities::Extensions;
|
||||
use state_machine::{
|
||||
self, Backend as StateBackend, OverlayedChanges, ExecutionStrategy, create_proof_check_backend,
|
||||
execution_proof_check_on_trie_backend, ExecutionManager, ChangesTrieTransaction, StorageProof,
|
||||
@@ -84,10 +85,10 @@ impl<Block, B, Local> CallExecutor<Block, Blake2Hasher> for
|
||||
method: &str,
|
||||
call_data: &[u8],
|
||||
strategy: ExecutionStrategy,
|
||||
side_effects_handler: Option<OffchainExt>,
|
||||
extensions: Option<Extensions>,
|
||||
) -> ClientResult<Vec<u8>> {
|
||||
match self.backend.is_local_state_available(id) {
|
||||
true => self.local.call(id, method, call_data, strategy, side_effects_handler),
|
||||
true => self.local.call(id, method, call_data, strategy, extensions),
|
||||
false => Err(ClientError::NotAvailableOnLightClient),
|
||||
}
|
||||
}
|
||||
@@ -111,9 +112,8 @@ impl<Block, B, Local> CallExecutor<Block, Blake2Hasher> for
|
||||
initialize_block: InitializeBlock<'a, Block>,
|
||||
_manager: ExecutionManager<EM>,
|
||||
native_call: Option<NC>,
|
||||
side_effects_handler: Option<OffchainExt>,
|
||||
recorder: &Option<ProofRecorder<Block>>,
|
||||
enable_keystore: bool,
|
||||
extensions: Option<Extensions>,
|
||||
) -> ClientResult<NativeOrEncoded<R>> where ExecutionManager<EM>: Clone {
|
||||
// there's no actual way/need to specify native/wasm execution strategy on light node
|
||||
// => we can safely ignore passed values
|
||||
@@ -137,9 +137,8 @@ impl<Block, B, Local> CallExecutor<Block, Blake2Hasher> for
|
||||
initialize_block,
|
||||
ExecutionManager::NativeWhenPossible,
|
||||
native_call,
|
||||
side_effects_handler,
|
||||
recorder,
|
||||
enable_keystore,
|
||||
extensions,
|
||||
).map_err(|e| ClientError::Execution(Box::new(e.to_string()))),
|
||||
false => Err(ClientError::NotAvailableOnLightClient),
|
||||
}
|
||||
@@ -167,7 +166,7 @@ impl<Block, B, Local> CallExecutor<Block, Blake2Hasher> for
|
||||
_call_data: &[u8],
|
||||
_manager: ExecutionManager<FF>,
|
||||
_native_call: Option<NC>,
|
||||
_side_effects_handler: Option<OffchainExt>,
|
||||
_extensions: Option<Extensions>,
|
||||
) -> ClientResult<(
|
||||
NativeOrEncoded<R>,
|
||||
(S::Transaction, <Blake2Hasher as Hasher>::Out),
|
||||
@@ -313,7 +312,7 @@ mod tests {
|
||||
_method: &str,
|
||||
_call_data: &[u8],
|
||||
_strategy: ExecutionStrategy,
|
||||
_side_effects_handler: Option<OffchainExt>,
|
||||
_extensions: Option<Extensions>,
|
||||
) -> Result<Vec<u8>, ClientError> {
|
||||
Ok(vec![42])
|
||||
}
|
||||
@@ -337,9 +336,8 @@ mod tests {
|
||||
_initialize_block: InitializeBlock<'a, Block>,
|
||||
_execution_manager: ExecutionManager<EM>,
|
||||
_native_call: Option<NC>,
|
||||
_side_effects_handler: Option<OffchainExt>,
|
||||
_proof_recorder: &Option<ProofRecorder<Block>>,
|
||||
_enable_keystore: bool,
|
||||
_extensions: Option<Extensions>,
|
||||
) -> ClientResult<NativeOrEncoded<R>> where ExecutionManager<EM>: Clone {
|
||||
unreachable!()
|
||||
}
|
||||
@@ -363,7 +361,7 @@ mod tests {
|
||||
_call_data: &[u8],
|
||||
_manager: ExecutionManager<F>,
|
||||
_native_call: Option<NC>,
|
||||
_side_effects_handler: Option<OffchainExt>,
|
||||
_extensions: Option<Extensions>,
|
||||
) -> Result<
|
||||
(
|
||||
NativeOrEncoded<R>,
|
||||
|
||||
@@ -68,7 +68,7 @@ pub fn new_light<B, S, GS, RA, E>(
|
||||
GS: BuildStorage,
|
||||
E: CodeExecutor + RuntimeInfo,
|
||||
{
|
||||
let local_executor = LocalCallExecutor::new(backend.clone(), code_executor, None);
|
||||
let local_executor = LocalCallExecutor::new(backend.clone(), code_executor);
|
||||
let executor = GenesisCallExecutor::new(backend.clone(), local_executor);
|
||||
Client::new(backend, executor, genesis_storage, Default::default(), Default::default())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user