Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
2001tx = self.wallet.create_self_transfer()['tx']2002assert_raises_rpc_error(-22, "TX decode failed", self.nodes[0].decoderawtransaction, hexstring=serialize_with_bogus_witness(tx).hex(), iswitness=True)2003with self.nodes[0].assert_debug_log(['Unknown transaction optional data']):2004self.test_node.send_and_ping(msg_bogus_tx(tx))2005tx.wit.vtxinwit = [] # drop witness2006assert_raises_rpc_error(-22, "TX decode failed", self.nodes[0].decoderawtransaction, hexstring=serialize_with_bogus_witness(tx).hex(), iswitness=True)2007with self.nodes[0].assert_debug_log(['Superfluous witness record']):2008self.test_node.send_and_ping(msg_bogus_tx(tx))2010@subtest2011def test_wtxid_relay(self):2012# Use brand new nodes to avoid contamination from earlier tests2013self.wtx_node = self.nodes[0].add_p2p_connection(TestP2PConn(wtxidrelay=True), services=P2P_SERVICES)2014self.tx_node = self.nodes[0].add_p2p_connection(TestP2PConn(wtxidrelay=False), services=P2P_SERVICES)2016# Check wtxidrelay feature negotiation message through connecting a new peer2017def received_wtxidrelay():2018return (len(self.wtx_node.last_wtxidrelay) > 0)2019self.wtx_node.wait_until(received_wtxidrelay)2021# Create a Segwit output from the latest UTXO2022# and announce it to the network2023witness_script = CScript([OP_TRUE])2024script_pubkey = script_to_p2wsh_script(witness_script)2026tx = CTransaction()2027tx.vin.append(CTxIn(COutPoint(self.utxo[0].sha256, self.utxo[0].n), b""))2028tx.vout.append(CTxOut(self.utxo[0].nValue - 1000, script_pubkey))2030# Create a Segwit transaction2031tx2 = CTransaction()2032tx2.vin.append(CTxIn(COutPoint(tx.txid_int, 0), b""))2033tx2.vout.append(CTxOut(tx.vout[0].nValue - 1000, script_pubkey))2034tx2.wit.vtxinwit.append(CTxInWitness())2035tx2.wit.vtxinwit[0].scriptWitness.stack = [witness_script]2037# Announce Segwit transaction with wtxid2038# and wait for getdata2039self.wtx_node.announce_tx_and_wait_for_getdata(tx2, use_wtxid=True)2040with p2p_lock:2041lgd = self.wtx_node.lastgetdata[:]2042assert_equal(lgd, [CInv(MSG_WTX, tx2.wtxid_int)])2044# Announce Segwit transaction from non wtxidrelay peer2045# and wait for getdata2046self.tx_node.announce_tx_and_wait_for_getdata(tx2, use_wtxid=False)2047with p2p_lock:2048lgd = self.tx_node.lastgetdata[:]2049assert_equal(lgd, [CInv(MSG_TX|MSG_WITNESS_FLAG, tx2.txid_int)])2051# Send tx2 through; it's an orphan so won't be accepted2052with p2p_lock:2053self.wtx_node.last_message.pop("getdata", None)2054test_transaction_acceptance(self.nodes[0], self.wtx_node, tx2, with_witness=True, accepted=False)2056# Disconnect tx_node to avoid the possibility of it being selected for orphan resolution.2057self.tx_node.peer_disconnect()2059# Expect a request for parent (tx) by txid despite use of WTX peer2060self.wtx_node.wait_for_getdata([tx.txid_int], timeout=60)2061with p2p_lock:2062lgd = self.wtx_node.lastgetdata[:]2063assert_equal(lgd, [CInv(MSG_WITNESS_TX, tx.txid_int)])2065# Send tx through2066test_transaction_acceptance(self.nodes[0], self.wtx_node, tx, with_witness=False, accepted=True)2068# Check tx2 is there now2069assert_equal(tx2.txid_hex in self.nodes[0].getrawmempool(), True)2072if __name__ == '__main__':2073SegWitTest(__file__).main()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.