Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Allow transaction for offchain indexing #7290

Merged
30 commits merged into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
afc95aa
Moving offchain change set to state machine overlay change set,
cheme Oct 8, 2020
5074e08
Make change set generic over key and value, and use it for offchain
cheme Oct 9, 2020
dfba4df
Merge branch 'master' into offchain_indexing_tx
cheme Oct 9, 2020
551c7bf
test ui change
cheme Oct 9, 2020
55d038a
remaining delta
cheme Oct 9, 2020
a9e1356
generating with standard method
cheme Oct 9, 2020
273b35c
Remove 'drain_committed' function, and documentation.
cheme Oct 13, 2020
9dfce19
Default constructor for enabling offchain indexing.
cheme Oct 20, 2020
35f6877
Remove offchain change specific iterators.
cheme Oct 20, 2020
12d1c9d
Merge branch 'master' into offchain_indexing_tx
cheme Oct 20, 2020
48db71b
remove pub accessor
cheme Oct 27, 2020
b0f10e0
keep previous hierarchy, just expose iterator instead.
cheme Oct 27, 2020
c868334
Merge branch 'master' into offchain_indexing_tx
cheme Oct 27, 2020
dd0c7d9
Merge branch 'master' into offchain_indexing_tx
cheme Nov 9, 2020
76b83aa
Merge branch 'offchain_indexing_tx' of github.com:cheme/substrate int…
cheme Nov 9, 2020
ca03c50
Update primitives/state-machine/src/overlayed_changes/mod.rs
wheresaddie Nov 25, 2020
01f3dbd
fix line break
cheme Nov 25, 2020
33106ce
Merge branch 'master' into offchain_indexing_tx
cheme Nov 25, 2020
c862d7b
missing renamings
cheme Nov 25, 2020
4894da4
Merge branch 'master' into offchain_indexing_tx
cheme Jan 20, 2021
e2813af
fix import
cheme Jan 20, 2021
b0fc789
fix new state-machine tests.
cheme Jan 20, 2021
bd82401
Don't expose InnerValue type.
cheme Jan 20, 2021
7e99e2d
Add test similar to set_storage.
cheme Jan 20, 2021
b13c279
Merge branch 'master' into offchain_indexing_tx
cheme Jan 20, 2021
d10dd3c
Merge branch 'master' into offchain_indexing_tx
cheme Jan 21, 2021
443e05f
Remove conditional offchain storage (hard to instantiate correctly).
cheme Jan 21, 2021
c796fbc
fix
cheme Jan 21, 2021
59f617c
offchain as children cannot fail if top doesn't
cheme Jan 22, 2021
0ec6d16
Merge branch 'master' into offchain_indexing_tx
cheme Jan 22, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions client/api/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
use std::sync::Arc;
use std::collections::{HashMap, HashSet};
use sp_core::ChangesTrieConfigurationRange;
use sp_core::offchain::{OffchainStorage,storage::OffchainOverlayedChanges};
use sp_core::offchain::OffchainStorage;
use sp_runtime::{generic::BlockId, Justification, Storage};
use sp_runtime::traits::{Block as BlockT, NumberFor, HashFor};
use sp_state_machine::{
ChangesTrieState, ChangesTrieStorage as StateChangesTrieStorage, ChangesTrieTransaction,
StorageCollection, ChildStorageCollection,
StorageCollection, ChildStorageCollection, OffchainChangesCollection,
};
use sp_storage::{StorageData, StorageKey, PrefixedStorageKey, ChildInfo};
use crate::{
Expand Down Expand Up @@ -174,7 +174,7 @@ pub trait BlockImportOperation<Block: BlockT> {
/// Write offchain storage changes to the database.
fn update_offchain_storage(
&mut self,
_offchain_update: OffchainOverlayedChanges,
_offchain_update: OffchainChangesCollection,
) -> sp_blockchain::Result<()> {
Ok(())
}
Expand Down
3 changes: 1 addition & 2 deletions client/api/src/call_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use sp_state_machine::{
};
use sc_executor::{RuntimeVersion, NativeVersion};
use sp_externalities::Extensions;
use sp_core::{NativeOrEncoded,offchain::storage::OffchainOverlayedChanges};
use sp_core::NativeOrEncoded;

use sp_api::{ProofRecorder, InitializeBlock, StorageTransactionCache};
use crate::execution_extensions::ExecutionExtensions;
Expand Down Expand Up @@ -86,7 +86,6 @@ pub trait CallExecutor<B: BlockT> {
method: &str,
call_data: &[u8],
changes: &RefCell<OverlayedChanges>,
offchain_changes: &RefCell<OffchainOverlayedChanges>,
storage_transaction_cache: Option<&RefCell<
StorageTransactionCache<B, <Self::Backend as crate::backend::Backend<B>>::State>,
>>,
Expand Down
10 changes: 5 additions & 5 deletions client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ use sp_trie::{MemoryDB, PrefixedMemoryDB, prefixed_key};
use sp_database::Transaction;
use parking_lot::RwLock;
use sp_core::ChangesTrieConfiguration;
use sp_core::offchain::storage::{OffchainOverlayedChange, OffchainOverlayedChanges};
use sp_core::offchain::OffchainOverlayedChange;
use sp_core::storage::{well_known_keys, ChildInfo};
use sp_arithmetic::traits::Saturating;
use sp_runtime::{generic::{DigestItem, BlockId}, Justification, Storage};
Expand All @@ -74,7 +74,7 @@ use sp_runtime::traits::{
};
use sp_state_machine::{
DBValue, ChangesTrieTransaction, ChangesTrieCacheAction, UsageInfo as StateUsageInfo,
StorageCollection, ChildStorageCollection,
StorageCollection, ChildStorageCollection, OffchainChangesCollection,
backend::Backend as StateBackend, StateMachineStats,
};
use crate::utils::{DatabaseType, Meta, meta_keys, read_db, read_meta};
Expand Down Expand Up @@ -581,7 +581,7 @@ pub struct BlockImportOperation<Block: BlockT> {
db_updates: PrefixedMemoryDB<HashFor<Block>>,
storage_updates: StorageCollection,
child_storage_updates: ChildStorageCollection,
offchain_storage_updates: OffchainOverlayedChanges,
offchain_storage_updates: OffchainChangesCollection,
changes_trie_updates: MemoryDB<HashFor<Block>>,
changes_trie_build_cache_update: Option<ChangesTrieCacheAction<Block::Hash, NumberFor<Block>>>,
changes_trie_config_update: Option<Option<ChangesTrieConfiguration>>,
Expand All @@ -594,7 +594,7 @@ pub struct BlockImportOperation<Block: BlockT> {

impl<Block: BlockT> BlockImportOperation<Block> {
fn apply_offchain(&mut self, transaction: &mut Transaction<DbHash>) {
for ((prefix, key), value_operation) in self.offchain_storage_updates.drain() {
for ((prefix, key), value_operation) in self.offchain_storage_updates.drain(..) {
let key: Vec<u8> = prefix
.into_iter()
.chain(sp_core::sp_std::iter::once(b'/'))
Expand Down Expand Up @@ -714,7 +714,7 @@ impl<Block: BlockT> sc_client_api::backend::BlockImportOperation<Block> for Bloc

fn update_offchain_storage(
&mut self,
offchain_update: OffchainOverlayedChanges,
offchain_update: OffchainChangesCollection,
) -> ClientResult<()> {
self.offchain_storage_updates = offchain_update;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion client/executor/src/integration_tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ fn offchain_index(wasm_method: WasmExecutionMethod) {
&mut ext.ext(),
).unwrap();

use sp_core::offchain::storage::OffchainOverlayedChange;
use sp_core::offchain::OffchainOverlayedChange;
assert_eq!(
ext.ext()
.get_offchain_storage_changes()
Expand Down
3 changes: 0 additions & 3 deletions client/light/src/call_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use std::{
use codec::{Encode, Decode};
use sp_core::{
convert_hash, NativeOrEncoded, traits::{CodeExecutor, SpawnNamed},
offchain::storage::OffchainOverlayedChanges,
};
use sp_runtime::{
generic::BlockId, traits::{One, Block as BlockT, Header as HeaderT, HashFor},
Expand Down Expand Up @@ -113,7 +112,6 @@ impl<Block, B, Local> CallExecutor<Block> for
method: &str,
call_data: &[u8],
changes: &RefCell<OverlayedChanges>,
offchain_changes: &RefCell<OffchainOverlayedChanges>,
_: Option<&RefCell<StorageTransactionCache<Block, B::State>>>,
initialize_block: InitializeBlock<'a, Block>,
_manager: ExecutionManager<EM>,
Expand All @@ -140,7 +138,6 @@ impl<Block, B, Local> CallExecutor<Block> for
method,
call_data,
changes,
offchain_changes,
None,
initialize_block,
ExecutionManager::NativeWhenPossible,
Expand Down
16 changes: 3 additions & 13 deletions client/service/src/client/call_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ use sc_executor::{RuntimeVersion, RuntimeInfo, NativeVersion};
use sp_externalities::Extensions;
use sp_core::{
NativeOrEncoded, NeverNativeValue, traits::{CodeExecutor, SpawnNamed},
offchain::storage::OffchainOverlayedChanges,
};
use sp_api::{ProofRecorder, InitializeBlock, StorageTransactionCache};
use sc_client_api::{backend, call_executor::CallExecutor};
Expand Down Expand Up @@ -91,11 +90,9 @@ where
extensions: Option<Extensions>,
) -> sp_blockchain::Result<Vec<u8>> {
let mut changes = OverlayedChanges::default();
let mut offchain_changes = if self.client_config.offchain_indexing_api {
OffchainOverlayedChanges::enabled()
} else {
OffchainOverlayedChanges::disabled()
};
if self.client_config.offchain_indexing_api {
changes.enable_offchain_indexing();
}
let changes_trie = backend::changes_tries_state_at_block(
id, self.backend.changes_trie_storage()
)?;
Expand All @@ -105,7 +102,6 @@ where
&state,
changes_trie,
&mut changes,
&mut offchain_changes,
&self.executor,
method,
call_data,
Expand Down Expand Up @@ -136,7 +132,6 @@ where
method: &str,
call_data: &[u8],
changes: &RefCell<OverlayedChanges>,
offchain_changes: &RefCell<OffchainOverlayedChanges>,
storage_transaction_cache: Option<&RefCell<
StorageTransactionCache<Block, B::State>
>>,
Expand All @@ -161,7 +156,6 @@ where
let mut state = self.backend.state_at(*at)?;

let changes = &mut *changes.borrow_mut();
let offchain_changes = &mut *offchain_changes.borrow_mut();

match recorder {
Some(recorder) => {
Expand All @@ -184,7 +178,6 @@ where
&backend,
changes_trie_state,
changes,
offchain_changes,
&self.executor,
method,
call_data,
Expand All @@ -203,7 +196,6 @@ where
&state,
changes_trie_state,
changes,
offchain_changes,
&self.executor,
method,
call_data,
Expand All @@ -218,7 +210,6 @@ where

fn runtime_version(&self, id: &BlockId<Block>) -> sp_blockchain::Result<RuntimeVersion> {
let mut overlay = OverlayedChanges::default();
let mut offchain_overlay = OffchainOverlayedChanges::default();
let changes_trie_state = backend::changes_tries_state_at_block(
id,
self.backend.changes_trie_storage(),
Expand All @@ -227,7 +218,6 @@ where
let mut cache = StorageTransactionCache::<Block, B::State>::default();
let mut ext = Ext::new(
&mut overlay,
&mut offchain_overlay,
&mut cache,
&state,
changes_trie_state,
Expand Down
1 change: 0 additions & 1 deletion client/service/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1650,7 +1650,6 @@ impl<B, E, Block, RA> CallApiAt<Block> for Client<B, E, Block, RA> where
params.function,
&params.arguments,
params.overlayed_changes,
params.offchain_changes,
Some(params.storage_transaction_cache),
params.initialize_block,
manager,
Expand Down
3 changes: 1 addition & 2 deletions client/service/test/src/client/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down
12 changes: 1 addition & 11 deletions client/service/test/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,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;
Expand Down Expand Up @@ -161,7 +161,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());
Expand All @@ -170,7 +169,6 @@ fn construct_block(
backend,
sp_state_machine::disabled_changes_trie_state::<_, u64>(),
&mut overlay,
&mut offchain_overlay,
&executor(),
"Core_initialize_block",
&header.encode(),
Expand All @@ -186,7 +184,6 @@ fn construct_block(
backend,
sp_state_machine::disabled_changes_trie_state::<_, u64>(),
&mut overlay,
&mut offchain_overlay,
&executor(),
"BlockBuilder_apply_extrinsic",
&tx.encode(),
Expand All @@ -202,7 +199,6 @@ fn construct_block(
backend,
sp_state_machine::disabled_changes_trie_state::<_, u64>(),
&mut overlay,
&mut offchain_overlay,
&executor(),
"BlockBuilder_finalize_block",
&[],
Expand Down Expand Up @@ -250,13 +246,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,
Expand Down Expand Up @@ -286,13 +280,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,
Expand Down Expand Up @@ -322,13 +314,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,
Expand Down
3 changes: 0 additions & 3 deletions primitives/api/proc-macro/src/decl_runtime_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ fn generate_call_api_at_calls(decl: &ItemTrait) -> Result<TokenStream> {
at: &#crate_::BlockId<Block>,
args: Vec<u8>,
changes: &std::cell::RefCell<#crate_::OverlayedChanges>,
offchain_changes: &std::cell::RefCell<#crate_::OffchainOverlayedChanges>,
storage_transaction_cache: &std::cell::RefCell<
#crate_::StorageTransactionCache<Block, T::StateBackend>
>,
Expand Down Expand Up @@ -439,7 +438,6 @@ fn generate_call_api_at_calls(decl: &ItemTrait) -> Result<TokenStream> {
native_call: None,
arguments: args,
overlayed_changes: changes,
offchain_changes,
storage_transaction_cache,
initialize_block,
context,
Expand All @@ -460,7 +458,6 @@ fn generate_call_api_at_calls(decl: &ItemTrait) -> Result<TokenStream> {
native_call,
arguments: args,
overlayed_changes: changes,
offchain_changes,
storage_transaction_cache,
initialize_block,
context,
Expand Down
6 changes: 0 additions & 6 deletions primitives/api/proc-macro/src/impl_runtime_apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ fn generate_runtime_api_base_structures() -> Result<TokenStream> {
commit_on_success: std::cell::RefCell<bool>,
initialized_block: std::cell::RefCell<Option<#crate_::BlockId<Block>>>,
changes: std::cell::RefCell<#crate_::OverlayedChanges>,
offchain_changes: std::cell::RefCell<#crate_::OffchainOverlayedChanges>,
storage_transaction_cache: std::cell::RefCell<
#crate_::StorageTransactionCache<Block, C::StateBackend>
>,
Expand Down Expand Up @@ -338,7 +337,6 @@ fn generate_runtime_api_base_structures() -> Result<TokenStream> {
commit_on_success: true.into(),
initialized_block: None.into(),
changes: Default::default(),
offchain_changes: Default::default(),
recorder: Default::default(),
storage_transaction_cache: Default::default(),
}.into()
Expand All @@ -357,7 +355,6 @@ fn generate_runtime_api_base_structures() -> Result<TokenStream> {
&C,
&Self,
&std::cell::RefCell<#crate_::OverlayedChanges>,
&std::cell::RefCell<#crate_::OffchainOverlayedChanges>,
&std::cell::RefCell<#crate_::StorageTransactionCache<Block, C::StateBackend>>,
&std::cell::RefCell<Option<#crate_::BlockId<Block>>>,
&Option<#crate_::ProofRecorder<Block>>,
Expand All @@ -374,7 +371,6 @@ fn generate_runtime_api_base_structures() -> Result<TokenStream> {
&self.call,
self,
&self.changes,
&self.offchain_changes,
&self.storage_transaction_cache,
&self.initialized_block,
&self.recorder,
Expand Down Expand Up @@ -531,7 +527,6 @@ impl<'a> Fold for ApiRuntimeImplToApiRuntimeApiImpl<'a> {
call_runtime_at,
core_api,
changes,
offchain_changes,
storage_transaction_cache,
initialized_block,
recorder
Expand All @@ -542,7 +537,6 @@ impl<'a> Fold for ApiRuntimeImplToApiRuntimeApiImpl<'a> {
at,
params_encoded,
changes,
offchain_changes,
storage_transaction_cache,
initialized_block,
params.map(|p| {
Expand Down
4 changes: 0 additions & 4 deletions primitives/api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ pub use sp_core::NativeOrEncoded;
#[doc(hidden)]
#[cfg(feature = "std")]
pub use hash_db::Hasher;
#[cfg(feature = "std")]
pub use sp_core::offchain::storage::OffchainOverlayedChanges;
#[doc(hidden)]
#[cfg(not(feature = "std"))]
pub use sp_core::to_substrate_wasm_fn_return_value;
Expand Down Expand Up @@ -439,8 +437,6 @@ pub struct CallApiAtParams<'a, Block: BlockT, C, NC, Backend: StateBackend<HashF
pub arguments: Vec<u8>,
/// The overlayed changes that are on top of the state.
pub overlayed_changes: &'a RefCell<OverlayedChanges>,
/// The overlayed changes to be applied to the offchain worker database.
pub offchain_changes: &'a RefCell<OffchainOverlayedChanges>,
/// The cache for storage transactions.
pub storage_transaction_cache: &'a RefCell<StorageTransactionCache<Block, Backend>>,
/// Determines if the function requires that `initialize_block` should be called before calling
Expand Down
Loading