Use JournalDB instead of OverlayDB.

This commit is contained in:
Gav Wood
2016-01-18 13:54:46 +01:00
parent 28c07cba52
commit b9b08af518
11 changed files with 47 additions and 36 deletions

View File

@@ -46,7 +46,7 @@ impl JournalDB {
/// Commit all recent insert operations and historical removals from the old era
/// to the backing database.
pub fn commit(&mut self, now: u64, id: &H256, end: Option<(u64, &H256)>) -> Result<u32, UtilError> {
pub fn commit(&mut self, now: u64, id: &H256, end: Option<(u64, H256)>) -> Result<u32, UtilError> {
// journal format:
// [era, 0] => [ id, [insert_0, ...], [remove_0, ...] ]
// [era, 1] => [ id, [insert_0, ...], [remove_0, ...] ]
@@ -95,7 +95,7 @@ impl JournalDB {
&last
})) {
let rlp = Rlp::new(&rlp_data);
let to_remove: Vec<H256> = rlp.val_at(if *canon_id == rlp.val_at(0) {2} else {1});
let to_remove: Vec<H256> = rlp.val_at(if canon_id == rlp.val_at(0) {2} else {1});
for i in to_remove.iter() {
self.forward.remove(i);
}

View File

@@ -89,6 +89,7 @@ pub use rlp::*;
pub use hashdb::*;
pub use memorydb::*;
pub use overlaydb::*;
pub use journaldb::*;
pub use math::*;
pub use chainfilter::*;
pub use crypto::*;

View File

@@ -131,10 +131,15 @@ impl OverlayDB {
/// Get the refs and value of the given key.
fn put_payload(&self, key: &H256, payload: (Bytes, u32)) {
let mut s = RlpStream::new_list(2);
s.append(&payload.1);
s.append(&payload.0);
self.backing.put(&key.bytes(), &s.out()).expect("Low-level database error. Some issue with your hard disk?");
if payload.1 > 0 {
let mut s = RlpStream::new_list(2);
s.append(&payload.1);
s.append(&payload.0);
self.backing.put(&key.bytes(), &s.out()).expect("Low-level database error. Some issue with your hard disk?");
} else {
self.backing.delete(&key.bytes()).expect("Low-level database error. Some issue with your hard disk?");
}
}
}