From a586e2cafe30ca0cd8c1a88dabbe1d01cf5623ad Mon Sep 17 00:00:00 2001 From: arkpar Date: Tue, 30 Jun 2015 23:04:07 +0200 Subject: [PATCH 1/2] blocks no longer stuck in verifying state --- libethereum/BlockQueue.cpp | 41 ++++++++++++++++++++------------------ libethereum/BlockQueue.h | 1 + 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/libethereum/BlockQueue.cpp b/libethereum/BlockQueue.cpp index 074278d9a..30ae65ed2 100644 --- a/libethereum/BlockQueue.cpp +++ b/libethereum/BlockQueue.cpp @@ -114,15 +114,11 @@ void BlockQueue::verifierBody() catch (...) { // bad block. - { - // has to be this order as that's how invariants() assumes. - WriteGuard l2(m_lock); - unique_lock l(m_verification); - m_readySet.erase(work.hash); - m_knownBad.insert(work.hash); - } - + // has to be this order as that's how invariants() assumes. + WriteGuard l2(m_lock); unique_lock l(m_verification); + m_readySet.erase(work.hash); + m_knownBad.insert(work.hash); for (auto it = m_verifying.begin(); it != m_verifying.end(); ++it) if (it->verified.info.mixHash == work.hash) { @@ -131,6 +127,7 @@ void BlockQueue::verifierBody() } cwarn << "BlockQueue missing our job: was there a GM?"; OK1:; + drainVerified(); continue; } @@ -149,17 +146,8 @@ void BlockQueue::verifierBody() } else m_verified.emplace_back(move(res)); - while (m_verifying.size() && !m_verifying.front().blockData.empty()) - { - if (m_knownBad.count(m_verifying.front().verified.info.parentHash)) - { - m_readySet.erase(m_verifying.front().verified.info.hash()); - m_knownBad.insert(res.verified.info.hash()); - } - else - m_verified.emplace_back(move(m_verifying.front())); - m_verifying.pop_front(); - } + + drainVerified(); ready = true; } else @@ -179,6 +167,21 @@ void BlockQueue::verifierBody() } } +void BlockQueue::drainVerified() +{ + while (m_verifying.size() && !m_verifying.front().blockData.empty()) + { + if (m_knownBad.count(m_verifying.front().verified.info.parentHash)) + { + m_readySet.erase(m_verifying.front().verified.info.hash()); + m_knownBad.insert(m_verifying.front().verified.info.hash()); + } + else + m_verified.emplace_back(move(m_verifying.front())); + m_verifying.pop_front(); + } +} + ImportResult BlockQueue::import(bytesConstRef _block, BlockChain const& _bc, bool _isOurs) { // Check if we already know this block. diff --git a/libethereum/BlockQueue.h b/libethereum/BlockQueue.h index 137048ec4..82547cd56 100644 --- a/libethereum/BlockQueue.h +++ b/libethereum/BlockQueue.h @@ -134,6 +134,7 @@ private: bool invariants() const override; void verifierBody(); + void drainVerified(); void collectUnknownBad(h256 const& _bad); void updateBad(h256 const& _bad); From 7ba71da2806ac8e9fbf58b65bc6435660a3c4b0b Mon Sep 17 00:00:00 2001 From: arkpar Date: Wed, 1 Jul 2015 11:47:34 +0200 Subject: [PATCH 2/2] style --- libethereum/BlockQueue.cpp | 8 ++++---- libethereum/BlockQueue.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/libethereum/BlockQueue.cpp b/libethereum/BlockQueue.cpp index 30ae65ed2..344ee0609 100644 --- a/libethereum/BlockQueue.cpp +++ b/libethereum/BlockQueue.cpp @@ -127,7 +127,7 @@ void BlockQueue::verifierBody() } cwarn << "BlockQueue missing our job: was there a GM?"; OK1:; - drainVerified(); + drainVerified_WITH_BOTH_LOCKS(); continue; } @@ -147,7 +147,7 @@ void BlockQueue::verifierBody() else m_verified.emplace_back(move(res)); - drainVerified(); + drainVerified_WITH_BOTH_LOCKS(); ready = true; } else @@ -167,9 +167,9 @@ void BlockQueue::verifierBody() } } -void BlockQueue::drainVerified() +void BlockQueue::drainVerified_WITH_BOTH_LOCKS() { - while (m_verifying.size() && !m_verifying.front().blockData.empty()) + while (!m_verifying.empty() && !m_verifying.front().blockData.empty()) { if (m_knownBad.count(m_verifying.front().verified.info.parentHash)) { diff --git a/libethereum/BlockQueue.h b/libethereum/BlockQueue.h index 82547cd56..18446c613 100644 --- a/libethereum/BlockQueue.h +++ b/libethereum/BlockQueue.h @@ -134,7 +134,7 @@ private: bool invariants() const override; void verifierBody(); - void drainVerified(); + void drainVerified_WITH_BOTH_LOCKS(); void collectUnknownBad(h256 const& _bad); void updateBad(h256 const& _bad);