aboutsummaryrefslogtreecommitdiff
path: root/src/net_processing.cpp
diff options
context:
space:
mode:
authorglozow <gloriajzhao@gmail.com>2024-05-10 09:23:18 +0100
committerglozow <gloriajzhao@gmail.com>2024-05-14 10:31:56 +0100
commit7e475b9648bbee04f5825b922ba0399373eaa5a9 (patch)
tree9a90818933c279bc00843cd5c9ba80889cfa94b3 /src/net_processing.cpp
parent842f7fdf786fcbbdf3df40522945813404f8a397 (diff)
downloadbitcoin-7e475b9648bbee04f5825b922ba0399373eaa5a9.tar.xz
[p2p] don't query orphanage by txid
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r--src/net_processing.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index bdbf077ab5..985b41b160 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -2295,7 +2295,20 @@ bool PeerManagerImpl::AlreadyHaveTx(const GenTxid& gtxid, bool include_reconside
const uint256& hash = gtxid.GetHash();
- if (m_orphanage.HaveTx(gtxid)) return true;
+ if (gtxid.IsWtxid()) {
+ // Normal query by wtxid.
+ if (m_orphanage.HaveTx(gtxid)) return true;
+ } else {
+ // Never query by txid: it is possible that the transaction in the orphanage has the same
+ // txid but a different witness, which would give us a false positive result. If we decided
+ // not to request the transaction based on this result, an attacker could prevent us from
+ // downloading a transaction by intentionally creating a malleated version of it.
+ //
+ // While we won't query by txid, we can try to "guess" what the wtxid is based on the txid.
+ // A non-segwit transaction's txid == wtxid. Query this txid "casted" to a wtxid. This will
+ // help us find non-segwit transactions, saving bandwidth, and should have no false positives.
+ if (m_orphanage.HaveTx(GenTxid::Wtxid(hash))) return true;
+ }
if (include_reconsiderable && m_recent_rejects_reconsiderable.contains(hash)) return true;