Skip to content

Commit be84075

Browse files
committed
refactor: drop fMasternodeMode global
We don't initialize mn_activeman in TestingSetup so we don't need to set `connOptions.m_active_masternode`
1 parent 562ad2b commit be84075

File tree

7 files changed

+15
-14
lines changed

7 files changed

+15
-14
lines changed

src/governance/governance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ int CGovernanceManager::RequestGovernanceObjectVotes(const std::vector<CNode*>&
13601360
// Don't try to sync any data from outbound non-relay "masternode" connections.
13611361
// Inbound connection this early is most likely a "masternode" connection
13621362
// initiated from another node, so skip it too.
1363-
if (!pnode->CanRelay() || (fMasternodeMode && pnode->IsInboundConn())) continue;
1363+
if (!pnode->CanRelay() || (connman.IsActiveMasternode() && pnode->IsInboundConn())) continue;
13641364
// stop early to prevent setAskFor overflow
13651365
{
13661366
LOCK(::cs_main);

src/init.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1692,19 +1692,15 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
16921692
}
16931693
}
16941694

1695-
fMasternodeMode = false;
16961695
std::string strMasterNodeBLSPrivKey = args.GetArg("-masternodeblsprivkey", "");
16971696
if (!strMasterNodeBLSPrivKey.empty()) {
16981697
CBLSSecretKey keyOperator(ParseHex(strMasterNodeBLSPrivKey));
16991698
if (!keyOperator.IsValid()) {
17001699
return InitError(_("Invalid masternodeblsprivkey. Please see documentation."));
17011700
}
1702-
fMasternodeMode = true;
1703-
{
1704-
// Create and register mn_activeman, will init later in ThreadImport
1705-
node.mn_activeman = std::make_unique<CActiveMasternodeManager>(keyOperator, *node.connman, node.dmnman);
1706-
RegisterValidationInterface(node.mn_activeman.get());
1707-
}
1701+
// Create and register mn_activeman, will init later in ThreadImport
1702+
node.mn_activeman = std::make_unique<CActiveMasternodeManager>(keyOperator, *node.connman, node.dmnman);
1703+
RegisterValidationInterface(node.mn_activeman.get());
17081704
}
17091705

17101706
// Check port numbers
@@ -2428,6 +2424,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
24282424
connOptions.nMaxOutboundLimit = *opt_max_upload;
24292425
connOptions.m_peer_connect_timeout = peer_connect_timeout;
24302426
connOptions.socketEventsMode = ::g_socket_events_mode;
2427+
connOptions.m_active_masternode = node.mn_activeman != nullptr;
24312428

24322429
// Port to bind to if `-bind=addr` is provided without a `:port` suffix.
24332430
const uint16_t default_bind_port =

src/masternode/sync.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ void CMasternodeSync::ProcessTick(const PeerManager& peerman, const CGovernanceM
124124

125125
// reset the sync process if the last call to this function was more than 60 minutes ago (client was in sleep mode)
126126
static int64_t nTimeLastProcess = GetTime();
127-
if (!Params().IsMockableChain() && GetTime() - nTimeLastProcess > 60 * 60 && !fMasternodeMode) {
127+
if (!Params().IsMockableChain() && GetTime() - nTimeLastProcess > 60 * 60 && !connman.IsActiveMasternode()) {
128128
LogPrintf("CMasternodeSync::ProcessTick -- WARNING: no actions for too long, restarting sync...\n");
129129
Reset(true);
130130
nTimeLastProcess = GetTime();
@@ -157,7 +157,7 @@ void CMasternodeSync::ProcessTick(const PeerManager& peerman, const CGovernanceM
157157
// Don't try to sync any data from outbound non-relay "masternode" connections.
158158
// Inbound connection this early is most likely a "masternode" connection
159159
// initiated from another node, so skip it too.
160-
if (!pnode->CanRelay() || (fMasternodeMode && pnode->IsInboundConn())) continue;
160+
if (!pnode->CanRelay() || (connman.IsActiveMasternode() && pnode->IsInboundConn())) continue;
161161

162162
{
163163
if ((pnode->HasPermission(NetPermissionFlags::NoBan) || pnode->IsManualConn()) && !m_netfulfilledman.HasFulfilledRequest(pnode->addr, strAllow)) {

src/net.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,7 +1801,7 @@ bool CConnman::AttemptToEvictConnection()
18011801
if (node->fDisconnect)
18021802
continue;
18031803

1804-
if (fMasternodeMode) {
1804+
if (m_active_masternode) {
18051805
// This handles eviction protected nodes. Nodes are always protected for a short time after the connection
18061806
// was accepted. This short time is meant for the VERSION/VERACK exchange and the possible MNAUTH that might
18071807
// follow when the incoming connection is from another masternode. When a message other than MNAUTH
@@ -1971,7 +1971,7 @@ void CConnman::CreateNodeFromAcceptedSocket(std::unique_ptr<Sock>&& sock,
19711971
}
19721972

19731973
// don't accept incoming connections until blockchain is synced
1974-
if (fMasternodeMode && !mn_sync.IsBlockchainSynced()) {
1974+
if (m_active_masternode && !mn_sync.IsBlockchainSynced()) {
19751975
LogPrint(BCLog::NET_NETCONN, "AcceptConnection -- blockchain is not synced yet, skipping inbound connection attempt\n");
19761976
return;
19771977
}

src/net.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,7 @@ friend class CNode;
11941194
std::vector<std::string> m_added_nodes;
11951195
SocketEventsMode socketEventsMode = SocketEventsMode::Select;
11961196
bool m_i2p_accept_incoming;
1197+
bool m_active_masternode = false;
11971198
};
11981199

11991200
void Init(const Options& connOptions) EXCLUSIVE_LOCKS_REQUIRED(!m_added_nodes_mutex, !m_total_bytes_sent_mutex)
@@ -1231,6 +1232,7 @@ friend class CNode;
12311232
}
12321233
socketEventsMode = connOptions.socketEventsMode;
12331234
m_onion_binds = connOptions.onion_binds;
1235+
m_active_masternode = connOptions.m_active_masternode;
12341236
}
12351237

12361238
CConnman(uint64_t seed0, uint64_t seed1, AddrMan& addrman, const NetGroupManager& netgroupman,
@@ -1255,6 +1257,7 @@ friend class CNode;
12551257
void SetNetworkActive(bool active, CMasternodeSync* const mn_sync);
12561258
bool GetMasternodeThreadActive() const { return m_masternode_thread_active; };
12571259
void SetMasternodeThreadActive(bool active) { m_masternode_thread_active = active; };
1260+
bool IsActiveMasternode() const { return m_active_masternode; }
12581261
SocketEventsMode GetSocketEventsMode() const { return socketEventsMode; }
12591262

12601263
enum class MasternodeConn {
@@ -1840,6 +1843,9 @@ friend class CNode;
18401843
*/
18411844
std::unique_ptr<i2p::sam::Session> m_i2p_sam_session;
18421845

1846+
/** Flag for activating masternode mode */
1847+
bool m_active_masternode{false};
1848+
18431849
SocketEventsMode socketEventsMode;
18441850
std::unique_ptr<EdgeTriggeredEvents> m_edge_trig_events{nullptr};
18451851
std::unique_ptr<WakeupPipe> m_wakeup_pipe{nullptr};

src/util/system.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@
8080
const int64_t nStartupTime = GetTime();
8181

8282
//Dash only features
83-
bool fMasternodeMode = false;
8483
const std::string gCoinJoinName = "CoinJoin";
8584

8685
/**

src/util/system.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
//Dash only features
3838

39-
extern bool fMasternodeMode;
4039
extern int nWalletBackups;
4140
extern const std::string gCoinJoinName;
4241

0 commit comments

Comments
 (0)