mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 09:51:10 +00:00
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:
@@ -79,6 +79,7 @@ pub struct TestClientBuilder<Block: BlockT, Executor, Backend, G: GenesisInit> {
|
||||
keystore: Option<SyncCryptoStorePtr>,
|
||||
fork_blocks: ForkBlocks<Block>,
|
||||
bad_blocks: BadBlocks<Block>,
|
||||
enable_offchain_indexing_api: bool,
|
||||
}
|
||||
|
||||
impl<Block: BlockT, Executor, G: GenesisInit> Default
|
||||
@@ -114,6 +115,7 @@ impl<Block: BlockT, Executor, Backend, G: GenesisInit> TestClientBuilder<Block,
|
||||
keystore: None,
|
||||
fork_blocks: None,
|
||||
bad_blocks: None,
|
||||
enable_offchain_indexing_api: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -175,6 +177,12 @@ impl<Block: BlockT, Executor, Backend, G: GenesisInit> TestClientBuilder<Block,
|
||||
self
|
||||
}
|
||||
|
||||
/// Enable the offchain indexing api.
|
||||
pub fn enable_offchain_indexing_api(mut self) -> Self {
|
||||
self.enable_offchain_indexing_api = true;
|
||||
self
|
||||
}
|
||||
|
||||
/// Build the test client with the given native executor.
|
||||
pub fn build_with_executor<RuntimeApi>(
|
||||
self,
|
||||
@@ -219,7 +227,10 @@ impl<Block: BlockT, Executor, Backend, G: GenesisInit> TestClientBuilder<Block,
|
||||
self.keystore,
|
||||
),
|
||||
None,
|
||||
ClientConfig::default(),
|
||||
ClientConfig {
|
||||
offchain_indexing_api: self.enable_offchain_indexing_api,
|
||||
..Default::default()
|
||||
},
|
||||
).expect("Creates new client");
|
||||
|
||||
let longest_chain = sc_consensus::LongestChain::new(self.backend);
|
||||
|
||||
@@ -149,6 +149,8 @@ pub enum Extrinsic {
|
||||
IncludeData(Vec<u8>),
|
||||
StorageChange(Vec<u8>, Option<Vec<u8>>),
|
||||
ChangesTrieConfigUpdate(Option<ChangesTrieConfiguration>),
|
||||
OffchainIndexSet(Vec<u8>, Vec<u8>),
|
||||
OffchainIndexClear(Vec<u8>),
|
||||
}
|
||||
|
||||
parity_util_mem::malloc_size_of_is_0!(Extrinsic); // non-opaque extrinsic does not need this
|
||||
@@ -177,6 +179,10 @@ impl BlindCheckable for Extrinsic {
|
||||
Extrinsic::StorageChange(key, value) => Ok(Extrinsic::StorageChange(key, value)),
|
||||
Extrinsic::ChangesTrieConfigUpdate(new_config) =>
|
||||
Ok(Extrinsic::ChangesTrieConfigUpdate(new_config)),
|
||||
Extrinsic::OffchainIndexSet(key, value) =>
|
||||
Ok(Extrinsic::OffchainIndexSet(key, value)),
|
||||
Extrinsic::OffchainIndexClear(key) =>
|
||||
Ok(Extrinsic::OffchainIndexClear(key)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1148,13 +1154,9 @@ fn test_witness(proof: StorageProof, root: crate::Hash) {
|
||||
root,
|
||||
);
|
||||
let mut overlay = sp_state_machine::OverlayedChanges::default();
|
||||
#[cfg(feature = "std")]
|
||||
let mut offchain_overlay = Default::default();
|
||||
let mut cache = sp_state_machine::StorageTransactionCache::<_, _, BlockNumber>::default();
|
||||
let mut ext = sp_state_machine::Ext::new(
|
||||
&mut overlay,
|
||||
#[cfg(feature = "std")]
|
||||
&mut offchain_overlay,
|
||||
&mut cache,
|
||||
&backend,
|
||||
#[cfg(feature = "std")]
|
||||
|
||||
@@ -261,6 +261,14 @@ fn execute_transaction_backend(utx: &Extrinsic, extrinsic_index: u32) -> ApplyEx
|
||||
execute_storage_change(key, value.as_ref().map(|v| &**v)),
|
||||
Extrinsic::ChangesTrieConfigUpdate(ref new_config) =>
|
||||
execute_changes_trie_config_update(new_config.clone()),
|
||||
Extrinsic::OffchainIndexSet(key, value) => {
|
||||
sp_io::offchain_index::set(&key, &value);
|
||||
Ok(Ok(()))
|
||||
},
|
||||
Extrinsic::OffchainIndexClear(key) => {
|
||||
sp_io::offchain_index::clear(&key);
|
||||
Ok(Ok(()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user