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
+10 -6
View File
@@ -58,12 +58,12 @@ pub trait MetaDb {
}
/// Backend database trait. Read-only.
pub trait HashDb {
type Hash: Hash;
pub trait NodeDb {
type Key: ?Sized;
type Error: fmt::Debug;
/// Get state trie node.
fn get(&self, key: &Self::Hash) -> Result<Option<DBValue>, Self::Error>;
fn get(&self, key: &Self::Key) -> Result<Option<DBValue>, Self::Error>;
}
/// Error type.
@@ -285,11 +285,13 @@ impl<BlockHash: Hash, Key: Hash> StateDbSync<BlockHash, Key> {
self.pinned.remove(hash);
}
pub fn get<D: HashDb<Hash=Key>>(&self, key: &Key, db: &D) -> Result<Option<DBValue>, Error<D::Error>> {
pub fn get<D: NodeDb>(&self, key: &Key, db: &D) -> Result<Option<DBValue>, Error<D::Error>>
where Key: AsRef<D::Key>
{
if let Some(value) = self.non_canonical.get(key) {
return Ok(Some(value));
}
db.get(key).map_err(|e| Error::Db(e))
db.get(key.as_ref()).map_err(|e| Error::Db(e))
}
pub fn apply_pending(&mut self) {
@@ -349,7 +351,9 @@ impl<BlockHash: Hash, Key: Hash> StateDb<BlockHash, Key> {
}
/// Get a value from non-canonical/pruning overlay or the backing DB.
pub fn get<D: HashDb<Hash=Key>>(&self, key: &Key, db: &D) -> Result<Option<DBValue>, Error<D::Error>> {
pub fn get<D: NodeDb>(&self, key: &Key, db: &D) -> Result<Option<DBValue>, Error<D::Error>>
where Key: AsRef<D::Key>
{
self.db.read().get(key, db)
}
+3 -3
View File
@@ -18,7 +18,7 @@
use std::collections::HashMap;
use primitives::H256;
use crate::{DBValue, ChangeSet, CommitSet, MetaDb, HashDb};
use crate::{DBValue, ChangeSet, CommitSet, MetaDb, NodeDb};
#[derive(Default, Debug, Clone, PartialEq, Eq)]
pub struct TestDb {
@@ -34,9 +34,9 @@ impl MetaDb for TestDb {
}
}
impl HashDb for TestDb {
impl NodeDb for TestDb {
type Error = ();
type Hash = H256;
type Key = H256;
fn get(&self, key: &H256) -> Result<Option<DBValue>, ()> {
Ok(self.data.get(key).cloned())