diff options
author | Jonas Schnelli <dev@jonasschnelli.ch> | 2017-12-13 11:06:51 -1000 |
---|---|---|
committer | Jonas Schnelli <dev@jonasschnelli.ch> | 2018-01-23 20:24:53 -1000 |
commit | ccd8ef65f93ed82a87cee634660bed3ac17d9eb5 (patch) | |
tree | 41ec340b182e8711b7b47a76e126f4a003396fc1 /src | |
parent | bc356b4268e222ac57d9e9297d2a986bb6e09de8 (diff) |
Reduce cs_main lock in ReadBlockFromDisk, only read GetBlockPos under the lock
Diffstat (limited to 'src')
-rw-r--r-- | src/validation.cpp | 8 | ||||
-rw-r--r-- | src/wallet/wallet.cpp | 7 |
2 files changed, 8 insertions, 7 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index 14d60bb269..8cee0dfac3 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -1121,7 +1121,13 @@ bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus: bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams) { - if (!ReadBlockFromDisk(block, pindex->GetBlockPos(), consensusParams)) + CDiskBlockPos blockPos; + { + LOCK(cs_main); + blockPos = pindex->GetBlockPos(); + } + + if (!ReadBlockFromDisk(block, blockPos, consensusParams)) return false; if (block.GetHash() != pindex->GetBlockHash()) return error("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s", diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 3bf649f266..dd9bc64728 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1689,13 +1689,8 @@ CBlockIndex* CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, CBlock LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, GuessVerificationProgress(chainParams.TxData(), pindex)); } - bool readRet = false; CBlock block; - { - LOCK(cs_main); - readRet = ReadBlockFromDisk(block, pindex, Params().GetConsensus()); - } - if (readRet) { + if (ReadBlockFromDisk(block, pindex, Params().GetConsensus())) { LOCK2(cs_main, cs_wallet); if (pindex && !chainActive.Contains(pindex)) { // Abort scan if current block is no longer active, to prevent |