Skip to content

Commit

Permalink
feat(tests): check that old masternode connections are dropped (#4863)
Browse files Browse the repository at this point in the history
* chore: Drop legacy ticks in CMasternodeUtils, use scheduler directly

* feat(tests): check that old masternode connections are dropped
  • Loading branch information
UdjinM6 authored Jun 7, 2022
1 parent 89ecf90 commit 2c54777
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2366,7 +2366,7 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA

node.scheduler->scheduleEvery(std::bind(&CNetFulfilledRequestManager::DoMaintenance, std::ref(netfulfilledman)), 60 * 1000);
node.scheduler->scheduleEvery(std::bind(&CMasternodeSync::DoMaintenance, std::ref(masternodeSync), std::ref(*node.connman)), 1 * 1000);
node.scheduler->scheduleEvery(std::bind(&CMasternodeUtils::DoMaintenance, std::ref(*node.connman)), 1 * 1000);
node.scheduler->scheduleEvery(std::bind(&CMasternodeUtils::DoMaintenance, std::ref(*node.connman)), 60 * 1000);
node.scheduler->scheduleEvery(std::bind(&CDeterministicMNManager::DoMaintenance, std::ref(*deterministicMNManager)), 10 * 1000);

if (!fDisableGovernance) {
Expand Down
20 changes: 4 additions & 16 deletions src/masternode/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
#include <util/ranges.h>


void CMasternodeUtils::ProcessMasternodeConnections(CConnman& connman)
void CMasternodeUtils::DoMaintenance(CConnman& connman)
{
if(!masternodeSync.IsBlockchainSynced() || ShutdownRequested())
return;

std::vector<CDeterministicMNCPtr> vecDmns; // will be empty when no wallet
#ifdef ENABLE_WALLET
for (const auto& pair : coinJoinClientManagers) {
Expand Down Expand Up @@ -77,18 +80,3 @@ void CMasternodeUtils::ProcessMasternodeConnections(CConnman& connman)
pnode->fDisconnect = true;
});
}

void CMasternodeUtils::DoMaintenance(CConnman& connman)
{
if(!masternodeSync.IsBlockchainSynced() || ShutdownRequested())
return;

static unsigned int nTick = 0;

nTick++;

if(nTick % 60 == 0) {
ProcessMasternodeConnections(connman);
}
}

1 change: 0 additions & 1 deletion src/masternode/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class CConnman;
class CMasternodeUtils
{
public:
static void ProcessMasternodeConnections(CConnman& connman);
static void DoMaintenance(CConnman &connman);
};

Expand Down
16 changes: 16 additions & 0 deletions test/functional/feature_llmq_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ def run_test(self):

self.check_reconnects(4)

self.log.info("check that old masternode conections are dropped")
removed = False
for mn in self.mninfo:
if len(mn.node.quorum("memberof", mn.proTxHash)) > 0:
try:
with mn.node.assert_debug_log(['removing masternodes quorum connections']):
with mn.node.assert_debug_log(['keeping mn quorum connections']):
self.mine_quorum()
mn.node.mockscheduler(60) # we check for old connections via the scheduler every 60 seconds
removed = True
except:
pass # it's ok to not remove connections sometimes
if removed:
break
assert removed # no way we removed none

def check_reconnects(self, expected_connection_count):
self.log.info("disable and re-enable networking on all masternodes")
for mn in self.mninfo:
Expand Down

0 comments on commit 2c54777

Please sign in to comment.