Revert "Don't include :code by default in storage proofs (#5060)" (#5136)

This reverts commit 6ee39261c8.
This commit is contained in:
Arkadiy Paronyan
2020-03-05 10:55:05 +01:00
committed by GitHub
parent ff2a36d7cb
commit 9a1b3b53f2
31 changed files with 182 additions and 478 deletions
+10 -54
View File
@@ -23,8 +23,8 @@ use log::{warn, trace};
use hash_db::Hasher;
use codec::{Decode, Encode, Codec};
use sp_core::{
storage::ChildInfo, NativeOrEncoded, NeverNativeValue, hexdisplay::HexDisplay,
traits::{CodeExecutor, CallInWasmExt, RuntimeCode},
storage::ChildInfo, NativeOrEncoded, NeverNativeValue,
traits::{CodeExecutor, CallInWasmExt}, hexdisplay::HexDisplay,
};
use overlayed_changes::OverlayedChangeSet;
use sp_externalities::Extensions;
@@ -42,7 +42,7 @@ mod trie_backend;
mod trie_backend_essence;
mod stats;
pub use sp_trie::{trie_types::{Layout, TrieDBMut}, StorageProof, TrieMut, DBValue, MemoryDB};
pub use sp_trie::{trie_types::{Layout, TrieDBMut}, TrieMut, DBValue, MemoryDB};
pub use testing::TestExternalities;
pub use basic::BasicExternalities;
pub use ext::Ext;
@@ -67,7 +67,8 @@ pub use overlayed_changes::{
StorageCollection, ChildStorageCollection,
};
pub use proving_backend::{
create_proof_check_backend, ProofRecorder, ProvingBackend, ProvingBackendRecorder,
create_proof_check_backend, create_proof_check_backend_storage, merge_storage_proofs,
ProofRecorder, ProvingBackend, ProvingBackendRecorder, StorageProof,
};
pub use trie_backend_essence::{TrieBackendStorage, Storage};
pub use trie_backend::TrieBackend;
@@ -190,7 +191,6 @@ pub struct StateMachine<'a, B, H, N, Exec>
changes_trie_state: Option<ChangesTrieState<'a, H, N>>,
_marker: PhantomData<(H, N)>,
storage_transaction_cache: Option<&'a mut StorageTransactionCache<B::Transaction, H, N>>,
runtime_code: &'a RuntimeCode,
}
impl<'a, B, H, N, Exec> StateMachine<'a, B, H, N, Exec> where
@@ -209,7 +209,6 @@ impl<'a, B, H, N, Exec> StateMachine<'a, B, H, N, Exec> where
method: &'a str,
call_data: &'a [u8],
mut extensions: Extensions,
runtime_code: &'a RuntimeCode,
) -> Self {
extensions.register(CallInWasmExt::new(exec.clone()));
@@ -223,7 +222,6 @@ impl<'a, B, H, N, Exec> StateMachine<'a, B, H, N, Exec> where
changes_trie_state,
_marker: PhantomData,
storage_transaction_cache: None,
runtime_code,
}
}
@@ -294,7 +292,6 @@ impl<'a, B, H, N, Exec> StateMachine<'a, B, H, N, Exec> where
let (result, was_native) = self.exec.call(
&mut ext,
self.runtime_code,
self.method,
self.call_data,
use_native,
@@ -439,7 +436,6 @@ pub fn prove_execution<B, H, N, Exec>(
exec: &Exec,
method: &str,
call_data: &[u8],
runtime_code: &RuntimeCode,
) -> Result<(Vec<u8>, StorageProof), Box<dyn Error>>
where
B: Backend<H>,
@@ -450,14 +446,7 @@ where
{
let trie_backend = backend.as_trie_backend()
.ok_or_else(|| Box::new(ExecutionError::UnableToGenerateProof) as Box<dyn Error>)?;
prove_execution_on_trie_backend::<_, _, N, _>(
trie_backend,
overlay,
exec,
method,
call_data,
runtime_code,
)
prove_execution_on_trie_backend::<_, _, N, _>(trie_backend, overlay, exec, method, call_data)
}
/// Prove execution using the given trie backend, overlayed changes, and call executor.
@@ -475,7 +464,6 @@ pub fn prove_execution_on_trie_backend<S, H, N, Exec>(
exec: &Exec,
method: &str,
call_data: &[u8],
runtime_code: &RuntimeCode,
) -> Result<(Vec<u8>, StorageProof), Box<dyn Error>>
where
S: trie_backend_essence::TrieBackendStorage<H>,
@@ -486,14 +474,7 @@ where
{
let proving_backend = proving_backend::ProvingBackend::new(trie_backend);
let mut sm = StateMachine::<_, H, N, Exec>::new(
&proving_backend,
None,
overlay,
exec,
method,
call_data,
Extensions::default(),
runtime_code,
&proving_backend, None, overlay, exec, method, call_data, Extensions::default(),
);
let result = sm.execute_using_consensus_failure_handler::<_, NeverNativeValue, fn() -> _>(
@@ -512,7 +493,6 @@ pub fn execution_proof_check<H, N, Exec>(
exec: &Exec,
method: &str,
call_data: &[u8],
runtime_code: &RuntimeCode,
) -> Result<Vec<u8>, Box<dyn Error>>
where
H: Hasher,
@@ -521,14 +501,7 @@ where
N: crate::changes_trie::BlockNumber,
{
let trie_backend = create_proof_check_backend::<H>(root.into(), proof)?;
execution_proof_check_on_trie_backend::<_, N, _>(
&trie_backend,
overlay,
exec,
method,
call_data,
runtime_code,
)
execution_proof_check_on_trie_backend::<_, N, _>(&trie_backend, overlay, exec, method, call_data)
}
/// Check execution proof on proving backend, generated by `prove_execution` call.
@@ -538,7 +511,6 @@ pub fn execution_proof_check_on_trie_backend<H, N, Exec>(
exec: &Exec,
method: &str,
call_data: &[u8],
runtime_code: &RuntimeCode,
) -> Result<Vec<u8>, Box<dyn Error>>
where
H: Hasher,
@@ -547,14 +519,7 @@ where
N: crate::changes_trie::BlockNumber,
{
let mut sm = StateMachine::<_, H, N, Exec>::new(
trie_backend,
None,
overlay,
exec,
method,
call_data,
Extensions::default(),
runtime_code,
trie_backend, None, overlay, exec, method, call_data, Extensions::default(),
);
sm.execute_using_consensus_failure_handler::<_, NeverNativeValue, fn() -> _>(
@@ -727,7 +692,7 @@ mod tests {
use super::*;
use super::ext::Ext;
use super::changes_trie::Configuration as ChangesTrieConfig;
use sp_core::{map, traits::{Externalities, RuntimeCode}, storage::ChildStorageKey};
use sp_core::{map, traits::Externalities, storage::ChildStorageKey};
use sp_runtime::traits::BlakeTwo256;
#[derive(Clone)]
@@ -750,7 +715,6 @@ mod tests {
>(
&self,
ext: &mut E,
_: &RuntimeCode,
_method: &str,
_data: &[u8],
use_native: bool,
@@ -804,7 +768,6 @@ mod tests {
fn execute_works() {
let backend = trie_backend::tests::test_trie();
let mut overlayed_changes = Default::default();
let wasm_code = RuntimeCode::empty();
let mut state_machine = StateMachine::new(
&backend,
@@ -819,7 +782,6 @@ mod tests {
"test",
&[],
Default::default(),
&wasm_code,
);
assert_eq!(
@@ -833,7 +795,6 @@ mod tests {
fn execute_works_with_native_else_wasm() {
let backend = trie_backend::tests::test_trie();
let mut overlayed_changes = Default::default();
let wasm_code = RuntimeCode::empty();
let mut state_machine = StateMachine::new(
&backend,
@@ -848,7 +809,6 @@ mod tests {
"test",
&[],
Default::default(),
&wasm_code,
);
assert_eq!(state_machine.execute(ExecutionStrategy::NativeElseWasm).unwrap(), vec![66]);
@@ -859,7 +819,6 @@ mod tests {
let mut consensus_failed = false;
let backend = trie_backend::tests::test_trie();
let mut overlayed_changes = Default::default();
let wasm_code = RuntimeCode::empty();
let mut state_machine = StateMachine::new(
&backend,
@@ -874,7 +833,6 @@ mod tests {
"test",
&[],
Default::default(),
&wasm_code,
);
assert!(
@@ -907,7 +865,6 @@ mod tests {
&executor,
"test",
&[],
&RuntimeCode::empty(),
).unwrap();
// check proof locally
@@ -918,7 +875,6 @@ mod tests {
&executor,
"test",
&[],
&RuntimeCode::empty(),
).unwrap();
// check that both results are correct