Skip to content
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

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

Merged
merged 3 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -175,6 +175,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.");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not it be JSONRPCError?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For whatever reason all such messages are thrown this way 🤷‍♂️
https://github.com/search?q=repo%3Abitcoin%2Fbitcoin+%22%28-regtest+mode%29%22&type=code

}

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