Browse Source

Avoid throwing out potentially good blocks.

cl-refactor
Gav Wood 10 years ago
parent
commit
cc668312b7
  1. 36
      libethereum/BlockQueue.cpp
  2. 4
      libethereum/BlockQueue.h

36
libethereum/BlockQueue.cpp

@ -111,10 +111,22 @@ void BlockQueue::verifierBody()
{ {
// we're next! // we're next!
m_verifying.pop_front(); m_verifying.pop_front();
m_verified.push_back(move(res)); if (m_knownBad.count(res.verified.info.hash()))
{
m_readySet.erase(res.verified.info.hash());
m_knownBad.insert(res.verified.info.hash());
}
else
m_verified.push_back(move(res));
while (m_verifying.size() && !m_verifying.front().blockData.empty()) while (m_verifying.size() && !m_verifying.front().blockData.empty())
{ {
m_verified.push_back(move(m_verifying.front())); if (m_knownBad.count(m_verifying.front().verified.info.hash()))
{
m_readySet.erase(m_verifying.front().verified.info.hash());
m_knownBad.insert(res.verified.info.hash());
}
else
m_verified.push_back(move(m_verifying.front()));
m_verifying.pop_front(); m_verifying.pop_front();
} }
ready = true; ready = true;
@ -229,8 +241,24 @@ bool BlockQueue::doneDrain(h256s const& _bad)
DEV_INVARIANT_CHECK; DEV_INVARIANT_CHECK;
m_drainingSet.clear(); m_drainingSet.clear();
if (_bad.size()) if (_bad.size())
// one of them was bad. since they all rely on their parent, all following are bad. {
// at least one of them was bad.
m_knownBad += _bad;
DEV_GUARDED(m_verification) DEV_GUARDED(m_verification)
{
std::vector<VerifiedBlock> oldVerified;
swap(m_verified, oldVerified);
for (auto& b: oldVerified)
if (m_knownBad.count(b.verified.info.parentHash))
{
m_knownBad.insert(b.verified.info.hash());
m_readySet.erase(b.verified.info.hash());
}
else
m_verified.push_back(std::move(b));
}
}
/* DEV_GUARDED(m_verification)
{ {
m_knownBad += _bad; m_knownBad += _bad;
m_knownBad += m_readySet; m_knownBad += m_readySet;
@ -238,7 +266,7 @@ bool BlockQueue::doneDrain(h256s const& _bad)
m_verified.clear(); m_verified.clear();
m_verifying.clear(); m_verifying.clear();
m_unverified.clear(); m_unverified.clear();
} }*/
return !m_readySet.empty(); return !m_readySet.empty();
} }

4
libethereum/BlockQueue.h

@ -132,8 +132,8 @@ private:
mutable Mutex m_verification; ///< Mutex that allows writing to m_verified, m_verifying and m_unverified. mutable Mutex m_verification; ///< Mutex that allows writing to m_verified, m_verifying and m_unverified.
std::condition_variable m_moreToVerify; ///< Signaled when m_unverified has a new entry. std::condition_variable m_moreToVerify; ///< Signaled when m_unverified has a new entry.
std::vector<VerifiedBlock> m_verified; ///< List of blocks, in correct order, verified and ready for chain-import. std::vector<VerifiedBlock> m_verified; ///< List of blocks, in correct order, verified and ready for chain-import.
std::deque<VerifiedBlock> m_verifying; ///< List of blocks being verified; as long as the second component (bytes) is empty, it's not finished. std::deque<VerifiedBlock> m_verifying; ///< List of blocks being verified; as long as the second component (bytes) is empty, it's not finished.
std::deque<std::pair<h256, bytes>> m_unverified; ///< List of blocks, in correct order, ready for verification. std::deque<std::pair<h256, bytes>> m_unverified; ///< List of blocks, in correct order, ready for verification.
std::vector<std::thread> m_verifiers; ///< Threads who only verify. std::vector<std::thread> m_verifiers; ///< Threads who only verify.

Loading…
Cancel
Save