{"number":339,"title":"WTXID-based transaction relay","authors":["Suhas Daftuar"],"status":"Deployed","type":"Specification","layer":"Peer Services","created":"2020-02-03","license":"BSD-2-Clause","requires":[],"replaces":[],"replacedBy":[],"discussion":[],"abstract":"This BIP describes two changes to the p2p protocol to support transaction relay based on the BIP 141 wtxid of a transaction, rather than its txid.","eli5":"Nodes share new transactions by announcing short identifiers, and this change lets them use the \"wtxid\", an identifier that also covers a transaction's SegWit signature data. The older identifier ignored that data, which could cause nodes to wrongly reject or repeatedly re-download valid transactions, so the switch makes relay more efficient and robust.","categories":["transactions"],"filename":"bip-0339.mediawiki","githubUrl":"https://github.com/bitcoin/bips/blob/master/bip-0339.mediawiki","format":"mediawiki","readingMinutes":2,"inbound":0,"revisions":10,"impact":17,"core":false,"references":[],"lastModified":"2025-10-08","html":"<h2 id=\"abstract\">Abstract</h2>\n<p>This BIP describes two changes to the p2p protocol to support transaction relay based on the BIP 141 wtxid of a transaction, rather than its txid.</p>\n<h2 id=\"motivation\">Motivation</h2>\n<p>Historically, the inv messages sent on the Bitcoin peer-to-peer network to announce transactions refer to transactions by their txid, which is a hash of the transaction that does not include the witness (see BIP 141). This has been the case even since Segregated Witness (BIP 141/143/144) has been adopted by the network.</p>\n<p>Not committing to the witness in transaction announcements creates inefficiencies: because a transaction's witness can be malleated without altering the txid, a node in receipt of a witness transaction that the node does not accept will generally still download that same transaction when announced by other peers. This is because the alternative -- of not downloading a given txid after rejecting a transaction with that txid -- would allow a third party to interfere with transaction relay by malleating a transaction's witness and announcing the resulting invalid transaction to nodes, preventing relay of the valid version of the transaction as well.</p>\n<p>We can eliminate this concern by using the wtxid in place of the txid when announcing and fetching transactions.</p>\n<h2 id=\"specification\">Specification</h2>\n<ol><li>\nA new wtxidrelay message is added, which is defined as an empty message where pchCommand == \"wtxidrelay\".\n</li></ol>\n<ol><li>\nThe protocol version of nodes implementing this BIP must be set to 70016 or higher.\n</li></ol>\n<ol><li>\nThe wtxidrelay message MUST be sent in response to a version message from a peer whose protocol version is >= 70016 and prior to sending a verack. A wtxidrelay message received after a verack message MUST be ignored or treated as invalid.\n</li></ol>\n<ol><li>\nA new inv type MSG_WTX (0x00000005) is added, for use in both inv messages and getdata requests, indicating that the hash being referenced is a transaction's wtxid. In the case of getdata requests, MSG_WTX implies that the transaction being requested should be serialized with witness as well, as described in BIP 144.\n</li></ol>\n<ol><li>\nAfter a node has received a wtxidrelay message from a peer, the node MUST use the MSG_WTX inv type when announcing transactions to that peer.\n</li></ol>\n<ol><li>\nAfter a node has received a wtxidrelay message from a peer, the node SHOULD use a MSG_WTX getdata message to request any announced transactions. A node MAY still request transactions from that peer using MSG_TX getdata messages, such as for transactions not recently announced by that peer (like the parents of recently announced transactions).\n</li></ol>\n<h2 id=\"backward-compatibility\">Backward compatibility</h2>\n<p>As wtxid-based transaction relay is only enabled between peers that both support it, older clients remain fully compatible and interoperable after this change.</p>\n<h2 id=\"implementation\">Implementation</h2>\n<p><a href=\"https://github.com/bitcoin/bitcoin/pull/18044\">https://github.com/bitcoin/bitcoin/pull/18044</a></p>\n<h2 id=\"copyright\">Copyright</h2>\n<p>This BIP is licensed under the 2-clause BSD license.</p>","toc":[{"id":"abstract","title":"Abstract","level":2},{"id":"motivation","title":"Motivation","level":2},{"id":"specification","title":"Specification","level":2},{"id":"backward-compatibility","title":"Backward compatibility","level":2},{"id":"implementation","title":"Implementation","level":2},{"id":"copyright","title":"Copyright","level":2}],"history":{"totalCommits":10,"firstCommit":"2020-06-25T05:19:50+00:00","lastUpdated":"2025-10-08T14:59:36-07:00","events":[{"sha":"24e96e870fffaa257b465ce1f0370c14aac588e8","date":"2025-10-08T14:59:36-07:00","author":"Murch","message":"process: Created ↦ Assigned","url":"https://github.com/bitcoin/bips/commit/24e96e870fffaa257b465ce1f0370c14aac588e8","kind":"edit"},{"sha":"5207ef92a52d0b8902895b0dbb40823a4d698ec9","date":"2025-04-11T20:08:17-07:00","author":"Murch","message":"process: Author ↦ Authors","url":"https://github.com/bitcoin/bips/commit/5207ef92a52d0b8902895b0dbb40823a4d698ec9","kind":"edit"},{"sha":"59730dec4fb641a41589aa1b91d3c452f13e0e36","date":"2025-04-11T20:05:13-07:00","author":"Murch","message":"process: Remove Comments-URI and -Summary","url":"https://github.com/bitcoin/bips/commit/59730dec4fb641a41589aa1b91d3c452f13e0e36","kind":"edit"},{"sha":"a233bde4af52c6a11269e2e6dd9707abce441ffe","date":"2025-04-11T18:19:21-07:00","author":"Murch","message":"process: Standards Track ↦ Specification","url":"https://github.com/bitcoin/bips/commit/a233bde4af52c6a11269e2e6dd9707abce441ffe","kind":"edit"},{"sha":"5d3ceb37734f80b2ec206fc94245e3bfd6d5b0f0","date":"2025-04-11T18:08:44-07:00","author":"Murch","message":"process: Final/Active ↦ Deployed","url":"https://github.com/bitcoin/bips/commit/5d3ceb37734f80b2ec206fc94245e3bfd6d5b0f0","kind":"status"},{"sha":"79e2d28efbc47212604cd41eb8b8466dc0e9a30e","date":"2024-07-10T14:54:52-04:00","author":"Suhas Daftuar","message":"Move BIP 339 to Final","url":"https://github.com/bitcoin/bips/commit/79e2d28efbc47212604cd41eb8b8466dc0e9a30e","kind":"status"},{"sha":"f319663c04ea5796d6fec706a85f50599e146607","date":"2020-08-07T15:37:03-04:00","author":"Suhas Daftuar","message":"BIP339: clarify fetching","url":"https://github.com/bitcoin/bips/commit/f319663c04ea5796d6fec706a85f50599e146607","kind":"edit"},{"sha":"5909b91b939e9f9f11be7a99d3d1afe49af7d6f5","date":"2020-08-03T09:44:47+01:00","author":"John Newbery","message":"BIP339: clarify handshake","url":"https://github.com/bitcoin/bips/commit/5909b91b939e9f9f11be7a99d3d1afe49af7d6f5","kind":"edit"},{"sha":"6014c8289ecca03ebe34fff7f2947a96c307dcac","date":"2020-08-03T09:43:35+01:00","author":"John Newbery","message":"BIP339: consistent capitalization","url":"https://github.com/bitcoin/bips/commit/6014c8289ecca03ebe34fff7f2947a96c307dcac","kind":"edit"},{"sha":"b8fefbf5761d5cef6aed3f8a9a315e68c7ee06f4","date":"2020-06-25T05:19:50+00:00","author":"Luke Dashjr","message":"Assign BIP 339: WTXID-based transaction relay","url":"https://github.com/bitcoin/bips/commit/b8fefbf5761d5cef6aed3f8a9a315e68c7ee06f4","kind":"edit"}]}}