Skip to content

Commit 0440481

Browse files
committed
wallet: Move CWallet::ReacceptWalletTransactions locks to callers
1 parent 7b13c64 commit 0440481

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

src/wallet/rpcdump.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,11 @@ UniValue importaddress(const JSONRPCRequest& request)
348348
if (fRescan)
349349
{
350350
RescanWallet(*pwallet, reserver);
351-
pwallet->ReacceptWalletTransactions();
351+
{
352+
auto locked_chain = pwallet->chain().lock();
353+
LOCK(pwallet->cs_wallet);
354+
pwallet->ReacceptWalletTransactions(*locked_chain);
355+
}
352356
}
353357

354358
return NullUniValue;
@@ -532,7 +536,11 @@ UniValue importpubkey(const JSONRPCRequest& request)
532536
if (fRescan)
533537
{
534538
RescanWallet(*pwallet, reserver);
535-
pwallet->ReacceptWalletTransactions();
539+
{
540+
auto locked_chain = pwallet->chain().lock();
541+
LOCK(pwallet->cs_wallet);
542+
pwallet->ReacceptWalletTransactions(*locked_chain);
543+
}
536544
}
537545

538546
return NullUniValue;
@@ -1468,7 +1476,11 @@ UniValue importmulti(const JSONRPCRequest& mainRequest)
14681476
}
14691477
if (fRescan && fRunScan && requests.size()) {
14701478
int64_t scannedTime = pwallet->RescanFromTime(nLowestTimestamp, reserver, true /* update */);
1471-
pwallet->ReacceptWalletTransactions();
1479+
{
1480+
auto locked_chain = pwallet->chain().lock();
1481+
LOCK(pwallet->cs_wallet);
1482+
pwallet->ReacceptWalletTransactions(*locked_chain);
1483+
}
14721484

14731485
if (pwallet->IsAbortingRescan()) {
14741486
throw JSONRPCError(RPC_MISC_ERROR, "Rescan aborted by user.");

src/wallet/wallet.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,13 +1861,11 @@ CWallet::ScanResult CWallet::ScanForWalletTransactions(const uint256& start_bloc
18611861
return result;
18621862
}
18631863

1864-
void CWallet::ReacceptWalletTransactions()
1864+
void CWallet::ReacceptWalletTransactions(interfaces::Chain::Lock& locked_chain)
18651865
{
18661866
// If transactions aren't being broadcasted, don't let them into local mempool either
18671867
if (!fBroadcastTransactions)
18681868
return;
1869-
auto locked_chain = chain().lock();
1870-
LOCK(cs_wallet);
18711869
std::map<int64_t, CWalletTx*> mapSorted;
18721870

18731871
// Sort pending wallet transactions based on their initial wallet insertion order
@@ -1877,7 +1875,7 @@ void CWallet::ReacceptWalletTransactions()
18771875
CWalletTx& wtx = item.second;
18781876
assert(wtx.GetHash() == wtxid);
18791877

1880-
int nDepth = wtx.GetDepthInMainChain(*locked_chain);
1878+
int nDepth = wtx.GetDepthInMainChain(locked_chain);
18811879

18821880
if (!wtx.IsCoinBase() && (nDepth == 0 && !wtx.isAbandoned())) {
18831881
mapSorted.insert(std::make_pair(wtx.nOrderPos, &wtx));
@@ -1888,7 +1886,7 @@ void CWallet::ReacceptWalletTransactions()
18881886
for (const std::pair<const int64_t, CWalletTx*>& item : mapSorted) {
18891887
CWalletTx& wtx = *(item.second);
18901888
CValidationState state;
1891-
wtx.AcceptToMemoryPool(*locked_chain, state);
1889+
wtx.AcceptToMemoryPool(locked_chain, state);
18921890
}
18931891
}
18941892

@@ -4398,9 +4396,12 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
43984396

43994397
void CWallet::postInitProcess()
44004398
{
4399+
auto locked_chain = chain().lock();
4400+
LOCK(cs_wallet);
4401+
44014402
// Add wallet transactions that aren't already in a block to mempool
44024403
// Do this here as mempool requires genesis block to be loaded
4403-
ReacceptWalletTransactions();
4404+
ReacceptWalletTransactions(*locked_chain);
44044405
}
44054406

44064407
bool CWallet::BackupWallet(const std::string& strDest)

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,7 @@ class CWallet final : public CCryptoKeyStore, private interfaces::Chain::Notific
945945
};
946946
ScanResult ScanForWalletTransactions(const uint256& first_block, const uint256& last_block, const WalletRescanReserver& reserver, bool fUpdate);
947947
void TransactionRemovedFromMempool(const CTransactionRef &ptx) override;
948-
void ReacceptWalletTransactions();
948+
void ReacceptWalletTransactions(interfaces::Chain::Lock& locked_chain) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
949949
void ResendWalletTransactions(interfaces::Chain::Lock& locked_chain, int64_t nBestBlockTime) override;
950950
// ResendWalletTransactionsBefore may only be called if fBroadcastTransactions!
951951
std::vector<uint256> ResendWalletTransactionsBefore(interfaces::Chain::Lock& locked_chain, int64_t nTime);

0 commit comments

Comments
 (0)