Refactor OverlayedChanges (#5989)

* Hide internal structure of OverlayChanges

* Fix tests for OverlayChanges refactor

* Do not clone pending changes

Discarding prospective changes should be equivalent as a state machine
is not to be called with peding changes.

This will be replaced by a storage transaction that is rolled back before
executing the call the second time removing this constraint.

* Doc fixes

* Remove overlong line

* Revert "Do not clone pending changes"

This reverts commit 4799491f4ac16f8517287a0fcf4a3f84ad56f46e.

* Deduplicate chield tries returned from child_infos()

* Remove redundant type annotation

* Avoid changing the storage root in tests

* Preserve extrinsic indices in trie build test

* Swap order of comitted and prospective in fn child_infos

This is only for consistency and does not impact the result.

* Rename set_pending to replace_pending for clearity
This commit is contained in:
Alexander Theißen
2020-05-20 11:39:45 +02:00
committed by GitHub
parent f275c6ab0b
commit 7a5bdb896b
5 changed files with 149 additions and 164 deletions
@@ -136,21 +136,19 @@ impl<H: Hasher, N: ChangesTrieBlockNumber> TestExternalities<H, N>
/// Return a new backend with all pending value.
pub fn commit_all(&self) -> InMemoryBackend<H> {
let top: Vec<_> = self.overlay.committed.top.clone().into_iter()
.chain(self.overlay.prospective.top.clone().into_iter())
.map(|(k, v)| (k, v.value)).collect();
let top: Vec<_> = self.overlay.changes(None)
.map(|(k, v)| (k.clone(), v.value().cloned()))
.collect();
let mut transaction = vec![(None, top)];
self.overlay.committed.children_default.clone().into_iter()
.chain(self.overlay.prospective.children_default.clone().into_iter())
.for_each(|(_storage_key, (map, child_info))| {
transaction.push((
Some(child_info),
map.into_iter()
.map(|(k, v)| (k, v.value))
.collect::<Vec<_>>(),
))
});
for child_info in self.overlay.child_infos() {
transaction.push((
Some(child_info.clone()),
self.overlay.changes(Some(child_info))
.map(|(k, v)| (k.clone(), v.value().cloned()))
.collect(),
))
}
self.backend.update(transaction)
}