Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Style polishing & comments improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Apr 28, 2017
1 parent d01152a commit 1d7ed3b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
3 changes: 2 additions & 1 deletion libethereum/Block.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 20 additions & 9 deletions libethereum/Executive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())),
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions libethereum/State.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ class State
/// This will change the state accordingly.
std::pair<ExecutionResult, TransactionReceipt> 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.
Expand Down

0 comments on commit 1d7ed3b

Please sign in to comment.