Browse Source

Cleanup and document some of the hairier State code.

Fixes #1458.
Fixes #1459.
Fixes #1460.
cl-refactor
Gav Wood 10 years ago
parent
commit
1a93beb7e1
  1. 40
      libethereum/State.cpp

40
libethereum/State.cpp

@ -111,22 +111,36 @@ State::State(OverlayDB const& _db, BlockChain const& _bc, h256 _h):
m_state(&m_db), m_state(&m_db),
m_blockReward(c_blockReward) m_blockReward(c_blockReward)
{ {
// TODO THINK: is this necessary?
m_state.init();
auto b = _bc.block(_h); auto b = _bc.block(_h);
BlockInfo bi; BlockInfo bi(b);
BlockInfo bip;
if (_h) if (!bi)
bi.populate(b); {
if (bi && bi.number) // Might be worth throwing here.
bip.populate(_bc.block(bi.parentHash)); cwarn << "Invalid block given for state population: " << _h;
if (!_h || !bip)
return; return;
m_ourAddress = bi.coinbaseAddress; }
sync(_bc, bi.parentHash, bip); if (bi.number)
enact(&b, _bc); {
// Non-genesis:
// 1. Start at parent's end state (state root).
BlockInfo bip;
bip.populate(_bc.block(bi.parentHash));
sync(_bc, bi.parentHash, bip);
// 2. Enact the block's transactions onto this state.
m_ourAddress = bi.coinbaseAddress;
enact(&b, _bc);
}
else
{
// Genesis required:
// We know there are no transactions, so just populate directly.
m_state.init();
sync(_bc, _h, bi);
}
} }
State::State(State const& _s): State::State(State const& _s):

Loading…
Cancel
Save