Skip to content

Commit

Permalink
Merge #6286: feat(rpc): introduce and use setmnthreadactive (regtes…
Browse files Browse the repository at this point in the history
…t-only)

1e17b74 test: no longer connect nodes in parallel in `start_masternodes` (UdjinM6)
be72ef5 test: use `setmnthreadactive` to get controlable `connect_nodes` behaviour (UdjinM6)
e2ed82a 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. 1e17b74 is extracted from ede1833 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 1e17b74
  PastaPastaPasta:
    utACK 1e17b74

Tree-SHA512: 83c1c07d0066e26202fd21942a09e41c3560c4d32229b44390946c4acb22319b32aa61a13b9106d20fc8cc197dd2a8ab5fdfcfdeaf3da76af062fc0fd7646972
  • Loading branch information
PastaPastaPasta committed Sep 25, 2024
2 parents 4e72902 + 1e17b74 commit 85764c4
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -1223,6 +1223,8 @@ friend class CNode;
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 {
Expand Down Expand Up @@ -1721,6 +1723,7 @@ friend class CNode;

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;
Expand Down
1 change: 1 addition & 0 deletions src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
27 changes: 27 additions & 0 deletions src/rpc/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -1042,6 +1068,7 @@ static const CRPCCommand commands[] =

{ "hidden", &addconnection, },
{ "hidden", &addpeeraddress, },
{ "hidden", &setmnthreadactive },
};
// clang-format on
for (const auto& c : commands) {
Expand Down
1 change: 1 addition & 0 deletions src/test/fuzz/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ const std::vector<std::string> RPC_COMMANDS_SAFE_FOR_FUZZING{
"reconsiderblock",
"scantxoutset",
"sendrawtransaction",
"setmnthreadactive",
"setmocktime",
"setnetworkactive",
"signmessagewithprivkey",
Expand Down
24 changes: 15 additions & 9 deletions test/functional/test_framework/test_framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,8 @@ def __init__(self, proTxHash, ownerAddr, votingAddr, rewards_address, operator_r
self.collateral_vout = collateral_vout
self.addr = addr
self.evo = evo
self.node = None
self.nodeIdx = None


class DashTestFramework(BitcoinTestFramework):
Expand All @@ -1097,6 +1099,15 @@ def run_test(self):
"""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
Expand Down Expand Up @@ -1432,17 +1443,12 @@ def do_connect(idx):
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:
Expand Down

0 comments on commit 85764c4

Please sign in to comment.