Skip to content

Commit 595f09d

Browse files
committed
Cache tx Trust per-call to avoid DoS
1 parent dce032c commit 595f09d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/wallet/wallet.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2294,6 +2294,12 @@ bool CWalletTx::InMempool() const
22942294
}
22952295

22962296
bool CWalletTx::IsTrusted(interfaces::Chain::Lock& locked_chain) const
2297+
{
2298+
std::set<uint256> s;
2299+
return IsTrusted(locked_chain, s);
2300+
}
2301+
2302+
bool CWalletTx::IsTrusted(interfaces::Chain::Lock& locked_chain, std::set<uint256>& trustedParents) const
22972303
{
22982304
// Quick answer in most cases
22992305
if (!locked_chain.checkFinalTx(*tx)) {
@@ -2322,9 +2328,13 @@ bool CWalletTx::IsTrusted(interfaces::Chain::Lock& locked_chain) const
23222328
// Check that this specific input being spent is trusted
23232329
if (pwallet->IsMine(parentOut) != ISMINE_SPENDABLE)
23242330
return false;
2331+
// If we've already trusted this parent, continue
2332+
if (trustedParents.count(parent->GetHash()))
2333+
continue;
23252334
// Recurse to check that the parent is also trusted
2326-
if (!parent->IsTrusted(locked_chain))
2335+
if (!parent->IsTrusted(locked_chain, trustedParents))
23272336
return false;
2337+
trustedParents.insert(parent->GetHash());
23282338
}
23292339
return true;
23302340
}

src/wallet/wallet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ class CWalletTx
616616

617617
bool InMempool() const;
618618
bool IsTrusted(interfaces::Chain::Lock& locked_chain) const;
619+
bool IsTrusted(interfaces::Chain::Lock& locked_chain, std::set<uint256>& trustedParents) const;
619620

620621
int64_t GetTxTime() const;
621622

0 commit comments

Comments
 (0)