Skip to content

Commit 80f52a2

Browse files
committed
Remove uses of CheckFinalTx in wallet code
This commit does not change behavior.
1 parent f3f9c1d commit 80f52a2

File tree

5 files changed

+18
-15
lines changed

5 files changed

+18
-15
lines changed

src/interfaces/chain.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <chainparams.h>
99
#include <primitives/block.h>
1010
#include <sync.h>
11+
#include <threadsafety.h>
1112
#include <uint256.h>
1213
#include <util/system.h>
1314
#include <validation.h>
@@ -132,6 +133,11 @@ class LockImpl : public Chain::Lock
132133
}
133134
return nullopt;
134135
}
136+
bool checkFinalTx(const CTransaction& tx) override
137+
{
138+
LockAnnotation lock(::cs_main);
139+
return CheckFinalTx(tx);
140+
}
135141
};
136142

137143
class LockingStateImpl : public LockImpl, public UniqueLock<CCriticalSection>

src/interfaces/chain.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
class CBlock;
1616
class CScheduler;
17+
class CTransaction;
1718
class uint256;
1819
struct CBlockLocator;
1920

@@ -102,6 +103,9 @@ class Chain
102103
//! is guaranteed to be an ancestor of the block used to create the
103104
//! locator.
104105
virtual Optional<int> findLocatorFork(const CBlockLocator& locator) = 0;
106+
107+
//! Check if transaction will be final given chain height current time.
108+
virtual bool checkFinalTx(const CTransaction& tx) = 0;
105109
};
106110

107111
//! Return Lock interface. Chain is locked when this is called, and

src/interfaces/wallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ WalletTx MakeWalletTx(interfaces::Chain::Lock& locked_chain, CWallet& wallet, co
9999
//! Construct wallet tx status struct.
100100
WalletTxStatus MakeWalletTxStatus(interfaces::Chain::Lock& locked_chain, const CWalletTx& wtx)
101101
{
102-
LockAnnotation lock(::cs_main); // Temporary, for CheckFinalTx below. Removed in upcoming commit.
102+
LockAnnotation lock(::cs_main); // Temporary, for mapBlockIndex below. Removed in upcoming commit.
103103

104104
WalletTxStatus result;
105105
auto mi = ::mapBlockIndex.find(wtx.hashBlock);
@@ -109,7 +109,7 @@ WalletTxStatus MakeWalletTxStatus(interfaces::Chain::Lock& locked_chain, const C
109109
result.depth_in_main_chain = wtx.GetDepthInMainChain(locked_chain);
110110
result.time_received = wtx.nTimeReceived;
111111
result.lock_time = wtx.tx->nLockTime;
112-
result.is_final = CheckFinalTx(*wtx.tx);
112+
result.is_final = locked_chain.checkFinalTx(*wtx.tx);
113113
result.is_trusted = wtx.IsTrusted(locked_chain);
114114
result.is_abandoned = wtx.isAbandoned();
115115
result.is_coinbase = wtx.IsCoinBase();

src/wallet/rpcwallet.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,6 @@ static UniValue getreceivedbyaddress(const JSONRPCRequest& request)
607607
// the user could have gotten from another RPC command prior to now
608608
pwallet->BlockUntilSyncedToCurrentChain();
609609

610-
LockAnnotation lock(::cs_main); // Temporary, for CheckFinalTx below. Removed in upcoming commit.
611610
auto locked_chain = pwallet->chain().lock();
612611
LOCK(pwallet->cs_wallet);
613612

@@ -630,7 +629,7 @@ static UniValue getreceivedbyaddress(const JSONRPCRequest& request)
630629
CAmount nAmount = 0;
631630
for (const std::pair<const uint256, CWalletTx>& pairWtx : pwallet->mapWallet) {
632631
const CWalletTx& wtx = pairWtx.second;
633-
if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx))
632+
if (wtx.IsCoinBase() || !locked_chain->checkFinalTx(*wtx.tx))
634633
continue;
635634

636635
for (const CTxOut& txout : wtx.tx->vout)
@@ -679,7 +678,6 @@ static UniValue getreceivedbylabel(const JSONRPCRequest& request)
679678
// the user could have gotten from another RPC command prior to now
680679
pwallet->BlockUntilSyncedToCurrentChain();
681680

682-
LockAnnotation lock(::cs_main); // Temporary, for CheckFinalTx below. Removed in upcoming commit.
683681
auto locked_chain = pwallet->chain().lock();
684682
LOCK(pwallet->cs_wallet);
685683

@@ -696,7 +694,7 @@ static UniValue getreceivedbylabel(const JSONRPCRequest& request)
696694
CAmount nAmount = 0;
697695
for (const std::pair<const uint256, CWalletTx>& pairWtx : pwallet->mapWallet) {
698696
const CWalletTx& wtx = pairWtx.second;
699-
if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx))
697+
if (wtx.IsCoinBase() || !locked_chain->checkFinalTx(*wtx.tx))
700698
continue;
701699

702700
for (const CTxOut& txout : wtx.tx->vout)
@@ -1051,8 +1049,6 @@ struct tallyitem
10511049

10521050
static UniValue ListReceived(interfaces::Chain::Lock& locked_chain, CWallet * const pwallet, const UniValue& params, bool by_label) EXCLUSIVE_LOCKS_REQUIRED(pwallet->cs_wallet)
10531051
{
1054-
LockAnnotation lock(::cs_main); // Temporary, for CheckFinalTx below. Removed in upcoming commit.
1055-
10561052
// Minimum confirmations
10571053
int nMinDepth = 1;
10581054
if (!params[0].isNull())
@@ -1083,7 +1079,7 @@ static UniValue ListReceived(interfaces::Chain::Lock& locked_chain, CWallet * co
10831079
for (const std::pair<const uint256, CWalletTx>& pairWtx : pwallet->mapWallet) {
10841080
const CWalletTx& wtx = pairWtx.second;
10851081

1086-
if (wtx.IsCoinBase() || !CheckFinalTx(*wtx.tx))
1082+
if (wtx.IsCoinBase() || !locked_chain.checkFinalTx(*wtx.tx))
10871083
continue;
10881084

10891085
int nDepth = wtx.GetDepthInMainChain(locked_chain);

src/wallet/wallet.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2075,10 +2075,8 @@ bool CWalletTx::InMempool() const
20752075

20762076
bool CWalletTx::IsTrusted(interfaces::Chain::Lock& locked_chain) const
20772077
{
2078-
LockAnnotation lock(::cs_main); // Temporary, for CheckFinalTx below. Removed in upcoming commit.
2079-
20802078
// Quick answer in most cases
2081-
if (!CheckFinalTx(*tx))
2079+
if (!locked_chain.checkFinalTx(*tx))
20822080
return false;
20832081
int nDepth = GetDepthInMainChain(locked_chain);
20842082
if (nDepth >= 1)
@@ -2263,15 +2261,14 @@ CAmount CWallet::GetImmatureWatchOnlyBalance() const
22632261
// trusted.
22642262
CAmount CWallet::GetLegacyBalance(const isminefilter& filter, int minDepth) const
22652263
{
2266-
LockAnnotation lock(::cs_main); // Temporary, for CheckFinalTx below. Removed in upcoming commit.
22672264
auto locked_chain = chain().lock();
22682265
LOCK(cs_wallet);
22692266

22702267
CAmount balance = 0;
22712268
for (const auto& entry : mapWallet) {
22722269
const CWalletTx& wtx = entry.second;
22732270
const int depth = wtx.GetDepthInMainChain(*locked_chain);
2274-
if (depth < 0 || !CheckFinalTx(*wtx.tx) || wtx.IsImmatureCoinBase(*locked_chain)) {
2271+
if (depth < 0 || !locked_chain->checkFinalTx(*wtx.tx) || wtx.IsImmatureCoinBase(*locked_chain)) {
22752272
continue;
22762273
}
22772274

@@ -2325,7 +2322,7 @@ void CWallet::AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector<
23252322
const uint256& wtxid = entry.first;
23262323
const CWalletTx* pcoin = &entry.second;
23272324

2328-
if (!CheckFinalTx(*pcoin->tx))
2325+
if (!locked_chain.checkFinalTx(*pcoin->tx))
23292326
continue;
23302327

23312328
if (pcoin->IsImmatureCoinBase(locked_chain))

0 commit comments

Comments
 (0)