From 7a5b4db728135bc7ea8784617159a224a6c4ea3c Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Wed, 1 Jul 2015 09:13:55 +0200 Subject: [PATCH] Minor renaming in BlockQueue, remove unnecessary invariant check, add additional one. --- libethash-cl/ethash_cl_miner.cpp | 1 + libethereum/BlockQueue.cpp | 19 +++++++++---------- libethereum/BlockQueue.h | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/libethash-cl/ethash_cl_miner.cpp b/libethash-cl/ethash_cl_miner.cpp index ec400f7a7..b4ef12cb5 100644 --- a/libethash-cl/ethash_cl_miner.cpp +++ b/libethash-cl/ethash_cl_miner.cpp @@ -495,6 +495,7 @@ void ethash_cl_miner::search(uint8_t const* header, uint64_t target, search_hook pending.pop(); } + (void)_msPerBatch; /* chrono::high_resolution_clock::duration d = chrono::high_resolution_clock::now() - t; if (d > chrono::milliseconds(_msPerBatch * 10 / 9)) { diff --git a/libethereum/BlockQueue.cpp b/libethereum/BlockQueue.cpp index 9e647c9c1..4eeeac066 100644 --- a/libethereum/BlockQueue.cpp +++ b/libethereum/BlockQueue.cpp @@ -242,7 +242,7 @@ ImportResult BlockQueue::import(bytesConstRef _block, BlockChain const& _bc, boo if (m_knownBad.count(bi.parentHash)) { m_knownBad.insert(bi.hash()); - updateBad(bi.hash()); + updateBad_WITH_LOCK(bi.hash()); // bad parent; this is bad too, note it as such return ImportResult::BadChain; } @@ -277,12 +277,12 @@ ImportResult BlockQueue::import(bytesConstRef _block, BlockChain const& _bc, boo } } -void BlockQueue::updateBad(h256 const& _bad) +void BlockQueue::updateBad_WITH_LOCK(h256 const& _bad) { DEV_INVARIANT_CHECK; DEV_GUARDED(m_verification) { - collectUnknownBad(_bad); + collectUnknownBad_WITH_BOTH_LOCKS(_bad); bool moreBad = true; while (moreBad) { @@ -294,7 +294,7 @@ void BlockQueue::updateBad(h256 const& _bad) { m_knownBad.insert(b.verified.info.hash()); m_readySet.erase(b.verified.info.hash()); - collectUnknownBad(b.verified.info.hash()); + collectUnknownBad_WITH_BOTH_LOCKS(b.verified.info.hash()); moreBad = true; } else @@ -307,7 +307,7 @@ void BlockQueue::updateBad(h256 const& _bad) { m_knownBad.insert(b.hash); m_readySet.erase(b.hash); - collectUnknownBad(b.hash); + collectUnknownBad_WITH_BOTH_LOCKS(b.hash); moreBad = true; } else @@ -321,18 +321,18 @@ void BlockQueue::updateBad(h256 const& _bad) h256 const& h = b.blockData.size() != 0 ? b.verified.info.hash() : b.verified.info.mixHash; m_knownBad.insert(h); m_readySet.erase(h); - collectUnknownBad(h); + collectUnknownBad_WITH_BOTH_LOCKS(h); moreBad = true; } else m_verifying.push_back(std::move(b)); } } - DEV_INVARIANT_CHECK; } -void BlockQueue::collectUnknownBad(h256 const& _bad) +void BlockQueue::collectUnknownBad_WITH_BOTH_LOCKS(h256 const& _bad) { + DEV_INVARIANT_CHECK; list badQueue(1, _bad); while (!badQueue.empty()) { @@ -349,7 +349,6 @@ void BlockQueue::collectUnknownBad(h256 const& _bad) } m_unknown.erase(r.first, r.second); } - } bool BlockQueue::doneDrain(h256s const& _bad) @@ -364,7 +363,7 @@ bool BlockQueue::doneDrain(h256s const& _bad) // at least one of them was bad. m_knownBad += _bad; for (h256 const& b : _bad) - updateBad(b); + updateBad_WITH_LOCK(b); } return !m_readySet.empty(); } diff --git a/libethereum/BlockQueue.h b/libethereum/BlockQueue.h index 137048ec4..e42b6a3bd 100644 --- a/libethereum/BlockQueue.h +++ b/libethereum/BlockQueue.h @@ -134,8 +134,8 @@ private: bool invariants() const override; void verifierBody(); - void collectUnknownBad(h256 const& _bad); - void updateBad(h256 const& _bad); + void collectUnknownBad_WITH_BOTH_LOCKS(h256 const& _bad); + void updateBad_WITH_LOCK(h256 const& _bad); mutable boost::shared_mutex m_lock; ///< General lock for the sets, m_future and m_unknown. h256Hash m_drainingSet; ///< All blocks being imported.