mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-23 15:22:46 +02:00
Cache tx Trust per-call to avoid DoS
This commit is contained in:
parent
dce032ce29
commit
595f09d6de
@ -2294,6 +2294,12 @@ bool CWalletTx::InMempool() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool CWalletTx::IsTrusted(interfaces::Chain::Lock& locked_chain) const
|
bool CWalletTx::IsTrusted(interfaces::Chain::Lock& locked_chain) const
|
||||||
|
{
|
||||||
|
std::set<uint256> s;
|
||||||
|
return IsTrusted(locked_chain, s);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CWalletTx::IsTrusted(interfaces::Chain::Lock& locked_chain, std::set<uint256>& trustedParents) const
|
||||||
{
|
{
|
||||||
// Quick answer in most cases
|
// Quick answer in most cases
|
||||||
if (!locked_chain.checkFinalTx(*tx)) {
|
if (!locked_chain.checkFinalTx(*tx)) {
|
||||||
@ -2322,9 +2328,13 @@ bool CWalletTx::IsTrusted(interfaces::Chain::Lock& locked_chain) const
|
|||||||
// Check that this specific input being spent is trusted
|
// Check that this specific input being spent is trusted
|
||||||
if (pwallet->IsMine(parentOut) != ISMINE_SPENDABLE)
|
if (pwallet->IsMine(parentOut) != ISMINE_SPENDABLE)
|
||||||
return false;
|
return false;
|
||||||
|
// If we've already trusted this parent, continue
|
||||||
|
if (trustedParents.count(parent->GetHash()))
|
||||||
|
continue;
|
||||||
// Recurse to check that the parent is also trusted
|
// Recurse to check that the parent is also trusted
|
||||||
if (!parent->IsTrusted(locked_chain))
|
if (!parent->IsTrusted(locked_chain, trustedParents))
|
||||||
return false;
|
return false;
|
||||||
|
trustedParents.insert(parent->GetHash());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -616,6 +616,7 @@ public:
|
|||||||
|
|
||||||
bool InMempool() const;
|
bool InMempool() const;
|
||||||
bool IsTrusted(interfaces::Chain::Lock& locked_chain) const;
|
bool IsTrusted(interfaces::Chain::Lock& locked_chain) const;
|
||||||
|
bool IsTrusted(interfaces::Chain::Lock& locked_chain, std::set<uint256>& trustedParents) const;
|
||||||
|
|
||||||
int64_t GetTxTime() const;
|
int64_t GetTxTime() const;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user