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:
Tomasz Drwięga
2019-11-22 17:10:23 +01:00
committed by Gavin Wood
parent f000392cc0
commit 86b6ac5571
39 changed files with 554 additions and 360 deletions
+13 -26
View File
@@ -24,12 +24,12 @@ use state_machine::{
backend::Backend as _, ChangesTrieTransaction, StorageProof,
};
use executor::{RuntimeVersion, RuntimeInfo, NativeVersion};
use externalities::Extensions;
use hash_db::Hasher;
use primitives::{
offchain::OffchainExt, H256, Blake2Hasher, NativeOrEncoded, NeverNativeValue,
traits::{CodeExecutor, KeystoreExt},
H256, Blake2Hasher, NativeOrEncoded, NeverNativeValue,
traits::CodeExecutor,
};
use sr_api::{ProofRecorder, InitializeBlock};
use client_api::{
error, backend, call_executor::CallExecutor,
@@ -40,7 +40,6 @@ use client_api::{
pub struct LocalCallExecutor<B, E> {
backend: Arc<B>,
executor: E,
keystore: Option<primitives::traits::BareCryptoStorePtr>,
}
impl<B, E> LocalCallExecutor<B, E> {
@@ -48,12 +47,10 @@ impl<B, E> LocalCallExecutor<B, E> {
pub fn new(
backend: Arc<B>,
executor: E,
keystore: Option<primitives::traits::BareCryptoStorePtr>,
) -> Self {
LocalCallExecutor {
backend,
executor,
keystore,
}
}
}
@@ -63,7 +60,6 @@ impl<B, E> Clone for LocalCallExecutor<B, E> where E: Clone {
LocalCallExecutor {
backend: self.backend.clone(),
executor: self.executor.clone(),
keystore: self.keystore.clone(),
}
}
}
@@ -82,19 +78,18 @@ where
method: &str,
call_data: &[u8],
strategy: ExecutionStrategy,
side_effects_handler: Option<OffchainExt>,
extensions: Option<Extensions>,
) -> error::Result<Vec<u8>> {
let mut changes = OverlayedChanges::default();
let state = self.backend.state_at(*id)?;
let return_data = StateMachine::new(
&state,
self.backend.changes_trie_storage(),
side_effects_handler,
&mut changes,
&self.executor,
method,
call_data,
self.keystore.clone().map(KeystoreExt),
extensions.unwrap_or_default(),
).execute_using_consensus_failure_handler::<_, NeverNativeValue, fn() -> _>(
strategy.get_manager(),
false,
@@ -124,9 +119,8 @@ where
initialize_block: InitializeBlock<'a, Block>,
execution_manager: ExecutionManager<EM>,
native_call: Option<NC>,
side_effects_handler: Option<OffchainExt>,
recorder: &Option<ProofRecorder<Block>>,
enable_keystore: bool,
extensions: Option<Extensions>,
) -> Result<NativeOrEncoded<R>, error::Error> where ExecutionManager<EM>: Clone {
match initialize_block {
InitializeBlock::Do(ref init_block)
@@ -137,12 +131,6 @@ where
_ => {},
}
let keystore = if enable_keystore {
self.keystore.clone().map(KeystoreExt)
} else {
None
};
let mut state = self.backend.state_at(*at)?;
let result = match recorder {
@@ -161,12 +149,11 @@ where
StateMachine::new(
&backend,
self.backend.changes_trie_storage(),
side_effects_handler,
&mut *changes.borrow_mut(),
&self.executor,
method,
call_data,
keystore,
extensions.unwrap_or_default(),
)
.execute_using_consensus_failure_handler(
execution_manager,
@@ -179,12 +166,11 @@ where
None => StateMachine::new(
&state,
self.backend.changes_trie_storage(),
side_effects_handler,
&mut *changes.borrow_mut(),
&self.executor,
method,
call_data,
keystore,
extensions.unwrap_or_default(),
)
.execute_using_consensus_failure_handler(
execution_manager,
@@ -227,7 +213,7 @@ where
call_data: &[u8],
manager: ExecutionManager<F>,
native_call: Option<NC>,
side_effects_handler: Option<OffchainExt>,
extensions: Option<Extensions>,
) -> error::Result<(
NativeOrEncoded<R>,
(S::Transaction, <Blake2Hasher as Hasher>::Out),
@@ -236,12 +222,11 @@ where
StateMachine::new(
state,
self.backend.changes_trie_storage(),
side_effects_handler,
changes,
&self.executor,
method,
call_data,
self.keystore.clone().map(KeystoreExt),
extensions.unwrap_or_default(),
).execute_using_consensus_failure_handler(
manager,
true,
@@ -268,7 +253,9 @@ where
&self.executor,
method,
call_data,
self.keystore.clone().map(KeystoreExt),
// Passing `None` here, since we don't really want to prove anything
// about our local keys.
None,
)
.map_err(Into::into)
}