2019-01-23 07:08:13 +01:00
|
|
|
#!/usr/bin/env python3
|
2023-01-12 22:26:21 +01:00
|
|
|
# Copyright (c) 2015-2022 The Dash Core developers
|
2019-01-23 07:08:13 +01: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_chainlocks.py
|
2019-01-23 07:08:13 +01:00
|
|
|
|
|
|
|
Checks LLMQs based ChainLocks
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
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 time
|
|
|
|
|
|
|
|
from test_framework.test_framework import DashTestFramework
|
test: ensure that mining is possible without CL info (#5689)
## Issue being fixed or feature implemented
With DIP29 added to v20, miners include best CL Signature in CbTx.
The purpose of this test, is to ensure that mining is still possible
when CL information isn't available.
In such case, miners are expected to copy best CL Signature from CbTx of
previous block.
## What was done?
Two scenarios are implemented:
- Add dynamically a node, make sure `getbestchainlock()` fails, let it
mine a block.
- Disable `SPORK_19_CHAINLOCKS_ENABLED`, add dynamically a node, make
sure `getbestchainlock()` fails, let it mine a block.
In both tests, we make sure the block is accepted by everyone and that
the `bestCLSignature` in CbTx is copied from previous block.
## How Has This Been Tested?
`feature_llmq_chainlocks.py`
## Breaking Changes
no
## Checklist:
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [x] I have added or updated relevant unit/integration/functional/e2e
tests
- [ ] I have made corresponding changes to the documentation
- [x] I have assigned this pull request to a milestone _(for repository
code-owners and collaborators only)_
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-11-10 15:32:01 +01:00
|
|
|
from test_framework.util import force_finish_mnsync, 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
|
|
|
|
|
|
|
|
2019-01-23 07:08:13 +01:00
|
|
|
class LLMQChainLocksTest(DashTestFramework):
|
2019-09-24 00:57:30 +02:00
|
|
|
def set_test_params(self):
|
2023-11-20 17:17:04 +01:00
|
|
|
self.set_dash_test_params(5, 4, fast_dip3_enforcement=True)
|
2019-01-23 07:08:13 +01:00
|
|
|
|
|
|
|
def run_test(self):
|
|
|
|
|
2020-03-21 13:30:35 +01:00
|
|
|
# Connect all nodes to node1 so that we always have the whole network connected
|
|
|
|
# Otherwise only masternode connections will be established between nodes, which won't propagate TXs/blocks
|
|
|
|
# Usually node0 is the one that does this, but in this test we isolate it multiple times
|
|
|
|
for i in range(len(self.nodes)):
|
|
|
|
if i != 1:
|
2022-09-24 14:36:35 +02:00
|
|
|
self.connect_nodes(i, 1)
|
2020-03-21 13:30:35 +01:00
|
|
|
|
2020-12-28 12:21:01 +01:00
|
|
|
self.activate_dip8()
|
2019-03-22 11:51:50 +01:00
|
|
|
|
2023-05-09 05:34:26 +02:00
|
|
|
self.test_coinbase_best_cl(self.nodes[0], expected_cl_in_cb=False)
|
|
|
|
|
2023-11-07 15:03:03 +01:00
|
|
|
self.activate_v20(expected_activation_height=1200)
|
2023-05-09 05:34:26 +02:00
|
|
|
self.log.info("Activated v20 at height:" + str(self.nodes[0].getblockcount()))
|
|
|
|
|
2023-05-11 11:25:41 +02:00
|
|
|
# v20 is active for the next block, not for the tip
|
|
|
|
self.test_coinbase_best_cl(self.nodes[0], expected_cl_in_cb=False)
|
|
|
|
|
|
|
|
# v20 is active, no quorums, no CLs - null CL in CbTx
|
|
|
|
self.nodes[0].generate(1)
|
2023-05-09 05:34:26 +02:00
|
|
|
self.test_coinbase_best_cl(self.nodes[0], expected_cl_in_cb=True, expected_null_cl=True)
|
|
|
|
|
2022-06-18 18:52:45 +02:00
|
|
|
self.nodes[0].sporkupdate("SPORK_17_QUORUM_DKG_ENABLED", 0)
|
2019-01-23 07:08:13 +01:00
|
|
|
self.wait_for_sporks_same()
|
|
|
|
|
2023-11-20 17:17:04 +01:00
|
|
|
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-01-23 07:08:13 +01:00
|
|
|
|
2019-10-02 15:24:57 +02:00
|
|
|
self.log.info("Mine single block, wait for chainlock")
|
2019-01-23 07:08:13 +01:00
|
|
|
self.nodes[0].generate(1)
|
2019-10-02 15:24:57 +02:00
|
|
|
self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash())
|
2023-05-09 05:34:26 +02:00
|
|
|
self.test_coinbase_best_cl(self.nodes[0])
|
2019-01-23 07:08:13 +01:00
|
|
|
|
2019-10-02 15:24:57 +02:00
|
|
|
self.log.info("Mine many blocks, wait for chainlock")
|
2019-01-23 07:08:13 +01:00
|
|
|
self.nodes[0].generate(20)
|
2019-10-02 15:24:57 +02:00
|
|
|
# We need more time here due to 20 blocks being generated at once
|
|
|
|
self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash(), timeout=30)
|
2023-05-09 05:34:26 +02:00
|
|
|
self.test_coinbase_best_cl(self.nodes[0])
|
2019-01-23 07:08:13 +01:00
|
|
|
|
2019-10-02 15:24:57 +02:00
|
|
|
self.log.info("Assert that all blocks up until the tip are chainlocked")
|
2019-01-23 07:08:13 +01:00
|
|
|
for h in range(1, self.nodes[0].getblockcount()):
|
|
|
|
block = self.nodes[0].getblock(self.nodes[0].getblockhash(h))
|
2021-08-27 21:03:02 +02:00
|
|
|
assert block['chainlock']
|
2019-01-23 07:08:13 +01:00
|
|
|
|
2023-05-31 22:34:14 +02:00
|
|
|
# Update spork to SPORK_19_CHAINLOCKS_ENABLED and test its behaviour
|
|
|
|
self.nodes[0].sporkupdate("SPORK_19_CHAINLOCKS_ENABLED", 1)
|
|
|
|
self.wait_for_sporks_same()
|
|
|
|
|
|
|
|
# Generate new blocks and verify that they are not chainlocked
|
|
|
|
previous_block_hash = self.nodes[0].getbestblockhash()
|
|
|
|
for _ in range(2):
|
|
|
|
block_hash = self.nodes[0].generate(1)[0]
|
|
|
|
self.wait_for_chainlocked_block_all_nodes(block_hash, expected=False)
|
|
|
|
assert self.nodes[0].getblock(previous_block_hash)["chainlock"]
|
|
|
|
|
|
|
|
self.nodes[0].sporkupdate("SPORK_19_CHAINLOCKS_ENABLED", 0)
|
|
|
|
self.wait_for_sporks_same()
|
|
|
|
|
2019-10-02 15:24:57 +02:00
|
|
|
self.log.info("Isolate node, mine on another, and reconnect")
|
2022-09-24 14:36:35 +02:00
|
|
|
self.isolate_node(0)
|
2019-09-15 22:08:21 +02:00
|
|
|
node0_mining_addr = self.nodes[0].getnewaddress()
|
2019-01-23 07:08:13 +01:00
|
|
|
node0_tip = self.nodes[0].getbestblockhash()
|
2019-09-15 22:08:21 +02:00
|
|
|
self.nodes[1].generatetoaddress(5, node0_mining_addr)
|
2019-10-02 15:24:57 +02:00
|
|
|
self.wait_for_chainlocked_block(self.nodes[1], self.nodes[1].getbestblockhash())
|
2023-05-09 05:34:26 +02:00
|
|
|
self.test_coinbase_best_cl(self.nodes[0])
|
2021-08-27 21:03:02 +02:00
|
|
|
assert self.nodes[0].getbestblockhash() == node0_tip
|
2022-09-24 14:36:35 +02:00
|
|
|
self.reconnect_isolated_node(0, 1)
|
2019-09-15 22:08:21 +02:00
|
|
|
self.nodes[1].generatetoaddress(1, node0_mining_addr)
|
2021-05-11 18:55:40 +02:00
|
|
|
self.wait_for_chainlocked_block_all_nodes(self.nodes[1].getbestblockhash())
|
2023-05-09 05:34:26 +02:00
|
|
|
self.test_coinbase_best_cl(self.nodes[0])
|
2019-01-23 07:08:13 +01:00
|
|
|
|
2019-10-02 15:24:57 +02:00
|
|
|
self.log.info("Isolate node, mine on both parts of the network, and reconnect")
|
2022-09-24 14:36:35 +02:00
|
|
|
self.isolate_node(0)
|
2021-01-16 20:47:13 +01:00
|
|
|
bad_tip = self.nodes[0].generate(5)[-1]
|
2019-09-15 22:08:21 +02:00
|
|
|
self.nodes[1].generatetoaddress(1, node0_mining_addr)
|
2019-01-23 07:08:13 +01:00
|
|
|
good_tip = self.nodes[1].getbestblockhash()
|
2019-10-02 15:24:57 +02:00
|
|
|
self.wait_for_chainlocked_block(self.nodes[1], good_tip)
|
2021-08-27 21:03:02 +02:00
|
|
|
assert not self.nodes[0].getblock(self.nodes[0].getbestblockhash())["chainlock"]
|
2022-09-24 14:36:35 +02:00
|
|
|
self.reconnect_isolated_node(0, 1)
|
2019-09-15 22:08:21 +02:00
|
|
|
self.nodes[1].generatetoaddress(1, node0_mining_addr)
|
2021-05-11 18:55:40 +02:00
|
|
|
self.wait_for_chainlocked_block_all_nodes(self.nodes[1].getbestblockhash())
|
2023-05-09 05:34:26 +02:00
|
|
|
self.test_coinbase_best_cl(self.nodes[0])
|
2021-08-27 21:03:02 +02:00
|
|
|
assert self.nodes[0].getblock(self.nodes[0].getbestblockhash())["previousblockhash"] == good_tip
|
|
|
|
assert self.nodes[1].getblock(self.nodes[1].getbestblockhash())["previousblockhash"] == good_tip
|
2019-01-23 07:08:13 +01:00
|
|
|
|
2021-01-16 20:47:13 +01:00
|
|
|
self.log.info("The tip mined while this node was isolated should be marked conflicting now")
|
|
|
|
found = False
|
|
|
|
for tip in self.nodes[0].getchaintips(2):
|
|
|
|
if tip["hash"] == bad_tip:
|
2021-08-27 21:03:02 +02:00
|
|
|
assert tip["status"] == "conflicting"
|
2021-01-16 20:47:13 +01:00
|
|
|
found = True
|
|
|
|
break
|
2021-08-27 21:03:02 +02:00
|
|
|
assert found
|
2021-01-16 20:47:13 +01:00
|
|
|
|
2019-10-02 15:24:57 +02:00
|
|
|
self.log.info("Keep node connected and let it try to reorg the chain")
|
2019-01-23 07:08:13 +01:00
|
|
|
good_tip = self.nodes[0].getbestblockhash()
|
2021-01-16 20:47:13 +01:00
|
|
|
self.log.info("Restart it so that it forgets all the chainlock messages from the past")
|
2020-06-22 18:24:41 +02:00
|
|
|
self.restart_node(0)
|
2022-09-24 14:36:35 +02:00
|
|
|
self.connect_nodes(0, 1)
|
2021-08-27 21:03:02 +02:00
|
|
|
assert self.nodes[0].getbestblockhash() == good_tip
|
2021-01-21 17:18:25 +01:00
|
|
|
self.nodes[0].invalidateblock(good_tip)
|
2019-10-02 15:24:57 +02:00
|
|
|
self.log.info("Now try to reorg the chain")
|
2019-01-23 07:08:13 +01:00
|
|
|
self.nodes[0].generate(2)
|
2019-08-28 13:51:59 +02:00
|
|
|
time.sleep(6)
|
2021-08-27 21:03:02 +02:00
|
|
|
assert self.nodes[1].getbestblockhash() == good_tip
|
2021-01-21 17:18:25 +01:00
|
|
|
bad_tip = self.nodes[0].generate(2)[-1]
|
2019-08-28 13:51:59 +02:00
|
|
|
time.sleep(6)
|
2021-08-27 21:03:02 +02:00
|
|
|
assert self.nodes[0].getbestblockhash() == bad_tip
|
|
|
|
assert self.nodes[1].getbestblockhash() == good_tip
|
2019-01-23 07:08:13 +01:00
|
|
|
|
2019-10-02 15:24:57 +02:00
|
|
|
self.log.info("Now let the node which is on the wrong chain reorg back to the locked chain")
|
2019-01-23 07:08:13 +01:00
|
|
|
self.nodes[0].reconsiderblock(good_tip)
|
2021-08-27 21:03:02 +02:00
|
|
|
assert self.nodes[0].getbestblockhash() != good_tip
|
2021-01-21 17:18:25 +01:00
|
|
|
good_fork = good_tip
|
|
|
|
good_tip = self.nodes[1].generatetoaddress(1, node0_mining_addr)[-1] # this should mark bad_tip as conflicting
|
2021-05-11 18:55:40 +02:00
|
|
|
self.wait_for_chainlocked_block_all_nodes(good_tip)
|
2023-05-09 05:34:26 +02:00
|
|
|
self.test_coinbase_best_cl(self.nodes[0])
|
2021-08-27 21:03:02 +02:00
|
|
|
assert self.nodes[0].getbestblockhash() == good_tip
|
2021-01-21 17:18:25 +01:00
|
|
|
found = False
|
|
|
|
for tip in self.nodes[0].getchaintips(2):
|
|
|
|
if tip["hash"] == bad_tip:
|
2021-08-27 21:03:02 +02:00
|
|
|
assert tip["status"] == "conflicting"
|
2021-01-21 17:18:25 +01:00
|
|
|
found = True
|
|
|
|
break
|
2021-08-27 21:03:02 +02:00
|
|
|
assert found
|
2021-01-21 17:18:25 +01:00
|
|
|
|
|
|
|
self.log.info("Should switch to the best non-conflicting tip (not to the most work chain) on restart")
|
2021-08-27 21:03:02 +02:00
|
|
|
assert int(self.nodes[0].getblock(bad_tip)["chainwork"], 16) > int(self.nodes[1].getblock(good_tip)["chainwork"], 16)
|
2020-06-22 18:24:41 +02:00
|
|
|
self.restart_node(0)
|
2021-01-21 17:18:25 +01:00
|
|
|
self.nodes[0].invalidateblock(good_fork)
|
2020-06-22 18:24:41 +02:00
|
|
|
self.restart_node(0)
|
2021-01-21 17:18:25 +01:00
|
|
|
time.sleep(1)
|
2021-08-27 21:03:02 +02:00
|
|
|
assert self.nodes[0].getbestblockhash() == good_tip
|
2019-01-23 07:08:13 +01:00
|
|
|
|
2019-10-02 15:24:57 +02:00
|
|
|
self.log.info("Isolate a node and let it create some transactions which won't get IS locked")
|
2021-11-11 14:15:18 +01:00
|
|
|
force_finish_mnsync(self.nodes[0])
|
2022-09-24 14:36:35 +02:00
|
|
|
self.isolate_node(0)
|
2019-03-19 11:55:51 +01:00
|
|
|
txs = []
|
|
|
|
for i in range(3):
|
|
|
|
txs.append(self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 1))
|
|
|
|
txs += self.create_chained_txs(self.nodes[0], 1)
|
2019-10-02 15:24:57 +02:00
|
|
|
self.log.info("Assert that after block generation these TXs are NOT included (as they are \"unsafe\")")
|
2021-01-21 17:18:25 +01:00
|
|
|
node0_tip = self.nodes[0].generate(1)[-1]
|
2019-03-19 11:55:51 +01:00
|
|
|
for txid in txs:
|
|
|
|
tx = self.nodes[0].getrawtransaction(txid, 1)
|
2021-08-27 21:03:02 +02:00
|
|
|
assert "confirmations" not in tx
|
2019-08-28 13:51:59 +02:00
|
|
|
time.sleep(1)
|
2021-01-21 17:18:25 +01:00
|
|
|
node0_tip_block = self.nodes[0].getblock(node0_tip)
|
2021-08-27 21:03:02 +02:00
|
|
|
assert not node0_tip_block["chainlock"]
|
|
|
|
assert node0_tip_block["previousblockhash"] == good_tip
|
2019-10-02 15:24:57 +02:00
|
|
|
self.log.info("Disable LLMQ based InstantSend for a very short time (this never gets propagated to other nodes)")
|
2022-06-18 18:52:45 +02:00
|
|
|
self.nodes[0].sporkupdate("SPORK_2_INSTANTSEND_ENABLED", 4070908800)
|
2019-10-02 15:24:57 +02:00
|
|
|
self.log.info("Now the TXs should be included")
|
2019-03-19 11:55:51 +01:00
|
|
|
self.nodes[0].generate(1)
|
2022-06-18 18:52:45 +02:00
|
|
|
self.nodes[0].sporkupdate("SPORK_2_INSTANTSEND_ENABLED", 0)
|
2019-10-02 15:24:57 +02:00
|
|
|
self.log.info("Assert that TXs got included now")
|
2019-03-19 11:55:51 +01:00
|
|
|
for txid in txs:
|
|
|
|
tx = self.nodes[0].getrawtransaction(txid, 1)
|
2021-08-27 21:03:02 +02:00
|
|
|
assert "confirmations" in tx and tx["confirmations"] > 0
|
2019-03-19 11:55:51 +01:00
|
|
|
# Enable network on first node again, which will cause the blocks to propagate and IS locks to happen retroactively
|
|
|
|
# for the mined TXs, which will then allow the network to create a CLSIG
|
2021-07-17 21:15:21 +02:00
|
|
|
self.log.info("Re-enable network on first node and wait for chainlock")
|
2022-09-24 14:36:35 +02:00
|
|
|
self.reconnect_isolated_node(0, 1)
|
2019-12-06 10:05:58 +01:00
|
|
|
self.wait_for_chainlocked_block(self.nodes[0], self.nodes[0].getbestblockhash(), timeout=30)
|
2019-01-23 07:08:13 +01:00
|
|
|
|
test: ensure that mining is possible without CL info (#5689)
## Issue being fixed or feature implemented
With DIP29 added to v20, miners include best CL Signature in CbTx.
The purpose of this test, is to ensure that mining is still possible
when CL information isn't available.
In such case, miners are expected to copy best CL Signature from CbTx of
previous block.
## What was done?
Two scenarios are implemented:
- Add dynamically a node, make sure `getbestchainlock()` fails, let it
mine a block.
- Disable `SPORK_19_CHAINLOCKS_ENABLED`, add dynamically a node, make
sure `getbestchainlock()` fails, let it mine a block.
In both tests, we make sure the block is accepted by everyone and that
the `bestCLSignature` in CbTx is copied from previous block.
## How Has This Been Tested?
`feature_llmq_chainlocks.py`
## Breaking Changes
no
## Checklist:
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [x] I have added or updated relevant unit/integration/functional/e2e
tests
- [ ] I have made corresponding changes to the documentation
- [x] I have assigned this pull request to a milestone _(for repository
code-owners and collaborators only)_
---------
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
2023-11-10 15:32:01 +01:00
|
|
|
for i in range(2):
|
|
|
|
self.log.info(f"{'Disable' if i == 0 else 'Enable'} Chainlock")
|
|
|
|
self.nodes[0].sporkupdate("SPORK_19_CHAINLOCKS_ENABLED", 4070908800 if i == 0 else 0)
|
|
|
|
self.wait_for_sporks_same()
|
|
|
|
|
|
|
|
self.log.info("Add a new node and let it sync")
|
|
|
|
self.dynamically_add_masternode(evo=False)
|
|
|
|
added_idx = len(self.nodes) - 1
|
|
|
|
assert_raises_rpc_error(-32603, "Unable to find any chainlock", self.nodes[added_idx].getbestchainlock)
|
|
|
|
|
|
|
|
self.log.info("Test that new node can mine without Chainlock info")
|
|
|
|
tip_0 = self.nodes[0].getblock(self.nodes[0].getbestblockhash(), 2)
|
|
|
|
self.nodes[added_idx].generate(1)
|
|
|
|
self.sync_blocks(self.nodes)
|
|
|
|
tip_1 = self.nodes[0].getblock(self.nodes[0].getbestblockhash(), 2)
|
|
|
|
assert_equal(tip_1['cbTx']['bestCLSignature'], tip_0['cbTx']['bestCLSignature'])
|
|
|
|
assert_equal(tip_1['cbTx']['bestCLHeightDiff'], tip_0['cbTx']['bestCLHeightDiff'] + 1)
|
|
|
|
|
2019-03-19 11:55:51 +01:00
|
|
|
def create_chained_txs(self, node, amount):
|
|
|
|
txid = node.sendtoaddress(node.getnewaddress(), amount)
|
|
|
|
tx = node.getrawtransaction(txid, 1)
|
|
|
|
inputs = []
|
|
|
|
valueIn = 0
|
|
|
|
for txout in tx["vout"]:
|
|
|
|
inputs.append({"txid": txid, "vout": txout["n"]})
|
|
|
|
valueIn += txout["value"]
|
|
|
|
outputs = {
|
|
|
|
node.getnewaddress(): round(float(valueIn) - 0.0001, 6)
|
|
|
|
}
|
|
|
|
|
|
|
|
rawtx = node.createrawtransaction(inputs, outputs)
|
2020-12-11 03:25:55 +01:00
|
|
|
rawtx = node.signrawtransactionwithwallet(rawtx)
|
2019-03-19 11:55:51 +01:00
|
|
|
rawtxid = node.sendrawtransaction(rawtx["hex"])
|
|
|
|
|
|
|
|
return [txid, rawtxid]
|
|
|
|
|
2023-05-09 05:34:26 +02:00
|
|
|
def test_coinbase_best_cl(self, node, expected_cl_in_cb=True, expected_null_cl=False):
|
|
|
|
block_hash = node.getbestblockhash()
|
|
|
|
block = node.getblock(block_hash, 2)
|
|
|
|
cbtx = block["cbTx"]
|
|
|
|
assert_equal(int(cbtx["version"]) > 2, expected_cl_in_cb)
|
|
|
|
if expected_cl_in_cb:
|
|
|
|
cb_height = int(cbtx["height"])
|
|
|
|
best_cl_height_diff = int(cbtx["bestCLHeightDiff"])
|
|
|
|
best_cl_signature = cbtx["bestCLSignature"]
|
|
|
|
assert_equal(expected_null_cl, int(best_cl_signature, 16) == 0)
|
|
|
|
if expected_null_cl:
|
|
|
|
# Null bestCLSignature is allowed.
|
|
|
|
# bestCLHeightDiff must be 0 if bestCLSignature is null
|
|
|
|
assert_equal(best_cl_height_diff, 0)
|
|
|
|
# Returning as no more tests can be conducted
|
|
|
|
return
|
|
|
|
best_cl_height = cb_height - best_cl_height_diff - 1
|
|
|
|
target_block_hash = node.getblockhash(best_cl_height)
|
|
|
|
# Verify CL signature
|
|
|
|
assert node.verifychainlock(target_block_hash, best_cl_signature, best_cl_height)
|
|
|
|
else:
|
|
|
|
assert "bestCLHeightDiff" not in cbtx and "bestCLSignature" not in cbtx
|
|
|
|
|
2019-01-23 07:08:13 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
LLMQChainLocksTest().main()
|