Browse Source

Helpers and fixes for uncles debugging.

cl-refactor
Gav Wood 10 years ago
parent
commit
9882e98606
  1. 2
      libethcore/Exceptions.h
  2. 7
      libethereum/State.cpp

2
libethcore/Exceptions.h

@ -25,7 +25,7 @@ class InvalidBlockHeaderFormat: public dev::Exception { public: InvalidBlockHead
class InvalidUnclesHash: public dev::Exception {}; class InvalidUnclesHash: public dev::Exception {};
class InvalidUncle: public dev::Exception {}; class InvalidUncle: public dev::Exception {};
class UncleTooOld: public dev::Exception {}; class UncleTooOld: public dev::Exception {};
class UncleInChain: public dev::Exception {}; class UncleInChain: public dev::Exception { public: UncleInChain(h256Set _uncles, h256 _block): m_uncles(_uncles), m_block(_block) {} h256Set m_uncles; h256 m_block; virtual std::string description() const { return "Uncle in block already mentioned: Uncles " + toString(m_uncles) + " (" + m_block.abridged() + ")"; } };
class DuplicateUncleNonce: public dev::Exception {}; class DuplicateUncleNonce: public dev::Exception {};
class InvalidStateRoot: public dev::Exception {}; class InvalidStateRoot: public dev::Exception {};
class InvalidTransactionsHash: public dev::Exception { public: InvalidTransactionsHash(h256 _head, h256 _real): m_head(_head), m_real(_real) {} h256 m_head; h256 m_real; virtual std::string description() const { return "Invalid transactions hash: header says: " + toHex(m_head.ref()) + " block is:" + toHex(m_real.ref()); } }; class InvalidTransactionsHash: public dev::Exception { public: InvalidTransactionsHash(h256 _head, h256 _real): m_head(_head), m_real(_real) {} h256 m_head; h256 m_real; virtual std::string description() const { return "Invalid transactions hash: header says: " + toHex(m_head.ref()) + " block is:" + toHex(m_real.ref()); } };

7
libethereum/State.cpp

@ -577,6 +577,9 @@ u256 State::enact(bytesConstRef _block, BlockChain const* _bc, bool _checkNonce)
set<h256> knownUncles = _bc ? _bc->allUnclesFrom(m_currentBlock.parentHash) : set<h256>(); set<h256> knownUncles = _bc ? _bc->allUnclesFrom(m_currentBlock.parentHash) : set<h256>();
for (auto const& i: RLP(_block)[2]) for (auto const& i: RLP(_block)[2])
{ {
if (knownUncles.count(sha3(i.data())))
throw UncleInChain(knownUncles, sha3(i.data()));
BlockInfo uncle = BlockInfo::fromHeader(i.data()); BlockInfo uncle = BlockInfo::fromHeader(i.data());
if (nonces.count(uncle.nonce)) if (nonces.count(uncle.nonce))
throw DuplicateUncleNonce(); throw DuplicateUncleNonce();
@ -585,8 +588,6 @@ u256 State::enact(bytesConstRef _block, BlockChain const* _bc, bool _checkNonce)
BlockInfo uncleParent(_bc->block(uncle.parentHash)); BlockInfo uncleParent(_bc->block(uncle.parentHash));
if ((bigint)uncleParent.number < (bigint)m_currentBlock.number - 6) if ((bigint)uncleParent.number < (bigint)m_currentBlock.number - 6)
throw UncleTooOld(); throw UncleTooOld();
if (knownUncles.count(sha3(i.data())))
throw UncleInChain();
uncle.verifyParent(uncleParent); uncle.verifyParent(uncleParent);
} }
@ -725,7 +726,7 @@ void State::commitToMine(BlockChain const& _bc)
auto us = _bc.details(p).children; auto us = _bc.details(p).children;
assert(us.size() >= 1); // must be at least 1 child of our grandparent - it's our own parent! assert(us.size() >= 1); // must be at least 1 child of our grandparent - it's our own parent!
for (auto const& u: us) for (auto const& u: us)
if (!knownUncles.count(BlockInfo::headerHash(_bc.block(u)))) // ignore any uncles/mainline blocks that we know about. We use header-hash for this. if (!knownUncles.count(u)) // ignore any uncles/mainline blocks that we know about.
{ {
BlockInfo ubi(_bc.block(u)); BlockInfo ubi(_bc.block(u));
ubi.fillStream(unclesData, true); ubi.fillStream(unclesData, true);

Loading…
Cancel
Save