Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
611f481
DigestItem::ChangesTrieSignal
svyatonik Jun 25, 2019
8b65b04
introduce changes_trie::State
svyatonik Jun 26, 2019
0cd05df
introduce config activation block
svyatonik Jun 26, 2019
40ed2c2
ChangesTrieSignal::as_new_configuration
svyatonik Jun 26, 2019
c01ecd6
moved well_known_cache_keys to client
svyatonik Jun 27, 2019
73f1933
extracted DbChangesTrieStorage to separate file
svyatonik Jun 27, 2019
315303a
change meaning of none in blockchain cache
svyatonik Jun 28, 2019
67642d1
changes trie config (FULL) cache draft
svyatonik Jul 1, 2019
a7e240d
eliminating const ChangesTrieConfiguration
svyatonik Jul 1, 2019
5256d03
delay pruning
svyatonik Jul 2, 2019
698e2ff
continue elimination
svyatonik Jul 3, 2019
04a8fa0
do not prune CT config from cache
svyatonik Jul 3, 2019
afda822
removed redundant code
svyatonik Jul 3, 2019
e08183d
fix some TODOs
svyatonik Jul 4, 2019
368563f
Merge branch 'master' into changes_tries_update_configuration
svyatonik Jul 24, 2019
01e3792
introduce ConfigurationRange
svyatonik Jul 29, 2019
c1913fc
use Configuration range in build
svyatonik Jul 29, 2019
fb6ae9c
build skewed digest
svyatonik Jul 29, 2019
e429061
remove debug print
svyatonik Jul 29, 2019
e6acae8
extracted surface iterator
svyatonik Jul 30, 2019
68527fb
key_changes works with skewed digests
svyatonik Jul 30, 2019
5a839e5
fix client build
svyatonik Jul 30, 2019
9729912
add test for NeverPrune
svyatonik Jul 30, 2019
bca439a
fix TODO
svyatonik Jul 30, 2019
383795a
fixed some TODOs
svyatonik Jul 30, 2019
f6993f6
more tests
svyatonik Jul 31, 2019
8b70450
fixing TODOs
svyatonik Aug 1, 2019
1b3b565
fixed compilation
svyatonik Aug 1, 2019
fa7d631
Merge branch 'master' into changes_tries_update_configuration
svyatonik Aug 1, 2019
1de7f77
update runtime version
svyatonik Aug 1, 2019
ce78f66
git rid of large tuple
svyatonik Aug 1, 2019
82e74d5
too long lines
svyatonik Aug 1, 2019
cfb1cf1
config_activation_block -> zero
svyatonik Aug 1, 2019
94979f8
obsolete TODO
svyatonik Aug 1, 2019
dd5b602
removed unjustified expect
svyatonik Aug 1, 2019
7260719
update TODOs with issue number
svyatonik Aug 1, 2019
c563d30
Merge branch 'master' into changes_tries_update_configuration
svyatonik Aug 6, 2019
4552586
new CT pruning algorithm
svyatonik Aug 7, 2019
62a5aa8
Merge branch 'master' into changes_tries_update_configuration
svyatonik Aug 13, 2019
27eecae
BlockIdOrHeader isn't really required
svyatonik Aug 14, 2019
a158250
Merge branch 'master' into changes_tries_update_configuration
svyatonik Nov 8, 2019
ce92672
Merge branch 'master' into changes_tries_update_configuration
svyatonik Nov 11, 2019
9da96a5
removed debug leftovers + some docs
svyatonik Nov 12, 2019
f8a14f5
more docs
svyatonik Nov 12, 2019
68c4db0
more post-merge fixes
svyatonik Nov 12, 2019
d63d65e
more post-merge fixes
svyatonik Nov 12, 2019
9baac30
Merge branch 'master' into changes_tries_update_configuration
svyatonik Nov 12, 2019
6da8b23
revertes some unnecessary changes
svyatonik Nov 12, 2019
d302d1e
reverted unnecessary changes
svyatonik Nov 12, 2019
f4a82de
fix compilation + unnecessary changes
svyatonik Nov 12, 2019
801169c
(restart CI)
svyatonik Nov 12, 2019
eae183b
fix cache update when finalizing multiple blocks
svyatonik Nov 12, 2019
6d2b4db
fixed tests
svyatonik Nov 12, 2019
d7abf44
Merge branch 'master' into changes_tries_update_configuration
svyatonik Nov 25, 2019
6b3d12d
Merge branch 'master' into changes_tries_update_configuration
svyatonik Nov 29, 2019
d89c979
Merge remote-tracking branch 'origin/master' into changes_tries_updat…
svyatonik Dec 11, 2019
ed31869
Merge remote-tracking branch 'origin/master' into changes_tries_updat…
svyatonik Dec 17, 2019
af3c925
collect_extrinsics -> set_collect_extrinsics
svyatonik Jan 5, 2020
935fb7b
restore lost test
svyatonik Jan 5, 2020
9da28c8
do not calculate block number twice
svyatonik Jan 5, 2020
bf7fea2
Update primitives/blockchain/src/error.rs
svyatonik Jan 5, 2020
3d570f1
map_err -> unwrap_or
svyatonik Jan 5, 2020
b898191
document get_at Result
svyatonik Jan 5, 2020
7db5596
delete abandoned file
svyatonik Jan 5, 2020
9481f59
added weight for set_changes_trie_config
svyatonik Jan 5, 2020
05630d8
Merge branch 'changes_tries_update_configuration' of https://github.c…
svyatonik Jan 5, 2020
06755b0
prefer_configs -> fail_if_disabled
svyatonik Jan 5, 2020
d0b2de2
Update client/api/src/backend.rs
svyatonik Jan 5, 2020
2f795e6
Merge branch 'changes_tries_update_configuration' of https://github.c…
svyatonik Jan 5, 2020
c4c8871
Update client/db/src/changes_tries_storage.rs
svyatonik Jan 6, 2020
51fa091
CommitOperation+merge -> CommitOperations
svyatonik Jan 6, 2020
98d1958
Merge branch 'changes_tries_update_configuration' of https://github.c…
svyatonik Jan 7, 2020
46d4721
fixed test compilation
svyatonik Jan 7, 2020
39c5f64
merged two different CTRange structs
svyatonik Jan 9, 2020
ee16f37
Merge remote-tracking branch 'origin/master' into changes_tries_updat…
svyatonik Jan 9, 2020
25452a5
lost file
svyatonik Jan 9, 2020
54f3d47
Merge remote-tracking branch 'origin/master' into changes_tries_updat…
svyatonik Jan 13, 2020
233afad
uggrade db from v0 to v1 (init CT cache + add column)
svyatonik Jan 14, 2020
0997bd6
Merge branch 'master' into changes_tries_update_configuration
gavofyork Jan 16, 2020
7658040
fix after merge
svyatonik Jan 16, 2020
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
Prev Previous commit
Next Next commit
Merge branch 'master' into changes_tries_update_configuration
  • Loading branch information
svyatonik committed Aug 13, 2019
commit 62a5aa823dcd503840eb342cfdd9871d60187c20
11 changes: 4 additions & 7 deletions core/client/db/src/changes_tries_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@

//! DB-backed changes tries storage.

// TODO: use last non-pruned digest block!!!

use std::collections::HashMap;
use std::sync::Arc;
use hash_db::Prefix;
use kvdb::{KeyValueDB, DBTransaction};
use parity_codec::Encode;
use codec::{Decode, Encode};
use parking_lot::RwLock;
use client::error::{Error as ClientError, Result as ClientResult};
use trie::MemoryDB;
use client::backend::ChangesTrieConfigurationRange;
use client::blockchain::well_known_cache_keys;
use parity_codec::Decode;
use primitives::{H256, Blake2Hasher, ChangesTrieConfiguration, convert_hash};
use sr_primitives::traits::{
Block as BlockT, Header as HeaderT, NumberFor, One, Zero, CheckedSub,
Expand Down Expand Up @@ -324,7 +321,7 @@ impl<Block: BlockT<Hash=H256>> DbChangesTrieStorage<Block> {
fn configuration_at_block(&self, at: BlockIdOrHeader<Block>) -> ClientResult<ChangesTrieConfigurationRange<Block>> {
self.cache
.get_at_block(&well_known_cache_keys::CHANGES_TRIE_CONFIG, at)
.and_then(|(zero, end, encoded)| Decode::decode(&mut &encoded[..])
.and_then(|(zero, end, encoded)| Decode::decode(&mut &encoded[..]).ok()
.map(|config| ChangesTrieConfigurationRange { zero, end, config }))
.ok_or_else(|| ClientError::ErrorReadingChangesTriesConfig)
}
Expand Down Expand Up @@ -438,8 +435,8 @@ fn read_tries_meta<Block: BlockT>(
) -> ClientResult<ChangesTriesMeta<Block>> {
match db.get(meta_column, meta_keys::CHANGES_TRIES_META).map_err(db_err)? {
Some(h) => match Decode::decode(&mut &h[..]) {
Some(h) => Ok(h),
None => Err(client::error::Error::Backend("Error decoding changes tries metadata".into())),
Ok(h) => Ok(h),
Err(err) => Err(ClientError::Backend(format!("Error decoding changes tries metadata: {}", err))),
},
None => Ok(ChangesTriesMeta {
oldest_digest_range: None,
Expand Down
2 changes: 1 addition & 1 deletion core/client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use client::backend::NewBlockState;
use client::blockchain::HeaderBackend;
use client::ExecutionStrategies;
use client::backend::{StorageCollection, ChildStorageCollection, PrunableStateChangesTrieStorage};
use parity_codec::{Decode, Encode};
use codec::{Decode, Encode};
use hash_db::{Hasher, Prefix};
use kvdb::{KeyValueDB, DBTransaction};
use trie::{MemoryDB, PrefixedMemoryDB, prefixed_key};
Expand Down
31 changes: 3 additions & 28 deletions core/client/db/src/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use client::backend::{AuxStore, NewBlockState};
use client::blockchain::{BlockStatus, Cache as BlockchainCache,
HeaderBackend as BlockchainHeaderBackend, Info as BlockchainInfo};
use client::{cht, well_known_cache_keys};
use client::leaves::{LeafSet, FinalizationDisplaced};
use client::error::{Error as ClientError, Result as ClientResult};
use client::light::blockchain::Storage as LightBlockchainStorage;
use codec::{Decode, Encode};
Expand Down Expand Up @@ -107,7 +106,6 @@ impl<Block> LightStorage<Block>
db,
meta: RwLock::new(meta),
cache: Arc::new(DbCacheSync::new(cache)),
leaves: RwLock::new(leaves),
})
}

Expand Down Expand Up @@ -445,9 +443,6 @@ impl<Block> LightBlockchainStorage<Block> for LightStorage<Block>
}

{
let mut leaves = self.leaves.write();
let displaced_leaf = leaves.import(hash, number, parent_hash);

let mut cache = self.cache.cache().write();
let cache_ops = cache.transaction(&mut transaction)
.on_block_insert(
Expand All @@ -459,23 +454,8 @@ impl<Block> LightBlockchainStorage<Block> for LightStorage<Block>
.into_ops();

debug!("Light DB Commit {:?} ({})", hash, number);
let write_result = self.db.write(transaction).map_err(db_err);
if let Err(e) = write_result {
let mut leaves = self.leaves.write();
let mut undo = leaves.undo();

// revert leaves set update if there was one.
if let Some(displaced_leaf) = displaced_leaf {
undo.undo_import(displaced_leaf);
}

if let Some(finalization_displaced) = finalization_displaced_leaves {
undo.undo_finalization(finalization_displaced);
}

return Err(e);
}

self.db.write(transaction).map_err(db_err)?;
cache.commit(cache_ops)
.expect("only fails if cache with given name isn't loaded yet;\
cache is already loaded because there are cache_ops; qed");
Expand Down Expand Up @@ -532,12 +512,7 @@ impl<Block> LightBlockchainStorage<Block> for LightStorage<Block>
)?
.into_ops();

if let Err(e) = self.db.write(transaction).map_err(db_err) {
if let Some(displaced) = displaced {
self.leaves.write().undo().undo_finalization(displaced);
}
return Err(e);
}
self.db.write(transaction).map_err(db_err)?;
cache.commit(cache_ops)
.expect("only fails if cache with given name isn't loaded yet;\
cache is already loaded because there are cache_ops; qed");
Expand Down Expand Up @@ -887,7 +862,7 @@ pub(crate) mod tests {

fn get_authorities(cache: &dyn BlockchainCache<Block>, at: BlockId<Block>) -> Option<Vec<AuthorityId>> {
cache.get_at(&well_known_cache_keys::AUTHORITIES, &at)
.and_then(|(_, _, val)| Decode::decode(&mut &val[..]))
.and_then(|(_, _, val)| Decode::decode(&mut &val[..]).ok())
}

let auth1 = || AuthorityId::from_raw([1u8; 32]);
Expand Down
12 changes: 10 additions & 2 deletions core/client/src/call_executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,16 @@ where
let mut overlay = OverlayedChanges::default();
let state = self.backend.state_at(*id)?;
let changes_trie_state = backend::changes_tries_state_at_block(id, self.backend.changes_trie_storage())?;
let mut ext = Ext::new(&mut overlay, &state, changes_trie_state.as_ref(), NeverOffchainExt::new());
self.executor.runtime_version(&mut ext).ok_or(error::Error::VersionInvalid.into())
let mut ext = Ext::new(
&mut overlay,
&state,
changes_trie_state.as_ref(),
NeverOffchainExt::new(),
None,
);
let version = self.executor.runtime_version(&mut ext);
self.backend.destroy_state(state)?;
version.ok_or(error::Error::VersionInvalid.into())
}

fn call_at_state<
Expand Down
36 changes: 3 additions & 33 deletions core/client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,8 @@ use std::{
use log::{info, trace, warn};
use futures::channel::mpsc;
use parking_lot::{Mutex, RwLock};
use primitives::NativeOrEncoded;
use sr_primitives::{
Justification,
generic::{BlockId, SignedBlock},
};
use consensus::{
Error as ConsensusError, BlockImportParams,
ImportResult, BlockOrigin, ForkChoiceStrategy,
SelectChain, self,
};
use sr_primitives::traits::{
Block as BlockT, Header as HeaderT, Zero, NumberFor,
ApiRef, ProvideRuntimeApi, SaturatedConversion, One, DigestFor,
};
use sr_primitives::generic::DigestItem;
use sr_primitives::BuildStorage;
use crate::runtime_api::{
CallRuntimeAt, ConstructRuntimeApi, Core as CoreApi, ProofRecorder,
InitializeBlock,
};
use codec::{Encode, Decode};
use hash_db::{Hasher, Prefix};
use primitives::{
Blake2Hasher, H256, ChangesTrieConfiguration, convert_hash,
NeverNativeValue, ExecutionContext,
Expand All @@ -64,23 +46,10 @@ use state_machine::{
ChangesTrieRootsStorage, ChangesTrieStorage,
key_changes, key_changes_proof, OverlayedChanges, NeverOffchainExt,
};
use hash_db::{Hasher, Prefix};

use crate::backend::{
self, BlockImportOperation, PrunableStateChangesTrieStorage,
StorageCollection, ChildStorageCollection,
};
use crate::blockchain::{
self, Info as ChainInfo, Backend as ChainBackend,
HeaderBackend as ChainHeaderBackend, ProvideCache, Cache,
well_known_cache_keys::Id as CacheKeyId,
};
use crate::call_executor::{CallExecutor, LocalCallExecutor};
use executor::{RuntimeVersion, RuntimeInfo};
use consensus::{
Error as ConsensusError, BlockImportParams,
ImportResult, BlockOrigin, ForkChoiceStrategy,
well_known_cache_keys::Id as CacheKeyId,
SelectChain, self,
};

Expand All @@ -96,6 +65,7 @@ use crate::{
blockchain::{
self, Info as ChainInfo, Backend as ChainBackend,
HeaderBackend as ChainHeaderBackend, ProvideCache, Cache,
well_known_cache_keys::Id as CacheKeyId,
},
call_executor::{CallExecutor, LocalCallExecutor},
notifications::{StorageNotifications, StorageEventStream},
Expand Down
6 changes: 3 additions & 3 deletions core/client/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ mod tests {
#[test]
fn construct_genesis_should_work_with_native() {
let mut storage = GenesisConfig::new(None,
vec![Sr25519Keyring::One.into(), Sr25519Keyring::Two.into()],
vec![Sr25519Keyring::One.public().into(), Sr25519Keyring::Two.public().into()],
vec![AccountKeyring::One.into(), AccountKeyring::Two.into()],
1000,
None,
Expand Down Expand Up @@ -177,7 +177,7 @@ mod tests {
#[test]
fn construct_genesis_should_work_with_wasm() {
let mut storage = GenesisConfig::new(None,
vec![Sr25519Keyring::One.into(), Sr25519Keyring::Two.into()],
vec![Sr25519Keyring::One.public().into(), Sr25519Keyring::Two.public().into()],
vec![AccountKeyring::One.into(), AccountKeyring::Two.into()],
1000,
None,
Expand Down Expand Up @@ -205,7 +205,7 @@ mod tests {
#[test]
fn construct_genesis_with_bad_transaction_should_panic() {
let mut storage = GenesisConfig::new(None,
vec![Sr25519Keyring::One.into(), Sr25519Keyring::Two.into()],
vec![Sr25519Keyring::One.public().into(), Sr25519Keyring::Two.public().into()],
vec![AccountKeyring::One.into(), AccountKeyring::Two.into()],
68,
None,
Expand Down
2 changes: 1 addition & 1 deletion core/client/src/light/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use std::collections::HashMap;
use std::sync::{Arc, Weak};
use parking_lot::{RwLock, Mutex};

use parity_codec::{Decode, Encode};
use codec::{Decode, Encode};
use primitives::{ChangesTrieConfiguration, storage::well_known_keys};
use sr_primitives::{generic::BlockId, Justification, StorageOverlay, ChildrenStorageOverlay};
use state_machine::{Backend as StateBackend, TrieBackend, backend::InMemory as InMemoryState};
Expand Down
11 changes: 4 additions & 7 deletions core/consensus/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,8 @@ use consensus_common::import_queue::{
Verifier, BasicQueue, BoxBlockImport, BoxJustificationImport, BoxFinalityProofImport,
};
use client::{
block_builder::api::BlockBuilder as BlockBuilderApi,
blockchain::ProvideCache,
runtime_api::ApiExt,
error::Result as CResult,
backend::AuxStore,
block_builder::api::BlockBuilder as BlockBuilderApi, blockchain::ProvideCache,
runtime_api::ApiExt, error::Result as CResult, backend::AuxStore, BlockOf,
well_known_cache_keys::{self, Id as CacheKeyId},
};

Expand Down Expand Up @@ -637,7 +634,7 @@ fn initialize_authorities_cache<A, B, C>(client: &C) -> Result<(), ConsensusErro
let genesis_id = BlockId::Number(Zero::zero());
let genesis_authorities: Option<Vec<A>> = cache
.get_at(&well_known_cache_keys::AUTHORITIES, &genesis_id)
.and_then(|(_, _, v)| Decode::decode(&mut &v[..]));
.and_then(|(_, _, v)| Decode::decode(&mut &v[..]).ok());
if genesis_authorities.is_some() {
return Ok(());
}
Expand Down Expand Up @@ -665,7 +662,7 @@ fn authorities<A, B, C>(client: &C, at: &BlockId<B>) -> Result<Vec<A>, Consensus
.cache()
.and_then(|cache| cache
.get_at(&well_known_cache_keys::AUTHORITIES, at)
.and_then(|(_, _, v)| Decode::decode(&mut &v[..]))
.and_then(|(_, _, v)| Decode::decode(&mut &v[..]).ok())
)
.or_else(|| AuraApi::authorities(&*client.runtime_api(), at).ok())
.ok_or_else(|| consensus_common::Error::InvalidAuthoritiesSet.into())
Expand Down
4 changes: 2 additions & 2 deletions core/consensus/babe/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ fn epoch<B, C>(client: &C, at: &BlockId<B>) -> Result<Epoch, ConsensusError> whe
client
.cache()
.and_then(|cache| cache.get_at(&well_known_cache_keys::EPOCH, at)
.and_then(|(_, _, v)| Decode::decode(&mut &v[..])))
.and_then(|(_, _, v)| Decode::decode(&mut &v[..]).ok()))
.or_else(|| {
if client.runtime_api().has_api::<dyn BabeApi<B>>(at).unwrap_or(false) {
let s = BabeApi::epoch(&*client.runtime_api(), at).ok()?;
Expand Down Expand Up @@ -869,7 +869,7 @@ fn initialize_authorities_cache<B, C>(client: &C) -> Result<(), ConsensusError>
let genesis_id = BlockId::Number(Zero::zero());
let genesis_epoch: Option<Epoch> = cache
.get_at(&well_known_cache_keys::EPOCH, &genesis_id)
.and_then(|(_, _, v)| Decode::decode(&mut &v[..]));
.and_then(|(_, _, v)| Decode::decode(&mut &v[..]).ok());
if genesis_epoch.is_some() {
return Ok(());
}
Expand Down
4 changes: 2 additions & 2 deletions core/network/src/protocol/light_dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ pub mod tests {
use crate::config::Roles;
use crate::message::{self, BlockAttributes, Direction, FromBlock, RequestId};
use libp2p::PeerId;
use super::{REQUEST_TIMEOUT, OnDemandCore, OnDemandNetwork, RequestData};
use super::{REQUEST_TIMEOUT, LightDispatch, LightDispatchNetwork, RequestData};
use test_client::runtime::{Block, Extrinsic, Header};

struct DummyFetchChecker { ok: bool }
Expand Down Expand Up @@ -1057,7 +1057,7 @@ pub mod tests {
light_dispatch.on_connect(&mut network_interface, peer0.clone(), Roles::FULL, 1000);

let (tx, response) = oneshot::channel();
on_demand.add_request(&mut network_interface, RequestData::RemoteChanges(RemoteChangesRequest {
light_dispatch.add_request(&mut network_interface, RequestData::RemoteChanges(RemoteChangesRequest {
changes_trie_configs: vec![(0, None, ChangesTrieConfiguration::new(4, 2))],
first_block: (1, Default::default()),
last_block: (100, Default::default()),
Expand Down
6 changes: 4 additions & 2 deletions core/sr-primitives/src/generic/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,10 @@ impl<Hash: Decode> Decode for DigestItem<Hash> {
let vals: (ConsensusEngineId, Vec<u8>) = Decode::decode(input)?;
Ok(DigestItem::Seal(vals.0, vals.1))
},
DigestItemType::ChangesTrieSignal => Some(DigestItem::ChangesTrieSignal(
DigestItemType::ChangesTrieSignal => Ok(DigestItem::ChangesTrieSignal(
Decode::decode(input)?,
)),
DigestItemType::Other => Some(DigestItem::Other(
DigestItemType::Other => Ok(DigestItem::Other(
Decode::decode(input)?,
)),
}
Expand Down Expand Up @@ -410,6 +410,8 @@ impl ChangesTrieSignal {
}
}

impl<'a, Hash: Encode> codec::EncodeLike for DigestItemRef<'a, Hash> {}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion core/state-machine/src/changes_trie/changes_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

use std::cell::RefCell;
use std::collections::VecDeque;
use parity_codec::{Decode, Encode};
use codec::{Decode, Encode};
use hash_db::Hasher;
use num_traits::Zero;
use trie::Recorder;
Expand Down
28 changes: 20 additions & 8 deletions core/state-machine/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,8 @@ where
mod tests {
use hex_literal::hex;
use num_traits::Zero;
use parity_codec::Encode;
use primitives::Blake2Hasher;
use codec::Encode;
use primitives::{Blake2Hasher};
use primitives::storage::well_known_keys::EXTRINSIC_INDEX;
use crate::backend::InMemory;
use crate::changes_trie::{
Expand Down Expand Up @@ -405,6 +405,14 @@ mod tests {
}
}

#[test]
fn storage_changes_root_is_none_when_storage_is_not_provided() {
let mut overlay = prepare_overlay_with_changes();
let backend = TestBackend::default();
let mut ext = TestExt::new(&mut overlay, &backend, None, None, None);
assert_eq!(ext.storage_changes_root(Default::default()).unwrap(), None);
}

#[test]
fn storage_changes_root_is_none_when_state_is_not_provided() {
let mut overlay = prepare_overlay_with_changes();
Expand All @@ -419,11 +427,13 @@ mod tests {
let storage = TestChangesTrieStorage::with_blocks(vec![(99, Default::default())]);
let state = Some(ChangesTrieState::new(changes_trie_config(), Zero::zero(), &storage));
let backend = TestBackend::default();
let mut ext = TestExt::new(&mut overlay, &backend, state.as_ref(), None);
let mut ext = TestExt::new(&mut overlay, &backend, state.as_ref(), None, None);
let root = hex!("bb0c2ef6e1d36d5490f9766cfcc7dfe2a6ca804504c3bb206053890d6dd02376").into();

assert_eq!(ext.storage_changes_root(Default::default()).unwrap(),
Some(root));
assert_eq!(
ext.storage_changes_root(Default::default()).unwrap(),
Some(root),
);
}

#[test]
Expand All @@ -433,10 +443,12 @@ mod tests {
let storage = TestChangesTrieStorage::with_blocks(vec![(99, Default::default())]);
let state = Some(ChangesTrieState::new(changes_trie_config(), Zero::zero(), &storage));
let backend = TestBackend::default();
let mut ext = TestExt::new(&mut overlay, &backend, state.as_ref(), None);
let mut ext = TestExt::new(&mut overlay, &backend, state.as_ref(), None, None);
let root = hex!("96f5aae4690e7302737b6f9b7f8567d5bbb9eac1c315f80101235a92d9ec27f4").into();

assert_eq!(ext.storage_changes_root(Default::default()).unwrap(),
Some(root));
assert_eq!(
ext.storage_changes_root(Default::default()).unwrap(),
Some(root),
);
}
}
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.