wallet: Add m_cached_from_me to cache "from me" status

m_cached_from_me is used to track whether a transaction is "from me", i.e. has
any inputs which belong to the wallet. This is held in memory only in
the same way that a transaction's balances are.

Github-Pull: #33268
Rebased-From: 113a422822
This commit is contained in:
Ava Chow 2024-02-20 11:54:35 -05:00 committed by fanquake
parent bbb4e118f3
commit 75026cddea
No known key found for this signature in database
GPG Key ID: 2EEB9F5CC09526C1
2 changed files with 7 additions and 1 deletions

View File

@ -195,7 +195,10 @@ void CachedTxGetAmounts(const CWallet& wallet, const CWalletTx& wtx,
bool CachedTxIsFromMe(const CWallet& wallet, const CWalletTx& wtx)
{
return (CachedTxGetDebit(wallet, wtx, /*avoid_reuse=*/false) > 0);
if (!wtx.m_cached_from_me.has_value()) {
wtx.m_cached_from_me = wallet.IsFromMe(*wtx.tx);
}
return wtx.m_cached_from_me.value();
}
// NOLINTNEXTLINE(misc-no-recursion)

View File

@ -232,6 +232,8 @@ public:
* CWallet::ComputeTimeSmart().
*/
unsigned int nTimeSmart;
// Cached value for whether the transaction spends any inputs known to the wallet
mutable std::optional<bool> m_cached_from_me{std::nullopt};
int64_t nOrderPos; //!< position in ordered transaction list
std::multimap<int64_t, CWalletTx*>::const_iterator m_it_wtxOrdered;
@ -339,6 +341,7 @@ public:
m_amounts[CREDIT].Reset();
fChangeCached = false;
m_is_cache_empty = true;
m_cached_from_me = std::nullopt;
}
/** True if only scriptSigs are different */