diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index 195f65f1d..10256900d 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -305,7 +305,7 @@ LastHashes BlockChain::lastHashes(unsigned _n) const return m_lastLastHashes; } -tuple BlockChain::sync(BlockQueue& _bq, OverlayDB const& _stateDB, unsigned _max) +tuple BlockChain::sync(BlockQueue& _bq, OverlayDB const& _stateDB, unsigned _max) { // _bq.tick(*this); @@ -326,8 +326,8 @@ tuple BlockChain::sync(BlockQueue& _bq, OverlayDB const& _st ImportRoute r; DEV_TIMED_ABOVE(Block import, 500) r = import(block.verified, _stateDB, ImportRequirements::Default & ~ImportRequirements::ValidNonce & ~ImportRequirements::CheckUncles); - fresh += r.first; - dead += r.second; + fresh += r.liveBlocks; + dead += r.deadBlocks; } catch (dev::eth::UnknownParent) { @@ -353,7 +353,7 @@ tuple BlockChain::sync(BlockQueue& _bq, OverlayDB const& _st badBlocks.push_back(block.verified.info.hash()); } } - return make_tuple(fresh, dead, _bq.doneDrain(badBlocks)); + return make_tuple(ImportRoute{dead, fresh}, _bq.doneDrain(badBlocks)); } pair BlockChain::attemptImport(bytes const& _block, OverlayDB const& _stateDB, ImportRequirements::value _ir) noexcept @@ -364,21 +364,21 @@ pair BlockChain::attemptImport(bytes const& _block, O } catch (UnknownParent&) { - return make_pair(ImportResult::UnknownParent, make_pair(h256s(), h256s())); + return make_pair(ImportResult::UnknownParent, ImportRoute()); } catch (AlreadyHaveBlock&) { - return make_pair(ImportResult::AlreadyKnown, make_pair(h256s(), h256s())); + return make_pair(ImportResult::AlreadyKnown, ImportRoute()); } catch (FutureTime&) { - return make_pair(ImportResult::FutureTime, make_pair(h256s(), h256s())); + return make_pair(ImportResult::FutureTime, ImportRoute()); } catch (Exception& ex) { if (m_onBad) m_onBad(ex); - return make_pair(ImportResult::Malformed, make_pair(h256s(), h256s())); + return make_pair(ImportResult::Malformed, ImportRoute()); } } @@ -699,7 +699,7 @@ ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const& dead.push_back(h); else fresh.push_back(h); - return make_pair(fresh, dead); + return ImportRoute{dead, fresh}; } void BlockChain::clearBlockBlooms(unsigned _begin, unsigned _end) diff --git a/libethereum/BlockChain.h b/libethereum/BlockChain.h index 534173a9a..2d3abd922 100644 --- a/libethereum/BlockChain.h +++ b/libethereum/BlockChain.h @@ -80,7 +80,12 @@ ldb::Slice toSlice(h256 const& _h, unsigned _sub = 0); using BlocksHash = std::unordered_map; using TransactionHashes = h256s; using UncleHashes = h256s; -using ImportRoute = std::pair; + +struct ImportRoute +{ + h256s deadBlocks; + h256s liveBlocks; +}; enum { ExtraDetails = 0, @@ -112,7 +117,7 @@ public: /// Sync the chain with any incoming blocks. All blocks should, if processed in order. /// @returns fresh blocks, dead blocks and true iff there are additional blocks to be processed waiting. - std::tuple sync(BlockQueue& _bq, OverlayDB const& _stateDB, unsigned _max); + std::tuple sync(BlockQueue& _bq, OverlayDB const& _stateDB, unsigned _max); /// Attempt to import the given block directly into the CanonBlockChain and sync with the state DB. /// @returns the block hashes of any blocks that came into/went out of the canonical block chain. diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index 2f742f658..8064e7e9f 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -620,7 +620,7 @@ void Client::syncBlockQueue() ImportRoute ir; cwork << "BQ ==> CHAIN ==> STATE"; boost::timer t; - tie(ir.first, ir.second, m_syncBlockQueue) = m_bc.sync(m_bq, m_stateDB, m_syncAmount); + tie(ir, m_syncBlockQueue) = m_bc.sync(m_bq, m_stateDB, m_syncAmount); double elapsed = t.elapsed(); cnote << m_syncAmount << "blocks imported in" << unsigned(elapsed * 1000) << "ms (" << (m_syncAmount / elapsed) << "blocks/s)"; @@ -629,7 +629,7 @@ void Client::syncBlockQueue() m_syncAmount = max(c_syncMin, m_syncAmount * 9 / 10); else if (elapsed < c_targetDuration * 0.9 && m_syncAmount < c_syncMax) m_syncAmount = min(c_syncMax, m_syncAmount * 11 / 10 + 1); - if (ir.first.empty()) + if (ir.liveBlocks.empty()) return; onChainChanged(ir); } @@ -671,7 +671,7 @@ void Client::syncTransactionQueue() void Client::onChainChanged(ImportRoute const& _ir) { // insert transactions that we are declaring the dead part of the chain - for (auto const& h: _ir.second) + for (auto const& h: _ir.deadBlocks) { clog(ClientNote) << "Dead block:" << h; for (auto const& t: m_bc.transactions(h)) @@ -682,7 +682,7 @@ void Client::onChainChanged(ImportRoute const& _ir) } // remove transactions from m_tq nicely rather than relying on out of date nonce later on. - for (auto const& h: _ir.first) + for (auto const& h: _ir.liveBlocks) { clog(ClientChat) << "Live block:" << h; for (auto const& th: m_bc.transactionHashes(h)) @@ -696,7 +696,7 @@ void Client::onChainChanged(ImportRoute const& _ir) h->noteNewBlocks(); h256Hash changeds; - for (auto const& h: _ir.first) + for (auto const& h: _ir.liveBlocks) appendFromNewBlock(h, changeds); // RESTART MINING