Skip to content

Commit

Permalink
wallet: lock cs_main while accessing chainActive
Browse files Browse the repository at this point in the history
  • Loading branch information
LarryRuane committed Aug 25, 2020
1 parent 595b15f commit 3261ba4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ void CWallet::ChainTipAdded(const CBlockIndex *pindex,
}
if (nLastSetChain + (int64_t)DATABASE_WRITE_INTERVAL * 1000000 < nNow) {
nLastSetChain = nNow;
LOCK(cs_main);
SetBestChain(chainActive.GetLocator());
}
}
Expand Down Expand Up @@ -2663,8 +2664,9 @@ void CWallet::WitnessNoteCommitment(std::vector<uint256> commitments,
uint256 &final_anchor)
{
witnesses.resize(commitments.size());
CBlockIndex* pindex = chainActive.Genesis();
SproutMerkleTree tree;
AssertLockHeld(cs_main);
CBlockIndex* pindex = chainActive.Genesis();

while (pindex) {
CBlock block;
Expand Down Expand Up @@ -3535,6 +3537,7 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt

wtxNew.fTimeReceivedIsTxTime = true;
wtxNew.BindWallet(this);
LOCK(cs_main);
int nextBlockHeight = chainActive.Height() + 1;
CMutableTransaction txNew = CreateNewContextualCMutableTransaction(
Params().GetConsensus(), nextBlockHeight);
Expand Down Expand Up @@ -3575,7 +3578,8 @@ bool CWallet::CreateTransaction(const vector<CRecipient>& vecSend, CWalletTx& wt
assert(txNew.nLockTime < LOCKTIME_THRESHOLD);

{
LOCK2(cs_main, cs_wallet);
// cs_main already taken above
LOCK(cs_wallet);
{
nFeeRet = 0;
// Start with no fee and loop until there is enough fee
Expand Down Expand Up @@ -4515,6 +4519,7 @@ class CAffectedKeysVisitor : public boost::static_visitor<void> {
};

void CWallet::GetKeyBirthTimes(std::map<CKeyID, int64_t> &mapKeyBirth) const {
AssertLockHeld(cs_main); // chainActive
AssertLockHeld(cs_wallet); // mapKeyMetadata
mapKeyBirth.clear();

Expand Down

0 comments on commit 3261ba4

Please sign in to comment.