properly rebuild state trie

This commit is contained in:
Robert Habermeier 2016-06-16 18:30:18 +02:00
parent f45254d485
commit e4867d7cb9

View File

@ -27,7 +27,7 @@ use error::Error;
use ids::BlockID; use ids::BlockID;
use views::BlockView; use views::BlockView;
use util::{Bytes, Hashable, HashDB, snappy, TrieDB}; use util::{Bytes, Hashable, HashDB, snappy, TrieDB, TrieDBMut, TrieMut};
use util::hash::{FixedHash, H256}; use util::hash::{FixedHash, H256};
use util::rlp::{DecoderError, RlpStream, Stream, UntrustedRlp, View}; use util::rlp::{DecoderError, RlpStream, Stream, UntrustedRlp, View};
@ -162,10 +162,10 @@ impl<'a> StateChunker<'a> {
// //
// If the buffer is greater than the desired chunk size, // If the buffer is greater than the desired chunk size,
// this will write out the data to disk. // this will write out the data to disk.
fn push(&mut self, key: Bytes, value: Bytes) -> Result<(), Error> { fn push(&mut self, account_hash: Bytes, data: Bytes) -> Result<(), Error> {
let pair = { let pair = {
let mut stream = RlpStream::new_list(2); let mut stream = RlpStream::new_list(2);
stream.append(&key).append(&value); stream.append(&account_hash).append_raw(&data, 1);
stream.out() stream.out()
}; };
@ -305,7 +305,12 @@ impl<'a> StateRebuilder<'a> {
acc.to_thin_rlp() acc.to_thin_rlp()
}; };
self.db.insert(&thin_rlp); let mut account_trie = if self.state_root != H256::zero() {
try!(TrieDBMut::from_existing(self.db, &mut self.state_root))
} else {
TrieDBMut::new(self.db, &mut self.state_root)
};
account_trie.insert(&hash, &thin_rlp);
} }
Ok(()) Ok(())