2019-05-07 14:14:33 +02:00
|
|
|
#!/usr/bin/env python3
|
2023-12-31 01:00:00 +01:00
|
|
|
# Copyright (c) 2015-2024 The Dash Core developers
|
2019-05-07 14:14:33 +02:00
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
'''
|
2020-07-17 01:44:20 +02:00
|
|
|
feature_llmq_is_cl_conflicts.py
|
2019-05-07 14:14:33 +02:00
|
|
|
|
|
|
|
Checks conflict handling between ChainLocks and InstantSend
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
Merge #13054: tests: Enable automatic detection of undefined names in Python tests scripts. Remove wildcard imports.
68400d8b96 tests: Use explicit imports (practicalswift)
Pull request description:
Enable automatic detection of undefined names in Python tests scripts. Remove wildcard imports.
Wildcard imports make it unclear which names are present in the namespace, confusing both readers and many automated tools.
An additional benefit of not using wildcard imports in tests scripts is that readers of a test script then can infer the rough testing scope just by looking at the imports.
Before this commit:
```
$ contrib/devtools/lint-python.sh | head -10
./test/functional/feature_rbf.py:8:1: F403 'from test_framework.util import *' used; unable to detect undefined names
./test/functional/feature_rbf.py:9:1: F403 'from test_framework.script import *' used; unable to detect undefined names
./test/functional/feature_rbf.py:10:1: F403 'from test_framework.mininode import *' used; unable to detect undefined names
./test/functional/feature_rbf.py:15:12: F405 bytes_to_hex_str may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util
./test/functional/feature_rbf.py:17:58: F405 CScript may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util
./test/functional/feature_rbf.py:25:13: F405 COIN may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util
./test/functional/feature_rbf.py:26:31: F405 satoshi_round may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util
./test/functional/feature_rbf.py:26:60: F405 COIN may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util
./test/functional/feature_rbf.py:30:41: F405 satoshi_round may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util
./test/functional/feature_rbf.py:30:68: F405 COIN may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util
$
```
After this commit:
```
$ contrib/devtools/lint-python.sh | head -10
$
```
Tree-SHA512: 3f826d39cffb6438388e5efcb20a9622ff8238247e882d68f7b38609877421b2a8e10e9229575f8eb6a8fa42dec4256986692e92922c86171f750a0e887438d9
2018-08-13 14:24:43 +02:00
|
|
|
import struct
|
|
|
|
|
2023-11-13 17:02:52 +01:00
|
|
|
from test_framework.blocktools import create_block_with_mnpayments
|
2021-06-24 12:47:04 +02:00
|
|
|
from test_framework.messages import CInv, hash256, msg_clsig, msg_inv, ser_string, tx_from_hex, uint256_from_str
|
2024-01-15 20:35:29 +01:00
|
|
|
from test_framework.p2p import P2PInterface
|
Merge #13054: tests: Enable automatic detection of undefined names in Python tests scripts. Remove wildcard imports.
68400d8b96 tests: Use explicit imports (practicalswift)
Pull request description:
Enable automatic detection of undefined names in Python tests scripts. Remove wildcard imports.
Wildcard imports make it unclear which names are present in the namespace, confusing both readers and many automated tools.
An additional benefit of not using wildcard imports in tests scripts is that readers of a test script then can infer the rough testing scope just by looking at the imports.
Before this commit:
```
$ contrib/devtools/lint-python.sh | head -10
./test/functional/feature_rbf.py:8:1: F403 'from test_framework.util import *' used; unable to detect undefined names
./test/functional/feature_rbf.py:9:1: F403 'from test_framework.script import *' used; unable to detect undefined names
./test/functional/feature_rbf.py:10:1: F403 'from test_framework.mininode import *' used; unable to detect undefined names
./test/functional/feature_rbf.py:15:12: F405 bytes_to_hex_str may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util
./test/functional/feature_rbf.py:17:58: F405 CScript may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util
./test/functional/feature_rbf.py:25:13: F405 COIN may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util
./test/functional/feature_rbf.py:26:31: F405 satoshi_round may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util
./test/functional/feature_rbf.py:26:60: F405 COIN may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util
./test/functional/feature_rbf.py:30:41: F405 satoshi_round may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util
./test/functional/feature_rbf.py:30:68: F405 COIN may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util
$
```
After this commit:
```
$ contrib/devtools/lint-python.sh | head -10
$
```
Tree-SHA512: 3f826d39cffb6438388e5efcb20a9622ff8238247e882d68f7b38609877421b2a8e10e9229575f8eb6a8fa42dec4256986692e92922c86171f750a0e887438d9
2018-08-13 14:24:43 +02:00
|
|
|
from test_framework.test_framework import DashTestFramework
|
2021-07-31 21:23:16 +02:00
|
|
|
from test_framework.util import assert_equal, assert_raises_rpc_error
|
Merge #13054: tests: Enable automatic detection of undefined names in Python tests scripts. Remove wildcard imports.
68400d8b96 tests: Use explicit imports (practicalswift)
Pull request description:
Enable automatic detection of undefined names in Python tests scripts. Remove wildcard imports.
Wildcard imports make it unclear which names are present in the namespace, confusing both readers and many automated tools.
An additional benefit of not using wildcard imports in tests scripts is that readers of a test script then can infer the rough testing scope just by looking at the imports.
Before this commit:
```
$ contrib/devtools/lint-python.sh | head -10
./test/functional/feature_rbf.py:8:1: F403 'from test_framework.util import *' used; unable to detect undefined names
./test/functional/feature_rbf.py:9:1: F403 'from test_framework.script import *' used; unable to detect undefined names
./test/functional/feature_rbf.py:10:1: F403 'from test_framework.mininode import *' used; unable to detect undefined names
./test/functional/feature_rbf.py:15:12: F405 bytes_to_hex_str may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util
./test/functional/feature_rbf.py:17:58: F405 CScript may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util
./test/functional/feature_rbf.py:25:13: F405 COIN may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util
./test/functional/feature_rbf.py:26:31: F405 satoshi_round may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util
./test/functional/feature_rbf.py:26:60: F405 COIN may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util
./test/functional/feature_rbf.py:30:41: F405 satoshi_round may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util
./test/functional/feature_rbf.py:30:68: F405 COIN may be undefined, or defined from star imports: test_framework.mininode, test_framework.script, test_framework.util
$
```
After this commit:
```
$ contrib/devtools/lint-python.sh | head -10
$
```
Tree-SHA512: 3f826d39cffb6438388e5efcb20a9622ff8238247e882d68f7b38609877421b2a8e10e9229575f8eb6a8fa42dec4256986692e92922c86171f750a0e887438d9
2018-08-13 14:24:43 +02:00
|
|
|
|
|
|
|
|
2020-07-09 11:31:01 +02:00
|
|
|
class TestP2PConn(P2PInterface):
|
2019-05-07 14:14:33 +02:00
|
|
|
def __init__(self):
|
2019-05-20 19:01:39 +02:00
|
|
|
super().__init__()
|
2019-05-07 14:14:33 +02:00
|
|
|
self.clsigs = {}
|
|
|
|
self.islocks = {}
|
|
|
|
|
|
|
|
def send_clsig(self, clsig):
|
|
|
|
hash = uint256_from_str(hash256(clsig.serialize()))
|
|
|
|
self.clsigs[hash] = clsig
|
|
|
|
|
|
|
|
inv = msg_inv([CInv(29, hash)])
|
|
|
|
self.send_message(inv)
|
|
|
|
|
2023-11-20 17:17:04 +01:00
|
|
|
def send_isdlock(self, isdlock):
|
|
|
|
hash = uint256_from_str(hash256(isdlock.serialize()))
|
|
|
|
self.islocks[hash] = isdlock
|
2019-05-07 14:14:33 +02:00
|
|
|
|
2023-11-20 17:17:04 +01:00
|
|
|
inv = msg_inv([CInv(31, hash)])
|
2019-05-07 14:14:33 +02:00
|
|
|
self.send_message(inv)
|
|
|
|
|
2020-04-05 13:12:45 +02:00
|
|
|
def on_getdata(self, message):
|
2019-05-07 14:14:33 +02:00
|
|
|
for inv in message.inv:
|
|
|
|
if inv.hash in self.clsigs:
|
|
|
|
self.send_message(self.clsigs[inv.hash])
|
|
|
|
if inv.hash in self.islocks:
|
|
|
|
self.send_message(self.islocks[inv.hash])
|
|
|
|
|
|
|
|
|
|
|
|
class LLMQ_IS_CL_Conflicts(DashTestFramework):
|
2019-09-24 00:57:30 +02:00
|
|
|
def set_test_params(self):
|
2024-08-21 14:55:28 +02:00
|
|
|
self.set_dash_test_params(5, 4, [["-testactivationheight=mn_rr@2000"]] * 5)
|
2022-04-25 21:12:04 +02:00
|
|
|
self.set_dash_llmq_test_params(4, 4)
|
2019-12-09 19:52:38 +01:00
|
|
|
self.supports_cli = False
|
2019-05-07 14:14:33 +02:00
|
|
|
|
|
|
|
def run_test(self):
|
2020-07-09 11:31:01 +02:00
|
|
|
self.test_node = self.nodes[0].add_p2p_connection(TestP2PConn())
|
2019-05-07 14:14:33 +02:00
|
|
|
|
2022-06-18 18:52:45 +02:00
|
|
|
self.nodes[0].sporkupdate("SPORK_17_QUORUM_DKG_ENABLED", 0)
|
2019-05-07 14:14:33 +02:00
|
|
|
self.wait_for_sporks_same()
|
|
|
|
|
2023-11-20 17:17:04 +01:00
|
|
|
self.activate_v19(expected_activation_height=900)
|
|
|
|
self.log.info("Activated v19 at height:" + str(self.nodes[0].getblockcount()))
|
|
|
|
self.move_to_next_cycle()
|
|
|
|
self.log.info("Cycle H height:" + str(self.nodes[0].getblockcount()))
|
|
|
|
self.move_to_next_cycle()
|
|
|
|
self.log.info("Cycle H+C height:" + str(self.nodes[0].getblockcount()))
|
|
|
|
self.move_to_next_cycle()
|
|
|
|
self.log.info("Cycle H+2C height:" + str(self.nodes[0].getblockcount()))
|
|
|
|
|
|
|
|
self.mine_cycle_quorum(llmq_type_name='llmq_test_dip0024', llmq_type=103)
|
2019-05-07 14:14:33 +02:00
|
|
|
|
|
|
|
# mine single block, wait for chainlock
|
2024-10-01 21:22:56 +02:00
|
|
|
self.generate(self.nodes[0], 1, sync_fun=self.no_op)
|
2019-10-02 15:24:57 +02:00
|
|
|
self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash())
|
2019-05-07 14:14:33 +02:00
|
|
|
|
|
|
|
self.test_chainlock_overrides_islock(False)
|
2021-02-14 23:09:21 +01:00
|
|
|
self.test_chainlock_overrides_islock(True, False)
|
|
|
|
self.test_chainlock_overrides_islock(True, True)
|
2023-11-20 17:17:04 +01:00
|
|
|
self.test_chainlock_overrides_islock_overrides_nonchainlock()
|
2019-05-07 14:14:33 +02:00
|
|
|
|
2021-02-14 23:09:21 +01:00
|
|
|
def test_chainlock_overrides_islock(self, test_block_conflict, mine_confllicting=False):
|
|
|
|
if not test_block_conflict:
|
|
|
|
assert not mine_confllicting
|
|
|
|
|
2019-05-07 14:14:33 +02:00
|
|
|
# create three raw TXs, they will conflict with each other
|
|
|
|
rawtx1 = self.create_raw_tx(self.nodes[0], self.nodes[0], 1, 1, 100)['hex']
|
|
|
|
rawtx2 = self.create_raw_tx(self.nodes[0], self.nodes[0], 1, 1, 100)['hex']
|
2021-06-24 12:47:04 +02:00
|
|
|
rawtx1_obj = tx_from_hex(rawtx1)
|
|
|
|
rawtx2_obj = tx_from_hex(rawtx2)
|
2019-05-07 14:14:33 +02:00
|
|
|
|
|
|
|
rawtx1_txid = self.nodes[0].sendrawtransaction(rawtx1)
|
2021-07-31 21:23:16 +02:00
|
|
|
rawtx2_txid = hash256(bytes.fromhex(rawtx2))[::-1].hex()
|
2019-05-07 14:14:33 +02:00
|
|
|
|
|
|
|
# Create a chained TX on top of tx1
|
|
|
|
inputs = []
|
|
|
|
n = 0
|
|
|
|
for out in rawtx1_obj.vout:
|
|
|
|
if out.nValue == 100000000:
|
|
|
|
inputs.append({"txid": rawtx1_txid, "vout": n})
|
|
|
|
n += 1
|
|
|
|
rawtx4 = self.nodes[0].createrawtransaction(inputs, {self.nodes[0].getnewaddress(): 0.999})
|
2020-12-11 03:25:55 +01:00
|
|
|
rawtx4 = self.nodes[0].signrawtransactionwithwallet(rawtx4)['hex']
|
2019-05-07 14:14:33 +02:00
|
|
|
rawtx4_txid = self.nodes[0].sendrawtransaction(rawtx4)
|
|
|
|
|
2019-10-01 16:14:26 +02:00
|
|
|
# wait for transactions to propagate
|
2020-04-14 12:00:16 +02:00
|
|
|
self.sync_mempools()
|
2019-05-07 14:14:33 +02:00
|
|
|
for node in self.nodes:
|
|
|
|
self.wait_for_instantlock(rawtx1_txid, node)
|
|
|
|
self.wait_for_instantlock(rawtx4_txid, node)
|
|
|
|
|
2023-11-13 17:02:52 +01:00
|
|
|
block = create_block_with_mnpayments(self.mninfo, self.nodes[0], [rawtx2_obj])
|
2019-05-07 14:14:33 +02:00
|
|
|
if test_block_conflict:
|
2019-09-27 20:20:22 +02:00
|
|
|
# The block shouldn't be accepted/connected but it should be known to node 0 now
|
2021-06-24 12:47:04 +02:00
|
|
|
submit_result = self.nodes[0].submitblock(block.serialize().hex())
|
2021-08-27 21:03:02 +02:00
|
|
|
assert submit_result == "conflict-tx-lock"
|
2019-05-07 14:14:33 +02:00
|
|
|
|
2020-11-17 20:40:15 +01:00
|
|
|
cl = self.create_chainlock(self.nodes[0].getblockcount() + 1, block)
|
2021-02-14 23:09:21 +01:00
|
|
|
|
|
|
|
if mine_confllicting:
|
2021-10-21 13:11:00 +02:00
|
|
|
# Make sure we won't sent clsig too early
|
2024-10-01 18:08:19 +02:00
|
|
|
islock_tip = self.generate(self.nodes[0], 1, sync_fun=lambda: self.sync_blocks())[-1]
|
2021-02-14 23:09:21 +01:00
|
|
|
|
2019-05-07 14:14:33 +02:00
|
|
|
self.test_node.send_clsig(cl)
|
|
|
|
|
2019-09-27 20:20:22 +02:00
|
|
|
for node in self.nodes:
|
2020-11-17 20:40:15 +01:00
|
|
|
self.wait_for_best_chainlock(node, block.hash)
|
2019-09-27 20:20:22 +02:00
|
|
|
|
2020-04-14 12:00:16 +02:00
|
|
|
self.sync_blocks()
|
2019-09-27 20:20:22 +02:00
|
|
|
|
2021-02-14 23:09:21 +01:00
|
|
|
if mine_confllicting:
|
|
|
|
# The tip with IS-locked txes should be marked conflicting now
|
|
|
|
found1 = False
|
|
|
|
found2 = False
|
|
|
|
for tip in self.nodes[0].getchaintips(2):
|
|
|
|
if tip["hash"] == islock_tip:
|
|
|
|
assert tip["status"] == "conflicting"
|
|
|
|
found1 = True
|
|
|
|
elif tip["hash"] == block.hash:
|
|
|
|
assert tip["status"] == "active"
|
|
|
|
found2 = True
|
|
|
|
assert found1 and found2
|
|
|
|
|
2019-09-27 20:20:22 +02:00
|
|
|
# At this point all nodes should be in sync and have the same "best chainlock"
|
2019-05-07 14:14:33 +02:00
|
|
|
|
2021-06-24 12:47:04 +02:00
|
|
|
submit_result = self.nodes[1].submitblock(block.serialize().hex())
|
2019-05-07 14:14:33 +02:00
|
|
|
if test_block_conflict:
|
2019-09-27 20:20:22 +02:00
|
|
|
# Node 1 should receive the block from node 0 and should not accept it again via submitblock
|
2021-08-27 21:03:02 +02:00
|
|
|
assert submit_result == "duplicate"
|
2019-05-07 14:14:33 +02:00
|
|
|
else:
|
2019-09-27 20:20:22 +02:00
|
|
|
# The block should get accepted now, and at the same time prune the conflicting ISLOCKs
|
2021-08-27 21:03:02 +02:00
|
|
|
assert submit_result is None
|
2019-05-07 14:14:33 +02:00
|
|
|
|
2021-05-11 18:55:40 +02:00
|
|
|
self.wait_for_chainlocked_block_all_nodes(block.hash)
|
2019-05-07 14:14:33 +02:00
|
|
|
|
|
|
|
# Create a chained TX on top of tx2
|
|
|
|
inputs = []
|
|
|
|
n = 0
|
|
|
|
for out in rawtx2_obj.vout:
|
|
|
|
if out.nValue == 100000000:
|
|
|
|
inputs.append({"txid": rawtx2_txid, "vout": n})
|
|
|
|
n += 1
|
|
|
|
rawtx5 = self.nodes[0].createrawtransaction(inputs, {self.nodes[0].getnewaddress(): 0.999})
|
2020-12-11 03:25:55 +01:00
|
|
|
rawtx5 = self.nodes[0].signrawtransactionwithwallet(rawtx5)['hex']
|
2019-05-07 14:14:33 +02:00
|
|
|
rawtx5_txid = self.nodes[0].sendrawtransaction(rawtx5)
|
2019-10-01 16:14:26 +02:00
|
|
|
# wait for the transaction to propagate
|
2020-04-14 12:00:16 +02:00
|
|
|
self.sync_mempools()
|
2019-05-07 14:14:33 +02:00
|
|
|
for node in self.nodes:
|
|
|
|
self.wait_for_instantlock(rawtx5_txid, node)
|
|
|
|
|
2021-02-14 23:09:21 +01:00
|
|
|
if mine_confllicting:
|
|
|
|
# Lets verify that the ISLOCKs got pruned and conflicting txes were mined but never confirmed
|
|
|
|
for node in self.nodes:
|
|
|
|
rawtx = node.getrawtransaction(rawtx1_txid, True)
|
|
|
|
assert not rawtx['chainlock']
|
|
|
|
assert not rawtx['instantlock']
|
|
|
|
assert not rawtx['instantlock_internal']
|
|
|
|
assert_equal(rawtx['confirmations'], 0)
|
|
|
|
assert_equal(rawtx['height'], -1)
|
|
|
|
rawtx = node.getrawtransaction(rawtx4_txid, True)
|
|
|
|
assert not rawtx['chainlock']
|
|
|
|
assert not rawtx['instantlock']
|
|
|
|
assert not rawtx['instantlock_internal']
|
|
|
|
assert_equal(rawtx['confirmations'], 0)
|
|
|
|
assert_equal(rawtx['height'], -1)
|
|
|
|
rawtx = node.getrawtransaction(rawtx2_txid, True)
|
|
|
|
assert rawtx['chainlock']
|
|
|
|
assert rawtx['instantlock']
|
|
|
|
assert not rawtx['instantlock_internal']
|
|
|
|
else:
|
|
|
|
# Lets verify that the ISLOCKs got pruned
|
|
|
|
for node in self.nodes:
|
|
|
|
assert_raises_rpc_error(-5, "No such mempool or blockchain transaction", node.getrawtransaction, rawtx1_txid, True)
|
|
|
|
assert_raises_rpc_error(-5, "No such mempool or blockchain transaction", node.getrawtransaction, rawtx4_txid, True)
|
|
|
|
rawtx = node.getrawtransaction(rawtx2_txid, True)
|
|
|
|
assert rawtx['chainlock']
|
|
|
|
assert rawtx['instantlock']
|
|
|
|
assert not rawtx['instantlock_internal']
|
2019-05-07 14:14:33 +02:00
|
|
|
|
2023-11-20 17:17:04 +01:00
|
|
|
def test_chainlock_overrides_islock_overrides_nonchainlock(self):
|
2019-05-07 14:14:33 +02:00
|
|
|
# create two raw TXs, they will conflict with each other
|
|
|
|
rawtx1 = self.create_raw_tx(self.nodes[0], self.nodes[0], 1, 1, 100)['hex']
|
|
|
|
rawtx2 = self.create_raw_tx(self.nodes[0], self.nodes[0], 1, 1, 100)['hex']
|
|
|
|
|
2021-07-31 21:23:16 +02:00
|
|
|
rawtx1_txid = hash256(bytes.fromhex(rawtx1))[::-1].hex()
|
|
|
|
rawtx2_txid = hash256(bytes.fromhex(rawtx2))[::-1].hex()
|
2019-05-07 14:14:33 +02:00
|
|
|
|
|
|
|
# Create an ISLOCK but don't broadcast it yet
|
2023-11-20 17:17:04 +01:00
|
|
|
isdlock = self.create_isdlock(rawtx2)
|
2019-05-07 14:14:33 +02:00
|
|
|
|
2021-10-21 13:11:00 +02:00
|
|
|
# Ensure spork uniqueness in multiple function runs
|
|
|
|
self.bump_mocktime(1)
|
2021-07-17 21:15:21 +02:00
|
|
|
# Disable ChainLocks to avoid accidental locking
|
2022-06-18 18:52:45 +02:00
|
|
|
self.nodes[0].sporkupdate("SPORK_19_CHAINLOCKS_ENABLED", 4070908800)
|
2021-10-21 13:11:00 +02:00
|
|
|
self.wait_for_sporks_same()
|
2019-05-07 14:14:33 +02:00
|
|
|
|
|
|
|
# Send tx1, which will later conflict with the ISLOCK
|
|
|
|
self.nodes[0].sendrawtransaction(rawtx1)
|
|
|
|
|
|
|
|
# fast forward 11 minutes, so that the TX is considered safe and included in the next block
|
2019-08-09 01:14:11 +02:00
|
|
|
self.bump_mocktime(int(60 * 11))
|
2019-05-07 14:14:33 +02:00
|
|
|
|
|
|
|
# Mine the conflicting TX into a block
|
|
|
|
good_tip = self.nodes[0].getbestblockhash()
|
2024-10-01 21:25:52 +02:00
|
|
|
self.generate(self.nodes[0], 2)
|
2019-05-07 14:14:33 +02:00
|
|
|
|
|
|
|
# Assert that the conflicting tx got mined and the locked TX is not valid
|
2021-08-27 21:03:02 +02:00
|
|
|
assert self.nodes[0].getrawtransaction(rawtx1_txid, True)['confirmations'] > 0
|
2019-10-30 15:27:22 +01:00
|
|
|
assert_raises_rpc_error(-25, "bad-txns-inputs-missingorspent", self.nodes[0].sendrawtransaction, rawtx2)
|
2019-05-07 14:14:33 +02:00
|
|
|
|
2021-05-11 18:50:14 +02:00
|
|
|
# Create the block and the corresponding clsig but do not relay clsig yet
|
2023-11-13 17:02:52 +01:00
|
|
|
cl_block = create_block_with_mnpayments(self.mninfo, self.nodes[0])
|
2021-05-11 18:50:14 +02:00
|
|
|
cl = self.create_chainlock(self.nodes[0].getblockcount() + 1, cl_block)
|
2021-06-24 12:47:04 +02:00
|
|
|
self.nodes[0].submitblock(cl_block.serialize().hex())
|
2021-05-11 18:50:14 +02:00
|
|
|
self.sync_all()
|
|
|
|
assert self.nodes[0].getbestblockhash() == cl_block.hash
|
|
|
|
|
2021-11-30 12:14:08 +01:00
|
|
|
# Send the ISLOCK, which should result in the last 2 blocks to be disconnected,
|
|
|
|
# even though the nodes don't know the locked transaction yet
|
2023-11-20 17:17:04 +01:00
|
|
|
self.test_node.send_isdlock(isdlock)
|
2021-10-21 13:11:00 +02:00
|
|
|
for node in self.nodes:
|
2020-09-03 05:47:08 +02:00
|
|
|
self.wait_until(lambda: node.getbestblockhash() == good_tip, timeout=10)
|
2021-11-30 12:14:08 +01:00
|
|
|
# islock for tx2 is incomplete, tx1 should return in mempool now that blocks are disconnected
|
|
|
|
assert rawtx1_txid in set(node.getrawmempool())
|
2019-05-07 14:14:33 +02:00
|
|
|
|
2023-11-20 17:17:04 +01:00
|
|
|
# Should drop tx1 and accept tx2 because there is an isdlock waiting for it
|
2019-05-07 14:14:33 +02:00
|
|
|
self.nodes[0].sendrawtransaction(rawtx2)
|
2021-11-30 12:14:08 +01:00
|
|
|
# bump mocktime to force tx relay
|
|
|
|
self.bump_mocktime(60)
|
|
|
|
for node in self.nodes:
|
|
|
|
self.wait_for_instantlock(rawtx2_txid, node)
|
|
|
|
|
|
|
|
# Should not allow competing txes now
|
|
|
|
assert_raises_rpc_error(-26, "tx-txlock-conflict", self.nodes[0].sendrawtransaction, rawtx1)
|
|
|
|
|
2024-10-01 21:25:52 +02:00
|
|
|
islock_tip = self.generate(self.nodes[0], 1)[0]
|
2019-05-07 14:14:33 +02:00
|
|
|
|
2021-10-21 13:11:00 +02:00
|
|
|
for node in self.nodes:
|
|
|
|
self.wait_for_instantlock(rawtx2_txid, node)
|
|
|
|
assert_equal(node.getrawtransaction(rawtx2_txid, True)['confirmations'], 1)
|
|
|
|
assert_equal(node.getbestblockhash(), islock_tip)
|
2019-05-07 14:14:33 +02:00
|
|
|
|
2021-05-11 18:50:14 +02:00
|
|
|
# Check that the CL-ed block overrides the one with islocks
|
2022-06-18 18:52:45 +02:00
|
|
|
self.nodes[0].sporkupdate("SPORK_19_CHAINLOCKS_ENABLED", 0) # Re-enable ChainLocks to accept clsig
|
2021-05-11 18:50:14 +02:00
|
|
|
self.test_node.send_clsig(cl) # relay clsig ASAP to prevent nodes from locking islock-ed tip
|
|
|
|
self.wait_for_sporks_same()
|
|
|
|
for node in self.nodes:
|
|
|
|
self.wait_for_chainlocked_block(node, cl_block.hash)
|
2021-10-21 13:11:00 +02:00
|
|
|
# Previous tip should be marked as conflicting now
|
|
|
|
assert_equal(node.getchaintips(2)[1]["status"], "conflicting")
|
2021-05-11 18:50:14 +02:00
|
|
|
|
2020-11-17 20:40:15 +01:00
|
|
|
def create_chainlock(self, height, block):
|
|
|
|
request_id_buf = ser_string(b"clsig") + struct.pack("<I", height)
|
|
|
|
request_id = hash256(request_id_buf)[::-1].hex()
|
|
|
|
message_hash = block.hash
|
2019-05-07 14:14:33 +02:00
|
|
|
|
2023-05-07 04:36:45 +02:00
|
|
|
recSig = self.get_recovered_sig(request_id, message_hash)
|
2021-07-31 21:23:16 +02:00
|
|
|
clsig = msg_clsig(height, block.sha256, bytes.fromhex(recSig['sig']))
|
2019-05-07 14:14:33 +02:00
|
|
|
return clsig
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
LLMQ_IS_CL_Conflicts().main()
|