Merge branch 'master' into sfedgecase

This commit is contained in:
Gav Wood 2016-06-23 11:19:19 +02:00
commit 4f39fb2551
13 changed files with 243 additions and 245 deletions

View File

@ -166,16 +166,16 @@ impl Account {
!self.code_cache.is_empty() || (self.code_cache.is_empty() && self.code_hash == Some(SHA3_EMPTY)) !self.code_cache.is_empty() || (self.code_cache.is_empty() && self.code_hash == Some(SHA3_EMPTY))
} }
/// Provide a database to lookup `code_hash`. Should not be called if it is a contract without code. /// Provide a database to get `code_hash`. Should not be called if it is a contract without code.
pub fn cache_code(&mut self, db: &AccountDB) -> bool { pub fn cache_code(&mut self, db: &AccountDB) -> bool {
// TODO: fill out self.code_cache; // TODO: fill out self.code_cache;
trace!("Account::cache_code: ic={}; self.code_hash={:?}, self.code_cache={}", self.is_cached(), self.code_hash, self.code_cache.pretty()); trace!("Account::cache_code: ic={}; self.code_hash={:?}, self.code_cache={}", self.is_cached(), self.code_hash, self.code_cache.pretty());
self.is_cached() || self.is_cached() ||
match self.code_hash { match self.code_hash {
Some(ref h) => match db.lookup(h) { Some(ref h) => match db.get(h) {
Some(x) => { self.code_cache = x.to_vec(); true }, Some(x) => { self.code_cache = x.to_vec(); true },
_ => { _ => {
warn!("Failed reverse lookup of {}", h); warn!("Failed reverse get of {}", h);
false false
}, },
}, },

View File

@ -30,18 +30,18 @@ impl<'db> HashDB for AccountDB<'db>{
unimplemented!() unimplemented!()
} }
fn lookup(&self, key: &H256) -> Option<&[u8]> { fn get(&self, key: &H256) -> Option<&[u8]> {
if key == &SHA3_NULL_RLP { if key == &SHA3_NULL_RLP {
return Some(&NULL_RLP_STATIC); return Some(&NULL_RLP_STATIC);
} }
self.db.lookup(&combine_key(&self.address, key)) self.db.get(&combine_key(&self.address, key))
} }
fn exists(&self, key: &H256) -> bool { fn contains(&self, key: &H256) -> bool {
if key == &SHA3_NULL_RLP { if key == &SHA3_NULL_RLP {
return true; return true;
} }
self.db.exists(&combine_key(&self.address, key)) self.db.contains(&combine_key(&self.address, key))
} }
fn insert(&mut self, _value: &[u8]) -> H256 { fn insert(&mut self, _value: &[u8]) -> H256 {
@ -52,7 +52,7 @@ impl<'db> HashDB for AccountDB<'db>{
unimplemented!() unimplemented!()
} }
fn kill(&mut self, _key: &H256) { fn remove(&mut self, _key: &H256) {
unimplemented!() unimplemented!()
} }
} }
@ -82,18 +82,18 @@ impl<'db> HashDB for AccountDBMut<'db>{
unimplemented!() unimplemented!()
} }
fn lookup(&self, key: &H256) -> Option<&[u8]> { fn get(&self, key: &H256) -> Option<&[u8]> {
if key == &SHA3_NULL_RLP { if key == &SHA3_NULL_RLP {
return Some(&NULL_RLP_STATIC); return Some(&NULL_RLP_STATIC);
} }
self.db.lookup(&combine_key(&self.address, key)) self.db.get(&combine_key(&self.address, key))
} }
fn exists(&self, key: &H256) -> bool { fn contains(&self, key: &H256) -> bool {
if key == &SHA3_NULL_RLP { if key == &SHA3_NULL_RLP {
return true; return true;
} }
self.db.exists(&combine_key(&self.address, key)) self.db.contains(&combine_key(&self.address, key))
} }
fn insert(&mut self, value: &[u8]) -> H256 { fn insert(&mut self, value: &[u8]) -> H256 {
@ -114,12 +114,12 @@ impl<'db> HashDB for AccountDBMut<'db>{
self.db.emplace(key, value.to_vec()) self.db.emplace(key, value.to_vec())
} }
fn kill(&mut self, key: &H256) { fn remove(&mut self, key: &H256) {
if key == &SHA3_NULL_RLP { if key == &SHA3_NULL_RLP {
return; return;
} }
let key = combine_key(&self.address, key); let key = combine_key(&self.address, key);
self.db.kill(&key) self.db.remove(&key)
} }
} }

View File

@ -99,7 +99,7 @@ API and Console Options:
--ipc-path PATH Specify custom path for JSON-RPC over IPC service --ipc-path PATH Specify custom path for JSON-RPC over IPC service
[default: $HOME/.parity/jsonrpc.ipc]. [default: $HOME/.parity/jsonrpc.ipc].
--ipc-apis APIS Specify custom API set available via JSON-RPC over --ipc-apis APIS Specify custom API set available via JSON-RPC over
IPC [default: web3,eth,net,ethcore,personal,traces]. IPC [default: web3,eth,net,ethcore,personal,traces,rpc].
--dapps-off Disable the Dapps server (e.g. status page). --dapps-off Disable the Dapps server (e.g. status page).
--dapps-port PORT Specify the port portion of the Dapps server --dapps-port PORT Specify the port portion of the Dapps server

View File

@ -199,7 +199,7 @@ fn execute_client(conf: Configuration, spec: Spec, client_config: ClientConfig)
} }
// Display warning about using unlock with signer // Display warning about using unlock with signer
if conf.args.flag_signer && conf.args.flag_unlock.is_some() { if !conf.args.flag_signer_off && conf.args.flag_unlock.is_some() {
warn!("Using Trusted Signer and --unlock is not recommended!"); warn!("Using Trusted Signer and --unlock is not recommended!");
warn!("NOTE that Signer will not ask you to confirm transactions from unlocked account."); warn!("NOTE that Signer will not ask you to confirm transactions from unlocked account.");
} }

View File

@ -20,12 +20,10 @@ use bytes::*;
use std::collections::HashMap; use std::collections::HashMap;
/// Trait modelling datastore keyed by a 32-byte Keccak hash. /// Trait modelling datastore keyed by a 32-byte Keccak hash.
pub trait HashDB : AsHashDB { pub trait HashDB: AsHashDB {
/// Get the keys in the database together with number of underlying references. /// Get the keys in the database together with number of underlying references.
fn keys(&self) -> HashMap<H256, i32>; fn keys(&self) -> HashMap<H256, i32>;
/// Deprecated. use `get`.
fn lookup(&self, key: &H256) -> Option<&[u8]>; // TODO: rename to get.
/// Look up a given hash into the bytes that hash to it, returning None if the /// Look up a given hash into the bytes that hash to it, returning None if the
/// hash is not known. /// hash is not known.
/// ///
@ -41,10 +39,8 @@ pub trait HashDB : AsHashDB {
/// assert_eq!(m.get(&hash).unwrap(), hello_bytes); /// assert_eq!(m.get(&hash).unwrap(), hello_bytes);
/// } /// }
/// ``` /// ```
fn get(&self, key: &H256) -> Option<&[u8]> { self.lookup(key) } fn get(&self, key: &H256) -> Option<&[u8]>;
/// Deprecated. Use `contains`.
fn exists(&self, key: &H256) -> bool; // TODO: rename to contains.
/// Check for the existance of a hash-key. /// Check for the existance of a hash-key.
/// ///
/// # Examples /// # Examples
@ -63,10 +59,10 @@ pub trait HashDB : AsHashDB {
/// assert!(!m.contains(&key)); /// assert!(!m.contains(&key));
/// } /// }
/// ``` /// ```
fn contains(&self, key: &H256) -> bool { self.exists(key) } fn contains(&self, key: &H256) -> bool;
/// Insert a datum item into the DB and return the datum's hash for a later lookup. Insertions /// Insert a datum item into the DB and return the datum's hash for a later lookup. Insertions
/// are counted and the equivalent number of `kill()`s must be performed before the data /// are counted and the equivalent number of `remove()`s must be performed before the data
/// is considered dead. /// is considered dead.
/// ///
/// # Examples /// # Examples
@ -86,8 +82,6 @@ pub trait HashDB : AsHashDB {
/// Like `insert()` , except you provide the key and the data is all moved. /// Like `insert()` , except you provide the key and the data is all moved.
fn emplace(&mut self, key: H256, value: Bytes); fn emplace(&mut self, key: H256, value: Bytes);
/// Deprecated - use `remove`.
fn kill(&mut self, key: &H256); // TODO: rename to remove.
/// Remove a datum previously inserted. Insertions can be "owed" such that the same number of `insert()`s may /// Remove a datum previously inserted. Insertions can be "owed" such that the same number of `insert()`s may
/// happen without the data being eventually being inserted into the DB. /// happen without the data being eventually being inserted into the DB.
/// ///
@ -109,7 +103,7 @@ pub trait HashDB : AsHashDB {
/// assert_eq!(m.get(key).unwrap(), d); /// assert_eq!(m.get(key).unwrap(), d);
/// } /// }
/// ``` /// ```
fn remove(&mut self, key: &H256) { self.kill(key) } fn remove(&mut self, key: &H256);
} }
/// Upcast trait. /// Upcast trait.
@ -121,6 +115,10 @@ pub trait AsHashDB {
} }
impl<T: HashDB> AsHashDB for T { impl<T: HashDB> AsHashDB for T {
fn as_hashdb(&self) -> &HashDB { self } fn as_hashdb(&self) -> &HashDB {
fn as_hashdb_mut(&mut self) -> &mut HashDB { self } self
}
fn as_hashdb_mut(&mut self) -> &mut HashDB {
self
}
} }

View File

@ -98,7 +98,7 @@ impl HashDB for ArchiveDB {
ret ret
} }
fn lookup(&self, key: &H256) -> Option<&[u8]> { fn get(&self, key: &H256) -> Option<&[u8]> {
let k = self.overlay.raw(key); let k = self.overlay.raw(key);
match k { match k {
Some(&(ref d, rc)) if rc > 0 => Some(d), Some(&(ref d, rc)) if rc > 0 => Some(d),
@ -113,8 +113,8 @@ impl HashDB for ArchiveDB {
} }
} }
fn exists(&self, key: &H256) -> bool { fn contains(&self, key: &H256) -> bool {
self.lookup(key).is_some() self.get(key).is_some()
} }
fn insert(&mut self, value: &[u8]) -> H256 { fn insert(&mut self, value: &[u8]) -> H256 {
@ -123,8 +123,8 @@ impl HashDB for ArchiveDB {
fn emplace(&mut self, key: H256, value: Bytes) { fn emplace(&mut self, key: H256, value: Bytes) {
self.overlay.emplace(key, value); self.overlay.emplace(key, value);
} }
fn kill(&mut self, key: &H256) { fn remove(&mut self, key: &H256) {
self.overlay.kill(key); self.overlay.remove(key);
} }
} }
@ -207,7 +207,7 @@ mod tests {
jdb.commit(5, &b"1004a".sha3(), Some((3, b"1002a".sha3()))).unwrap(); jdb.commit(5, &b"1004a".sha3(), Some((3, b"1002a".sha3()))).unwrap();
jdb.commit(6, &b"1005a".sha3(), Some((4, b"1003a".sha3()))).unwrap(); jdb.commit(6, &b"1005a".sha3(), Some((4, b"1003a".sha3()))).unwrap();
assert!(jdb.exists(&x)); assert!(jdb.contains(&x));
} }
#[test] #[test]
@ -216,14 +216,14 @@ mod tests {
let mut jdb = ArchiveDB::new_temp(); let mut jdb = ArchiveDB::new_temp();
let h = jdb.insert(b"foo"); let h = jdb.insert(b"foo");
jdb.commit(0, &b"0".sha3(), None).unwrap(); jdb.commit(0, &b"0".sha3(), None).unwrap();
assert!(jdb.exists(&h)); assert!(jdb.contains(&h));
jdb.remove(&h); jdb.remove(&h);
jdb.commit(1, &b"1".sha3(), None).unwrap(); jdb.commit(1, &b"1".sha3(), None).unwrap();
assert!(jdb.exists(&h)); assert!(jdb.contains(&h));
jdb.commit(2, &b"2".sha3(), None).unwrap(); jdb.commit(2, &b"2".sha3(), None).unwrap();
assert!(jdb.exists(&h)); assert!(jdb.contains(&h));
jdb.commit(3, &b"3".sha3(), Some((0, b"0".sha3()))).unwrap(); jdb.commit(3, &b"3".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.exists(&h)); assert!(jdb.contains(&h));
jdb.commit(4, &b"4".sha3(), Some((1, b"1".sha3()))).unwrap(); jdb.commit(4, &b"4".sha3(), Some((1, b"1".sha3()))).unwrap();
} }
@ -235,26 +235,26 @@ mod tests {
let foo = jdb.insert(b"foo"); let foo = jdb.insert(b"foo");
let bar = jdb.insert(b"bar"); let bar = jdb.insert(b"bar");
jdb.commit(0, &b"0".sha3(), None).unwrap(); jdb.commit(0, &b"0".sha3(), None).unwrap();
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(jdb.exists(&bar)); assert!(jdb.contains(&bar));
jdb.remove(&foo); jdb.remove(&foo);
jdb.remove(&bar); jdb.remove(&bar);
let baz = jdb.insert(b"baz"); let baz = jdb.insert(b"baz");
jdb.commit(1, &b"1".sha3(), Some((0, b"0".sha3()))).unwrap(); jdb.commit(1, &b"1".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(jdb.exists(&bar)); assert!(jdb.contains(&bar));
assert!(jdb.exists(&baz)); assert!(jdb.contains(&baz));
let foo = jdb.insert(b"foo"); let foo = jdb.insert(b"foo");
jdb.remove(&baz); jdb.remove(&baz);
jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap(); jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap();
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(jdb.exists(&baz)); assert!(jdb.contains(&baz));
jdb.remove(&foo); jdb.remove(&foo);
jdb.commit(3, &b"3".sha3(), Some((2, b"2".sha3()))).unwrap(); jdb.commit(3, &b"3".sha3(), Some((2, b"2".sha3()))).unwrap();
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
jdb.commit(4, &b"4".sha3(), Some((3, b"3".sha3()))).unwrap(); jdb.commit(4, &b"4".sha3(), Some((3, b"3".sha3()))).unwrap();
} }
@ -267,8 +267,8 @@ mod tests {
let foo = jdb.insert(b"foo"); let foo = jdb.insert(b"foo");
let bar = jdb.insert(b"bar"); let bar = jdb.insert(b"bar");
jdb.commit(0, &b"0".sha3(), None).unwrap(); jdb.commit(0, &b"0".sha3(), None).unwrap();
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(jdb.exists(&bar)); assert!(jdb.contains(&bar));
jdb.remove(&foo); jdb.remove(&foo);
let baz = jdb.insert(b"baz"); let baz = jdb.insert(b"baz");
@ -277,12 +277,12 @@ mod tests {
jdb.remove(&bar); jdb.remove(&bar);
jdb.commit(1, &b"1b".sha3(), Some((0, b"0".sha3()))).unwrap(); jdb.commit(1, &b"1b".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(jdb.exists(&bar)); assert!(jdb.contains(&bar));
assert!(jdb.exists(&baz)); assert!(jdb.contains(&baz));
jdb.commit(2, &b"2b".sha3(), Some((1, b"1b".sha3()))).unwrap(); jdb.commit(2, &b"2b".sha3(), Some((1, b"1b".sha3()))).unwrap();
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
} }
#[test] #[test]
@ -292,16 +292,16 @@ mod tests {
let foo = jdb.insert(b"foo"); let foo = jdb.insert(b"foo");
jdb.commit(0, &b"0".sha3(), None).unwrap(); jdb.commit(0, &b"0".sha3(), None).unwrap();
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
jdb.remove(&foo); jdb.remove(&foo);
jdb.commit(1, &b"1".sha3(), Some((0, b"0".sha3()))).unwrap(); jdb.commit(1, &b"1".sha3(), Some((0, b"0".sha3()))).unwrap();
jdb.insert(b"foo"); jdb.insert(b"foo");
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap(); jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap();
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
jdb.commit(3, &b"2".sha3(), Some((0, b"2".sha3()))).unwrap(); jdb.commit(3, &b"2".sha3(), Some((0, b"2".sha3()))).unwrap();
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
} }
#[test] #[test]
@ -315,10 +315,10 @@ mod tests {
jdb.insert(b"foo"); jdb.insert(b"foo");
jdb.commit(1, &b"1b".sha3(), Some((0, b"0".sha3()))).unwrap(); jdb.commit(1, &b"1b".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
jdb.commit(2, &b"2a".sha3(), Some((1, b"1a".sha3()))).unwrap(); jdb.commit(2, &b"2a".sha3(), Some((1, b"1a".sha3()))).unwrap();
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
} }
#[test] #[test]
@ -344,8 +344,8 @@ mod tests {
{ {
let mut jdb = ArchiveDB::new(dir.to_str().unwrap(), None); let mut jdb = ArchiveDB::new(dir.to_str().unwrap(), None);
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(jdb.exists(&bar)); assert!(jdb.contains(&bar));
jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap(); jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap();
} }
} }
@ -373,7 +373,7 @@ mod tests {
let mut jdb = ArchiveDB::new(dir.to_str().unwrap(), None); let mut jdb = ArchiveDB::new(dir.to_str().unwrap(), None);
jdb.remove(&foo); jdb.remove(&foo);
jdb.commit(3, &b"3".sha3(), Some((2, b"2".sha3()))).unwrap(); jdb.commit(3, &b"3".sha3(), Some((2, b"2".sha3()))).unwrap();
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
jdb.remove(&foo); jdb.remove(&foo);
jdb.commit(4, &b"4".sha3(), Some((3, b"3".sha3()))).unwrap(); jdb.commit(4, &b"4".sha3(), Some((3, b"3".sha3()))).unwrap();
jdb.commit(5, &b"5".sha3(), Some((4, b"4".sha3()))).unwrap(); jdb.commit(5, &b"5".sha3(), Some((4, b"4".sha3()))).unwrap();
@ -402,7 +402,7 @@ mod tests {
{ {
let mut jdb = ArchiveDB::new(dir.to_str().unwrap(), None); let mut jdb = ArchiveDB::new(dir.to_str().unwrap(), None);
jdb.commit(2, &b"2b".sha3(), Some((1, b"1b".sha3()))).unwrap(); jdb.commit(2, &b"2b".sha3(), Some((1, b"1b".sha3()))).unwrap();
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
} }
} }

View File

@ -172,8 +172,8 @@ impl EarlyMergeDB {
trace!(target: "jdb.fine", "replay_keys: (end) refs={:?}", refs); trace!(target: "jdb.fine", "replay_keys: (end) refs={:?}", refs);
} }
fn kill_keys(deletes: &[H256], refs: &mut HashMap<H256, RefInfo>, batch: &DBTransaction, from: RemoveFrom, trace: bool) { fn remove_keys(deletes: &[H256], refs: &mut HashMap<H256, RefInfo>, batch: &DBTransaction, from: RemoveFrom, trace: bool) {
// with a kill on {queue_refs: 1, in_archive: true}, we have two options: // with a remove on {queue_refs: 1, in_archive: true}, we have two options:
// - convert to {queue_refs: 1, in_archive: false} (i.e. remove it from the conceptual archive) // - convert to {queue_refs: 1, in_archive: false} (i.e. remove it from the conceptual archive)
// - convert to {queue_refs: 0, in_archive: true} (i.e. remove it from the conceptual queue) // - convert to {queue_refs: 0, in_archive: true} (i.e. remove it from the conceptual queue)
// (the latter option would then mean removing the RefInfo, since it would no longer be counted in the queue.) // (the latter option would then mean removing the RefInfo, since it would no longer be counted in the queue.)
@ -186,13 +186,13 @@ impl EarlyMergeDB {
c.in_archive = false; c.in_archive = false;
Self::reset_already_in(batch, h); Self::reset_already_in(batch, h);
if trace { if trace {
trace!(target: "jdb.fine", " kill({}): In archive, 1 in queue: Reducing to queue only and recording", h); trace!(target: "jdb.fine", " remove({}): In archive, 1 in queue: Reducing to queue only and recording", h);
} }
continue; continue;
} else if c.queue_refs > 1 { } else if c.queue_refs > 1 {
c.queue_refs -= 1; c.queue_refs -= 1;
if trace { if trace {
trace!(target: "jdb.fine", " kill({}): In queue > 1 refs: Decrementing ref count to {}", h, c.queue_refs); trace!(target: "jdb.fine", " remove({}): In queue > 1 refs: Decrementing ref count to {}", h, c.queue_refs);
} }
continue; continue;
} else { } else {
@ -204,14 +204,14 @@ impl EarlyMergeDB {
refs.remove(h); refs.remove(h);
Self::reset_already_in(batch, h); Self::reset_already_in(batch, h);
if trace { if trace {
trace!(target: "jdb.fine", " kill({}): In archive, 1 in queue: Removing from queue and leaving in archive", h); trace!(target: "jdb.fine", " remove({}): In archive, 1 in queue: Removing from queue and leaving in archive", h);
} }
} }
Some(RefInfo{queue_refs: 1, in_archive: false}) => { Some(RefInfo{queue_refs: 1, in_archive: false}) => {
refs.remove(h); refs.remove(h);
batch.delete(&h.bytes()).expect("Low-level database error. Some issue with your hard disk?"); batch.delete(&h.bytes()).expect("Low-level database error. Some issue with your hard disk?");
if trace { if trace {
trace!(target: "jdb.fine", " kill({}): Not in archive, only 1 ref in queue: Removing from queue and DB", h); trace!(target: "jdb.fine", " remove({}): Not in archive, only 1 ref in queue: Removing from queue and DB", h);
} }
} }
None => { None => {
@ -219,7 +219,7 @@ impl EarlyMergeDB {
//assert!(!Self::is_already_in(db, &h)); //assert!(!Self::is_already_in(db, &h));
batch.delete(&h.bytes()).expect("Low-level database error. Some issue with your hard disk?"); batch.delete(&h.bytes()).expect("Low-level database error. Some issue with your hard disk?");
if trace { if trace {
trace!(target: "jdb.fine", " kill({}): Not in queue - MUST BE IN ARCHIVE: Removing from DB", h); trace!(target: "jdb.fine", " remove({}): Not in queue - MUST BE IN ARCHIVE: Removing from DB", h);
} }
} }
_ => panic!("Invalid value in refs: {:?}", n), _ => panic!("Invalid value in refs: {:?}", n),
@ -290,7 +290,7 @@ impl HashDB for EarlyMergeDB {
ret ret
} }
fn lookup(&self, key: &H256) -> Option<&[u8]> { fn get(&self, key: &H256) -> Option<&[u8]> {
let k = self.overlay.raw(key); let k = self.overlay.raw(key);
match k { match k {
Some(&(ref d, rc)) if rc > 0 => Some(d), Some(&(ref d, rc)) if rc > 0 => Some(d),
@ -305,8 +305,8 @@ impl HashDB for EarlyMergeDB {
} }
} }
fn exists(&self, key: &H256) -> bool { fn contains(&self, key: &H256) -> bool {
self.lookup(key).is_some() self.get(key).is_some()
} }
fn insert(&mut self, value: &[u8]) -> H256 { fn insert(&mut self, value: &[u8]) -> H256 {
@ -315,8 +315,8 @@ impl HashDB for EarlyMergeDB {
fn emplace(&mut self, key: H256, value: Bytes) { fn emplace(&mut self, key: H256, value: Bytes) {
self.overlay.emplace(key, value); self.overlay.emplace(key, value);
} }
fn kill(&mut self, key: &H256) { fn remove(&mut self, key: &H256) {
self.overlay.kill(key); self.overlay.remove(key);
} }
} }
@ -472,7 +472,7 @@ impl JournalDB for EarlyMergeDB {
if trace { if trace {
trace!(target: "jdb.ops", " Expunging: {:?}", deletes); trace!(target: "jdb.ops", " Expunging: {:?}", deletes);
} }
Self::kill_keys(&deletes, &mut refs, &batch, RemoveFrom::Archive, trace); Self::remove_keys(&deletes, &mut refs, &batch, RemoveFrom::Archive, trace);
if trace { if trace {
trace!(target: "jdb.ops", " Finalising: {:?}", inserts); trace!(target: "jdb.ops", " Finalising: {:?}", inserts);
@ -504,7 +504,7 @@ impl JournalDB for EarlyMergeDB {
if trace { if trace {
trace!(target: "jdb.ops", " Reverting: {:?}", inserts); trace!(target: "jdb.ops", " Reverting: {:?}", inserts);
} }
Self::kill_keys(&inserts, &mut refs, &batch, RemoveFrom::Queue, trace); Self::remove_keys(&inserts, &mut refs, &batch, RemoveFrom::Queue, trace);
} }
try!(batch.delete(&last)); try!(batch.delete(&last));
@ -565,7 +565,7 @@ mod tests {
jdb.commit(6, &b"1005a".sha3(), Some((4, b"1003a".sha3()))).unwrap(); jdb.commit(6, &b"1005a".sha3(), Some((4, b"1003a".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&x)); assert!(jdb.contains(&x));
} }
#[test] #[test]
@ -584,8 +584,8 @@ mod tests {
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap(); jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap();
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(jdb.exists(&bar)); assert!(jdb.contains(&bar));
} }
#[test] #[test]
@ -595,20 +595,20 @@ mod tests {
let h = jdb.insert(b"foo"); let h = jdb.insert(b"foo");
jdb.commit(0, &b"0".sha3(), None).unwrap(); jdb.commit(0, &b"0".sha3(), None).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&h)); assert!(jdb.contains(&h));
jdb.remove(&h); jdb.remove(&h);
jdb.commit(1, &b"1".sha3(), None).unwrap(); jdb.commit(1, &b"1".sha3(), None).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&h)); assert!(jdb.contains(&h));
jdb.commit(2, &b"2".sha3(), None).unwrap(); jdb.commit(2, &b"2".sha3(), None).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&h)); assert!(jdb.contains(&h));
jdb.commit(3, &b"3".sha3(), Some((0, b"0".sha3()))).unwrap(); jdb.commit(3, &b"3".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&h)); assert!(jdb.contains(&h));
jdb.commit(4, &b"4".sha3(), Some((1, b"1".sha3()))).unwrap(); jdb.commit(4, &b"4".sha3(), Some((1, b"1".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(!jdb.exists(&h)); assert!(!jdb.contains(&h));
} }
#[test] #[test]
@ -620,38 +620,38 @@ mod tests {
let bar = jdb.insert(b"bar"); let bar = jdb.insert(b"bar");
jdb.commit(0, &b"0".sha3(), None).unwrap(); jdb.commit(0, &b"0".sha3(), None).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(jdb.exists(&bar)); assert!(jdb.contains(&bar));
jdb.remove(&foo); jdb.remove(&foo);
jdb.remove(&bar); jdb.remove(&bar);
let baz = jdb.insert(b"baz"); let baz = jdb.insert(b"baz");
jdb.commit(1, &b"1".sha3(), Some((0, b"0".sha3()))).unwrap(); jdb.commit(1, &b"1".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(jdb.exists(&bar)); assert!(jdb.contains(&bar));
assert!(jdb.exists(&baz)); assert!(jdb.contains(&baz));
let foo = jdb.insert(b"foo"); let foo = jdb.insert(b"foo");
jdb.remove(&baz); jdb.remove(&baz);
jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap(); jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(!jdb.exists(&bar)); assert!(!jdb.contains(&bar));
assert!(jdb.exists(&baz)); assert!(jdb.contains(&baz));
jdb.remove(&foo); jdb.remove(&foo);
jdb.commit(3, &b"3".sha3(), Some((2, b"2".sha3()))).unwrap(); jdb.commit(3, &b"3".sha3(), Some((2, b"2".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(!jdb.exists(&bar)); assert!(!jdb.contains(&bar));
assert!(!jdb.exists(&baz)); assert!(!jdb.contains(&baz));
jdb.commit(4, &b"4".sha3(), Some((3, b"3".sha3()))).unwrap(); jdb.commit(4, &b"4".sha3(), Some((3, b"3".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(!jdb.exists(&foo)); assert!(!jdb.contains(&foo));
assert!(!jdb.exists(&bar)); assert!(!jdb.contains(&bar));
assert!(!jdb.exists(&baz)); assert!(!jdb.contains(&baz));
} }
#[test] #[test]
@ -663,8 +663,8 @@ mod tests {
let bar = jdb.insert(b"bar"); let bar = jdb.insert(b"bar");
jdb.commit(0, &b"0".sha3(), None).unwrap(); jdb.commit(0, &b"0".sha3(), None).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(jdb.exists(&bar)); assert!(jdb.contains(&bar));
jdb.remove(&foo); jdb.remove(&foo);
let baz = jdb.insert(b"baz"); let baz = jdb.insert(b"baz");
@ -675,15 +675,15 @@ mod tests {
jdb.commit(1, &b"1b".sha3(), Some((0, b"0".sha3()))).unwrap(); jdb.commit(1, &b"1b".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(jdb.exists(&bar)); assert!(jdb.contains(&bar));
assert!(jdb.exists(&baz)); assert!(jdb.contains(&baz));
jdb.commit(2, &b"2b".sha3(), Some((1, b"1b".sha3()))).unwrap(); jdb.commit(2, &b"2b".sha3(), Some((1, b"1b".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(!jdb.exists(&baz)); assert!(!jdb.contains(&baz));
assert!(!jdb.exists(&bar)); assert!(!jdb.contains(&bar));
} }
#[test] #[test]
@ -694,19 +694,19 @@ mod tests {
let foo = jdb.insert(b"foo"); let foo = jdb.insert(b"foo");
jdb.commit(0, &b"0".sha3(), None).unwrap(); jdb.commit(0, &b"0".sha3(), None).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
jdb.remove(&foo); jdb.remove(&foo);
jdb.commit(1, &b"1".sha3(), Some((0, b"0".sha3()))).unwrap(); jdb.commit(1, &b"1".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
jdb.insert(b"foo"); jdb.insert(b"foo");
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap(); jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
jdb.commit(3, &b"2".sha3(), Some((0, b"2".sha3()))).unwrap(); jdb.commit(3, &b"2".sha3(), Some((0, b"2".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
} }
#[test] #[test]
@ -730,11 +730,11 @@ mod tests {
jdb.commit(1, &b"1c".sha3(), Some((0, b"0".sha3()))).unwrap(); jdb.commit(1, &b"1c".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
jdb.commit(2, &b"2a".sha3(), Some((1, b"1a".sha3()))).unwrap(); jdb.commit(2, &b"2a".sha3(), Some((1, b"1a".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
} }
#[test] #[test]
@ -758,11 +758,11 @@ mod tests {
jdb.commit(1, &b"1c".sha3(), Some((0, b"0".sha3()))).unwrap(); jdb.commit(1, &b"1c".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
jdb.commit(2, &b"2b".sha3(), Some((1, b"1b".sha3()))).unwrap(); jdb.commit(2, &b"2b".sha3(), Some((1, b"1b".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
} }
#[test] #[test]
@ -826,11 +826,11 @@ mod tests {
{ {
let mut jdb = EarlyMergeDB::new(dir.to_str().unwrap(), None); let mut jdb = EarlyMergeDB::new(dir.to_str().unwrap(), None);
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(jdb.exists(&bar)); assert!(jdb.contains(&bar));
jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap(); jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(!jdb.exists(&foo)); assert!(!jdb.contains(&foo));
} }
} }
@ -933,7 +933,7 @@ mod tests {
jdb.insert(b"foo"); jdb.insert(b"foo");
jdb.commit(3, &b"3".sha3(), Some((2, b"2".sha3()))).unwrap(); // BROKEN jdb.commit(3, &b"3".sha3(), Some((2, b"2".sha3()))).unwrap(); // BROKEN
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
jdb.remove(&foo); jdb.remove(&foo);
jdb.commit(4, &b"4".sha3(), Some((3, b"3".sha3()))).unwrap(); jdb.commit(4, &b"4".sha3(), Some((3, b"3".sha3()))).unwrap();
@ -941,7 +941,7 @@ mod tests {
jdb.commit(5, &b"5".sha3(), Some((4, b"4".sha3()))).unwrap(); jdb.commit(5, &b"5".sha3(), Some((4, b"4".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(!jdb.exists(&foo)); assert!(!jdb.contains(&foo));
} }
#[test] #[test]
@ -1002,12 +1002,12 @@ mod tests {
jdb.remove(&foo); jdb.remove(&foo);
jdb.commit(2, &b"2".sha3(), Some((0, b"0".sha3()))).unwrap(); jdb.commit(2, &b"2".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
jdb.insert(b"foo"); jdb.insert(b"foo");
jdb.commit(3, &b"3".sha3(), Some((1, b"1".sha3()))).unwrap(); jdb.commit(3, &b"3".sha3(), Some((1, b"1".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
// incantation to reopen the db // incantation to reopen the db
}; { let mut jdb = EarlyMergeDB::new(dir.to_str().unwrap(), None); }; { let mut jdb = EarlyMergeDB::new(dir.to_str().unwrap(), None);
@ -1015,21 +1015,21 @@ mod tests {
jdb.remove(&foo); jdb.remove(&foo);
jdb.commit(4, &b"4".sha3(), Some((2, b"2".sha3()))).unwrap(); jdb.commit(4, &b"4".sha3(), Some((2, b"2".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
// incantation to reopen the db // incantation to reopen the db
}; { let mut jdb = EarlyMergeDB::new(dir.to_str().unwrap(), None); }; { let mut jdb = EarlyMergeDB::new(dir.to_str().unwrap(), None);
jdb.commit(5, &b"5".sha3(), Some((3, b"3".sha3()))).unwrap(); jdb.commit(5, &b"5".sha3(), Some((3, b"3".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
// incantation to reopen the db // incantation to reopen the db
}; { let mut jdb = EarlyMergeDB::new(dir.to_str().unwrap(), None); }; { let mut jdb = EarlyMergeDB::new(dir.to_str().unwrap(), None);
jdb.commit(6, &b"6".sha3(), Some((4, b"4".sha3()))).unwrap(); jdb.commit(6, &b"6".sha3(), Some((4, b"4".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(!jdb.exists(&foo)); assert!(!jdb.contains(&foo));
} }
} }
@ -1059,9 +1059,9 @@ mod tests {
let mut jdb = EarlyMergeDB::new(dir.to_str().unwrap(), None); let mut jdb = EarlyMergeDB::new(dir.to_str().unwrap(), None);
jdb.commit(2, &b"2b".sha3(), Some((1, b"1b".sha3()))).unwrap(); jdb.commit(2, &b"2b".sha3(), Some((1, b"1b".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(!jdb.exists(&baz)); assert!(!jdb.contains(&baz));
assert!(!jdb.exists(&bar)); assert!(!jdb.contains(&bar));
} }
} }
} }

View File

@ -288,11 +288,11 @@ impl JournalDB for OverlayRecentDB {
} }
// update the overlay // update the overlay
for k in overlay_deletions { for k in overlay_deletions {
journal_overlay.backing_overlay.kill(&k); journal_overlay.backing_overlay.remove(&k);
} }
// apply canon deletions // apply canon deletions
for k in canon_deletions { for k in canon_deletions {
if !journal_overlay.backing_overlay.exists(&k) { if !journal_overlay.backing_overlay.contains(&k) {
try!(batch.delete(&k)); try!(batch.delete(&k));
} }
} }
@ -321,12 +321,12 @@ impl HashDB for OverlayRecentDB {
ret ret
} }
fn lookup(&self, key: &H256) -> Option<&[u8]> { fn get(&self, key: &H256) -> Option<&[u8]> {
let k = self.transaction_overlay.raw(key); let k = self.transaction_overlay.raw(key);
match k { match k {
Some(&(ref d, rc)) if rc > 0 => Some(d), Some(&(ref d, rc)) if rc > 0 => Some(d),
_ => { _ => {
let v = self.journal_overlay.read().unwrap().backing_overlay.lookup(key).map(|v| v.to_vec()); let v = self.journal_overlay.read().unwrap().backing_overlay.get(key).map(|v| v.to_vec());
match v { match v {
Some(x) => { Some(x) => {
Some(&self.transaction_overlay.denote(key, x).0) Some(&self.transaction_overlay.denote(key, x).0)
@ -344,8 +344,8 @@ impl HashDB for OverlayRecentDB {
} }
} }
fn exists(&self, key: &H256) -> bool { fn contains(&self, key: &H256) -> bool {
self.lookup(key).is_some() self.get(key).is_some()
} }
fn insert(&mut self, value: &[u8]) -> H256 { fn insert(&mut self, value: &[u8]) -> H256 {
@ -354,8 +354,8 @@ impl HashDB for OverlayRecentDB {
fn emplace(&mut self, key: H256, value: Bytes) { fn emplace(&mut self, key: H256, value: Bytes) {
self.transaction_overlay.emplace(key, value); self.transaction_overlay.emplace(key, value);
} }
fn kill(&mut self, key: &H256) { fn remove(&mut self, key: &H256) {
self.transaction_overlay.kill(key); self.transaction_overlay.remove(key);
} }
} }
@ -397,7 +397,7 @@ mod tests {
jdb.commit(6, &b"1005a".sha3(), Some((4, b"1003a".sha3()))).unwrap(); jdb.commit(6, &b"1005a".sha3(), Some((4, b"1003a".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&x)); assert!(jdb.contains(&x));
} }
#[test] #[test]
@ -407,20 +407,20 @@ mod tests {
let h = jdb.insert(b"foo"); let h = jdb.insert(b"foo");
jdb.commit(0, &b"0".sha3(), None).unwrap(); jdb.commit(0, &b"0".sha3(), None).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&h)); assert!(jdb.contains(&h));
jdb.remove(&h); jdb.remove(&h);
jdb.commit(1, &b"1".sha3(), None).unwrap(); jdb.commit(1, &b"1".sha3(), None).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&h)); assert!(jdb.contains(&h));
jdb.commit(2, &b"2".sha3(), None).unwrap(); jdb.commit(2, &b"2".sha3(), None).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&h)); assert!(jdb.contains(&h));
jdb.commit(3, &b"3".sha3(), Some((0, b"0".sha3()))).unwrap(); jdb.commit(3, &b"3".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&h)); assert!(jdb.contains(&h));
jdb.commit(4, &b"4".sha3(), Some((1, b"1".sha3()))).unwrap(); jdb.commit(4, &b"4".sha3(), Some((1, b"1".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(!jdb.exists(&h)); assert!(!jdb.contains(&h));
} }
#[test] #[test]
@ -432,38 +432,38 @@ mod tests {
let bar = jdb.insert(b"bar"); let bar = jdb.insert(b"bar");
jdb.commit(0, &b"0".sha3(), None).unwrap(); jdb.commit(0, &b"0".sha3(), None).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(jdb.exists(&bar)); assert!(jdb.contains(&bar));
jdb.remove(&foo); jdb.remove(&foo);
jdb.remove(&bar); jdb.remove(&bar);
let baz = jdb.insert(b"baz"); let baz = jdb.insert(b"baz");
jdb.commit(1, &b"1".sha3(), Some((0, b"0".sha3()))).unwrap(); jdb.commit(1, &b"1".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(jdb.exists(&bar)); assert!(jdb.contains(&bar));
assert!(jdb.exists(&baz)); assert!(jdb.contains(&baz));
let foo = jdb.insert(b"foo"); let foo = jdb.insert(b"foo");
jdb.remove(&baz); jdb.remove(&baz);
jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap(); jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(!jdb.exists(&bar)); assert!(!jdb.contains(&bar));
assert!(jdb.exists(&baz)); assert!(jdb.contains(&baz));
jdb.remove(&foo); jdb.remove(&foo);
jdb.commit(3, &b"3".sha3(), Some((2, b"2".sha3()))).unwrap(); jdb.commit(3, &b"3".sha3(), Some((2, b"2".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(!jdb.exists(&bar)); assert!(!jdb.contains(&bar));
assert!(!jdb.exists(&baz)); assert!(!jdb.contains(&baz));
jdb.commit(4, &b"4".sha3(), Some((3, b"3".sha3()))).unwrap(); jdb.commit(4, &b"4".sha3(), Some((3, b"3".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(!jdb.exists(&foo)); assert!(!jdb.contains(&foo));
assert!(!jdb.exists(&bar)); assert!(!jdb.contains(&bar));
assert!(!jdb.exists(&baz)); assert!(!jdb.contains(&baz));
} }
#[test] #[test]
@ -475,8 +475,8 @@ mod tests {
let bar = jdb.insert(b"bar"); let bar = jdb.insert(b"bar");
jdb.commit(0, &b"0".sha3(), None).unwrap(); jdb.commit(0, &b"0".sha3(), None).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(jdb.exists(&bar)); assert!(jdb.contains(&bar));
jdb.remove(&foo); jdb.remove(&foo);
let baz = jdb.insert(b"baz"); let baz = jdb.insert(b"baz");
@ -487,15 +487,15 @@ mod tests {
jdb.commit(1, &b"1b".sha3(), Some((0, b"0".sha3()))).unwrap(); jdb.commit(1, &b"1b".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(jdb.exists(&bar)); assert!(jdb.contains(&bar));
assert!(jdb.exists(&baz)); assert!(jdb.contains(&baz));
jdb.commit(2, &b"2b".sha3(), Some((1, b"1b".sha3()))).unwrap(); jdb.commit(2, &b"2b".sha3(), Some((1, b"1b".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(!jdb.exists(&baz)); assert!(!jdb.contains(&baz));
assert!(!jdb.exists(&bar)); assert!(!jdb.contains(&bar));
} }
#[test] #[test]
@ -506,19 +506,19 @@ mod tests {
let foo = jdb.insert(b"foo"); let foo = jdb.insert(b"foo");
jdb.commit(0, &b"0".sha3(), None).unwrap(); jdb.commit(0, &b"0".sha3(), None).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
jdb.remove(&foo); jdb.remove(&foo);
jdb.commit(1, &b"1".sha3(), Some((0, b"0".sha3()))).unwrap(); jdb.commit(1, &b"1".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
jdb.insert(b"foo"); jdb.insert(b"foo");
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap(); jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
jdb.commit(3, &b"2".sha3(), Some((0, b"2".sha3()))).unwrap(); jdb.commit(3, &b"2".sha3(), Some((0, b"2".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
} }
#[test] #[test]
@ -542,11 +542,11 @@ mod tests {
jdb.commit(1, &b"1c".sha3(), Some((0, b"0".sha3()))).unwrap(); jdb.commit(1, &b"1c".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
jdb.commit(2, &b"2a".sha3(), Some((1, b"1a".sha3()))).unwrap(); jdb.commit(2, &b"2a".sha3(), Some((1, b"1a".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
} }
#[test] #[test]
@ -570,11 +570,11 @@ mod tests {
jdb.commit(1, &b"1c".sha3(), Some((0, b"0".sha3()))).unwrap(); jdb.commit(1, &b"1c".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
jdb.commit(2, &b"2b".sha3(), Some((1, b"1b".sha3()))).unwrap(); jdb.commit(2, &b"2b".sha3(), Some((1, b"1b".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
} }
#[test] #[test]
@ -638,11 +638,11 @@ mod tests {
{ {
let mut jdb = OverlayRecentDB::new(dir.to_str().unwrap(), None); let mut jdb = OverlayRecentDB::new(dir.to_str().unwrap(), None);
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(jdb.exists(&bar)); assert!(jdb.contains(&bar));
jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap(); jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(!jdb.exists(&foo)); assert!(!jdb.contains(&foo));
} }
} }
@ -745,7 +745,7 @@ mod tests {
jdb.insert(b"foo"); jdb.insert(b"foo");
jdb.commit(3, &b"3".sha3(), Some((2, b"2".sha3()))).unwrap(); // BROKEN jdb.commit(3, &b"3".sha3(), Some((2, b"2".sha3()))).unwrap(); // BROKEN
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
jdb.remove(&foo); jdb.remove(&foo);
jdb.commit(4, &b"4".sha3(), Some((3, b"3".sha3()))).unwrap(); jdb.commit(4, &b"4".sha3(), Some((3, b"3".sha3()))).unwrap();
@ -753,7 +753,7 @@ mod tests {
jdb.commit(5, &b"5".sha3(), Some((4, b"4".sha3()))).unwrap(); jdb.commit(5, &b"5".sha3(), Some((4, b"4".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(!jdb.exists(&foo)); assert!(!jdb.contains(&foo));
} }
#[test] #[test]
@ -814,12 +814,12 @@ mod tests {
jdb.remove(&foo); jdb.remove(&foo);
jdb.commit(2, &b"2".sha3(), Some((0, b"0".sha3()))).unwrap(); jdb.commit(2, &b"2".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
jdb.insert(b"foo"); jdb.insert(b"foo");
jdb.commit(3, &b"3".sha3(), Some((1, b"1".sha3()))).unwrap(); jdb.commit(3, &b"3".sha3(), Some((1, b"1".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
// incantation to reopen the db // incantation to reopen the db
}; { let mut jdb = OverlayRecentDB::new(dir.to_str().unwrap(), None); }; { let mut jdb = OverlayRecentDB::new(dir.to_str().unwrap(), None);
@ -827,21 +827,21 @@ mod tests {
jdb.remove(&foo); jdb.remove(&foo);
jdb.commit(4, &b"4".sha3(), Some((2, b"2".sha3()))).unwrap(); jdb.commit(4, &b"4".sha3(), Some((2, b"2".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
// incantation to reopen the db // incantation to reopen the db
}; { let mut jdb = OverlayRecentDB::new(dir.to_str().unwrap(), None); }; { let mut jdb = OverlayRecentDB::new(dir.to_str().unwrap(), None);
jdb.commit(5, &b"5".sha3(), Some((3, b"3".sha3()))).unwrap(); jdb.commit(5, &b"5".sha3(), Some((3, b"3".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
// incantation to reopen the db // incantation to reopen the db
}; { let mut jdb = OverlayRecentDB::new(dir.to_str().unwrap(), None); }; { let mut jdb = OverlayRecentDB::new(dir.to_str().unwrap(), None);
jdb.commit(6, &b"6".sha3(), Some((4, b"4".sha3()))).unwrap(); jdb.commit(6, &b"6".sha3(), Some((4, b"4".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(!jdb.exists(&foo)); assert!(!jdb.contains(&foo));
} }
} }
@ -871,9 +871,9 @@ mod tests {
let mut jdb = OverlayRecentDB::new(dir.to_str().unwrap(), None); let mut jdb = OverlayRecentDB::new(dir.to_str().unwrap(), None);
jdb.commit(2, &b"2b".sha3(), Some((1, b"1b".sha3()))).unwrap(); jdb.commit(2, &b"2b".sha3(), Some((1, b"1b".sha3()))).unwrap();
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(!jdb.exists(&baz)); assert!(!jdb.contains(&baz));
assert!(!jdb.exists(&bar)); assert!(!jdb.contains(&bar));
} }
} }
@ -893,7 +893,7 @@ mod tests {
assert!(jdb.can_reconstruct_refs()); assert!(jdb.can_reconstruct_refs());
jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap(); jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap();
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(jdb.exists(&bar)); assert!(jdb.contains(&bar));
} }
} }

View File

@ -88,11 +88,11 @@ impl RefCountedDB {
impl HashDB for RefCountedDB { impl HashDB for RefCountedDB {
fn keys(&self) -> HashMap<H256, i32> { self.forward.keys() } fn keys(&self) -> HashMap<H256, i32> { self.forward.keys() }
fn lookup(&self, key: &H256) -> Option<&[u8]> { self.forward.lookup(key) } fn get(&self, key: &H256) -> Option<&[u8]> { self.forward.get(key) }
fn exists(&self, key: &H256) -> bool { self.forward.exists(key) } fn contains(&self, key: &H256) -> bool { self.forward.contains(key) }
fn insert(&mut self, value: &[u8]) -> H256 { let r = self.forward.insert(value); self.inserts.push(r.clone()); r } fn insert(&mut self, value: &[u8]) -> H256 { let r = self.forward.insert(value); self.inserts.push(r.clone()); r }
fn emplace(&mut self, key: H256, value: Bytes) { self.inserts.push(key.clone()); self.forward.emplace(key, value); } fn emplace(&mut self, key: H256, value: Bytes) { self.inserts.push(key.clone()); self.forward.emplace(key, value); }
fn kill(&mut self, key: &H256) { self.removes.push(key.clone()); } fn remove(&mut self, key: &H256) { self.removes.push(key.clone()); }
} }
impl JournalDB for RefCountedDB { impl JournalDB for RefCountedDB {
@ -212,16 +212,16 @@ mod tests {
let mut jdb = RefCountedDB::new_temp(); let mut jdb = RefCountedDB::new_temp();
let h = jdb.insert(b"foo"); let h = jdb.insert(b"foo");
jdb.commit(0, &b"0".sha3(), None).unwrap(); jdb.commit(0, &b"0".sha3(), None).unwrap();
assert!(jdb.exists(&h)); assert!(jdb.contains(&h));
jdb.remove(&h); jdb.remove(&h);
jdb.commit(1, &b"1".sha3(), None).unwrap(); jdb.commit(1, &b"1".sha3(), None).unwrap();
assert!(jdb.exists(&h)); assert!(jdb.contains(&h));
jdb.commit(2, &b"2".sha3(), None).unwrap(); jdb.commit(2, &b"2".sha3(), None).unwrap();
assert!(jdb.exists(&h)); assert!(jdb.contains(&h));
jdb.commit(3, &b"3".sha3(), Some((0, b"0".sha3()))).unwrap(); jdb.commit(3, &b"3".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.exists(&h)); assert!(jdb.contains(&h));
jdb.commit(4, &b"4".sha3(), Some((1, b"1".sha3()))).unwrap(); jdb.commit(4, &b"4".sha3(), Some((1, b"1".sha3()))).unwrap();
assert!(!jdb.exists(&h)); assert!(!jdb.contains(&h));
} }
#[test] #[test]
@ -251,34 +251,34 @@ mod tests {
let foo = jdb.insert(b"foo"); let foo = jdb.insert(b"foo");
let bar = jdb.insert(b"bar"); let bar = jdb.insert(b"bar");
jdb.commit(0, &b"0".sha3(), None).unwrap(); jdb.commit(0, &b"0".sha3(), None).unwrap();
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(jdb.exists(&bar)); assert!(jdb.contains(&bar));
jdb.remove(&foo); jdb.remove(&foo);
jdb.remove(&bar); jdb.remove(&bar);
let baz = jdb.insert(b"baz"); let baz = jdb.insert(b"baz");
jdb.commit(1, &b"1".sha3(), Some((0, b"0".sha3()))).unwrap(); jdb.commit(1, &b"1".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(jdb.exists(&bar)); assert!(jdb.contains(&bar));
assert!(jdb.exists(&baz)); assert!(jdb.contains(&baz));
let foo = jdb.insert(b"foo"); let foo = jdb.insert(b"foo");
jdb.remove(&baz); jdb.remove(&baz);
jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap(); jdb.commit(2, &b"2".sha3(), Some((1, b"1".sha3()))).unwrap();
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(!jdb.exists(&bar)); assert!(!jdb.contains(&bar));
assert!(jdb.exists(&baz)); assert!(jdb.contains(&baz));
jdb.remove(&foo); jdb.remove(&foo);
jdb.commit(3, &b"3".sha3(), Some((2, b"2".sha3()))).unwrap(); jdb.commit(3, &b"3".sha3(), Some((2, b"2".sha3()))).unwrap();
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(!jdb.exists(&bar)); assert!(!jdb.contains(&bar));
assert!(!jdb.exists(&baz)); assert!(!jdb.contains(&baz));
jdb.commit(4, &b"4".sha3(), Some((3, b"3".sha3()))).unwrap(); jdb.commit(4, &b"4".sha3(), Some((3, b"3".sha3()))).unwrap();
assert!(!jdb.exists(&foo)); assert!(!jdb.contains(&foo));
assert!(!jdb.exists(&bar)); assert!(!jdb.contains(&bar));
assert!(!jdb.exists(&baz)); assert!(!jdb.contains(&baz));
} }
#[test] #[test]
@ -289,8 +289,8 @@ mod tests {
let foo = jdb.insert(b"foo"); let foo = jdb.insert(b"foo");
let bar = jdb.insert(b"bar"); let bar = jdb.insert(b"bar");
jdb.commit(0, &b"0".sha3(), None).unwrap(); jdb.commit(0, &b"0".sha3(), None).unwrap();
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(jdb.exists(&bar)); assert!(jdb.contains(&bar));
jdb.remove(&foo); jdb.remove(&foo);
let baz = jdb.insert(b"baz"); let baz = jdb.insert(b"baz");
@ -299,13 +299,13 @@ mod tests {
jdb.remove(&bar); jdb.remove(&bar);
jdb.commit(1, &b"1b".sha3(), Some((0, b"0".sha3()))).unwrap(); jdb.commit(1, &b"1b".sha3(), Some((0, b"0".sha3()))).unwrap();
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(jdb.exists(&bar)); assert!(jdb.contains(&bar));
assert!(jdb.exists(&baz)); assert!(jdb.contains(&baz));
jdb.commit(2, &b"2b".sha3(), Some((1, b"1b".sha3()))).unwrap(); jdb.commit(2, &b"2b".sha3(), Some((1, b"1b".sha3()))).unwrap();
assert!(jdb.exists(&foo)); assert!(jdb.contains(&foo));
assert!(!jdb.exists(&baz)); assert!(!jdb.contains(&baz));
assert!(!jdb.exists(&bar)); assert!(!jdb.contains(&bar));
} }
} }

View File

@ -162,7 +162,7 @@ impl MemoryDB {
static NULL_RLP_STATIC: [u8; 1] = [0x80; 1]; static NULL_RLP_STATIC: [u8; 1] = [0x80; 1];
impl HashDB for MemoryDB { impl HashDB for MemoryDB {
fn lookup(&self, key: &H256) -> Option<&[u8]> { fn get(&self, key: &H256) -> Option<&[u8]> {
if key == &SHA3_NULL_RLP { if key == &SHA3_NULL_RLP {
return Some(&NULL_RLP_STATIC); return Some(&NULL_RLP_STATIC);
} }
@ -176,7 +176,7 @@ impl HashDB for MemoryDB {
self.data.iter().filter_map(|(k, v)| if v.1 != 0 {Some((k.clone(), v.1))} else {None}).collect() self.data.iter().filter_map(|(k, v)| if v.1 != 0 {Some((k.clone(), v.1))} else {None}).collect()
} }
fn exists(&self, key: &H256) -> bool { fn contains(&self, key: &H256) -> bool {
if key == &SHA3_NULL_RLP { if key == &SHA3_NULL_RLP {
return true; return true;
} }
@ -222,7 +222,7 @@ impl HashDB for MemoryDB {
self.data.insert(key, (value, 1)); self.data.insert(key, (value, 1));
} }
fn kill(&mut self, key: &H256) { fn remove(&mut self, key: &H256) {
if key == &SHA3_NULL_RLP { if key == &SHA3_NULL_RLP {
return; return;
} }

View File

@ -92,7 +92,7 @@ impl OverlayDB {
/// ///
/// Returns either an error or the number of items changed in the backing database. /// Returns either an error or the number of items changed in the backing database.
/// ///
/// Will return an error if the number of `kill()`s ever exceeds the number of /// Will return an error if the number of `remove()`s ever exceeds the number of
/// `insert()`s for any key. This will leave the database in an undeterminate /// `insert()`s for any key. This will leave the database in an undeterminate
/// state. Don't ever let it happen. /// state. Don't ever let it happen.
/// ///
@ -104,15 +104,15 @@ impl OverlayDB {
/// fn main() { /// fn main() {
/// let mut m = OverlayDB::new_temp(); /// let mut m = OverlayDB::new_temp();
/// let key = m.insert(b"foo"); // insert item. /// let key = m.insert(b"foo"); // insert item.
/// assert!(m.exists(&key)); // key exists (in memory). /// assert!(m.contains(&key)); // key exists (in memory).
/// assert_eq!(m.commit().unwrap(), 1); // 1 item changed. /// assert_eq!(m.commit().unwrap(), 1); // 1 item changed.
/// assert!(m.exists(&key)); // key still exists (in backing). /// assert!(m.contains(&key)); // key still exists (in backing).
/// m.kill(&key); // delete item. /// m.remove(&key); // delete item.
/// assert!(!m.exists(&key)); // key "doesn't exist" (though still does in backing). /// assert!(!m.contains(&key)); // key "doesn't exist" (though still does in backing).
/// m.kill(&key); // oh dear... more kills than inserts for the key... /// m.remove(&key); // oh dear... more removes than inserts for the key...
/// //m.commit().unwrap(); // this commit/unwrap would cause a panic. /// //m.commit().unwrap(); // this commit/unwrap would cause a panic.
/// m.revert(); // revert both kills. /// m.revert(); // revert both removes.
/// assert!(m.exists(&key)); // key now still exists. /// assert!(m.contains(&key)); // key now still exists.
/// } /// }
/// ``` /// ```
pub fn commit(&mut self) -> Result<u32, UtilError> { pub fn commit(&mut self) -> Result<u32, UtilError> {
@ -224,7 +224,7 @@ impl HashDB for OverlayDB {
} }
ret ret
} }
fn lookup(&self, key: &H256) -> Option<&[u8]> { fn get(&self, key: &H256) -> Option<&[u8]> {
// return ok if positive; if negative, check backing - might be enough references there to make // return ok if positive; if negative, check backing - might be enough references there to make
// it positive again. // it positive again.
let k = self.overlay.raw(key); let k = self.overlay.raw(key);
@ -249,7 +249,7 @@ impl HashDB for OverlayDB {
} }
} }
} }
fn exists(&self, key: &H256) -> bool { fn contains(&self, key: &H256) -> bool {
// return ok if positive; if negative, check backing - might be enough references there to make // return ok if positive; if negative, check backing - might be enough references there to make
// it positive again. // it positive again.
let k = self.overlay.raw(key); let k = self.overlay.raw(key);
@ -271,7 +271,7 @@ impl HashDB for OverlayDB {
} }
fn insert(&mut self, value: &[u8]) -> H256 { self.overlay.insert(value) } fn insert(&mut self, value: &[u8]) -> H256 { self.overlay.insert(value) }
fn emplace(&mut self, key: H256, value: Bytes) { self.overlay.emplace(key, value); } fn emplace(&mut self, key: H256, value: Bytes) { self.overlay.emplace(key, value); }
fn kill(&mut self, key: &H256) { self.overlay.kill(key); } fn remove(&mut self, key: &H256) { self.overlay.remove(key); }
} }
#[test] #[test]

View File

@ -133,7 +133,7 @@ impl<'db> TrieDB<'db> {
/// Get the data of the root node. /// Get the data of the root node.
fn root_data(&self) -> &[u8] { fn root_data(&self) -> &[u8] {
self.db.lookup(&self.root).expect("Trie root not found!") self.db.get(&self.root).expect("Trie root not found!")
} }
/// Get the root node as a `Node`. /// Get the root node as a `Node`.
@ -184,7 +184,7 @@ impl<'db> TrieDB<'db> {
/// Return optional data for a key given as a `NibbleSlice`. Returns `None` if no data exists. /// Return optional data for a key given as a `NibbleSlice`. Returns `None` if no data exists.
fn do_lookup<'a, 'key>(&'a self, key: &NibbleSlice<'key>) -> Option<&'a [u8]> where 'a: 'key { fn do_lookup<'a, 'key>(&'a self, key: &NibbleSlice<'key>) -> Option<&'a [u8]> where 'a: 'key {
let root_rlp = self.db.lookup(&self.root).expect("Trie root not found!"); let root_rlp = self.db.get(&self.root).expect("Trie root not found!");
self.get_from_node(&root_rlp, key) self.get_from_node(&root_rlp, key)
} }
@ -213,7 +213,7 @@ impl<'db> TrieDB<'db> {
// check if its sha3 + len // check if its sha3 + len
let r = Rlp::new(node); let r = Rlp::new(node);
match r.is_data() && r.size() == 32 { match r.is_data() && r.size() == 32 {
true => self.db.lookup(&r.as_val::<H256>()).unwrap_or_else(|| panic!("Not found! {:?}", r.as_val::<H256>())), true => self.db.get(&r.as_val::<H256>()).unwrap_or_else(|| panic!("Not found! {:?}", r.as_val::<H256>())),
false => node false => node
} }
} }
@ -349,7 +349,7 @@ impl<'db> Trie for TrieDB<'db> {
impl<'db> fmt::Debug for TrieDB<'db> { impl<'db> fmt::Debug for TrieDB<'db> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(writeln!(f, "c={:?} [", self.hash_count)); try!(writeln!(f, "c={:?} [", self.hash_count));
let root_rlp = self.db.lookup(&self.root).expect("Trie root not found!"); let root_rlp = self.db.get(&self.root).expect("Trie root not found!");
try!(self.fmt_all(Node::decoded(root_rlp), f, 0)); try!(self.fmt_all(Node::decoded(root_rlp), f, 0));
writeln!(f, "]") writeln!(f, "]")
} }

View File

@ -87,7 +87,7 @@ impl<'db> TrieDBMut<'db> {
/// Create a new trie with the backing database `db` and `root`. /// Create a new trie with the backing database `db` and `root`.
/// Returns an error if `root` does not exist. /// Returns an error if `root` does not exist.
pub fn from_existing(db: &'db mut HashDB, root: &'db mut H256) -> Result<Self, TrieError> { pub fn from_existing(db: &'db mut HashDB, root: &'db mut H256) -> Result<Self, TrieError> {
if !db.exists(root) { if !db.contains(root) {
Err(TrieError::InvalidStateRoot) Err(TrieError::InvalidStateRoot)
} else { } else {
Ok(TrieDBMut { Ok(TrieDBMut {
@ -143,7 +143,7 @@ impl<'db> TrieDBMut<'db> {
/// Set the trie to a new root node's RLP, inserting the new RLP into the backing database /// Set the trie to a new root node's RLP, inserting the new RLP into the backing database
/// and removing the old. /// and removing the old.
fn set_root_rlp(&mut self, root_data: &[u8]) { fn set_root_rlp(&mut self, root_data: &[u8]) {
self.db.kill(&self.root); self.db.remove(&self.root);
*self.root = self.db.insert(root_data); *self.root = self.db.insert(root_data);
self.hash_count += 1; self.hash_count += 1;
trace!("set_root_rlp {:?} {:?}", root_data.pretty(), self.root); trace!("set_root_rlp {:?} {:?}", root_data.pretty(), self.root);
@ -174,7 +174,7 @@ impl<'db> TrieDBMut<'db> {
/// Get the root node's RLP. /// Get the root node's RLP.
fn root_node(&self) -> Node { fn root_node(&self) -> Node {
Node::decoded(self.db.lookup(&self.root).expect("Trie root not found!")) Node::decoded(self.db.get(&self.root).expect("Trie root not found!"))
} }
/// Get the root node as a `Node`. /// Get the root node as a `Node`.
@ -225,7 +225,7 @@ impl<'db> TrieDBMut<'db> {
/// Return optional data for a key given as a `NibbleSlice`. Returns `None` if no data exists. /// Return optional data for a key given as a `NibbleSlice`. Returns `None` if no data exists.
fn do_lookup<'a, 'key>(&'a self, key: &NibbleSlice<'key>) -> Option<&'a [u8]> where 'a: 'key { fn do_lookup<'a, 'key>(&'a self, key: &NibbleSlice<'key>) -> Option<&'a [u8]> where 'a: 'key {
let root_rlp = self.db.lookup(&self.root).expect("Trie root not found!"); let root_rlp = self.db.get(&self.root).expect("Trie root not found!");
self.get_from_node(&root_rlp, key) self.get_from_node(&root_rlp, key)
} }
@ -254,7 +254,7 @@ impl<'db> TrieDBMut<'db> {
// check if its sha3 + len // check if its sha3 + len
let r = Rlp::new(node); let r = Rlp::new(node);
match r.is_data() && r.size() == 32 { match r.is_data() && r.size() == 32 {
true => self.db.lookup(&r.as_val::<H256>()).expect("Not found!"), true => self.db.get(&r.as_val::<H256>()).expect("Not found!"),
false => node false => node
} }
} }
@ -266,7 +266,7 @@ impl<'db> TrieDBMut<'db> {
trace!("ADD: {:?} {:?}", key, value.pretty()); trace!("ADD: {:?} {:?}", key, value.pretty());
// determine what the new root is, insert new nodes and remove old as necessary. // determine what the new root is, insert new nodes and remove old as necessary.
let mut todo: Journal = Journal::new(); let mut todo: Journal = Journal::new();
let root_rlp = self.augmented(self.db.lookup(&self.root).expect("Trie root not found!"), key, value, &mut todo); let root_rlp = self.augmented(self.db.get(&self.root).expect("Trie root not found!"), key, value, &mut todo);
self.apply(todo); self.apply(todo);
self.set_root_rlp(&root_rlp); self.set_root_rlp(&root_rlp);
trace!("/"); trace!("/");
@ -279,7 +279,7 @@ impl<'db> TrieDBMut<'db> {
trace!("DELETE: {:?}", key); trace!("DELETE: {:?}", key);
// determine what the new root is, insert new nodes and remove old as necessary. // determine what the new root is, insert new nodes and remove old as necessary.
let mut todo: Journal = Journal::new(); let mut todo: Journal = Journal::new();
match self.cleared_from_slice(self.db.lookup(&self.root).expect("Trie root not found!"), key, &mut todo) { match self.cleared_from_slice(self.db.get(&self.root).expect("Trie root not found!"), key, &mut todo) {
Some(root_rlp) => { Some(root_rlp) => {
self.apply(todo); self.apply(todo);
self.set_root_rlp(&root_rlp); self.set_root_rlp(&root_rlp);
@ -335,7 +335,7 @@ impl<'db> TrieDBMut<'db> {
} }
else if rlp.is_data() && rlp.size() == 32 { else if rlp.is_data() && rlp.size() == 32 {
let h = rlp.as_val(); let h = rlp.as_val();
let r = self.db.lookup(&h).unwrap_or_else(||{ let r = self.db.get(&h).unwrap_or_else(||{
println!("Node not found! rlp={:?}, node_hash={:?}", rlp.as_raw().pretty(), h); println!("Node not found! rlp={:?}, node_hash={:?}", rlp.as_raw().pretty(), h);
println!("Journal: {:?}", journal); println!("Journal: {:?}", journal);
panic!(); panic!();
@ -670,7 +670,7 @@ impl<'db> TrieMut for TrieDBMut<'db> {
impl<'db> fmt::Debug for TrieDBMut<'db> { impl<'db> fmt::Debug for TrieDBMut<'db> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
try!(writeln!(f, "c={:?} [", self.hash_count)); try!(writeln!(f, "c={:?} [", self.hash_count));
let root_rlp = self.db.lookup(&self.root).expect("Trie root not found!"); let root_rlp = self.db.get(&self.root).expect("Trie root not found!");
try!(self.fmt_all(Node::decoded(root_rlp), f, 0)); try!(self.fmt_all(Node::decoded(root_rlp), f, 0));
writeln!(f, "]") writeln!(f, "]")
} }