Refactor triedb constructors to error on invalid state root (#1230)
* add TrieError, refactor Trie DB creation * remove Result type alias due to glob import conflicts * fix fallout in state.rs * add debug, display impl for TrieError * fix fallout in account.rs * ethcore::Error::TrieError variant * fix remaining fallout in ethcore crate * added From<TrieError> impl for Error, removed map_err calls * fix test breakages * fix doc tests * update docs [ci skip]
This commit is contained in:
committed by
Gav Wood
parent
fdc22db3f4
commit
13968aaa38
@@ -386,18 +386,14 @@ impl<V> Client<V> where V: Verifier {
|
||||
|
||||
let root = HeaderView::new(&header).state_root();
|
||||
|
||||
// TODO [rob]: refactor State::from_existing so we avoid doing redundant lookups.
|
||||
if !db.contains(&root) {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(State::from_existing(db, root, self.engine.account_start_nonce()))
|
||||
State::from_existing(db, root, self.engine.account_start_nonce()).ok()
|
||||
})
|
||||
}
|
||||
|
||||
/// Get a copy of the best block's state.
|
||||
pub fn state(&self) -> State {
|
||||
State::from_existing(self.state_db.lock().unwrap().boxed_clone(), HeaderView::new(&self.best_block_header()).state_root(), self.engine.account_start_nonce())
|
||||
.expect("State root of best block header always valid.")
|
||||
}
|
||||
|
||||
/// Get info on the cache.
|
||||
@@ -481,7 +477,7 @@ impl<V> BlockChainClient for Client<V> where V: Verifier {
|
||||
}
|
||||
let options = TransactOptions { tracing: analytics.transaction_tracing, vm_tracing: analytics.vm_tracing, check_nonce: false };
|
||||
let mut ret = Executive::new(&mut state, &env_info, self.engine.deref().deref(), &self.vm_factory).transact(t, options);
|
||||
|
||||
|
||||
// TODO gav move this into Executive.
|
||||
if analytics.state_diffing {
|
||||
if let Ok(ref mut x) = ret {
|
||||
@@ -776,7 +772,8 @@ impl<V> MiningBlockChainClient for Client<V> where V: Verifier {
|
||||
author,
|
||||
gas_floor_target,
|
||||
extra_data,
|
||||
);
|
||||
).expect("OpenBlock::new only fails if parent state root invalid. State root of best block's header is never invalid. \
|
||||
Therefore creating an OpenBlock with the best block's header will not fail.");
|
||||
|
||||
// Add uncles
|
||||
self.chain
|
||||
|
||||
Reference in New Issue
Block a user