Avoid changing overlay committed layer. (#5839)

* Avoid changing overlay committed layer.

* basic test

* Add some tx in the test.

* only update from backend value on missing entry in both layer.
deleted entry is replace by empty vec.

* test and review changes

* additional test and review change

* remove test on changing existing value, it does not always panic
depending on existing content

* Update primitives/state-machine/src/overlayed_changes.rs

* Update primitives/state-machine/src/overlayed_changes.rs

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
cheme
2020-04-30 13:59:21 +02:00
committed by GitHub
parent 71d7dc1dfc
commit c05ec630ff
4 changed files with 139 additions and 25 deletions
@@ -262,9 +262,8 @@ impl Externalities for BasicExternalities {
key: Vec<u8>,
value: Vec<u8>,
) {
let previous = self.storage(&key).unwrap_or_default();
let new = crate::ext::append_to_storage(previous, value).expect("Failed to append to storage");
self.place_storage(key.clone(), Some(new));
let previous = self.inner.top.entry(key).or_default();
crate::ext::append_to_storage(previous, value).expect("Failed to append to storage");
}
fn chain_id(&self) -> u64 { 42 }