diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index 7c03bc24f..68eccddf5 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -981,13 +981,13 @@ vector BlockChain::withBlockBloom(LogBloom const& _b, unsigned _earlie return ret; } -h256Hash BlockChain::allUnclesFrom(h256 const& _parent) const +h256Hash BlockChain::allKinFrom(h256 const& _parent, unsigned _generations) const { // Get all uncles cited given a parent (i.e. featured as uncles/main in parent, parent + 1, ... parent + 5). h256 p = _parent; h256Hash ret = { p }; // p and (details(p).parent: i == 5) is likely to be overkill, but can't hurt to be cautious. - for (unsigned i = 0; i < 6 && p != m_genesisHash; ++i, p = details(p).parent) + for (unsigned i = 0; i < _generations && p != m_genesisHash; ++i, p = details(p).parent) { ret.insert(details(p).parent); auto b = block(p); diff --git a/libethereum/BlockChain.h b/libethereum/BlockChain.h index e77369534..02f3f618a 100644 --- a/libethereum/BlockChain.h +++ b/libethereum/BlockChain.h @@ -203,10 +203,10 @@ public: /// Get the hash of the genesis block. Thread-safe. h256 genesisHash() const { return m_genesisHash; } - /// Get all blocks not allowed as uncles given a parent (i.e. featured as uncles/main in parent, parent + 1, ... parent + 5). - /// @returns set including the header-hash of every parent (including @a _parent) up to and including generation +5 + /// Get all blocks not allowed as uncles given a parent (i.e. featured as uncles/main in parent, parent + 1, ... parent + @a _generations). + /// @returns set including the header-hash of every parent (including @a _parent) up to and including generation + @a _generations /// togther with all their quoted uncles. - h256Hash allUnclesFrom(h256 const& _parent) const; + h256Hash allKinFrom(h256 const& _parent, unsigned _generations) const; /// Run through database and verify all blocks by reevaluating. /// Will call _progress with the progress in this operation first param done, second total. diff --git a/libethereum/State.cpp b/libethereum/State.cpp index f5739aadb..67fa5395b 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -652,7 +652,7 @@ u256 State::enact(bytesConstRef _block, BlockChain const& _bc, ImportRequirement BOOST_THROW_EXCEPTION(TooManyUncles()); vector rewarded; - h256Hash excluded = _bc.allUnclesFrom(m_currentBlock.parentHash); + h256Hash excluded = _bc.allKinFrom(m_currentBlock.parentHash, 6); excluded.insert(m_currentBlock.hash()); for (auto const& i: rlp[2]) @@ -816,7 +816,7 @@ void State::commitToMine(BlockChain const& _bc) { // Find great-uncles (or second-cousins or whatever they are) - children of great-grandparents, great-great-grandparents... that were not already uncles in previous generations. // cout << "Checking " << m_previousBlock.hash << ", parent=" << m_previousBlock.parentHash << endl; - h256Hash knownUncles = _bc.allUnclesFrom(m_currentBlock.parentHash); + h256Hash knownUncles = _bc.allKinFrom(m_currentBlock.parentHash); auto p = m_previousBlock.parentHash; for (unsigned gen = 0; gen < 6 && p != _bc.genesisHash() && unclesCount < 2; ++gen, p = _bc.details(p).parent) {