Repository navigation
fix: refuse to start a masternode with settings that silently skip its duties #7754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
23c18d5
b42f43a
cac35f8
67e6850
5c3a3e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| Masternode configuration | ||
| ------------------------ | ||
|
|
||
| A masternode (`-masternodeblsprivkey`) now refuses to start unless: | ||
|
|
||
| * `-blocksonly=0` | ||
| * `-peerblockfilters=1` | ||
| * `-maxuploadtarget=0` | ||
| * `-minrelaytxfee`, `-incrementalrelayfee`, `-dustrelayfee` and `-bytespersigop` are not above | ||
| their defaults | ||
| * `-datacarrier=1`, `-datacarriersize` is not below its default and `-permitbaremultisig=1` | ||
| * `-limitancestorcount`, `-limitancestorsize`, `-limitdescendantcount`, `-limitdescendantsize`, | ||
| `-maxmempool` and `-mempoolexpiry` are not below their defaults | ||
|
|
||
| The relay policy checks do not apply on regtest. |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -100,3 +100,33 @@ std::optional<bilingual_str> ApplyArgsManOptions(const ArgsManager& argsman, con | |||||||||||||
|
|
||||||||||||||
| return std::nullopt; | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| std::vector<std::string> GetStricterThanDefaultRelayPolicy(const MemPoolOptions& mempool_opts) | ||||||||||||||
| { | ||||||||||||||
| const MemPoolOptions defaults{}; | ||||||||||||||
| std::vector<std::string> stricter; | ||||||||||||||
|
Comment on lines
+104
to
+107
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Blocking: Reject reduced mempool capacity for masternodes
Suggested change
source:
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved (re-reviewed at |
||||||||||||||
| // -incrementalrelayfee also raises the minimum relay fee unless -minrelaytxfee is set explicitly. | ||||||||||||||
| if (mempool_opts.incremental_relay_feerate > defaults.incremental_relay_feerate) { | ||||||||||||||
| stricter.emplace_back("-incrementalrelayfee"); | ||||||||||||||
| } else if (mempool_opts.min_relay_feerate > defaults.min_relay_feerate) { | ||||||||||||||
| stricter.emplace_back("-minrelaytxfee"); | ||||||||||||||
| } | ||||||||||||||
| if (mempool_opts.dust_relay_feerate > defaults.dust_relay_feerate) stricter.emplace_back("-dustrelayfee"); | ||||||||||||||
| if (mempool_opts.max_datacarrier_bytes.value_or(0) < defaults.max_datacarrier_bytes.value_or(0)) { | ||||||||||||||
| stricter.emplace_back("-datacarrier/-datacarriersize"); | ||||||||||||||
| } | ||||||||||||||
| if (!mempool_opts.permit_bare_multisig && defaults.permit_bare_multisig) | ||||||||||||||
| stricter.emplace_back("-permitbaremultisig"); | ||||||||||||||
| if (mempool_opts.limits.ancestor_count < defaults.limits.ancestor_count) | ||||||||||||||
| stricter.emplace_back("-limitancestorcount"); | ||||||||||||||
| if (mempool_opts.limits.ancestor_size_vbytes < defaults.limits.ancestor_size_vbytes) | ||||||||||||||
| stricter.emplace_back("-limitancestorsize"); | ||||||||||||||
| if (mempool_opts.limits.descendant_count < defaults.limits.descendant_count) | ||||||||||||||
| stricter.emplace_back("-limitdescendantcount"); | ||||||||||||||
| if (mempool_opts.limits.descendant_size_vbytes < defaults.limits.descendant_size_vbytes) | ||||||||||||||
| stricter.emplace_back("-limitdescendantsize"); | ||||||||||||||
| // A full smaller mempool evicts transactions a default-sized one keeps and raises its fee floor. | ||||||||||||||
| if (mempool_opts.max_size_bytes < defaults.max_size_bytes) stricter.emplace_back("-maxmempool"); | ||||||||||||||
| if (mempool_opts.expiry < defaults.expiry) stricter.emplace_back("-mempoolexpiry"); | ||||||||||||||
| return stricter; | ||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
Comment on lines
+128
to
+131
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Blocking: Include mempool expiry in the stricter-policy check
source:
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 5c3a3e0: 🤖 Posted autonomously by Claude on behalf of pasta.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resolved (re-reviewed at |
||||||||||||||
| } | ||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| // Copyright (c) 2026 The Dash Core developers | ||
| // Distributed under the MIT software license, see the accompanying | ||
| // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
|
||
| #include <chainparams.h> | ||
| #include <kernel/mempool_options.h> | ||
| #include <node/mempool_args.h> | ||
| #include <util/system.h> | ||
|
|
||
| #include <test/util/setup_common.h> | ||
|
|
||
| #include <boost/test/unit_test.hpp> | ||
|
|
||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| BOOST_FIXTURE_TEST_SUITE(masternode_params_tests, BasicTestingSetup) | ||
|
|
||
| static std::vector<std::string> StricterFor(const std::vector<std::string>& args) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why brand-new test-suite but not a new scenario for existing
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🤖 Posted autonomously by Claude on behalf of pasta. |
||
| { | ||
| ArgsManager argsman; | ||
| std::vector<const char*> argv{"dashd"}; | ||
| for (const auto& arg : args) argv.push_back(arg.c_str()); | ||
| std::string error; | ||
| argsman.AddArg("-minrelaytxfee", "", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); | ||
| argsman.AddArg("-incrementalrelayfee", "", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); | ||
| argsman.AddArg("-dustrelayfee", "", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); | ||
| argsman.AddArg("-datacarrier", "", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); | ||
| argsman.AddArg("-datacarriersize", "", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); | ||
| argsman.AddArg("-permitbaremultisig", "", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); | ||
| argsman.AddArg("-limitancestorcount", "", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); | ||
| argsman.AddArg("-limitancestorsize", "", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); | ||
| argsman.AddArg("-limitdescendantcount", "", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); | ||
| argsman.AddArg("-limitdescendantsize", "", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); | ||
| argsman.AddArg("-maxmempool", "", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); | ||
| argsman.AddArg("-mempoolexpiry", "", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS); | ||
| BOOST_REQUIRE(argsman.ParseParameters(argv.size(), argv.data(), error)); | ||
| kernel::MemPoolOptions opts{}; | ||
| BOOST_REQUIRE(!ApplyArgsManOptions(argsman, Params(), opts)); | ||
| return GetStricterThanDefaultRelayPolicy(opts); | ||
| } | ||
|
|
||
| BOOST_AUTO_TEST_CASE(default_relay_policy_is_not_stricter) | ||
| { | ||
| BOOST_CHECK(StricterFor({}).empty()); | ||
| } | ||
|
|
||
| BOOST_AUTO_TEST_CASE(looser_relay_policy_is_not_stricter) | ||
| { | ||
| BOOST_CHECK(StricterFor({"-minrelaytxfee=0.000001", "-limitancestorcount=50", "-datacarriersize=160", | ||
| "-maxmempool=301", "-mempoolexpiry=337"}) | ||
| .empty()); | ||
| } | ||
|
|
||
| BOOST_AUTO_TEST_CASE(each_stricter_relay_option_is_reported) | ||
| { | ||
| using V = std::vector<std::string>; | ||
| BOOST_CHECK(StricterFor({"-minrelaytxfee=0.001"}) == V{"-minrelaytxfee"}); | ||
| BOOST_CHECK(StricterFor({"-incrementalrelayfee=0.001"}) == V{"-incrementalrelayfee"}); | ||
| BOOST_CHECK(StricterFor({"-dustrelayfee=0.001"}) == V{"-dustrelayfee"}); | ||
| BOOST_CHECK(StricterFor({"-datacarrier=0"}) == V{"-datacarrier/-datacarriersize"}); | ||
| // An asset lock carries a two-byte OP_RETURN, which a smaller limit makes nonstandard. | ||
| BOOST_CHECK(StricterFor({"-datacarriersize=1"}) == V{"-datacarrier/-datacarriersize"}); | ||
| BOOST_CHECK(StricterFor({"-permitbaremultisig=0"}) == V{"-permitbaremultisig"}); | ||
| BOOST_CHECK(StricterFor({"-limitancestorcount=5"}) == V{"-limitancestorcount"}); | ||
| BOOST_CHECK(StricterFor({"-limitancestorsize=50"}) == V{"-limitancestorsize"}); | ||
| BOOST_CHECK(StricterFor({"-limitdescendantcount=5"}) == V{"-limitdescendantcount"}); | ||
| BOOST_CHECK(StricterFor({"-limitdescendantsize=50"}) == V{"-limitdescendantsize"}); | ||
| BOOST_CHECK(StricterFor({"-maxmempool=299"}) == V{"-maxmempool"}); | ||
| BOOST_CHECK(StricterFor({"-mempoolexpiry=335"}) == V{"-mempoolexpiry"}); | ||
| BOOST_CHECK(StricterFor({"-mempoolexpiry=-1"}) == V{"-mempoolexpiry"}); | ||
| } | ||
|
|
||
| BOOST_AUTO_TEST_SUITE_END() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #!/usr/bin/env python3 | ||
| # Copyright (c) 2026 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 that a masternode refuses a stricter-than-default relay policy outside regtest. | ||
|
|
||
| Regtest exempts masternodes from this check (see feature_llmq_is_retroactive.py), so it is | ||
| exercised on devnet here. | ||
| """ | ||
|
|
||
| from test_framework.test_framework import BitcoinTestFramework | ||
|
|
||
|
|
||
| class MasternodeParamsDevnetTest(BitcoinTestFramework): | ||
| def set_test_params(self): | ||
| self.setup_clean_chain = True | ||
| self.chain = "devnet" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why chain is devnet but not mainnet?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because it's a test?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To expand on that: the functional test framework can't run a mainnet node ( 🤖 Posted autonomously by Claude on behalf of pasta. |
||
| self.num_nodes = 1 | ||
|
|
||
| def run_test(self): | ||
| bls_key = self.nodes[0].bls('generate')['secret'] | ||
| self.stop_node(0) | ||
| mn_args = [f"-masternodeblsprivkey={bls_key}", "-listen=1"] | ||
| relay_policy_msg = ("Error: Masternode must not use a stricter transaction relay policy than the default, " | ||
| "which would make it skip InstantSend signing. Remove or restore: ") | ||
| for extra_args, flags in [ | ||
| (["-datacarrier=0"], "-datacarrier/-datacarriersize"), | ||
| (["-minrelaytxfee=0.001"], "-minrelaytxfee"), | ||
| (["-incrementalrelayfee=0.001"], "-incrementalrelayfee"), | ||
| (["-dustrelayfee=0.001", "-permitbaremultisig=0"], "-dustrelayfee, -permitbaremultisig"), | ||
| (["-limitancestorcount=5", "-limitdescendantsize=50"], "-limitancestorcount, -limitdescendantsize"), | ||
| (["-maxmempool=299"], "-maxmempool"), | ||
| (["-bytespersigop=21"], "-bytespersigop"), | ||
| (["-mempoolexpiry=335"], "-mempoolexpiry"), | ||
| ]: | ||
| self.log.info(f"Test that a masternode refuses {' '.join(extra_args)}") | ||
| self.nodes[0].assert_start_raises_init_error(extra_args=mn_args + extra_args, | ||
| expected_msg=relay_policy_msg + flags) | ||
|
|
||
| self.log.info("Test that a looser relay policy is still allowed") | ||
| self.start_node(0, extra_args=mn_args + ["-minrelaytxfee=0.000001", "-limitancestorcount=50", "-datacarriersize=160", | ||
| "-maxmempool=301", "-bytespersigop=19", "-mempoolexpiry=337"]) | ||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| MasternodeParamsDevnetTest().main() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
either move this function from public namespace to test suite, either use it all over codebase.
The only usage of its a regression test and that's a wrong location for this funciton.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It isn't test-only: the production caller is the masternode startup check in
AppInitParameterInteraction(src/init.cpp:1432at 67e6850), which refuses to start a masternode whose relay policy is stricter than the default. The unit test covers the helper directly because the init path can't exercise it on regtest, where that check is skipped. It sits next toApplyArgsManOptionsbecause it compares theMemPoolOptionsthat function produces against the defaults.🤖 Posted autonomously by Claude on behalf of pasta.