Skip to content

Commit

Permalink
Allow empty values in the storage (paritytech#6364)
Browse files Browse the repository at this point in the history
* Allow empty values in the storage

* Bump trie-bench

* Bump trie-bench
  • Loading branch information
arkpar authored Jun 18, 2020
1 parent f8afa52 commit b02101e
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 16 deletions.
12 changes: 6 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion frame/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,7 +709,7 @@ mod tests {
header: Header {
parent_hash: [69u8; 32].into(),
number: 1,
state_root: hex!("05a38fa4a48ca80ffa8482304be7749a484dc8c9c31462a570d0fbadde6a3633").into(),
state_root: hex!("e8ff7b3dd4375f6f3a76e24a1999e2a7be2d15b353e49ac94ace1eae3e80eb87").into(),
extrinsics_root: hex!("03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314").into(),
digest: Digest { logs: vec![], },
},
Expand Down
2 changes: 1 addition & 1 deletion primitives/state-machine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ targets = ["x86_64-unknown-linux-gnu"]
log = "0.4.8"
parking_lot = "0.10.0"
hash-db = "0.15.2"
trie-db = "0.20.1"
trie-db = "0.21.0"
trie-root = "0.16.0"
sp-trie = { version = "2.0.0-rc3", path = "../trie" }
sp-core = { version = "2.0.0-rc3", path = "../core" }
Expand Down
36 changes: 36 additions & 0 deletions primitives/state-machine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1306,4 +1306,40 @@ mod tests {
}
assert!(!duplicate);
}

#[test]
fn set_storage_empty_allowed() {
let initial: BTreeMap<_, _> = map![
b"aaa".to_vec() => b"0".to_vec(),
b"bbb".to_vec() => b"".to_vec()
];
let mut state = InMemoryBackend::<BlakeTwo256>::from(initial);
let backend = state.as_trie_backend().unwrap();

let mut overlay = OverlayedChanges::default();
overlay.set_storage(b"ccc".to_vec(), Some(b"".to_vec()));
assert_eq!(overlay.storage(b"ccc"), Some(Some(&[][..])));
overlay.commit_prospective();
assert_eq!(overlay.storage(b"ccc"), Some(Some(&[][..])));
assert_eq!(overlay.storage(b"bbb"), None);

{
let mut offchain_overlay = Default::default();
let mut cache = StorageTransactionCache::default();
let mut ext = Ext::new(
&mut overlay,
&mut offchain_overlay,
&mut cache,
backend,
changes_trie::disabled_state::<_, u64>(),
None,
);
assert_eq!(ext.storage(b"bbb"), Some(vec![]));
assert_eq!(ext.storage(b"ccc"), Some(vec![]));
ext.clear_storage(b"ccc");
assert_eq!(ext.storage(b"ccc"), None);
}
overlay.commit_prospective();
assert_eq!(overlay.storage(b"ccc"), Some(None));
}
}
6 changes: 3 additions & 3 deletions primitives/state-machine/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ impl<H, N> sp_externalities::ExtensionStore for TestExternalities<H, N> where
#[cfg(test)]
mod tests {
use super::*;
use sp_core::traits::Externalities;
use sp_core::{H256, traits::Externalities};
use sp_runtime::traits::BlakeTwo256;
use hex_literal::hex;

Expand All @@ -253,8 +253,8 @@ mod tests {
ext.set_storage(b"doe".to_vec(), b"reindeer".to_vec());
ext.set_storage(b"dog".to_vec(), b"puppy".to_vec());
ext.set_storage(b"dogglesworth".to_vec(), b"cat".to_vec());
const ROOT: [u8; 32] = hex!("555d4777b52e9196e3f6373c556cc661e79cd463f881ab9e921e70fc30144bf4");
assert_eq!(&ext.storage_root()[..], &ROOT);
let root = H256::from(hex!("2a340d3dfd52f5992c6b117e9e45f479e6da5afffafeb26ab619cf137a95aeb8"));
assert_eq!(H256::from_slice(ext.storage_root().as_slice()), root);
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions primitives/trie/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ harness = false
codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false }
sp-std = { version = "2.0.0-rc3", default-features = false, path = "../std" }
hash-db = { version = "0.15.2", default-features = false }
trie-db = { version = "0.20.1", default-features = false }
trie-db = { version = "0.21.0", default-features = false }
trie-root = { version = "0.16.0", default-features = false }
memory-db = { version = "0.20.0", default-features = false }
memory-db = { version = "0.21.0", default-features = false }
sp-core = { version = "2.0.0-rc3", default-features = false, path = "../core" }

[dev-dependencies]
trie-bench = "0.21.0"
trie-bench = "0.22.0"
trie-standardmap = "0.15.2"
criterion = "0.2.11"
hex-literal = "0.2.1"
Expand Down
1 change: 1 addition & 0 deletions primitives/trie/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub struct Layout<H>(sp_std::marker::PhantomData<H>);

impl<H: Hasher> TrieLayout for Layout<H> {
const USE_EXTENSION: bool = false;
const ALLOW_EMPTY: bool = true;
type Hash = H;
type Codec = NodeCodec<Self::Hash>;
}
Expand Down
4 changes: 2 additions & 2 deletions test-utils/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ codec = { package = "parity-scale-codec", version = "1.3.0", default-features =
frame-executive = { version = "2.0.0-rc3", default-features = false, path = "../../frame/executive" }
sp-inherents = { version = "2.0.0-rc3", default-features = false, path = "../../primitives/inherents" }
sp-keyring = { version = "2.0.0-rc3", optional = true, path = "../../primitives/keyring" }
memory-db = { version = "0.20.0", default-features = false }
memory-db = { version = "0.21.0", default-features = false }
sp-offchain = { path = "../../primitives/offchain", default-features = false, version = "2.0.0-rc3"}
sp-core = { version = "2.0.0-rc3", default-features = false, path = "../../primitives/core" }
sp-std = { version = "2.0.0-rc3", default-features = false, path = "../../primitives/std" }
Expand All @@ -39,7 +39,7 @@ pallet-timestamp = { version = "2.0.0-rc3", default-features = false, path = "..
sp-finality-grandpa = { version = "2.0.0-rc3", default-features = false, path = "../../primitives/finality-grandpa" }
sp-trie = { version = "2.0.0-rc3", default-features = false, path = "../../primitives/trie" }
sp-transaction-pool = { version = "2.0.0-rc3", default-features = false, path = "../../primitives/transaction-pool" }
trie-db = { version = "0.20.1", default-features = false }
trie-db = { version = "0.21.0", default-features = false }
parity-util-mem = { version = "0.6.1", default-features = false, features = ["primitive-types"] }
sc-service = { version = "0.8.0-rc3", default-features = false, optional = true, features = ["test-helpers"], path = "../../client/service" }

Expand Down

0 comments on commit b02101e

Please sign in to comment.