batch state trie writes

This commit is contained in:
Robert Habermeier 2016-06-29 18:37:17 +02:00
parent 6977d335e9
commit 6ecd6eaa12
2 changed files with 11 additions and 1 deletions

View File

@ -498,6 +498,7 @@ impl BlockChainClient for TestBlockChainClient {
// import right here // import right here
let tx = transactions.into_iter().filter_map(|bytes| UntrustedRlp::new(&bytes).as_val().ok()).collect(); let tx = transactions.into_iter().filter_map(|bytes| UntrustedRlp::new(&bytes).as_val().ok()).collect();
self.import_transactions(tx); self.import_transactions(tx);
}
fn take_snapshot(&self, _root_dir: &Path) { fn take_snapshot(&self, _root_dir: &Path) {
unimplemented!() unimplemented!()

View File

@ -292,6 +292,7 @@ impl StateRebuilder {
pub fn feed(&mut self, compressed: &[u8]) -> Result<(), Error> { pub fn feed(&mut self, compressed: &[u8]) -> Result<(), Error> {
let len = try!(snappy::decompress_into(compressed, &mut self.snappy_buffer)); let len = try!(snappy::decompress_into(compressed, &mut self.snappy_buffer));
let rlp = UntrustedRlp::new(&self.snappy_buffer[..len]); let rlp = UntrustedRlp::new(&self.snappy_buffer[..len]);
let mut pairs = Vec::with_capacity(rlp.item_count());
for account_pair in rlp.iter() { for account_pair in rlp.iter() {
let hash: H256 = try!(account_pair.val_at(0)); let hash: H256 = try!(account_pair.val_at(0));
@ -305,12 +306,20 @@ impl StateRebuilder {
acc.to_thin_rlp() acc.to_thin_rlp()
}; };
pairs.push((hash, thin_rlp));
}
// batch trie writes
{
let mut account_trie = if self.state_root != H256::zero() { let mut account_trie = if self.state_root != H256::zero() {
try!(TrieDBMut::from_existing(self.db.as_hashdb_mut(), &mut self.state_root)) try!(TrieDBMut::from_existing(self.db.as_hashdb_mut(), &mut self.state_root))
} else { } else {
TrieDBMut::new(self.db.as_hashdb_mut(), &mut self.state_root) TrieDBMut::new(self.db.as_hashdb_mut(), &mut self.state_root)
}; };
account_trie.insert(&hash, &thin_rlp);
for (hash, thin_rlp) in pairs {
account_trie.insert(&hash, &thin_rlp);
}
} }
try!(self.db.commit(0, &H256::zero(), None)); try!(self.db.commit(0, &H256::zero(), None));