Use prefixed keys for trie node. (#2130)

* Account for pending insertions when pruning

* Prefixed trie storage

* Comments

* Prefixed trie storage

* Fixed tests

* Fixed tests

* Bumped runtime version

* Bumped runtime version again
This commit is contained in:
Arkadiy Paronyan
2019-03-28 18:46:21 +01:00
committed by Gav Wood
parent f9d0da0a18
commit 7046e13de2
29 changed files with 295 additions and 266 deletions
@@ -115,7 +115,7 @@ pub fn key_changes_proof_check<S: RootsStorage<H>, H: Hasher>(
let mut proof_db = MemoryDB::<H>::default();
for item in proof {
proof_db.insert(&item);
proof_db.insert(&[], &item);
}
let proof_db = InMemoryStorage::with_db(proof_db);
@@ -77,7 +77,7 @@ pub trait RootsStorage<H: Hasher>: Send + Sync {
/// Changes trie storage. Provides access to trie roots and trie nodes.
pub trait Storage<H: Hasher>: RootsStorage<H> {
/// Get a trie node.
fn get(&self, key: &H::Out) -> Result<Option<DBValue>, String>;
fn get(&self, key: &H::Out, prefix: &[u8]) -> Result<Option<DBValue>, String>;
}
/// Changes trie configuration.
@@ -92,7 +92,7 @@ impl<H: Hasher> InMemoryStorage<H> where H::Out: HeapSizeOf {
pub fn remove_from_storage(&self, keys: &HashSet<H::Out>) {
let mut data = self.data.write();
for key in keys {
data.mdb.remove_and_purge(key);
data.mdb.remove_and_purge(key, &[]);
}
}
@@ -116,8 +116,8 @@ impl<H: Hasher> RootsStorage<H> for InMemoryStorage<H> where H::Out: HeapSizeOf
}
impl<H: Hasher> Storage<H> for InMemoryStorage<H> where H::Out: HeapSizeOf {
fn get(&self, key: &H::Out) -> Result<Option<DBValue>, String> {
MemoryDB::<H>::get(&self.data.read().mdb, key)
fn get(&self, key: &H::Out, prefix: &[u8]) -> Result<Option<DBValue>, String> {
MemoryDB::<H>::get(&self.data.read().mdb, key, prefix)
}
}
@@ -128,7 +128,9 @@ impl<'a, H: Hasher, S: 'a + Storage<H>> TrieBackendAdapter<'a, H, S> {
}
impl<'a, H: Hasher, S: 'a + Storage<H>> TrieBackendStorage<H> for TrieBackendAdapter<'a, H, S> {
fn get(&self, key: &H::Out) -> Result<Option<DBValue>, String> {
self.storage.get(key)
type Overlay = MemoryDB<H>;
fn get(&self, key: &H::Out, prefix: &[u8]) -> Result<Option<DBValue>, String> {
self.storage.get(key, prefix)
}
}