[31.x] Backport #35878 and prep for v31.3

bitcoin/bitcoin: PR #36892

Backport verdict: Needs clarification

Fidelity could not be established from the available evidence.

Evidence:

Limitations:

Coverage details

Background

Ralph's summary of historical context for the behaviour affected by this change. The historical record reviewed here is incomplete.

Documented decisions

The historical record distinguishes accidental acceptance from a later compatibility reason for preserving it. The #35920 proposal describes MSG_WITNESS_TX announcements as never protocol-valid and their acceptance alongside wtxidrelay filtering as an oversight—not as an originally designed extension to INV.

At the pinned base, IsGenTxMsg handling accepts this announcement form. At the head, the change explicitly retains it and deduplicates it as a txid. That should be understood as preserving existing permissive behavior, not implementing a protocol requirement to accept witness-flagged INV entries.

Source 1

A concrete interoperability concern subsequently justified retaining permissive handling: the #35920 discussion reports that /btcwire:0.5.0/neutrino:0.12.0-beta/ announced transactions using InvTypeWitnessTx. The discussion then records changing that proposal to continue allowing witness-tx INV entries for non-wtxidrelay peers.

This supplies a compatibility reason beyond general tolerance of malformed messages: rejecting this announcement form could interrupt transaction announcements from deployed software. The backport continues to process its first occurrence rather than discarding every MSG_WITNESS_TX entry.

Source 1

Ralph's inferences

Processing only the first eligible MSG_TX or MSG_WITNESS_TX occurrence for a hash preserves the identified compatibility behavior: the nonstandard announcement can still introduce that txid into transaction-download processing. Repeated processing of the two encodings is not necessary for that interoperability.

In the inspected head, both encodings select seen_txids and ToGenTxid maps both to Txid; neither the retained inventory type nor its witness flag is passed to AddTxAnnouncement. Thus either ordering retains one announcement of the same identifier. Filtering precedes deduplication, so an ignored MSG_TX entry on a wtxidrelay connection does not suppress a later MSG_WITNESS_TX entry. MSG_WTX remains in a separate identifier namespace, and the sets reset for each INV message. The added tests encode both MSG_TX/MSG_WITNESS_TX orderings and separate txid/wtxid handling, although they were not executed. This conclusion concerns announcement compatibility, not identical diagnostic output: duplicate log entries are intentionally removed.

Source 1 · Source 2