Browse Source

Make terms more clear for uncle exclusion API.

cl-refactor
Gav Wood 10 years ago
parent
commit
eb8dc43e8a
  1. 4
      libethereum/BlockChain.cpp
  2. 6
      libethereum/BlockChain.h
  3. 4
      libethereum/State.cpp

4
libethereum/BlockChain.cpp

@ -981,13 +981,13 @@ vector<unsigned> 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);

6
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.

4
libethereum/State.cpp

@ -652,7 +652,7 @@ u256 State::enact(bytesConstRef _block, BlockChain const& _bc, ImportRequirement
BOOST_THROW_EXCEPTION(TooManyUncles());
vector<BlockInfo> 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)
{

Loading…
Cancel
Save