Skip to content

Commit

Permalink
Hold cs_wallet for whole block [dis]connection processing
Browse files Browse the repository at this point in the history
This simplifies fixing the wallet-returns-stale-info issue as we
now hold cs_wallet across an entire block instead of only per-tx.
  • Loading branch information
TheBlueMatt authored and furszy committed Jan 28, 2021
1 parent 1a45036 commit 10ccbbf
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,7 @@ void CWallet::TransactionAddedToMempool(const CTransactionRef& ptx)

void CWallet::BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex *pindex, const std::vector<CTransactionRef>& vtxConflicted)
{
LOCK2(cs_main, cs_wallet);
// TODO: Tempoarily ensure that mempool removals are notified before
// connected transactions. This shouldn't matter, but the abandoned
// state of transactions in our wallet is currently cleared when we
Expand All @@ -1270,19 +1271,17 @@ void CWallet::BlockConnected(const std::shared_ptr<const CBlock>& pblock, const
// the notification that the conflicted transaction was evicted.

for (const CTransactionRef& ptx : vtxConflicted) {
LOCK2(cs_main, cs_wallet);
SyncTransaction(ptx, NULL, -1);
}
for (size_t i = 0; i < pblock->vtx.size(); i++) {
LOCK2(cs_main, cs_wallet);
SyncTransaction(pblock->vtx[i], pindex, i);
}
}

void CWallet::BlockDisconnected(const std::shared_ptr<const CBlock>& pblock)
{
LOCK2(cs_main, cs_wallet);
for (const CTransactionRef& ptx : pblock->vtx) {
LOCK2(cs_main, cs_wallet);
SyncTransaction(ptx, NULL, -1);
}
}
Expand Down

0 comments on commit 10ccbbf

Please sign in to comment.