Skip to content

Commit 5dd7da4

Browse files
committed
Reuse trustedParents in looped calls to IsTrusted
1 parent 595f09d commit 5dd7da4

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/wallet/wallet.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2420,10 +2420,11 @@ CWallet::Balance CWallet::GetBalance(const int min_depth, bool avoid_reuse) cons
24202420
{
24212421
auto locked_chain = chain().lock();
24222422
LOCK(cs_wallet);
2423+
std::set<uint256> trustedParents;
24232424
for (const auto& entry : mapWallet)
24242425
{
24252426
const CWalletTx& wtx = entry.second;
2426-
const bool is_trusted{wtx.IsTrusted(*locked_chain)};
2427+
const bool is_trusted{wtx.IsTrusted(*locked_chain, trustedParents)};
24272428
const int tx_depth{wtx.GetDepthInMainChain(*locked_chain)};
24282429
const CAmount tx_credit_mine{wtx.GetAvailableCredit(*locked_chain, /* fUseCache */ true, ISMINE_SPENDABLE | reuse_filter)};
24292430
const CAmount tx_credit_watchonly{wtx.GetAvailableCredit(*locked_chain, /* fUseCache */ true, ISMINE_WATCH_ONLY | reuse_filter)};
@@ -2470,6 +2471,7 @@ void CWallet::AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector<
24702471
const int min_depth = {coinControl ? coinControl->m_min_depth : DEFAULT_MIN_DEPTH};
24712472
const int max_depth = {coinControl ? coinControl->m_max_depth : DEFAULT_MAX_DEPTH};
24722473

2474+
std::set<uint256> trustedParents;
24732475
for (const auto& entry : mapWallet)
24742476
{
24752477
const uint256& wtxid = entry.first;
@@ -2491,7 +2493,7 @@ void CWallet::AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector<
24912493
if (nDepth == 0 && !wtx.InMempool())
24922494
continue;
24932495

2494-
bool safeTx = wtx.IsTrusted(locked_chain);
2496+
bool safeTx = wtx.IsTrusted(locked_chain, trustedParents);
24952497

24962498
// We should not consider coins from transactions that are replacing
24972499
// other transactions.
@@ -3776,11 +3778,12 @@ std::map<CTxDestination, CAmount> CWallet::GetAddressBalances(interfaces::Chain:
37763778

37773779
{
37783780
LOCK(cs_wallet);
3781+
std::set<uint256> trustedParents;
37793782
for (const auto& walletEntry : mapWallet)
37803783
{
37813784
const CWalletTx& wtx = walletEntry.second;
37823785

3783-
if (!wtx.IsTrusted(locked_chain))
3786+
if (!wtx.IsTrusted(locked_chain, trustedParents))
37843787
continue;
37853788

37863789
if (wtx.IsImmatureCoinBase(locked_chain))

0 commit comments

Comments
 (0)