test: avoid unneeded (w)txid hex -> integer conversions

Rather than determining a CTransaction's (w)txid as an integer by
converting it's hex value, it can be directly accessed via the
introduced `.{w,}txid_int` property.
This commit is contained in:
Sebastian Falbesoner committed 2025-06-11 00:52:25 +02:00
1 parent 472f3770ae
commit 4ef6253017
4 files changed
+26 -26

No files matched your search

+10 -10
View File
@@ -83,7 +83,7 @@ class PackageRelayTest(BitcoinTestFramework):
peer_sender = node.add_p2p_connection(P2PInterface())
# 1. Child is received first (perhaps the low feerate parent didn't meet feefilter or the requests were sent to different nodes). It is missing an input.
high_child_wtxid_int = int(high_fee_child["tx"].wtxid_hex, 16)
high_child_wtxid_int = high_fee_child["tx"].wtxid_int
peer_sender.send_and_ping(msg_inv([CInv(t=MSG_WTX, h=high_child_wtxid_int)]))
peer_sender.wait_for_getdata([high_child_wtxid_int])
peer_sender.send_and_ping(msg_tx(high_fee_child["tx"]))
@@ -112,7 +112,7 @@ class PackageRelayTest(BitcoinTestFramework):
peer_ignored = node.add_outbound_p2p_connection(P2PInterface(), p2p_idx=2, connection_type="outbound-full-relay")
# 1. Parent is relayed first. It is too low feerate.
parent_wtxid_int = int(low_fee_parent["tx"].wtxid_hex, 16)
parent_wtxid_int = low_fee_parent["tx"].wtxid_int
peer_sender.send_and_ping(msg_inv([CInv(t=MSG_WTX, h=parent_wtxid_int)]))
peer_sender.wait_for_getdata([parent_wtxid_int])
peer_sender.send_and_ping(msg_tx(low_fee_parent["tx"]))
@@ -123,7 +123,7 @@ class PackageRelayTest(BitcoinTestFramework):
assert "getdata" not in peer_ignored.last_message
# 2. Child is relayed next. It is missing an input.
high_child_wtxid_int = int(high_fee_child["tx"].wtxid_hex, 16)
high_child_wtxid_int = high_fee_child["tx"].wtxid_int
peer_sender.send_and_ping(msg_inv([CInv(t=MSG_WTX, h=high_child_wtxid_int)]))
peer_sender.wait_for_getdata([high_child_wtxid_int])
peer_sender.send_and_ping(msg_tx(high_fee_child["tx"]))
@@ -156,7 +156,7 @@ class PackageRelayTest(BitcoinTestFramework):
self.log.info("Check that tx caches low fee parent + low fee child package rejections")
# 1. Send parent, rejected for being low feerate.
parent_wtxid_int = int(low_fee_parent["tx"].wtxid_hex, 16)
parent_wtxid_int = low_fee_parent["tx"].wtxid_int
peer_sender.send_and_ping(msg_inv([CInv(t=MSG_WTX, h=parent_wtxid_int)]))
peer_sender.wait_for_getdata([parent_wtxid_int])
peer_sender.send_and_ping(msg_tx(low_fee_parent["tx"]))
@@ -167,7 +167,7 @@ class PackageRelayTest(BitcoinTestFramework):
assert "getdata" not in peer_ignored.last_message
# 2. Send an (orphan) child that has a higher feerate, but not enough to bump the parent.
med_child_wtxid_int = int(med_fee_child["tx"].wtxid_hex, 16)
med_child_wtxid_int = med_fee_child["tx"].wtxid_int
peer_sender.send_and_ping(msg_inv([CInv(t=MSG_WTX, h=med_child_wtxid_int)]))
peer_sender.wait_for_getdata([med_child_wtxid_int])
peer_sender.send_and_ping(msg_tx(med_fee_child["tx"]))
@@ -193,7 +193,7 @@ class PackageRelayTest(BitcoinTestFramework):
assert med_fee_child["txid"] not in node.getrawmempool()
# 5. Send the high feerate (orphan) child
high_child_wtxid_int = int(high_fee_child["tx"].wtxid_hex, 16)
high_child_wtxid_int = high_fee_child["tx"].wtxid_int
peer_sender.send_and_ping(msg_inv([CInv(t=MSG_WTX, h=high_child_wtxid_int)]))
peer_sender.wait_for_getdata([high_child_wtxid_int])
peer_sender.send_and_ping(msg_tx(high_fee_child["tx"]))
@@ -229,7 +229,7 @@ class PackageRelayTest(BitcoinTestFramework):
parent_sender = node.add_p2p_connection(P2PInterface())
# 1. Child is received first. It is missing an input.
child_wtxid_int = int(tx_orphan_bad_wit.wtxid_hex, 16)
child_wtxid_int = tx_orphan_bad_wit.wtxid_int
bad_orphan_sender.send_and_ping(msg_inv([CInv(t=MSG_WTX, h=child_wtxid_int)]))
bad_orphan_sender.wait_for_getdata([child_wtxid_int])
bad_orphan_sender.send_and_ping(msg_tx(tx_orphan_bad_wit))
@@ -270,13 +270,13 @@ class PackageRelayTest(BitcoinTestFramework):
fake_parent_sender = node.add_p2p_connection(P2PInterface())
# 1. Child is received first. It is missing an input.
child_wtxid_int = int(high_fee_child["tx"].wtxid_hex, 16)
child_wtxid_int = high_fee_child["tx"].wtxid_int
package_sender.send_and_ping(msg_inv([CInv(t=MSG_WTX, h=child_wtxid_int)]))
package_sender.wait_for_getdata([child_wtxid_int])
package_sender.send_and_ping(msg_tx(high_fee_child["tx"]))
# 2. Node requests the missing parent by txid.
parent_txid_int = int(tx_parent_bad_wit.txid_hex, 16)
parent_txid_int = tx_parent_bad_wit.txid_int
package_sender.wait_for_getdata([parent_txid_int])
# 3. A different node relays the parent. The parent is first evaluated by itself and
@@ -292,7 +292,7 @@ class PackageRelayTest(BitcoinTestFramework):
self.log.info("Check that fake parent does not cause orphan to be deleted and real package can still be submitted")
# 5. Child-sending should not have been punished and the orphan should remain in orphanage.
# It can send the "real" parent transaction, and the package is accepted.
parent_wtxid_int = int(low_fee_parent["tx"].wtxid_hex, 16)
parent_wtxid_int = low_fee_parent["tx"].wtxid_int
package_sender.send_and_ping(msg_inv([CInv(t=MSG_WTX, h=parent_wtxid_int)]))
package_sender.wait_for_getdata([parent_wtxid_int])
package_sender.send_and_ping(msg_tx(low_fee_parent["tx"]))