Merge #6286: feat(rpc): introduce and use setmnthreadactive (regtest-only)

1e17b74207 test: no longer connect nodes in parallel in `start_masternodes` (UdjinM6)
be72ef5592 test: use `setmnthreadactive` to get controlable `connect_nodes` behaviour (UdjinM6)
e2ed82a7ae feat(rpc): introduce `setmnthreadactive` (regtest-only) (UdjinM6)

Pull request description:

  ## Issue being fixed or feature implemented
  This adds a new rpc command to enable/disable automatic masternode connections creation. We need this for #6276. 1e17b74207 is extracted from ede1833ba4 to avoid multiple jobs calling `setmnthreadactive` on the same node in parallel.

  ## What was done?
  Add `setmnthreadactive` rpc and use it

  ## How Has This Been Tested?
  run tests

  ## Breaking Changes
  n/a

  ## Checklist:
  - [x] I have performed a self-review of my own code
  - [ ] I have commented my code, particularly in hard-to-understand areas
  - [ ] 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

ACKs for top commit:
  kwvg:
    LGTM, ACK 1e17b74207
  PastaPastaPasta:
    utACK 1e17b74207

Tree-SHA512: 83c1c07d0066e26202fd21942a09e41c3560c4d32229b44390946c4acb22319b32aa61a13b9106d20fc8cc197dd2a8ab5fdfcfdeaf3da76af062fc0fd7646972
This commit is contained in:
pasta 2024-09-25 12:24:17 -05:00
commit 85764c4b73
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984
6 changed files with 48 additions and 11 deletions

View File

@ -3486,8 +3486,7 @@ void CConnman::ThreadOpenMasternodeConnections(CDeterministicMNManager& dmnman,
didConnect = false; didConnect = false;
if (!fNetworkActive || !mn_sync.IsBlockchainSynced()) if (!fNetworkActive || !m_masternode_thread_active || !mn_sync.IsBlockchainSynced()) continue;
continue;
std::set<CService> connectedNodes; std::set<CService> connectedNodes;
std::map<uint256 /*proTxHash*/, bool /*fInbound*/> connectedProRegTxHashes; std::map<uint256 /*proTxHash*/, bool /*fInbound*/> connectedProRegTxHashes;

View File

@ -1223,6 +1223,8 @@ public:
bool GetNetworkActive() const { return fNetworkActive; }; bool GetNetworkActive() const { return fNetworkActive; };
bool GetUseAddrmanOutgoing() const { return m_use_addrman_outgoing; }; bool GetUseAddrmanOutgoing() const { return m_use_addrman_outgoing; };
void SetNetworkActive(bool active, CMasternodeSync* const mn_sync); void SetNetworkActive(bool active, CMasternodeSync* const mn_sync);
bool GetMasternodeThreadActive() const { return m_masternode_thread_active; };
void SetMasternodeThreadActive(bool active) { m_masternode_thread_active = active; };
SocketEventsMode GetSocketEventsMode() const { return socketEventsMode; } SocketEventsMode GetSocketEventsMode() const { return socketEventsMode; }
enum class MasternodeConn { enum class MasternodeConn {
@ -1721,6 +1723,7 @@ private:
std::vector<ListenSocket> vhListenSocket; std::vector<ListenSocket> vhListenSocket;
std::atomic<bool> fNetworkActive{true}; std::atomic<bool> fNetworkActive{true};
std::atomic<bool> m_masternode_thread_active{true};
bool fAddressesInitialized{false}; bool fAddressesInitialized{false};
AddrMan& addrman; AddrMan& addrman;
const NetGroupManager& m_netgroupman; const NetGroupManager& m_netgroupman;

View File

@ -178,6 +178,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "prioritisetransaction", 1, "fee_delta" }, { "prioritisetransaction", 1, "fee_delta" },
{ "setban", 2, "bantime" }, { "setban", 2, "bantime" },
{ "setban", 3, "absolute" }, { "setban", 3, "absolute" },
{ "setmnthreadactive", 0, "state" },
{ "setnetworkactive", 0, "state" }, { "setnetworkactive", 0, "state" },
{ "setcoinjoinrounds", 0, "rounds" }, { "setcoinjoinrounds", 0, "rounds" },
{ "setcoinjoinamount", 0, "amount" }, { "setcoinjoinamount", 0, "amount" },

View File

@ -1019,6 +1019,32 @@ static RPCHelpMan addpeeraddress()
}; };
} }
static RPCHelpMan setmnthreadactive()
{
return RPCHelpMan{"setmnthreadactive",
"\nDisable/enable automatic masternode connections thread activity.\n",
{
{"state", RPCArg::Type::BOOL, RPCArg::Optional::NO, "true to enable the thread, false to disable"},
},
RPCResult{RPCResult::Type::BOOL, "", "The value that was passed in"},
RPCExamples{""},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
if (Params().NetworkIDString() != CBaseChainParams::REGTEST) {
throw std::runtime_error("setmnthreadactive is for regression testing (-regtest mode) only.");
}
const NodeContext& node = EnsureAnyNodeContext(request.context);
CConnman& connman = EnsureConnman(node);
connman.SetMasternodeThreadActive(request.params[0].get_bool());
return connman.GetMasternodeThreadActive();
},
};
}
void RegisterNetRPCCommands(CRPCTable &t) void RegisterNetRPCCommands(CRPCTable &t)
{ {
// clang-format off // clang-format off
@ -1042,6 +1068,7 @@ static const CRPCCommand commands[] =
{ "hidden", &addconnection, }, { "hidden", &addconnection, },
{ "hidden", &addpeeraddress, }, { "hidden", &addpeeraddress, },
{ "hidden", &setmnthreadactive },
}; };
// clang-format on // clang-format on
for (const auto& c : commands) { for (const auto& c : commands) {

View File

@ -150,6 +150,7 @@ const std::vector<std::string> RPC_COMMANDS_SAFE_FOR_FUZZING{
"reconsiderblock", "reconsiderblock",
"scantxoutset", "scantxoutset",
"sendrawtransaction", "sendrawtransaction",
"setmnthreadactive",
"setmocktime", "setmocktime",
"setnetworkactive", "setnetworkactive",
"signmessagewithprivkey", "signmessagewithprivkey",

View File

@ -1083,6 +1083,8 @@ class MasternodeInfo:
self.collateral_vout = collateral_vout self.collateral_vout = collateral_vout
self.addr = addr self.addr = addr
self.evo = evo self.evo = evo
self.node = None
self.nodeIdx = None
class DashTestFramework(BitcoinTestFramework): class DashTestFramework(BitcoinTestFramework):
@ -1097,6 +1099,15 @@ class DashTestFramework(BitcoinTestFramework):
"""Tests must override this method to define test logic""" """Tests must override this method to define test logic"""
raise NotImplementedError raise NotImplementedError
def connect_nodes(self, a, b):
for mn2 in self.mninfo:
if mn2.node is not None:
mn2.node.setmnthreadactive(False)
super().connect_nodes(a, b)
for mn2 in self.mninfo:
if mn2.node is not None:
mn2.node.setmnthreadactive(True)
def set_dash_test_params(self, num_nodes, masterodes_count, extra_args=None, fast_dip3_enforcement=False, evo_count=0): def set_dash_test_params(self, num_nodes, masterodes_count, extra_args=None, fast_dip3_enforcement=False, evo_count=0):
self.mn_count = masterodes_count self.mn_count = masterodes_count
self.evo_count = evo_count self.evo_count = evo_count
@ -1432,17 +1443,12 @@ class DashTestFramework(BitcoinTestFramework):
job.result() job.result()
jobs.clear() jobs.clear()
# connect nodes in parallel
for idx in range(0, self.mn_count):
jobs.append(executor.submit(do_connect, idx))
# wait for all nodes to connect
for job in jobs:
job.result()
jobs.clear()
executor.shutdown() executor.shutdown()
# connect nodes
for idx in range(0, self.mn_count):
do_connect(idx)
def start_masternode(self, mninfo, extra_args=None): def start_masternode(self, mninfo, extra_args=None):
args = ['-masternodeblsprivkey=%s' % mninfo.keyOperator] + self.extra_args[mninfo.nodeIdx] args = ['-masternodeblsprivkey=%s' % mninfo.keyOperator] + self.extra_args[mninfo.nodeIdx]
if extra_args is not None: if extra_args is not None: