mirror of
https://github.com/dashpay/dash.git
synced 2024-12-24 11:32:46 +01:00
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 fromede1833ba4
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, ACK1e17b74207
PastaPastaPasta: utACK1e17b74207
Tree-SHA512: 83c1c07d0066e26202fd21942a09e41c3560c4d32229b44390946c4acb22319b32aa61a13b9106d20fc8cc197dd2a8ab5fdfcfdeaf3da76af062fc0fd7646972
This commit is contained in:
commit
85764c4b73
@ -3486,8 +3486,7 @@ void CConnman::ThreadOpenMasternodeConnections(CDeterministicMNManager& dmnman,
|
||||
|
||||
didConnect = false;
|
||||
|
||||
if (!fNetworkActive || !mn_sync.IsBlockchainSynced())
|
||||
continue;
|
||||
if (!fNetworkActive || !m_masternode_thread_active || !mn_sync.IsBlockchainSynced()) continue;
|
||||
|
||||
std::set<CService> connectedNodes;
|
||||
std::map<uint256 /*proTxHash*/, bool /*fInbound*/> connectedProRegTxHashes;
|
||||
|
@ -1223,6 +1223,8 @@ public:
|
||||
bool GetNetworkActive() const { return fNetworkActive; };
|
||||
bool GetUseAddrmanOutgoing() const { return m_use_addrman_outgoing; };
|
||||
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; }
|
||||
|
||||
enum class MasternodeConn {
|
||||
@ -1721,6 +1723,7 @@ private:
|
||||
|
||||
std::vector<ListenSocket> vhListenSocket;
|
||||
std::atomic<bool> fNetworkActive{true};
|
||||
std::atomic<bool> m_masternode_thread_active{true};
|
||||
bool fAddressesInitialized{false};
|
||||
AddrMan& addrman;
|
||||
const NetGroupManager& m_netgroupman;
|
||||
|
@ -178,6 +178,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
|
||||
{ "prioritisetransaction", 1, "fee_delta" },
|
||||
{ "setban", 2, "bantime" },
|
||||
{ "setban", 3, "absolute" },
|
||||
{ "setmnthreadactive", 0, "state" },
|
||||
{ "setnetworkactive", 0, "state" },
|
||||
{ "setcoinjoinrounds", 0, "rounds" },
|
||||
{ "setcoinjoinamount", 0, "amount" },
|
||||
|
@ -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)
|
||||
{
|
||||
// clang-format off
|
||||
@ -1042,6 +1068,7 @@ static const CRPCCommand commands[] =
|
||||
|
||||
{ "hidden", &addconnection, },
|
||||
{ "hidden", &addpeeraddress, },
|
||||
{ "hidden", &setmnthreadactive },
|
||||
};
|
||||
// clang-format on
|
||||
for (const auto& c : commands) {
|
||||
|
@ -150,6 +150,7 @@ const std::vector<std::string> RPC_COMMANDS_SAFE_FOR_FUZZING{
|
||||
"reconsiderblock",
|
||||
"scantxoutset",
|
||||
"sendrawtransaction",
|
||||
"setmnthreadactive",
|
||||
"setmocktime",
|
||||
"setnetworkactive",
|
||||
"signmessagewithprivkey",
|
||||
|
@ -1083,6 +1083,8 @@ class MasternodeInfo:
|
||||
self.collateral_vout = collateral_vout
|
||||
self.addr = addr
|
||||
self.evo = evo
|
||||
self.node = None
|
||||
self.nodeIdx = None
|
||||
|
||||
|
||||
class DashTestFramework(BitcoinTestFramework):
|
||||
@ -1097,6 +1099,15 @@ class DashTestFramework(BitcoinTestFramework):
|
||||
"""Tests must override this method to define test logic"""
|
||||
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):
|
||||
self.mn_count = masterodes_count
|
||||
self.evo_count = evo_count
|
||||
@ -1432,17 +1443,12 @@ class DashTestFramework(BitcoinTestFramework):
|
||||
job.result()
|
||||
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()
|
||||
|
||||
# connect nodes
|
||||
for idx in range(0, self.mn_count):
|
||||
do_connect(idx)
|
||||
|
||||
def start_masternode(self, mninfo, extra_args=None):
|
||||
args = ['-masternodeblsprivkey=%s' % mninfo.keyOperator] + self.extra_args[mninfo.nodeIdx]
|
||||
if extra_args is not None:
|
||||
|
Loading…
Reference in New Issue
Block a user