Make offchain indexing work (#7940)

* Make offchain indexing work

This fixes some bugs with offchain indexing to make it actually working ;)

* Fix tests

* Fix browser build

* Update client/db/src/offchain.rs

Co-authored-by: cheme <emericchevalier.pro@gmail.com>

* Remove seperation between prefix and key

Co-authored-by: cheme <emericchevalier.pro@gmail.com>
This commit is contained in:
Bastian Köcher
2021-01-21 13:12:42 +01:00
committed by GitHub
parent a3a9e7667c
commit cd0ad4805d
24 changed files with 188 additions and 306 deletions
@@ -36,7 +36,7 @@ use parking_lot::Mutex;
use substrate_test_runtime_client::{
runtime::{Hash, Block, Header}, TestClient, ClientBlockImportExt,
};
use sp_api::{InitializeBlock, StorageTransactionCache, ProofRecorder, OffchainOverlayedChanges};
use sp_api::{InitializeBlock, StorageTransactionCache, ProofRecorder};
use sp_consensus::BlockOrigin;
use sc_executor::{NativeExecutor, WasmExecutionMethod, RuntimeVersion, NativeVersion};
use sp_core::{H256, NativeOrEncoded, testing::TaskExecutor};
@@ -223,7 +223,6 @@ impl CallExecutor<Block> for DummyCallExecutor {
_method: &str,
_call_data: &[u8],
_changes: &RefCell<OverlayedChanges>,
_offchain_changes: &RefCell<OffchainOverlayedChanges>,
_storage_transaction_cache: Option<&RefCell<
StorageTransactionCache<
Block,
@@ -41,7 +41,7 @@ use sp_runtime::traits::{
};
use substrate_test_runtime::TestAPI;
use sp_state_machine::backend::Backend as _;
use sp_api::{ProvideRuntimeApi, OffchainOverlayedChanges};
use sp_api::ProvideRuntimeApi;
use sp_core::{H256, ChangesTrieConfiguration, blake2_256, testing::TaskExecutor};
use std::collections::{HashMap, HashSet};
use std::sync::Arc;
@@ -163,7 +163,6 @@ fn construct_block(
};
let hash = header.hash();
let mut overlay = OverlayedChanges::default();
let mut offchain_overlay = OffchainOverlayedChanges::default();
let backend_runtime_code = sp_state_machine::backend::BackendRuntimeCode::new(&backend);
let runtime_code = backend_runtime_code.runtime_code().expect("Code is part of the backend");
let task_executor = Box::new(TaskExecutor::new());
@@ -172,7 +171,6 @@ fn construct_block(
backend,
sp_state_machine::disabled_changes_trie_state::<_, u64>(),
&mut overlay,
&mut offchain_overlay,
&executor(),
"Core_initialize_block",
&header.encode(),
@@ -188,7 +186,6 @@ fn construct_block(
backend,
sp_state_machine::disabled_changes_trie_state::<_, u64>(),
&mut overlay,
&mut offchain_overlay,
&executor(),
"BlockBuilder_apply_extrinsic",
&tx.encode(),
@@ -204,7 +201,6 @@ fn construct_block(
backend,
sp_state_machine::disabled_changes_trie_state::<_, u64>(),
&mut overlay,
&mut offchain_overlay,
&executor(),
"BlockBuilder_finalize_block",
&[],
@@ -252,13 +248,11 @@ fn construct_genesis_should_work_with_native() {
let runtime_code = backend_runtime_code.runtime_code().expect("Code is part of the backend");
let mut overlay = OverlayedChanges::default();
let mut offchain_overlay = OffchainOverlayedChanges::default();
let _ = StateMachine::new(
&backend,
sp_state_machine::disabled_changes_trie_state::<_, u64>(),
&mut overlay,
&mut offchain_overlay,
&executor(),
"Core_execute_block",
&b1data,
@@ -288,13 +282,11 @@ fn construct_genesis_should_work_with_wasm() {
let runtime_code = backend_runtime_code.runtime_code().expect("Code is part of the backend");
let mut overlay = OverlayedChanges::default();
let mut offchain_overlay = OffchainOverlayedChanges::default();
let _ = StateMachine::new(
&backend,
sp_state_machine::disabled_changes_trie_state::<_, u64>(),
&mut overlay,
&mut offchain_overlay,
&executor(),
"Core_execute_block",
&b1data,
@@ -324,13 +316,11 @@ fn construct_genesis_with_bad_transaction_should_panic() {
let runtime_code = backend_runtime_code.runtime_code().expect("Code is part of the backend");
let mut overlay = OverlayedChanges::default();
let mut offchain_overlay = OffchainOverlayedChanges::default();
let r = StateMachine::new(
&backend,
sp_state_machine::disabled_changes_trie_state::<_, u64>(),
&mut overlay,
&mut offchain_overlay,
&executor(),
"Core_execute_block",
&b1data,