diff --git a/ethcore/src/account_db.rs b/ethcore/src/account_db.rs index 0761b7fba..63524a442 100644 --- a/ethcore/src/account_db.rs +++ b/ethcore/src/account_db.rs @@ -121,10 +121,6 @@ impl<'db> HashDB for AccountDB<'db>{ fn remove(&mut self, _key: &H256) { unimplemented!() } - - fn get_aux(&self, hash: &[u8]) -> Option { - self.db.get_aux(hash) - } } /// DB backend wrapper for Account trie @@ -197,18 +193,6 @@ impl<'db> HashDB for AccountDBMut<'db>{ let key = combine_key(&self.address_hash, key); self.db.remove(&key) } - - fn insert_aux(&mut self, hash: Vec, value: Vec) { - self.db.insert_aux(hash, value); - } - - fn get_aux(&self, hash: &[u8]) -> Option { - self.db.get_aux(hash) - } - - fn remove_aux(&mut self, hash: &[u8]) { - self.db.remove_aux(hash); - } } struct Wrapping<'db>(&'db HashDB); diff --git a/parity/blockchain.rs b/parity/blockchain.rs index 4aeba504e..b43cf478f 100644 --- a/parity/blockchain.rs +++ b/parity/blockchain.rs @@ -265,6 +265,7 @@ fn execute_import(cmd: ImportBlockchain) -> Result { // save user defaults user_defaults.pruning = algorithm; user_defaults.tracing = tracing; + user_defaults.fat_db = fat_db; try!(user_defaults.save(&user_defaults_path)); let report = client.report(); @@ -393,7 +394,7 @@ fn execute_export_state(cmd: ExportState) -> Result { let at = cmd.at; let mut i = 0usize; - out.write_fmt(format_args!("{{ "state\": [", )).expect("Couldn't write to stream."); + out.write_fmt(format_args!("{{ \"state\": [", )).expect("Couldn't write to stream."); loop { let accounts = try!(client.list_accounts(at, last.as_ref(), 1000).ok_or("Specified block not found")); if accounts.is_empty() { diff --git a/parity/params.rs b/parity/params.rs index 3d0740148..3ce07e889 100644 --- a/parity/params.rs +++ b/parity/params.rs @@ -257,17 +257,13 @@ pub fn tracing_switch_to_bool(switch: Switch, user_defaults: &UserDefaults) -> R } } -pub fn fatdb_switch_to_bool(switch: Switch, user_defaults: &UserDefaults, algorithm: Algorithm) -> Result { +pub fn fatdb_switch_to_bool(switch: Switch, user_defaults: &UserDefaults, _algorithm: Algorithm) -> Result { let result = match (user_defaults.is_first_launch, switch, user_defaults.fat_db) { (false, Switch::On, false) => Err("FatDB resync required".into()), (_, Switch::On, _) => Ok(true), (_, Switch::Off, _) => Ok(false), (_, Switch::Auto, def) => Ok(def), }; - - if result.clone().unwrap_or(false) && algorithm != Algorithm::Archive && algorithm != Algorithm::OverlayRecent { - return Err("Fat DB is not supported with the chosen pruning option. Please rerun with `--pruning=archive`".into()); - } result } diff --git a/util/src/hashdb.rs b/util/src/hashdb.rs index 671b32ed5..092d40d8a 100644 --- a/util/src/hashdb.rs +++ b/util/src/hashdb.rs @@ -107,21 +107,6 @@ pub trait HashDB: AsHashDB + Send + Sync { /// } /// ``` fn remove(&mut self, key: &H256); - - /// Insert auxiliary data into hashdb. - fn insert_aux(&mut self, _hash: Vec, _value: Vec) { - unimplemented!(); - } - - /// Get auxiliary data from hashdb. - fn get_aux(&self, _hash: &[u8]) -> Option { - unimplemented!(); - } - - /// Removes auxiliary data from hashdb. - fn remove_aux(&mut self, _hash: &[u8]) { - unimplemented!(); - } } /// Upcast trait. diff --git a/util/src/journaldb/archivedb.rs b/util/src/journaldb/archivedb.rs index a8800045b..30a358bdb 100644 --- a/util/src/journaldb/archivedb.rs +++ b/util/src/journaldb/archivedb.rs @@ -26,10 +26,6 @@ use kvdb::{Database, DBTransaction}; #[cfg(test)] use std::env; -/// Suffix appended to auxiliary keys to distinguish them from normal keys. -/// Would be nich to use rocksdb columns for this eventually. -const AUX_FLAG: u8 = 255; - /// Implementation of the `HashDB` trait for a disk-backed database with a memory overlay /// and latent-removal semantics. /// @@ -108,26 +104,6 @@ impl HashDB for ArchiveDB { fn remove(&mut self, key: &H256) { self.overlay.remove(key); } - - fn insert_aux(&mut self, hash: Vec, value: Vec) { - self.overlay.insert_aux(hash, value); - } - - fn get_aux(&self, hash: &[u8]) -> Option { - if let Some(res) = self.overlay.get_aux(hash) { - return Some(res) - } - - let mut db_hash = hash.to_vec(); - db_hash.push(AUX_FLAG); - - self.backing.get(self.column, &db_hash) - .expect("Low-level database error. Some issue with your hard disk?") - } - - fn remove_aux(&mut self, hash: &[u8]) { - self.overlay.remove_aux(hash); - } } impl JournalDB for ArchiveDB { @@ -164,11 +140,6 @@ impl JournalDB for ArchiveDB { } } - for (mut key, value) in self.overlay.drain_aux() { - key.push(AUX_FLAG); - batch.put(self.column, &key, &value); - } - if self.latest_era.map_or(true, |e| now > e) { batch.put(self.column, &LATEST_ERA_KEY, &encode(&now)); self.latest_era = Some(now); @@ -204,11 +175,6 @@ impl JournalDB for ArchiveDB { } } - for (mut key, value) in self.overlay.drain_aux() { - key.push(AUX_FLAG); - batch.put(self.column, &key, &value); - } - Ok((inserts + deletes) as u32) } diff --git a/util/src/memorydb.rs b/util/src/memorydb.rs index 338f12b1e..20dd3a41f 100644 --- a/util/src/memorydb.rs +++ b/util/src/memorydb.rs @@ -17,7 +17,6 @@ //! Reference-counted memory-based `HashDB` implementation. use hash::*; -use bytes::*; use rlp::*; use sha3::*; use hashdb::*; @@ -72,7 +71,6 @@ use std::collections::hash_map::Entry; #[derive(Default, Clone, PartialEq)] pub struct MemoryDB { data: H256FastMap<(DBValue, i32)>, - aux: HashMap, } impl MemoryDB { @@ -80,7 +78,6 @@ impl MemoryDB { pub fn new() -> MemoryDB { MemoryDB { data: H256FastMap::default(), - aux: HashMap::new(), } } @@ -118,11 +115,6 @@ impl MemoryDB { mem::replace(&mut self.data, H256FastMap::default()) } - /// Return the internal map of auxiliary data, clearing the current state. - pub fn drain_aux(&mut self) -> HashMap { - mem::replace(&mut self.aux, HashMap::new()) - } - /// Grab the raw information associated with a key. Returns None if the key /// doesn't exist. /// @@ -138,7 +130,6 @@ impl MemoryDB { /// Returns the size of allocated heap memory pub fn mem_used(&self) -> usize { self.data.heap_size_of_children() - + self.aux.heap_size_of_children() } /// Remove an element and delete it from storage if reference count reaches zero. @@ -256,18 +247,6 @@ impl HashDB for MemoryDB { self.data.insert(key.clone(), (DBValue::new(), -1)); } } - - fn insert_aux(&mut self, hash: Vec, value: Vec) { - self.aux.insert(hash, DBValue::from_vec(value)); - } - - fn get_aux(&self, hash: &[u8]) -> Option { - self.aux.get(hash).cloned() - } - - fn remove_aux(&mut self, hash: &[u8]) { - self.aux.remove(hash); - } } #[test] diff --git a/util/src/trie/fatdb.rs b/util/src/trie/fatdb.rs index 3a4ad8fc6..ca3f4ca79 100644 --- a/util/src/trie/fatdb.rs +++ b/util/src/trie/fatdb.rs @@ -94,7 +94,8 @@ impl<'db> Iterator for FatDBIterator<'db> { self.trie_iterator.next() .map(|res| res.map(|(hash, value)| { - (self.trie.db().get_aux(&hash).expect("Missing fatdb hash").to_vec(), value) + let aux_hash = hash.sha3(); + (self.trie.db().get(&aux_hash).expect("Missing fatdb hash").to_vec(), value) }) ) } diff --git a/util/src/trie/fatdbmut.rs b/util/src/trie/fatdbmut.rs index fa1c168e8..c81c62f71 100644 --- a/util/src/trie/fatdbmut.rs +++ b/util/src/trie/fatdbmut.rs @@ -51,6 +51,10 @@ impl<'db> FatDBMut<'db> { pub fn db_mut(&mut self) -> &mut HashDB { self.raw.db_mut() } + + fn to_aux_key(key: &[u8]) -> H256 { + key.sha3() + } } impl<'db> TrieMut for FatDBMut<'db> { @@ -76,12 +80,14 @@ impl<'db> TrieMut for FatDBMut<'db> { let hash = key.sha3(); try!(self.raw.insert(&hash, value)); let db = self.raw.db_mut(); - db.insert_aux(hash.to_vec(), key.to_vec()); + db.emplace(Self::to_aux_key(&hash), DBValue::from_slice(key)); Ok(()) } fn remove(&mut self, key: &[u8]) -> super::Result<()> { - self.raw.remove(&key.sha3()) + let hash = key.sha3(); + self.raw.db_mut().remove(&Self::to_aux_key(&hash)); + self.raw.remove(&hash) } }