historical slashing w ocw w adhoc tree creation (#6220)

* draft

* steps

* chore: fmt

* step by step

* more details

* make test public

* refactor: split into on and offchain

* test stab

* tabs my friend

* offchain overlay: split key into prefix and true key

Simplifies inspection and makes key actually unique.

* test: share state

* fix & test

* docs improv

* address review comments

* cleanup test chore

* refactor, abbrev link text

* chore: linewidth

* fix prefix key split fallout

* minor fallout

* minor changes

* addresses review comments

* rename historical.rs -> historical/mod.rs

* avoid shared::* wildcard import

* fix: add missing call to store_session_validator_set_to_offchain

* fix/compile: missing shared:: prefix

* fix/test: flow

* fix/review: Apply suggestions from code review

Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* fix/review: more review comment fixes

* fix/review: make ValidatorSet private

* fix/include: core -> sp_core

* fix/review: fallout

* fix/visbility: make them public API

Ref #6358

* fix/review: review changes fallout - again

Co-authored-by: Bernhard Schuster <bernhard@parity.io>
Co-authored-by: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
This commit is contained in:
Bernhard Schuster
2020-06-16 13:14:49 +02:00
committed by GitHub
parent 622dff9ca7
commit 3f30f69b5b
9 changed files with 496 additions and 39 deletions
@@ -31,7 +31,10 @@ use crate::{
},
};
use sp_core::{
offchain::storage::OffchainOverlayedChanges,
offchain::{
testing::TestPersistentOffchainDB,
storage::OffchainOverlayedChanges
},
storage::{
well_known_keys::{CHANGES_TRIE_CONFIG, CODE, HEAP_PAGES, is_child_storage_key},
Storage,
@@ -47,6 +50,7 @@ where
{
overlay: OverlayedChanges,
offchain_overlay: OffchainOverlayedChanges,
offchain_db: TestPersistentOffchainDB,
storage_transaction_cache: StorageTransactionCache<
<InMemoryBackend<H> as Backend<H>>::Transaction, H, N
>,
@@ -108,9 +112,12 @@ impl<H: Hasher, N: ChangesTrieBlockNumber> TestExternalities<H, N>
extensions.register(sp_core::traits::TaskExecutorExt(sp_core::tasks::executor()));
let offchain_db = TestPersistentOffchainDB::new();
TestExternalities {
overlay,
offchain_overlay,
offchain_db,
changes_trie_config,
extensions,
changes_trie_storage: ChangesTrieInMemoryStorage::new(),
@@ -119,6 +126,16 @@ impl<H: Hasher, N: ChangesTrieBlockNumber> TestExternalities<H, N>
}
}
/// Move offchain changes from overlay to the persistent store.
pub fn persist_offchain_overlay(&mut self) {
self.offchain_db.apply_offchain_changes(&mut self.offchain_overlay);
}
/// A shared reference type around the offchain worker storage.
pub fn offchain_db(&self) -> TestPersistentOffchainDB {
self.offchain_db.clone()
}
/// Insert key/value into backend
pub fn insert(&mut self, k: StorageKey, v: StorageValue) {
self.backend.insert(vec![(None, vec![(k, Some(v))])]);