mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-09 21:21:11 +00:00
Don't panic if parameter can not be converted between node and native runtime (#1659)
* Don't panic if parameter can not be converted between node and native runtime * FIxes after merge * Use correct copyright year
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
|
||||
#![warn(missing_docs)]
|
||||
|
||||
use std::{fmt, panic::UnwindSafe};
|
||||
use std::{fmt, panic::UnwindSafe, result};
|
||||
use log::warn;
|
||||
use hash_db::Hasher;
|
||||
use heapsize::HeapSizeOf;
|
||||
@@ -45,7 +45,8 @@ pub use changes_trie::{
|
||||
InMemoryStorage as InMemoryChangesTrieStorage,
|
||||
key_changes, key_changes_proof, key_changes_proof_check,
|
||||
prune as prune_changes_tries,
|
||||
oldest_non_pruned_trie as oldest_non_pruned_changes_trie};
|
||||
oldest_non_pruned_trie as oldest_non_pruned_changes_trie
|
||||
};
|
||||
pub use overlayed_changes::OverlayedChanges;
|
||||
pub use proving_backend::{create_proof_check_backend, create_proof_check_backend_storage};
|
||||
pub use trie_backend_essence::{TrieBackendStorage, Storage};
|
||||
@@ -156,7 +157,9 @@ pub trait CodeExecutor<H: Hasher>: Sized + Send + Sync {
|
||||
|
||||
/// Call a given method in the runtime. Returns a tuple of the result (either the output data
|
||||
/// or an execution error) together with a `bool`, which is true if native execution was used.
|
||||
fn call<E: Externalities<H>, R: Encode + Decode + PartialEq, NC: FnOnce() -> R + UnwindSafe>(
|
||||
fn call<
|
||||
E: Externalities<H>, R: Encode + Decode + PartialEq, NC: FnOnce() -> result::Result<R, &'static str> + UnwindSafe
|
||||
>(
|
||||
&self,
|
||||
ext: &mut E,
|
||||
method: &str,
|
||||
@@ -248,7 +251,7 @@ where
|
||||
{
|
||||
// We are not giving a native call and thus we are sure that the result can never be a native
|
||||
// value.
|
||||
execute_using_consensus_failure_handler::<_, _, _, _, _, NeverNativeValue, fn() -> NeverNativeValue>(
|
||||
execute_using_consensus_failure_handler::<_, _, _, _, _, NeverNativeValue, fn() -> _>(
|
||||
backend,
|
||||
changes_trie_storage,
|
||||
overlay,
|
||||
@@ -286,7 +289,7 @@ where
|
||||
/// Note: changes to code will be in place if this call is made again. For running partial
|
||||
/// blocks (e.g. a transaction at a time), ensure a different method is used.
|
||||
pub fn execute_using_consensus_failure_handler<
|
||||
H, B, T, Exec, Handler, R: Decode + Encode + PartialEq, NC: FnOnce() -> R + UnwindSafe
|
||||
H, B, T, Exec, Handler, R: Decode + Encode + PartialEq, NC: FnOnce() -> result::Result<R, &'static str> + UnwindSafe
|
||||
>(
|
||||
backend: &B,
|
||||
changes_trie_storage: Option<&T>,
|
||||
@@ -443,7 +446,7 @@ where
|
||||
{
|
||||
let proving_backend = proving_backend::ProvingBackend::new(trie_backend);
|
||||
let (result, _, _) = execute_using_consensus_failure_handler::
|
||||
<H, _, changes_trie::InMemoryStorage<H>, _, _, NeverNativeValue, fn() -> NeverNativeValue>
|
||||
<H, _, changes_trie::InMemoryStorage<H>, _, _, NeverNativeValue, fn() -> _>
|
||||
(
|
||||
&proving_backend,
|
||||
None,
|
||||
@@ -491,7 +494,7 @@ where
|
||||
H::Out: Ord + HeapSizeOf,
|
||||
{
|
||||
execute_using_consensus_failure_handler::
|
||||
<H, _, changes_trie::InMemoryStorage<H>, _, _, NeverNativeValue, fn() -> NeverNativeValue>
|
||||
<H, _, changes_trie::InMemoryStorage<H>, _, _, NeverNativeValue, fn() -> _>
|
||||
(
|
||||
trie_backend,
|
||||
None,
|
||||
@@ -621,7 +624,7 @@ mod tests {
|
||||
impl<H: Hasher> CodeExecutor<H> for DummyCodeExecutor {
|
||||
type Error = u8;
|
||||
|
||||
fn call<E: Externalities<H>, R: Encode + Decode + PartialEq, NC: FnOnce() -> R>(
|
||||
fn call<E: Externalities<H>, R: Encode + Decode + PartialEq, NC: FnOnce() -> result::Result<R, &'static str>>(
|
||||
&self,
|
||||
ext: &mut E,
|
||||
_method: &str,
|
||||
@@ -684,7 +687,7 @@ mod tests {
|
||||
#[test]
|
||||
fn dual_execution_strategy_detects_consensus_failure() {
|
||||
let mut consensus_failed = false;
|
||||
assert!(execute_using_consensus_failure_handler::<_, _, _, _, _, NeverNativeValue, fn() -> NeverNativeValue>(
|
||||
assert!(execute_using_consensus_failure_handler::<_, _, _, _, _, NeverNativeValue, fn() -> _>(
|
||||
&trie_backend::tests::test_trie(),
|
||||
Some(&InMemoryChangesTrieStorage::new()),
|
||||
&mut Default::default(),
|
||||
|
||||
Reference in New Issue
Block a user