|
@ -99,7 +99,7 @@ State::State(OverlayDB const& _db, BaseState _bs, Address _coinbaseAddress): |
|
|
m_previousBlock = CanonBlockChain::genesis(); |
|
|
m_previousBlock = CanonBlockChain::genesis(); |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
m_previousBlock.setEmpty(); |
|
|
m_previousBlock.clear(); |
|
|
|
|
|
|
|
|
resetCurrent(); |
|
|
resetCurrent(); |
|
|
|
|
|
|
|
@ -190,6 +190,8 @@ State& State::operator=(State const& _s) |
|
|
m_blockReward = _s.m_blockReward; |
|
|
m_blockReward = _s.m_blockReward; |
|
|
m_lastTx = _s.m_lastTx; |
|
|
m_lastTx = _s.m_lastTx; |
|
|
paranoia("after state cloning (assignment op)", true); |
|
|
paranoia("after state cloning (assignment op)", true); |
|
|
|
|
|
|
|
|
|
|
|
m_committedToMine = false; |
|
|
return *this; |
|
|
return *this; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -276,8 +278,8 @@ bool State::sync(BlockChain const& _bc, h256 _block, BlockInfo const& _bi) |
|
|
{ |
|
|
{ |
|
|
bool ret = false; |
|
|
bool ret = false; |
|
|
// BLOCK
|
|
|
// BLOCK
|
|
|
BlockInfo bi = _bi; |
|
|
BlockInfo bi = _bi ? _bi : _bc.info(_block); |
|
|
if (!bi) |
|
|
/* if (!bi)
|
|
|
while (1) |
|
|
while (1) |
|
|
{ |
|
|
{ |
|
|
try |
|
|
try |
|
@ -299,7 +301,7 @@ bool State::sync(BlockChain const& _bc, h256 _block, BlockInfo const& _bi) |
|
|
cerr << "ERROR: Corrupt block-chain! Delete your block-chain DB and restart." << endl; |
|
|
cerr << "ERROR: Corrupt block-chain! Delete your block-chain DB and restart." << endl; |
|
|
cerr << _e.what() << endl; |
|
|
cerr << _e.what() << endl; |
|
|
} |
|
|
} |
|
|
} |
|
|
}*/ |
|
|
if (bi == m_currentBlock) |
|
|
if (bi == m_currentBlock) |
|
|
{ |
|
|
{ |
|
|
// We mined the last block.
|
|
|
// We mined the last block.
|
|
@ -364,7 +366,7 @@ u256 State::enactOn(bytesConstRef _block, BlockInfo const& _bi, BlockChain const |
|
|
#endif |
|
|
#endif |
|
|
|
|
|
|
|
|
// Check family:
|
|
|
// Check family:
|
|
|
BlockInfo biParent(_bc.block(_bi.parentHash)); |
|
|
BlockInfo biParent = _bc.info(_bi.parentHash); |
|
|
_bi.verifyParent(biParent); |
|
|
_bi.verifyParent(biParent); |
|
|
|
|
|
|
|
|
#if ETH_TIMED_ENACTMENTS |
|
|
#if ETH_TIMED_ENACTMENTS |
|
@ -374,7 +376,7 @@ u256 State::enactOn(bytesConstRef _block, BlockInfo const& _bi, BlockChain const |
|
|
|
|
|
|
|
|
BlockInfo biGrandParent; |
|
|
BlockInfo biGrandParent; |
|
|
if (biParent.number) |
|
|
if (biParent.number) |
|
|
biGrandParent.populate(_bc.block(biParent.parentHash)); |
|
|
biGrandParent = _bc.info(biParent.parentHash); |
|
|
|
|
|
|
|
|
#if ETH_TIMED_ENACTMENTS |
|
|
#if ETH_TIMED_ENACTMENTS |
|
|
populateGrand = t.elapsed(); |
|
|
populateGrand = t.elapsed(); |
|
@ -434,6 +436,8 @@ void State::resetCurrent() |
|
|
m_lastTx = m_db; |
|
|
m_lastTx = m_db; |
|
|
m_state.setRoot(m_previousBlock.stateRoot); |
|
|
m_state.setRoot(m_previousBlock.stateRoot); |
|
|
|
|
|
|
|
|
|
|
|
m_committedToMine = false; |
|
|
|
|
|
|
|
|
paranoia("begin resetCurrent", true); |
|
|
paranoia("begin resetCurrent", true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -539,6 +543,9 @@ u256 State::enact(bytesConstRef _block, BlockChain const& _bc, bool _checkNonce) |
|
|
// m_currentBlock is assumed to be prepopulated and reset.
|
|
|
// m_currentBlock is assumed to be prepopulated and reset.
|
|
|
|
|
|
|
|
|
BlockInfo bi(_block, _checkNonce ? CheckEverything : IgnoreNonce); |
|
|
BlockInfo bi(_block, _checkNonce ? CheckEverything : IgnoreNonce); |
|
|
|
|
|
cdebug << "enacting" << BlockInfo::headerHash(_block).abridged() << "==" << bi.hash().abridged() << "on" << m_previousBlock.hash().abridged(); |
|
|
|
|
|
cdebug << m_currentBlock; |
|
|
|
|
|
|
|
|
#if !ETH_RELEASE |
|
|
#if !ETH_RELEASE |
|
|
assert(m_previousBlock.hash() == bi.parentHash); |
|
|
assert(m_previousBlock.hash() == bi.parentHash); |
|
|
assert(m_currentBlock.parentHash == bi.parentHash); |
|
|
assert(m_currentBlock.parentHash == bi.parentHash); |
|
@ -551,6 +558,10 @@ u256 State::enact(bytesConstRef _block, BlockChain const& _bc, bool _checkNonce) |
|
|
// Populate m_currentBlock with the correct values.
|
|
|
// Populate m_currentBlock with the correct values.
|
|
|
m_currentBlock = bi; |
|
|
m_currentBlock = bi; |
|
|
m_currentBlock.verifyInternals(_block); |
|
|
m_currentBlock.verifyInternals(_block); |
|
|
|
|
|
m_currentBlock.noteDirty(); |
|
|
|
|
|
|
|
|
|
|
|
cdebug << "populated and verified. incoming block hash is" << m_currentBlock.hash().abridged(); |
|
|
|
|
|
cdebug << m_currentBlock; |
|
|
|
|
|
|
|
|
// cnote << "playback begins:" << m_state.root();
|
|
|
// cnote << "playback begins:" << m_state.root();
|
|
|
// cnote << m_state;
|
|
|
// cnote << m_state;
|
|
@ -620,6 +631,7 @@ u256 State::enact(bytesConstRef _block, BlockChain const& _bc, bool _checkNonce) |
|
|
// Initialise total difficulty calculation.
|
|
|
// Initialise total difficulty calculation.
|
|
|
u256 tdIncrease = m_currentBlock.difficulty; |
|
|
u256 tdIncrease = m_currentBlock.difficulty; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Check uncles & apply their rewards to state.
|
|
|
// Check uncles & apply their rewards to state.
|
|
|
if (rlp[2].itemCount() > 2) |
|
|
if (rlp[2].itemCount() > 2) |
|
|
BOOST_THROW_EXCEPTION(TooManyUncles()); |
|
|
BOOST_THROW_EXCEPTION(TooManyUncles()); |
|
@ -646,6 +658,7 @@ u256 State::enact(bytesConstRef _block, BlockChain const& _bc, bool _checkNonce) |
|
|
tdIncrease += uncle.difficulty; |
|
|
tdIncrease += uncle.difficulty; |
|
|
rewarded.push_back(uncle); |
|
|
rewarded.push_back(uncle); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
applyRewards(rewarded); |
|
|
applyRewards(rewarded); |
|
|
|
|
|
|
|
|
// Commit all cached state changes to the state trie.
|
|
|
// Commit all cached state changes to the state trie.
|
|
@ -673,6 +686,11 @@ u256 State::enact(bytesConstRef _block, BlockChain const& _bc, bool _checkNonce) |
|
|
BOOST_THROW_EXCEPTION(InvalidGasUsed() << RequirementError(bigint(gasUsed()), bigint(m_currentBlock.gasUsed))); |
|
|
BOOST_THROW_EXCEPTION(InvalidGasUsed() << RequirementError(bigint(gasUsed()), bigint(m_currentBlock.gasUsed))); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cdebug << m_currentBlock; |
|
|
|
|
|
auto hh = m_currentBlock.hash(); |
|
|
|
|
|
m_currentBlock.noteDirty(); |
|
|
|
|
|
cdebug << "done enacting. new stateroot is" << m_currentBlock.stateRoot.abridged() << ", hash is" << m_currentBlock.hash().abridged() << " = " << hh; |
|
|
|
|
|
|
|
|
return tdIncrease; |
|
|
return tdIncrease; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -687,6 +705,9 @@ void State::cleanup(bool _fullCommit) |
|
|
|
|
|
|
|
|
paranoia("immediately after database commit", true); |
|
|
paranoia("immediately after database commit", true); |
|
|
m_previousBlock = m_currentBlock; |
|
|
m_previousBlock = m_currentBlock; |
|
|
|
|
|
m_currentBlock.populateFromParent(m_previousBlock); |
|
|
|
|
|
|
|
|
|
|
|
cdebug << "finalising enactment. current -> previous, hash is" << m_previousBlock.hash().abridged(); |
|
|
} |
|
|
} |
|
|
else |
|
|
else |
|
|
m_db.rollback(); |
|
|
m_db.rollback(); |
|
@ -696,7 +717,7 @@ void State::cleanup(bool _fullCommit) |
|
|
|
|
|
|
|
|
void State::uncommitToMine() |
|
|
void State::uncommitToMine() |
|
|
{ |
|
|
{ |
|
|
if (m_currentBlock.sha3Uncles) |
|
|
if (m_committedToMine) |
|
|
{ |
|
|
{ |
|
|
m_cache.clear(); |
|
|
m_cache.clear(); |
|
|
if (!m_transactions.size()) |
|
|
if (!m_transactions.size()) |
|
@ -705,7 +726,7 @@ void State::uncommitToMine() |
|
|
m_state.setRoot(m_receipts.back().stateRoot()); |
|
|
m_state.setRoot(m_receipts.back().stateRoot()); |
|
|
m_db = m_lastTx; |
|
|
m_db = m_lastTx; |
|
|
paranoia("Uncommited to mine", true); |
|
|
paranoia("Uncommited to mine", true); |
|
|
m_currentBlock.sha3Uncles = h256(); |
|
|
m_committedToMine = false; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -842,6 +863,8 @@ void State::commitToMine(BlockChain const& _bc) |
|
|
m_currentBlock.gasUsed = gasUsed(); |
|
|
m_currentBlock.gasUsed = gasUsed(); |
|
|
m_currentBlock.stateRoot = m_state.root(); |
|
|
m_currentBlock.stateRoot = m_state.root(); |
|
|
m_currentBlock.parentHash = m_previousBlock.hash(); |
|
|
m_currentBlock.parentHash = m_previousBlock.hash(); |
|
|
|
|
|
|
|
|
|
|
|
m_committedToMine = true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
MineInfo State::mine(unsigned _msTimeout, bool _turbo) |
|
|
MineInfo State::mine(unsigned _msTimeout, bool _turbo) |
|
|