* Revert #2172, pretty much. * Tidy up whitespace. [ci:skip] * Force CI.
This commit is contained in:
@@ -70,7 +70,7 @@ impl Decodable for Block {
|
||||
}
|
||||
}
|
||||
|
||||
/// Internal type for a block's common elements.
|
||||
/// An internal type for a block's common elements.
|
||||
#[derive(Clone)]
|
||||
pub struct ExecutedBlock {
|
||||
base: Block,
|
||||
@@ -206,6 +206,7 @@ pub struct ClosedBlock {
|
||||
block: ExecutedBlock,
|
||||
uncle_bytes: Bytes,
|
||||
last_hashes: Arc<LastHashes>,
|
||||
unclosed_state: State,
|
||||
}
|
||||
|
||||
/// Just like `ClosedBlock` except that we can't reopen it and it's faster.
|
||||
@@ -347,8 +348,7 @@ impl<'x> OpenBlock<'x> {
|
||||
pub fn close(self) -> ClosedBlock {
|
||||
let mut s = self;
|
||||
|
||||
// take a snapshot so the engine's changes can be rolled back.
|
||||
s.block.state.snapshot();
|
||||
let unclosed_state = s.block.state.clone();
|
||||
|
||||
s.engine.on_close_block(&mut s.block);
|
||||
s.block.base.header.set_transactions_root(ordered_trie_root(s.block.base.transactions.iter().map(|e| e.rlp_bytes().to_vec())));
|
||||
@@ -363,6 +363,7 @@ impl<'x> OpenBlock<'x> {
|
||||
block: s.block,
|
||||
uncle_bytes: uncle_bytes,
|
||||
last_hashes: s.last_hashes,
|
||||
unclosed_state: unclosed_state,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -370,9 +371,6 @@ impl<'x> OpenBlock<'x> {
|
||||
pub fn close_and_lock(self) -> LockedBlock {
|
||||
let mut s = self;
|
||||
|
||||
// take a snapshot so the engine's changes can be rolled back.
|
||||
s.block.state.snapshot();
|
||||
|
||||
s.engine.on_close_block(&mut s.block);
|
||||
if s.block.base.header.transactions_root().is_zero() || s.block.base.header.transactions_root() == &SHA3_NULL_RLP {
|
||||
s.block.base.header.set_transactions_root(ordered_trie_root(s.block.base.transactions.iter().map(|e| e.rlp_bytes().to_vec())));
|
||||
@@ -389,11 +387,10 @@ impl<'x> OpenBlock<'x> {
|
||||
s.block.base.header.set_log_bloom(s.block.receipts.iter().fold(LogBloom::zero(), |mut b, r| {b = &b | &r.log_bloom; b})); //TODO: use |= operator
|
||||
s.block.base.header.set_gas_used(s.block.receipts.last().map_or(U256::zero(), |r| r.gas_used));
|
||||
|
||||
ClosedBlock {
|
||||
LockedBlock {
|
||||
block: s.block,
|
||||
uncle_bytes: uncle_bytes,
|
||||
last_hashes: s.last_hashes,
|
||||
}.lock()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -415,16 +412,6 @@ impl ClosedBlock {
|
||||
|
||||
/// Turn this into a `LockedBlock`, unable to be reopened again.
|
||||
pub fn lock(mut self) -> LockedBlock {
|
||||
// finalize the changes made by the engine.
|
||||
self.block.state.clear_snapshot();
|
||||
if let Err(e) = self.block.state.commit() {
|
||||
warn!("Error committing closed block's state: {:?}", e);
|
||||
}
|
||||
|
||||
// set the state root here, after commit recalculates with the block
|
||||
// rewards.
|
||||
self.block.base.header.set_state_root(self.block.state.root().clone());
|
||||
|
||||
LockedBlock {
|
||||
block: self.block,
|
||||
uncle_bytes: self.uncle_bytes,
|
||||
@@ -432,12 +419,12 @@ impl ClosedBlock {
|
||||
}
|
||||
|
||||
/// Given an engine reference, reopen the `ClosedBlock` into an `OpenBlock`.
|
||||
pub fn reopen(mut self, engine: &Engine) -> OpenBlock {
|
||||
pub fn reopen(self, engine: &Engine) -> OpenBlock {
|
||||
// revert rewards (i.e. set state back at last transaction's state).
|
||||
self.block.state.revert_snapshot();
|
||||
|
||||
let mut block = self.block;
|
||||
block.state = self.unclosed_state;
|
||||
OpenBlock {
|
||||
block: self.block,
|
||||
block: block,
|
||||
engine: engine,
|
||||
last_hashes: self.last_hashes,
|
||||
}
|
||||
@@ -463,11 +450,11 @@ impl LockedBlock {
|
||||
/// Provide a valid seal in order to turn this into a `SealedBlock`.
|
||||
/// This does check the validity of `seal` with the engine.
|
||||
/// Returns the `ClosedBlock` back again if the seal is no good.
|
||||
pub fn try_seal(self, engine: &Engine, seal: Vec<Bytes>) -> Result<SealedBlock, LockedBlock> {
|
||||
pub fn try_seal(self, engine: &Engine, seal: Vec<Bytes>) -> Result<SealedBlock, (Error, LockedBlock)> {
|
||||
let mut s = self;
|
||||
s.block.base.header.set_seal(seal);
|
||||
match engine.verify_block_seal(&s.block.base.header) {
|
||||
Err(_) => Err(s),
|
||||
Err(e) => Err((e, s)),
|
||||
_ => Ok(SealedBlock { block: s.block, uncle_bytes: s.uncle_bytes }),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user