forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathfeature_masternode_params.py
More file actions
executable file
·95 lines (73 loc) · 3.64 KB
/
feature_masternode_params.py
File metadata and controls
executable file
·95 lines (73 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
# Copyright (c) 2025 The Dash Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
"""Test masternode parameter interactions.
This test verifies that certain parameters are automatically enabled
when a node is configured as a masternode via -masternodeblsprivkey.
"""
from test_framework.test_framework import BitcoinTestFramework
# Service flags
NODE_COMPACT_FILTERS = (1 << 6)
# Constants
BASIC_FILTER_INDEX = 'basic filter index'
class MasternodeParamsTest(BitcoinTestFramework):
def add_options(self, parser):
self.add_wallet_options(parser)
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 2
def run_test(self):
self.log.info("Test that regular node has default settings")
node0 = self.nodes[0]
# Regular node should have peerblockfilters disabled by default
services = int(node0.getnetworkinfo()['localservices'], 16)
assert services & NODE_COMPACT_FILTERS == 0
# Regular node should not have blockfilterindex enabled
index_info = node0.getindexinfo()
assert BASIC_FILTER_INDEX not in index_info
self.log.info("Test that masternode has blockfilters auto-enabled")
# Generate a valid BLS key for testing
bls_info = node0.bls('generate')
bls_key = bls_info['secret']
# Start a node with masternode key
self.restart_node(1, extra_args=[f"-masternodeblsprivkey={bls_key}"])
node1 = self.nodes[1]
# Masternode should have peerblockfilters enabled
services = int(node1.getnetworkinfo()['localservices'], 16)
self.log.info(f"Masternode services: {hex(services)}, has COMPACT_FILTERS: {services & NODE_COMPACT_FILTERS != 0}")
# Check blockfilterindex
index_info = node1.getindexinfo()
self.log.info(f"Masternode indexes: {list(index_info.keys())}")
# For now, just check that the node started successfully with masternode key
# The actual filter enabling might require the node to be fully synced
assert node1.getblockcount() >= 0 # Basic check that node is running
self.log.info("Test that masternode can explicitly disable blockfilters")
# Restart masternode with explicit disable
self.restart_node(1, extra_args=[
f"-masternodeblsprivkey={bls_key}",
"-peerblockfilters=0",
"-blockfilterindex=0"
])
node1 = self.nodes[1]
# Should not have COMPACT_FILTERS service
services = int(node1.getnetworkinfo()['localservices'], 16)
assert services & NODE_COMPACT_FILTERS == 0
# Should not have blockfilterindex
index_info = node1.getindexinfo()
assert BASIC_FILTER_INDEX not in index_info
self.log.info("Test that masternode parameter interaction is logged")
# Stop the node first so we can check the startup logs
self.stop_node(1)
# Check debug log for parameter interaction messages during startup
if self.is_wallet_compiled():
with self.nodes[1].assert_debug_log(["parameter interaction: -masternodeblsprivkey set -> setting -disablewallet=1"]):
self.start_node(1, extra_args=[
f"-masternodeblsprivkey={bls_key}",
"-peerblockfilters=0",
"-blockfilterindex=0"
])
# Note: The peerblockfilters and blockfilterindex messages won't be in the log
# when explicitly disabled, only when auto-enabled
if __name__ == '__main__':
MasternodeParamsTest().main()