From 1d7ed3b2c3a91ee9f07342fe71f4a28d0748dc18 Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Fri, 28 Apr 2017 18:02:07 +0200 Subject: [PATCH] Style polishing & comments improvement --- libethereum/Block.h | 3 ++- libethereum/Executive.cpp | 29 ++++++++++++++++++++--------- libethereum/State.h | 2 ++ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/libethereum/Block.h b/libethereum/Block.h index c6d827aadfd..868aa8c45e0 100644 --- a/libethereum/Block.h +++ b/libethereum/Block.h @@ -202,9 +202,10 @@ class Block /// Get the bloom filter of a particular transaction that happened in the block. LogBloom const& logBloom(unsigned _i) const { return receipt(_i).bloom(); } - /// Get the State root hash immediately after the given number of pending transactions have been applied. + /// Get the State root hash immediately before after all previous transactions before transaction @a _i have been applied. /// If (_i == 0) returns the initial state of the block. /// If (_i == pending().size()) returns the final state of the block, prior to rewards. + /// Returns zero hash if intermediate state root is not available in the receipt (the case after EIP98) h256 stateRootBeforeTx(unsigned _i) const; // State-change operations diff --git a/libethereum/Executive.cpp b/libethereum/Executive.cpp index 4871d9c95d0..c15078478b0 100644 --- a/libethereum/Executive.cpp +++ b/libethereum/Executive.cpp @@ -141,6 +141,25 @@ string StandardTrace::json(bool _styled) const return _styled ? Json::StyledWriter().write(m_trace) : Json::FastWriter().write(m_trace); } +namespace +{ + +State& initIntermediateState(State& _s, Block const& _block, unsigned _txIndex, BlockChain const& _bc) +{ + _s = _block.state(); + u256 const rootHash = _block.stateRootBeforeTx(_txIndex); + if (rootHash) + _s.setRoot(rootHash); + else + { + _s.setRoot(_block.stateRootBeforeTx(0)); + _s.executeBlockTransactions(_block, _txIndex, _bc.lastHashes(_block.info().parentHash()), *_bc.sealEngine()); + } + return _s; +} + +} + Executive::Executive(Block& _s, BlockChain const& _bc, unsigned _level): m_s(_s.mutableState()), m_envInfo(_s.info(), _bc.lastHashes(_s.info().parentHash())), @@ -158,19 +177,11 @@ Executive::Executive(Block& _s, LastHashes const& _lh, unsigned _level): } Executive::Executive(State& _s, Block const& _block, unsigned _txIndex, BlockChain const& _bc, unsigned _level): - m_s(_s = _block.state()), + m_s(initIntermediateState(_s, _block, _txIndex, _bc)), m_envInfo(_block.info(), _bc.lastHashes(_block.info().parentHash()), _txIndex ? _block.receipt(_txIndex - 1).gasUsed() : 0), m_depth(_level), m_sealEngine(*_bc.sealEngine()) { - u256 const rootHash = _block.stateRootBeforeTx(_txIndex); - if (rootHash) - m_s.setRoot(rootHash); - else - { - m_s.setRoot(_block.stateRootBeforeTx(0)); - m_s.executeBlockTransactions(_block, _txIndex, _bc.lastHashes(_block.info().parentHash()), *_bc.sealEngine()); - } } u256 Executive::gasUsed() const diff --git a/libethereum/State.h b/libethereum/State.h index 2ef4760c878..9a69aa6be6f 100644 --- a/libethereum/State.h +++ b/libethereum/State.h @@ -207,6 +207,8 @@ class State /// This will change the state accordingly. std::pair execute(EnvInfo const& _envInfo, SealEngineFace const& _sealEngine, Transaction const& _t, Permanence _p = Permanence::Committed, OnOpFunc const& _onOp = OnOpFunc()); + /// Execute @a _txCount transactions of a given block. + /// This will change the state accordingly. void executeBlockTransactions(Block const& _block, unsigned _txCount, LastHashes const& _lastHashes, SealEngineFace const& _sealEngine); /// Check if the address is in use.