From 49a861726163cd14837ecb0c44894c17265b6d27 Mon Sep 17 00:00:00 2001 From: arkpar Date: Tue, 30 Jun 2015 14:08:26 +0200 Subject: [PATCH] fixed block memory management --- libethereum/BlockChain.cpp | 2 +- libethereum/BlockQueue.cpp | 6 +++--- libethereum/State.cpp | 2 +- libethereum/VerifiedBlock.h | 24 ++++++++++++++++++++++++ 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index 55c213a64..d58a80ec2 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -541,7 +541,7 @@ ImportRoute BlockChain::import(VerifiedBlockRef const& _block, OverlayDB const& #endif } #if ETH_CATCH - catch (BadRoot& ex) + catch (BadRoot&) { cwarn << "BadRoot error. Retrying import later."; BOOST_THROW_EXCEPTION(FutureTime()); diff --git a/libethereum/BlockQueue.cpp b/libethereum/BlockQueue.cpp index 9e647c9c1..074278d9a 100644 --- a/libethereum/BlockQueue.cpp +++ b/libethereum/BlockQueue.cpp @@ -102,7 +102,7 @@ void BlockQueue::verifierBody() BlockInfo bi; bi.mixHash = work.hash; bi.parentHash = work.parentHash; - m_verifying.push_back(VerifiedBlock { VerifiedBlockRef { bytesConstRef(), move(bi), Transactions() }, bytes() }); + m_verifying.emplace_back(move(bi)); } VerifiedBlock res; @@ -148,7 +148,7 @@ void BlockQueue::verifierBody() m_knownBad.insert(res.verified.info.hash()); } else - m_verified.push_back(move(res)); + 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)) @@ -157,7 +157,7 @@ void BlockQueue::verifierBody() m_knownBad.insert(res.verified.info.hash()); } else - m_verified.push_back(move(m_verifying.front())); + m_verified.emplace_back(move(m_verifying.front())); m_verifying.pop_front(); } ready = true; diff --git a/libethereum/State.cpp b/libethereum/State.cpp index ead72f496..badc05887 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -117,7 +117,7 @@ State::State(OverlayDB const& _db, BaseState _bs, Address _coinbaseAddress): PopulationStatistics State::populateFromChain(BlockChain const& _bc, h256 const& _h, ImportRequirements::value _ir) { - PopulationStatistics ret; + PopulationStatistics ret { 0.0, 0.0 }; if (!_bc.isKnown(_h)) { diff --git a/libethereum/VerifiedBlock.h b/libethereum/VerifiedBlock.h index ddd808901..6cafe4b2f 100644 --- a/libethereum/VerifiedBlock.h +++ b/libethereum/VerifiedBlock.h @@ -43,8 +43,32 @@ struct VerifiedBlockRef /// @brief Verified block info, combines block data and verified info/transactions struct VerifiedBlock { + VerifiedBlock() {}; + + VerifiedBlock(BlockInfo&& _bi) + { + verified.info = _bi; + } + + VerifiedBlock(VerifiedBlock&& _other): + verified(std::move(_other.verified)), + blockData(std::move(_other.blockData)) + { + } + + VerifiedBlock& operator=(VerifiedBlock&& _other) + { + verified = (std::move(_other.verified)); + blockData = (std::move(_other.blockData)); + return *this; + } + VerifiedBlockRef verified; ///< Verified block structures bytes blockData; ///< Block data + +private: + VerifiedBlock(VerifiedBlock const&) = delete; + VerifiedBlock operator=(VerifiedBlock const&) = delete; }; using VerifiedBlocks = std::vector;