From 1e8c241f2b33813e8ad68f1239608b320977d4a4 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Sat, 4 Apr 2015 14:44:44 +0200 Subject: [PATCH] Lock bug fix. --- libethereum/BlockChain.cpp | 11 +++++++---- libethereum/Client.cpp | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index 03c5c6525..832d9465f 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -522,16 +522,19 @@ h256s BlockChain::import(bytes const& _block, OverlayDB const& _db, bool _force) // Collate logs into blooms. h256s alteredBlooms; { - WriteGuard l(x_blocksBlooms); LogBloom blockBloom = bi.logBloom; blockBloom.shiftBloom<3>(sha3(bi.coinbaseAddress.ref())); - unsigned index = (unsigned)bi.number; - for (unsigned level = 0; level < c_bloomIndexLevels; level++, index /= c_bloomIndexSize) + + // Pre-memoize everything we need before locking x_blocksBlooms + for (unsigned level = 0, index = (unsigned)bi.number; level < c_bloomIndexLevels; level++, index /= c_bloomIndexSize) + blocksBlooms(chunkId(level, index / c_bloomIndexSize)); + + WriteGuard l(x_blocksBlooms); + for (unsigned level = 0, index = (unsigned)bi.number; level < c_bloomIndexLevels; level++, index /= c_bloomIndexSize) { unsigned i = index / c_bloomIndexSize; unsigned o = index % c_bloomIndexSize; alteredBlooms.push_back(chunkId(level, i)); - blocksBlooms(alteredBlooms.back()); m_blocksBlooms[alteredBlooms.back()].blooms[o] |= blockBloom; } } diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index d73299877..3d9f17335 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -145,7 +145,7 @@ Client::Client(p2p::Host* _extNet, std::string const& _dbPath, WithExisting _for Client::Client(p2p::Host* _extNet, std::shared_ptr _gp, std::string const& _dbPath, WithExisting _forceAction, u256 _networkId, int _miners): Worker("eth"), m_vc(_dbPath), - m_bc(_dbPath, max(m_vc.action(), _forceAction), [](unsigned d, unsigned t){ cerr << "REVISING BLOCKCHAIN: Processed " << d << " of " << t << "..." << endl; }), + m_bc(_dbPath, max(m_vc.action(), _forceAction), [](unsigned d, unsigned t){ cerr << "REVISING BLOCKCHAIN: Processed " << d << " of " << t << "...\r"; }), m_gp(_gp), m_stateDB(State::openDB(_dbPath, max(m_vc.action(), _forceAction))), m_preMine(Address(), m_stateDB),