mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-09 10:43:19 -05:00
[test] Allow rebroadcast for same-txid-different-wtxid transactions
Co-authored-by: John Newbery <john@johnnewbery.com>
This commit is contained in:
parent
cd48372b67
commit
7282d4c036
1 changed files with 16 additions and 1 deletions
|
@ -16,6 +16,7 @@ from test_framework.messages import (
|
||||||
CTxOut,
|
CTxOut,
|
||||||
sha256,
|
sha256,
|
||||||
)
|
)
|
||||||
|
from test_framework.p2p import P2PTxInvStore
|
||||||
from test_framework.script import (
|
from test_framework.script import (
|
||||||
CScript,
|
CScript,
|
||||||
OP_0,
|
OP_0,
|
||||||
|
@ -62,6 +63,8 @@ class MempoolWtxidTest(BitcoinTestFramework):
|
||||||
parent_txid = node.sendrawtransaction(hexstring=raw_parent, maxfeerate=0)
|
parent_txid = node.sendrawtransaction(hexstring=raw_parent, maxfeerate=0)
|
||||||
node.generate(1)
|
node.generate(1)
|
||||||
|
|
||||||
|
peer_wtxid_relay = node.add_p2p_connection(P2PTxInvStore())
|
||||||
|
|
||||||
# Create a new transaction with witness solving first branch
|
# Create a new transaction with witness solving first branch
|
||||||
child_witness_script = CScript([OP_TRUE])
|
child_witness_script = CScript([OP_TRUE])
|
||||||
child_witness_program = sha256(child_witness_script)
|
child_witness_program = sha256(child_witness_script)
|
||||||
|
@ -87,10 +90,13 @@ class MempoolWtxidTest(BitcoinTestFramework):
|
||||||
assert_equal(child_one_txid, child_two_txid)
|
assert_equal(child_one_txid, child_two_txid)
|
||||||
assert child_one_wtxid != child_two_wtxid
|
assert child_one_wtxid != child_two_wtxid
|
||||||
|
|
||||||
self.log.info("Submit one child to the mempool")
|
self.log.info("Submit child_one to the mempool")
|
||||||
txid_submitted = node.sendrawtransaction(child_one.serialize().hex())
|
txid_submitted = node.sendrawtransaction(child_one.serialize().hex())
|
||||||
assert_equal(node.getrawmempool(True)[txid_submitted]['wtxid'], child_one_wtxid)
|
assert_equal(node.getrawmempool(True)[txid_submitted]['wtxid'], child_one_wtxid)
|
||||||
|
|
||||||
|
peer_wtxid_relay.wait_for_broadcast([child_one_wtxid])
|
||||||
|
assert_equal(node.getmempoolinfo()["unbroadcastcount"], 0)
|
||||||
|
|
||||||
# testmempoolaccept reports the "already in mempool" error
|
# testmempoolaccept reports the "already in mempool" error
|
||||||
assert_equal(node.testmempoolaccept([child_one.serialize().hex()]), [{
|
assert_equal(node.testmempoolaccept([child_one.serialize().hex()]), [{
|
||||||
"txid": child_one_txid,
|
"txid": child_one_txid,
|
||||||
|
@ -108,9 +114,18 @@ class MempoolWtxidTest(BitcoinTestFramework):
|
||||||
|
|
||||||
# sendrawtransaction will not throw but quits early when the exact same transaction is already in mempool
|
# sendrawtransaction will not throw but quits early when the exact same transaction is already in mempool
|
||||||
node.sendrawtransaction(child_one.serialize().hex())
|
node.sendrawtransaction(child_one.serialize().hex())
|
||||||
|
|
||||||
|
self.log.info("Connect another peer that hasn't seen child_one before")
|
||||||
|
peer_wtxid_relay_2 = node.add_p2p_connection(P2PTxInvStore())
|
||||||
|
|
||||||
|
self.log.info("Submit child_two to the mempool")
|
||||||
# sendrawtransaction will not throw but quits early when a transaction with the same non-witness data is already in mempool
|
# sendrawtransaction will not throw but quits early when a transaction with the same non-witness data is already in mempool
|
||||||
node.sendrawtransaction(child_two.serialize().hex())
|
node.sendrawtransaction(child_two.serialize().hex())
|
||||||
|
|
||||||
|
# The node should rebroadcast the transaction using the wtxid of the correct transaction
|
||||||
|
# (child_one, which is in its mempool).
|
||||||
|
peer_wtxid_relay_2.wait_for_broadcast([child_one_wtxid])
|
||||||
|
assert_equal(node.getmempoolinfo()["unbroadcastcount"], 0)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
MempoolWtxidTest().main()
|
MempoolWtxidTest().main()
|
||||||
|
|
Loading…
Add table
Reference in a new issue