2023-03-11 18:42:27 +01:00
|
|
|
#!/usr/bin/env python3
|
2023-12-31 01:00:00 +01:00
|
|
|
# Copyright (c) 2015-2024 The Dash Core developers
|
2023-03-11 18:42:27 +01:00
|
|
|
# Distributed under the MIT software license, see the accompanying
|
|
|
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
'''
|
|
|
|
feature_dip3_v19.py
|
|
|
|
|
|
|
|
Checks DIP3 for v19
|
|
|
|
|
|
|
|
'''
|
|
|
|
from io import BytesIO
|
|
|
|
|
2024-01-15 20:35:29 +01:00
|
|
|
from test_framework.p2p import P2PInterface
|
2021-06-24 12:47:04 +02:00
|
|
|
from test_framework.messages import CBlock, CBlockHeader, CCbTx, CMerkleBlock, from_hex, hash256, msg_getmnlistd, \
|
2023-03-11 18:42:27 +01:00
|
|
|
QuorumId, ser_uint256
|
|
|
|
from test_framework.test_framework import DashTestFramework
|
|
|
|
from test_framework.util import (
|
2020-08-27 08:21:53 +02:00
|
|
|
assert_equal
|
2023-03-11 18:42:27 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class TestP2PConn(P2PInterface):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
self.last_mnlistdiff = None
|
|
|
|
|
|
|
|
def on_mnlistdiff(self, message):
|
|
|
|
self.last_mnlistdiff = message
|
|
|
|
|
|
|
|
def wait_for_mnlistdiff(self, timeout=30):
|
|
|
|
def received_mnlistdiff():
|
|
|
|
return self.last_mnlistdiff is not None
|
2020-08-27 08:21:53 +02:00
|
|
|
return self.wait_until(received_mnlistdiff, timeout=timeout)
|
2023-03-11 18:42:27 +01:00
|
|
|
|
|
|
|
def getmnlistdiff(self, base_block_hash, block_hash):
|
|
|
|
msg = msg_getmnlistd(base_block_hash, block_hash)
|
|
|
|
self.last_mnlistdiff = None
|
|
|
|
self.send_message(msg)
|
|
|
|
self.wait_for_mnlistdiff()
|
|
|
|
return self.last_mnlistdiff
|
|
|
|
|
|
|
|
|
|
|
|
class DIP3V19Test(DashTestFramework):
|
|
|
|
def set_test_params(self):
|
2024-08-15 09:35:37 +02:00
|
|
|
self.extra_args = [[
|
|
|
|
'-testactivationheight=v20@1200', # required otherwise mine_quorum("llmq_test [100]") fails
|
|
|
|
]] * 6
|
2024-08-27 12:30:39 +02:00
|
|
|
self.set_dash_test_params(6, 5, evo_count=2, extra_args=self.extra_args)
|
2023-03-11 18:42:27 +01:00
|
|
|
|
|
|
|
def run_test(self):
|
|
|
|
# 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
|
|
|
|
|
|
|
|
self.test_node = self.nodes[0].add_p2p_connection(TestP2PConn())
|
|
|
|
null_hash = format(0, "064x")
|
|
|
|
|
|
|
|
self.nodes[0].sporkupdate("SPORK_17_QUORUM_DKG_ENABLED", 0)
|
|
|
|
self.wait_for_sporks_same()
|
|
|
|
|
|
|
|
expected_updated = [mn.proTxHash for mn in self.mninfo]
|
|
|
|
b_0 = self.nodes[0].getbestblockhash()
|
|
|
|
self.test_getmnlistdiff(null_hash, b_0, {}, [], expected_updated)
|
|
|
|
|
2023-06-04 22:45:56 +02:00
|
|
|
mn_list_before = self.nodes[0].masternodelist()
|
|
|
|
pubkeyoperator_list_before = set([mn_list_before[e]["pubkeyoperator"] for e in mn_list_before])
|
|
|
|
|
2023-03-11 18:42:27 +01:00
|
|
|
self.activate_v19(expected_activation_height=900)
|
|
|
|
self.log.info("Activated v19 at height:" + str(self.nodes[0].getblockcount()))
|
|
|
|
|
2023-06-04 22:45:56 +02:00
|
|
|
mn_list_after = self.nodes[0].masternodelist()
|
|
|
|
pubkeyoperator_list_after = set([mn_list_after[e]["pubkeyoperator"] for e in mn_list_after])
|
|
|
|
|
|
|
|
self.log.info("pubkeyoperator should still be shown using legacy scheme")
|
|
|
|
assert_equal(pubkeyoperator_list_before, pubkeyoperator_list_after)
|
|
|
|
|
2023-03-11 18:42:27 +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)
|
|
|
|
|
2023-08-17 21:01:12 +02:00
|
|
|
evo_info_0 = self.dynamically_add_masternode(evo=True, rnd=7)
|
|
|
|
assert evo_info_0 is not None
|
2024-10-01 21:25:52 +02:00
|
|
|
self.generate(self.nodes[0], 8)
|
2024-10-01 18:06:39 +02:00
|
|
|
self.sync_blocks()
|
fix: check HPMNs duplicate on tx broadcast (#5257)
<!--
*** Please remove the following help text before submitting: ***
Provide a general summary of your changes in the Title above
Pull requests without a rationale and clear improvement may be closed
immediately.
Please provide clear motivation for your patch and explain how it
improves
Dash Core user experience or Dash Core developer experience
significantly:
* Any test improvements or new tests that improve coverage are always
welcome.
* All other changes should have accompanying unit tests (see
`src/test/`) or
functional tests (see `test/`). Contributors should note which tests
cover
modified code. If no tests exist for a region of modified code, new
tests
should accompany the change.
* Bug fixes are most welcome when they come with steps to reproduce or
an
explanation of the potential issue as well as reasoning for the way the
bug
was fixed.
* Features are welcome, but might be rejected due to design or scope
issues.
If a feature is based on a lot of dependencies, contributors should
first
consider building the system outside of Dash Core, if possible.
-->
## Issue being fixed or feature implemented
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->
Before this fix, uniqueness of HPMN `platformNodeID` was checked only
while processing a block containing a `ProRegTx` or a `ProUpServTx`.
This is not enough as a `ProRegTx` or `ProUpServTx` containing duplicate
HPMN `platformNodeID` must be rejected at tx broadcast level.
## What was done?
<!--- Describe your changes in detail -->
Checking uniqueness when calling respective RPC and when receiving such
txs.
## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->
## Breaking Changes
<!--- Please describe any breaking changes your code introduces -->
## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [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
**For repository code-owners and collaborators only**
- [x] I have assigned this pull request to a milestone
2023-03-16 17:28:38 +01:00
|
|
|
|
2023-08-17 21:01:12 +02:00
|
|
|
self.log.info("Checking that protxs with duplicate EvoNodes fields are rejected")
|
|
|
|
evo_info_1 = self.dynamically_add_masternode(evo=True, rnd=7, should_be_rejected=True)
|
|
|
|
assert evo_info_1 is None
|
|
|
|
self.dynamically_evo_update_service(evo_info_0, 8)
|
|
|
|
evo_info_2 = self.dynamically_add_masternode(evo=True, rnd=8, should_be_rejected=True)
|
|
|
|
assert evo_info_2 is None
|
|
|
|
evo_info_3 = self.dynamically_add_masternode(evo=True, rnd=9)
|
|
|
|
assert evo_info_3 is not None
|
2024-10-01 21:25:52 +02:00
|
|
|
self.generate(self.nodes[0], 8)
|
2024-10-01 18:06:39 +02:00
|
|
|
self.sync_blocks()
|
2023-08-17 21:01:12 +02:00
|
|
|
self.dynamically_evo_update_service(evo_info_0, 9, should_be_rejected=True)
|
fix: check HPMNs duplicate on tx broadcast (#5257)
<!--
*** Please remove the following help text before submitting: ***
Provide a general summary of your changes in the Title above
Pull requests without a rationale and clear improvement may be closed
immediately.
Please provide clear motivation for your patch and explain how it
improves
Dash Core user experience or Dash Core developer experience
significantly:
* Any test improvements or new tests that improve coverage are always
welcome.
* All other changes should have accompanying unit tests (see
`src/test/`) or
functional tests (see `test/`). Contributors should note which tests
cover
modified code. If no tests exist for a region of modified code, new
tests
should accompany the change.
* Bug fixes are most welcome when they come with steps to reproduce or
an
explanation of the potential issue as well as reasoning for the way the
bug
was fixed.
* Features are welcome, but might be rejected due to design or scope
issues.
If a feature is based on a lot of dependencies, contributors should
first
consider building the system outside of Dash Core, if possible.
-->
## Issue being fixed or feature implemented
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->
Before this fix, uniqueness of HPMN `platformNodeID` was checked only
while processing a block containing a `ProRegTx` or a `ProUpServTx`.
This is not enough as a `ProRegTx` or `ProUpServTx` containing duplicate
HPMN `platformNodeID` must be rejected at tx broadcast level.
## What was done?
<!--- Describe your changes in detail -->
Checking uniqueness when calling respective RPC and when receiving such
txs.
## How Has This Been Tested?
<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->
## Breaking Changes
<!--- Please describe any breaking changes your code introduces -->
## Checklist:
<!--- Go over all the following points, and put an `x` in all the boxes
that apply. -->
- [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
**For repository code-owners and collaborators only**
- [x] I have assigned this pull request to a milestone
2023-03-16 17:28:38 +01:00
|
|
|
|
2023-03-11 18:42:27 +01:00
|
|
|
revoke_protx = self.mninfo[-1].proTxHash
|
|
|
|
revoke_keyoperator = self.mninfo[-1].keyOperator
|
|
|
|
self.log.info(f"Trying to revoke proTx:{revoke_protx}")
|
2024-02-09 18:35:33 +01:00
|
|
|
self.test_revoke_protx(evo_info_3.nodeIdx, revoke_protx, revoke_keyoperator)
|
2023-03-11 18:42:27 +01:00
|
|
|
|
|
|
|
self.mine_quorum(llmq_type_name='llmq_test', llmq_type=100)
|
|
|
|
|
2023-05-31 22:34:30 +02:00
|
|
|
self.log.info("Checking that adding more regular MNs after v19 doesn't break DKGs and IS/CLs")
|
|
|
|
|
|
|
|
for i in range(6):
|
2023-08-17 21:01:12 +02:00
|
|
|
new_mn = self.dynamically_add_masternode(evo=False, rnd=(10 + i))
|
2023-05-31 22:34:30 +02:00
|
|
|
assert new_mn is not None
|
|
|
|
|
|
|
|
# mine more quorums and make sure everything still works
|
|
|
|
prev_quorum = None
|
|
|
|
for _ in range(5):
|
|
|
|
quorum = self.mine_quorum()
|
|
|
|
assert prev_quorum != quorum
|
|
|
|
|
|
|
|
self.wait_for_chainlocked_block_all_nodes(self.nodes[0].getbestblockhash())
|
2023-03-11 18:42:27 +01:00
|
|
|
|
2024-02-09 18:35:33 +01:00
|
|
|
def test_revoke_protx(self, node_idx, revoke_protx, revoke_keyoperator):
|
2023-03-11 18:42:27 +01:00
|
|
|
funds_address = self.nodes[0].getnewaddress()
|
2023-04-09 07:09:18 +02:00
|
|
|
fund_txid = self.nodes[0].sendtoaddress(funds_address, 1)
|
|
|
|
self.wait_for_instantlock(fund_txid, self.nodes[0])
|
2024-10-01 21:25:52 +02:00
|
|
|
tip = self.generate(self.nodes[0], 1)[0]
|
2023-04-09 07:09:18 +02:00
|
|
|
assert_equal(self.nodes[0].getrawtransaction(fund_txid, 1, tip)['confirmations'], 1)
|
2024-10-01 18:06:39 +02:00
|
|
|
self.sync_all()
|
2023-03-11 18:42:27 +01:00
|
|
|
|
2023-04-09 07:09:18 +02:00
|
|
|
protx_result = self.nodes[0].protx('revoke', revoke_protx, revoke_keyoperator, 1, funds_address)
|
|
|
|
self.wait_for_instantlock(protx_result, self.nodes[0])
|
2024-10-01 21:25:52 +02:00
|
|
|
tip = self.generate(self.nodes[0], 1)[0]
|
2023-04-09 07:09:18 +02:00
|
|
|
assert_equal(self.nodes[0].getrawtransaction(protx_result, 1, tip)['confirmations'], 1)
|
2024-02-09 18:35:33 +01:00
|
|
|
# Revoking a MN results in disconnects. Wait for disconnects to actually happen
|
|
|
|
# and then reconnect the corresponding node back to let sync_blocks finish correctly.
|
|
|
|
self.wait_until(lambda: self.nodes[node_idx].getconnectioncount() == 0)
|
|
|
|
self.connect_nodes(node_idx, 0)
|
2024-10-01 18:06:39 +02:00
|
|
|
self.sync_all()
|
2024-02-20 15:22:37 +01:00
|
|
|
self.log.info(f"Successfully revoked={revoke_protx}")
|
2023-03-11 18:42:27 +01:00
|
|
|
for mn in self.mninfo:
|
|
|
|
if mn.proTxHash == revoke_protx:
|
|
|
|
self.mninfo.remove(mn)
|
|
|
|
return
|
|
|
|
|
|
|
|
def test_getmnlistdiff(self, base_block_hash, block_hash, base_mn_list, expected_deleted, expected_updated):
|
|
|
|
d = self.test_getmnlistdiff_base(base_block_hash, block_hash)
|
|
|
|
|
|
|
|
# Assert that the deletedMNs and mnList fields are what we expected
|
|
|
|
assert_equal(set(d.deletedMNs), set([int(e, 16) for e in expected_deleted]))
|
|
|
|
assert_equal(set([e.proRegTxHash for e in d.mnList]), set(int(e, 16) for e in expected_updated))
|
|
|
|
|
|
|
|
# Build a new list based on the old list and the info from the diff
|
|
|
|
new_mn_list = base_mn_list.copy()
|
|
|
|
for e in d.deletedMNs:
|
|
|
|
new_mn_list.pop(format(e, '064x'))
|
|
|
|
for e in d.mnList:
|
|
|
|
new_mn_list[format(e.proRegTxHash, '064x')] = e
|
|
|
|
|
|
|
|
cbtx = CCbTx()
|
|
|
|
cbtx.deserialize(BytesIO(d.cbTx.vExtraPayload))
|
|
|
|
|
|
|
|
# Verify that the merkle root matches what we locally calculate
|
|
|
|
hashes = []
|
|
|
|
for mn in sorted(new_mn_list.values(), key=lambda mn: ser_uint256(mn.proRegTxHash)):
|
2023-06-11 19:29:00 +02:00
|
|
|
hashes.append(hash256(mn.serialize(with_version = False)))
|
2023-03-11 18:42:27 +01:00
|
|
|
merkle_root = CBlock.get_merkle_root(hashes)
|
|
|
|
assert_equal(merkle_root, cbtx.merkleRootMNList)
|
|
|
|
|
|
|
|
return new_mn_list
|
|
|
|
|
|
|
|
def test_getmnlistdiff_base(self, base_block_hash, block_hash):
|
|
|
|
hexstr = self.nodes[0].getblockheader(block_hash, False)
|
2021-06-24 12:47:04 +02:00
|
|
|
header = from_hex(CBlockHeader(), hexstr)
|
2023-03-11 18:42:27 +01:00
|
|
|
|
|
|
|
d = self.test_node.getmnlistdiff(int(base_block_hash, 16), int(block_hash, 16))
|
|
|
|
assert_equal(d.baseBlockHash, int(base_block_hash, 16))
|
|
|
|
assert_equal(d.blockHash, int(block_hash, 16))
|
|
|
|
|
|
|
|
# Check that the merkle proof is valid
|
|
|
|
proof = CMerkleBlock(header, d.merkleProof)
|
|
|
|
proof = proof.serialize().hex()
|
|
|
|
assert_equal(self.nodes[0].verifytxoutproof(proof), [d.cbTx.hash])
|
|
|
|
|
|
|
|
# Check if P2P messages match with RPCs
|
|
|
|
d2 = self.nodes[0].protx("diff", base_block_hash, block_hash)
|
|
|
|
assert_equal(d2["baseBlockHash"], base_block_hash)
|
|
|
|
assert_equal(d2["blockHash"], block_hash)
|
|
|
|
assert_equal(d2["cbTxMerkleTree"], d.merkleProof.serialize().hex())
|
|
|
|
assert_equal(d2["cbTx"], d.cbTx.serialize().hex())
|
|
|
|
assert_equal(set([int(e, 16) for e in d2["deletedMNs"]]), set(d.deletedMNs))
|
|
|
|
assert_equal(set([int(e["proRegTxHash"], 16) for e in d2["mnList"]]), set([e.proRegTxHash for e in d.mnList]))
|
|
|
|
assert_equal(set([QuorumId(e["llmqType"], int(e["quorumHash"], 16)) for e in d2["deletedQuorums"]]), set(d.deletedQuorums))
|
|
|
|
assert_equal(set([QuorumId(e["llmqType"], int(e["quorumHash"], 16)) for e in d2["newQuorums"]]), set([QuorumId(e.llmqType, e.quorumHash) for e in d.newQuorums]))
|
|
|
|
|
|
|
|
return d
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
DIP3V19Test().main()
|