Skip to content

Commit 7282d4c

Browse files
glozowjnewbery
andcommitted
[test] Allow rebroadcast for same-txid-different-wtxid transactions
Co-authored-by: John Newbery <[email protected]>
1 parent cd48372 commit 7282d4c

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

test/functional/mempool_accept_wtxid.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
CTxOut,
1717
sha256,
1818
)
19+
from test_framework.p2p import P2PTxInvStore
1920
from test_framework.script import (
2021
CScript,
2122
OP_0,
@@ -62,6 +63,8 @@ def run_test(self):
6263
parent_txid = node.sendrawtransaction(hexstring=raw_parent, maxfeerate=0)
6364
node.generate(1)
6465

66+
peer_wtxid_relay = node.add_p2p_connection(P2PTxInvStore())
67+
6568
# Create a new transaction with witness solving first branch
6669
child_witness_script = CScript([OP_TRUE])
6770
child_witness_program = sha256(child_witness_script)
@@ -87,10 +90,13 @@ def run_test(self):
8790
assert_equal(child_one_txid, child_two_txid)
8891
assert child_one_wtxid != child_two_wtxid
8992

90-
self.log.info("Submit one child to the mempool")
93+
self.log.info("Submit child_one to the mempool")
9194
txid_submitted = node.sendrawtransaction(child_one.serialize().hex())
9295
assert_equal(node.getrawmempool(True)[txid_submitted]['wtxid'], child_one_wtxid)
9396

97+
peer_wtxid_relay.wait_for_broadcast([child_one_wtxid])
98+
assert_equal(node.getmempoolinfo()["unbroadcastcount"], 0)
99+
94100
# testmempoolaccept reports the "already in mempool" error
95101
assert_equal(node.testmempoolaccept([child_one.serialize().hex()]), [{
96102
"txid": child_one_txid,
@@ -108,9 +114,18 @@ def run_test(self):
108114

109115
# sendrawtransaction will not throw but quits early when the exact same transaction is already in mempool
110116
node.sendrawtransaction(child_one.serialize().hex())
117+
118+
self.log.info("Connect another peer that hasn't seen child_one before")
119+
peer_wtxid_relay_2 = node.add_p2p_connection(P2PTxInvStore())
120+
121+
self.log.info("Submit child_two to the mempool")
111122
# sendrawtransaction will not throw but quits early when a transaction with the same non-witness data is already in mempool
112123
node.sendrawtransaction(child_two.serialize().hex())
113124

125+
# The node should rebroadcast the transaction using the wtxid of the correct transaction
126+
# (child_one, which is in its mempool).
127+
peer_wtxid_relay_2.wait_for_broadcast([child_one_wtxid])
128+
assert_equal(node.getmempoolinfo()["unbroadcastcount"], 0)
114129

115130
if __name__ == '__main__':
116131
MempoolWtxidTest().main()

0 commit comments

Comments
 (0)