Browse Source

Reduce cs_main lock in ReadBlockFromDisk, only read GetBlockPos under the lock

0.16
Jonas Schnelli 7 years ago
parent
commit
ccd8ef65f9
No known key found for this signature in database
GPG Key ID: 1EB776BB03C7922D
  1. 8
      src/validation.cpp
  2. 7
      src/wallet/wallet.cpp

8
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) 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; return false;
if (block.GetHash() != pindex->GetBlockHash()) if (block.GetHash() != pindex->GetBlockHash())
return error("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s", return error("ReadBlockFromDisk(CBlock&, CBlockIndex*): GetHash() doesn't match index for %s at %s",

7
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)); LogPrintf("Still rescanning. At block %d. Progress=%f\n", pindex->nHeight, GuessVerificationProgress(chainParams.TxData(), pindex));
} }
bool readRet = false;
CBlock block; CBlock block;
{ if (ReadBlockFromDisk(block, pindex, Params().GetConsensus())) {
LOCK(cs_main);
readRet = ReadBlockFromDisk(block, pindex, Params().GetConsensus());
}
if (readRet) {
LOCK2(cs_main, cs_wallet); LOCK2(cs_main, cs_wallet);
if (pindex && !chainActive.Contains(pindex)) { if (pindex && !chainActive.Contains(pindex)) {
// Abort scan if current block is no longer active, to prevent // Abort scan if current block is no longer active, to prevent

Loading…
Cancel
Save