Skip to content

Commit e6d5e6c

Browse files
committed
Hold cs_wallet for whole block [dis]connection processing
This simplifies fixing the wallet-returns-stale-info issue as we now hold cs_wallet across an entire block instead of only per-tx.
1 parent 461e49f commit e6d5e6c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/wallet/wallet.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,7 @@ void CWallet::TransactionAddedToMempool(const CTransactionRef& ptx) {
11381138
}
11391139

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

11491150
for (const CTransactionRef& ptx : vtxConflicted) {
1150-
LOCK2(cs_main, cs_wallet);
11511151
SyncTransaction(ptx, NULL, -1);
11521152
}
11531153
for (size_t i = 0; i < pblock->vtx.size(); i++) {
1154-
LOCK2(cs_main, cs_wallet);
11551154
SyncTransaction(pblock->vtx[i], pindex, i);
11561155
}
11571156
}
11581157

11591158
void CWallet::BlockDisconnected(const std::shared_ptr<const CBlock>& pblock) {
1159+
LOCK2(cs_main, cs_wallet);
1160+
11601161
for (const CTransactionRef& ptx : pblock->vtx) {
1161-
LOCK2(cs_main, cs_wallet);
11621162
SyncTransaction(ptx, NULL, -1);
11631163
}
11641164
}

0 commit comments

Comments
 (0)