Skip to content

Commit 7e475b9

Browse files
committed
[p2p] don't query orphanage by txid
1 parent 842f7fd commit 7e475b9

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/net_processing.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2295,7 +2295,20 @@ bool PeerManagerImpl::AlreadyHaveTx(const GenTxid& gtxid, bool include_reconside
22952295

22962296
const uint256& hash = gtxid.GetHash();
22972297

2298-
if (m_orphanage.HaveTx(gtxid)) return true;
2298+
if (gtxid.IsWtxid()) {
2299+
// Normal query by wtxid.
2300+
if (m_orphanage.HaveTx(gtxid)) return true;
2301+
} else {
2302+
// Never query by txid: it is possible that the transaction in the orphanage has the same
2303+
// txid but a different witness, which would give us a false positive result. If we decided
2304+
// not to request the transaction based on this result, an attacker could prevent us from
2305+
// downloading a transaction by intentionally creating a malleated version of it.
2306+
//
2307+
// While we won't query by txid, we can try to "guess" what the wtxid is based on the txid.
2308+
// A non-segwit transaction's txid == wtxid. Query this txid "casted" to a wtxid. This will
2309+
// help us find non-segwit transactions, saving bandwidth, and should have no false positives.
2310+
if (m_orphanage.HaveTx(GenTxid::Wtxid(hash))) return true;
2311+
}
22992312

23002313
if (include_reconsiderable && m_recent_rejects_reconsiderable.contains(hash)) return true;
23012314

0 commit comments

Comments
 (0)