From 3850ee64bbdea6fd605d6ae0e7f8937faaa1cf6c Mon Sep 17 00:00:00 2001 From: Robert Habermeier Date: Fri, 17 Jun 2016 12:56:57 +0200 Subject: [PATCH] have StateRebuilder take a JournalDB and commit post-chunk --- ethcore/src/snapshot/mod.rs | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ethcore/src/snapshot/mod.rs b/ethcore/src/snapshot/mod.rs index 37d8d1873..e1beece19 100644 --- a/ethcore/src/snapshot/mod.rs +++ b/ethcore/src/snapshot/mod.rs @@ -27,7 +27,7 @@ use error::Error; use ids::BlockID; use views::BlockView; -use util::{Bytes, Hashable, HashDB, snappy, TrieDB, TrieDBMut, TrieMut}; +use util::{Bytes, Hashable, HashDB, JournalDB, snappy, TrieDB, TrieDBMut, TrieMut}; use util::hash::{FixedHash, H256}; use util::rlp::{DecoderError, RlpStream, Stream, UntrustedRlp, View}; @@ -272,15 +272,15 @@ impl ManifestData { } /// Used to rebuild the state trie piece by piece. -pub struct StateRebuilder<'a> { - db: &'a mut HashDB, +pub struct StateRebuilder { + db: Box, state_root: H256, snappy_buffer: Vec } -impl<'a> StateRebuilder<'a> { +impl StateRebuilder { /// Create a new state rebuilder to write into the given backing DB. - pub fn new(db: &'a mut HashDB) -> Self { + pub fn new(db: Box) -> Self { StateRebuilder { db: db, state_root: H256::zero(), @@ -298,7 +298,7 @@ impl<'a> StateRebuilder<'a> { let fat_rlp = try!(account_pair.at(1)); let thin_rlp = { - let mut acct_db = AccountDBMut::from_hash(self.db, hash); + let mut acct_db = AccountDBMut::from_hash(self.db.as_hashdb_mut(), hash); // fill out the storage trie and code while decoding. let acc = try!(Account::from_fat_rlp(&mut acct_db, fat_rlp)); @@ -306,13 +306,14 @@ impl<'a> StateRebuilder<'a> { }; let mut account_trie = if self.state_root != H256::zero() { - try!(TrieDBMut::from_existing(self.db, &mut self.state_root)) + try!(TrieDBMut::from_existing(self.db.as_hashdb_mut(), &mut self.state_root)) } else { - TrieDBMut::new(self.db, &mut self.state_root) + TrieDBMut::new(self.db.as_hashdb_mut(), &mut self.state_root) }; account_trie.insert(&hash, &thin_rlp); } + try!(self.db.commit(0, &H256::zero(), None)); Ok(()) }