Storage chains sync (#9171)

* Sync storage chains

* Test

* Apply suggestions from code review

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

* Separate block body and indexed body

* Update client/db/src/lib.rs

Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>

Co-authored-by: cheme <emericchevalier.pro@gmail.com>
Co-authored-by: Shawn Tabrizi <shawntabrizi@gmail.com>
Co-authored-by: André Silva <123550+andresilva@users.noreply.github.com>
This commit is contained in:
Arkadiy Paronyan
2021-07-17 10:58:37 +02:00
committed by GitHub
parent f07a41e87d
commit 5a65bf5515
27 changed files with 221 additions and 59 deletions
+10
View File
@@ -102,6 +102,16 @@ impl<Block: BlockT, Executor, G: GenesisInit> TestClientBuilder<Block, Executor,
let backend = Arc::new(Backend::new_test(keep_blocks, 0));
Self::with_backend(backend)
}
/// Create new `TestClientBuilder` with default backend and storage chain mode
pub fn with_tx_storage(keep_blocks: u32) -> Self {
let backend = Arc::new(Backend::new_test_with_tx_storage(
keep_blocks,
0,
sc_client_db::TransactionStorageMode::StorageChain,
));
Self::with_backend(backend)
}
}
impl<Block: BlockT, Executor, Backend, G: GenesisInit> TestClientBuilder<Block, Executor, Backend, G> {
+2
View File
@@ -167,6 +167,7 @@ pub enum Extrinsic {
ChangesTrieConfigUpdate(Option<ChangesTrieConfiguration>),
OffchainIndexSet(Vec<u8>, Vec<u8>),
OffchainIndexClear(Vec<u8>),
Store(Vec<u8>),
}
parity_util_mem::malloc_size_of_is_0!(Extrinsic); // non-opaque extrinsic does not need this
@@ -199,6 +200,7 @@ impl BlindCheckable for Extrinsic {
Ok(Extrinsic::OffchainIndexSet(key, value)),
Extrinsic::OffchainIndexClear(key) =>
Ok(Extrinsic::OffchainIndexClear(key)),
Extrinsic::Store(data) => Ok(Extrinsic::Store(data)),
}
}
}
@@ -272,6 +272,8 @@ fn execute_transaction_backend(utx: &Extrinsic, extrinsic_index: u32) -> ApplyEx
sp_io::offchain_index::clear(&key);
Ok(Ok(()))
}
Extrinsic::Store(data) =>
execute_store(data.clone()),
}
}
@@ -301,6 +303,13 @@ fn execute_transfer_backend(tx: &Transfer) -> ApplyExtrinsicResult {
Ok(Ok(()))
}
fn execute_store(data: Vec<u8>) -> ApplyExtrinsicResult {
let content_hash = sp_io::hashing::blake2_256(&data);
let extrinsic_index: u32 = storage::unhashed::get(well_known_keys::EXTRINSIC_INDEX).unwrap();
sp_io::transaction_index::index(extrinsic_index, data.len() as u32, content_hash);
Ok(Ok(()))
}
fn execute_new_authorities_backend(new_authorities: &[AuthorityId]) -> ApplyExtrinsicResult {
NewAuthorities::put(new_authorities.to_vec());
Ok(Ok(()))