Skip to content

Commit 4d629a0

Browse files
committed
refactor: limit fMasternodeMode usage in blockstorage, init, net_processing
1 parent a9cbdfc commit 4d629a0

File tree

6 files changed

+28
-25
lines changed

6 files changed

+28
-25
lines changed

src/init.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ void PrepareShutdown(NodeContext& node)
366366
delete pdsNotificationInterface;
367367
pdsNotificationInterface = nullptr;
368368
}
369-
if (fMasternodeMode) {
369+
if (node.mn_activeman) {
370370
UnregisterValidationInterface(node.mn_activeman.get());
371371
node.mn_activeman.reset();
372372
}
@@ -2316,7 +2316,7 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
23162316
node.scheduler->scheduleEvery(std::bind(&CGovernanceManager::DoMaintenance, std::ref(*node.govman), std::ref(*node.connman)), std::chrono::minutes{5});
23172317
}
23182318

2319-
if (fMasternodeMode) {
2319+
if (node.mn_activeman) {
23202320
node.scheduler->scheduleEvery(std::bind(&CCoinJoinServer::DoMaintenance, std::ref(*node.cj_ctx->server)), std::chrono::seconds{1});
23212321
node.scheduler->scheduleEvery(std::bind(&llmq::CDKGSessionManager::CleanupOldContributions, std::ref(*node.llmq_ctx->qdkgsman)), std::chrono::hours{1});
23222322
#ifdef ENABLE_WALLET

src/llmq/instantsend.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,7 +1062,7 @@ void CInstantSendManager::ProcessInstantSendLock(NodeId from, const uint256& has
10621062
// bump mempool counter to make sure newly locked txes are picked up by getblocktemplate
10631063
mempool.AddTransactionsUpdated(1);
10641064
} else {
1065-
AskNodesForLockedTx(islock->txid, connman, *m_peerman);
1065+
AskNodesForLockedTx(islock->txid, connman, *m_peerman, m_is_masternode);
10661066
}
10671067
}
10681068

@@ -1338,7 +1338,7 @@ void CInstantSendManager::RemoveMempoolConflictsForLock(const uint256& hash, con
13381338
for (const auto& p : toDelete) {
13391339
RemoveConflictedTx(*p.second);
13401340
}
1341-
AskNodesForLockedTx(islock.txid, connman, *m_peerman);
1341+
AskNodesForLockedTx(islock.txid, connman, *m_peerman, m_is_masternode);
13421342
}
13431343
}
13441344

@@ -1443,7 +1443,7 @@ void CInstantSendManager::RemoveConflictingLock(const uint256& islockHash, const
14431443
}
14441444
}
14451445

1446-
void CInstantSendManager::AskNodesForLockedTx(const uint256& txid, const CConnman& connman, const PeerManager& peerman)
1446+
void CInstantSendManager::AskNodesForLockedTx(const uint256& txid, const CConnman& connman, const PeerManager& peerman, bool is_masternode)
14471447
{
14481448
std::vector<CNode*> nodesToAskFor;
14491449
nodesToAskFor.reserve(4);
@@ -1476,7 +1476,7 @@ void CInstantSendManager::AskNodesForLockedTx(const uint256& txid, const CConnma
14761476
txid.ToString(), pnode->GetId());
14771477

14781478
CInv inv(MSG_TX, txid);
1479-
RequestObject(pnode->GetId(), inv, GetTime<std::chrono::microseconds>(), true);
1479+
RequestObject(pnode->GetId(), inv, GetTime<std::chrono::microseconds>(), is_masternode, /* fForce = */ true);
14801480
}
14811481
}
14821482
for (CNode* pnode : nodesToAskFor) {

src/llmq/instantsend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ class CInstantSendManager : public CRecoveredSigsListener
301301

302302
void RemoveMempoolConflictsForLock(const uint256& hash, const CInstantSendLock& islock);
303303
void ResolveBlockConflicts(const uint256& islockHash, const CInstantSendLock& islock) LOCKS_EXCLUDED(cs_pendingLocks, cs_nonLocked);
304-
static void AskNodesForLockedTx(const uint256& txid, const CConnman& connman, const PeerManager& peerman);
304+
static void AskNodesForLockedTx(const uint256& txid, const CConnman& connman, const PeerManager& peerman, bool is_masternode);
305305
void ProcessPendingRetryLockTxs() LOCKS_EXCLUDED(cs_creating, cs_nonLocked, cs_pendingRetry);
306306

307307
void WorkThreadMain();

src/net.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1564,7 +1564,7 @@ class CExplicitNetCleanup
15641564
extern RecursiveMutex cs_main;
15651565

15661566
void EraseObjectRequest(NodeId nodeId, const CInv& inv) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1567-
void RequestObject(NodeId nodeId, const CInv& inv, std::chrono::microseconds current_time, bool fForce=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1567+
void RequestObject(NodeId nodeId, const CInv& inv, std::chrono::microseconds current_time, bool is_masternode, bool fForce=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
15681568
size_t GetRequestedObjectCount(NodeId nodeId) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
15691569

15701570
/** Protect desirable or disadvantaged inbound peers from eviction by ratio.

src/net_processing.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,7 @@ std::chrono::microseconds GetObjectRandomDelay(int invType)
12591259
return {};
12601260
}
12611261

1262-
std::chrono::microseconds CalculateObjectGetDataTime(const CInv& inv, std::chrono::microseconds current_time, bool use_inbound_delay) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1262+
std::chrono::microseconds CalculateObjectGetDataTime(const CInv& inv, std::chrono::microseconds current_time, bool is_masternode, bool use_inbound_delay) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
12631263
{
12641264
AssertLockHeld(cs_main);
12651265
std::chrono::microseconds process_time;
@@ -1274,12 +1274,12 @@ std::chrono::microseconds CalculateObjectGetDataTime(const CInv& inv, std::chron
12741274
}
12751275

12761276
// We delay processing announcements from inbound peers
1277-
if (inv.IsMsgTx() && !fMasternodeMode && use_inbound_delay) process_time += INBOUND_PEER_TX_DELAY;
1277+
if (inv.IsMsgTx() && !is_masternode && use_inbound_delay) process_time += INBOUND_PEER_TX_DELAY;
12781278

12791279
return process_time;
12801280
}
12811281

1282-
void RequestObject(CNodeState* state, const CInv& inv, std::chrono::microseconds current_time, bool fForce = false) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1282+
void RequestObject(CNodeState* state, const CInv& inv, std::chrono::microseconds current_time, bool is_masternode, bool fForce = false) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
12831283
{
12841284
AssertLockHeld(cs_main);
12851285
CNodeState::ObjectDownloadState& peer_download_state = state->m_object_download;
@@ -1294,7 +1294,7 @@ void RequestObject(CNodeState* state, const CInv& inv, std::chrono::microseconds
12941294

12951295
// Calculate the time to try requesting this transaction. Use
12961296
// fPreferredDownload as a proxy for outbound peers.
1297-
std::chrono::microseconds process_time = CalculateObjectGetDataTime(inv, current_time, !state->fPreferredDownload);
1297+
std::chrono::microseconds process_time = CalculateObjectGetDataTime(inv, current_time, is_masternode, !state->fPreferredDownload);
12981298

12991299
peer_download_state.m_object_process_time.emplace(process_time, inv);
13001300

@@ -1307,14 +1307,14 @@ void RequestObject(CNodeState* state, const CInv& inv, std::chrono::microseconds
13071307
LogPrint(BCLog::NET, "%s -- inv=(%s), current_time=%d, process_time=%d, delta=%d\n", __func__, inv.ToString(), current_time.count(), process_time.count(), (process_time - current_time).count());
13081308
}
13091309

1310-
void RequestObject(NodeId nodeId, const CInv& inv, std::chrono::microseconds current_time, bool fForce) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1310+
void RequestObject(NodeId nodeId, const CInv& inv, std::chrono::microseconds current_time, bool is_masternode, bool fForce) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
13111311
{
13121312
AssertLockHeld(cs_main);
13131313
auto* state = State(nodeId);
13141314
if (!state) {
13151315
return;
13161316
}
1317-
RequestObject(state, inv, current_time, fForce);
1317+
RequestObject(state, inv, current_time, is_masternode, fForce);
13181318
}
13191319

13201320
size_t GetRequestedObjectCount(NodeId nodeId)
@@ -3127,6 +3127,7 @@ void PeerManagerImpl::ProcessMessage(
31273127
LogPrint(BCLog::NET, "received: %s (%u bytes) peer=%d\n", SanitizeString(msg_type), vRecv.size(), pfrom.GetId());
31283128
statsClient.inc("message.received." + SanitizeString(msg_type), 1.0f);
31293129

3130+
const bool is_masternode = m_mn_activeman != nullptr;
31303131

31313132
PeerRef peer = GetPeerRef(pfrom.GetId());
31323133
if (peer == nullptr) return;
@@ -3197,7 +3198,7 @@ void PeerManagerImpl::ProcessMessage(
31973198
pfrom.m_masternode_connection = fOtherMasternode;
31983199
if (fOtherMasternode) {
31993200
LogPrint(BCLog::NET_NETCONN, "peer=%d is an inbound masternode connection, not relaying anything to it\n", pfrom.GetId());
3200-
if (!fMasternodeMode) {
3201+
if (!is_masternode) {
32013202
LogPrint(BCLog::NET_NETCONN, "but we're not a masternode, disconnecting\n");
32023203
pfrom.fDisconnect = true;
32033204
return;
@@ -3374,8 +3375,8 @@ void PeerManagerImpl::ProcessMessage(
33743375
pfrom.ConnectionTypeAsString());
33753376
}
33763377

3377-
if (fMasternodeMode && !pfrom.m_masternode_probe_connection) {
3378-
CMNAuth::PushMNAUTH(pfrom, m_connman, *Assert(m_mn_activeman), m_chainman.ActiveChain().Tip());
3378+
if (is_masternode && !pfrom.m_masternode_probe_connection) {
3379+
CMNAuth::PushMNAUTH(pfrom, m_connman, *m_mn_activeman, m_chainman.ActiveChain().Tip());
33793380
}
33803381

33813382
// Tell our peer we prefer to receive headers rather than inv's
@@ -3674,7 +3675,7 @@ void PeerManagerImpl::ProcessMessage(
36743675
}
36753676
bool allowWhileInIBD = allowWhileInIBDObjs.count(inv.type);
36763677
if (allowWhileInIBD || !m_chainman.ActiveChainstate().IsInitialBlockDownload()) {
3677-
RequestObject(State(pfrom.GetId()), inv, current_time);
3678+
RequestObject(State(pfrom.GetId()), inv, current_time, is_masternode);
36783679
}
36793680
}
36803681
}
@@ -4026,11 +4027,11 @@ void PeerManagerImpl::ProcessMessage(
40264027
for (const uint256& parent_txid : unique_parents) {
40274028
CInv _inv(MSG_TX, parent_txid);
40284029
pfrom.AddKnownInventory(_inv.hash);
4029-
if (!AlreadyHave(_inv)) RequestObject(State(pfrom.GetId()), _inv, current_time);
4030+
if (!AlreadyHave(_inv)) RequestObject(State(pfrom.GetId()), _inv, current_time, is_masternode);
40304031
// We don't know if the previous tx was a regular or a mixing one, try both
40314032
CInv _inv2(MSG_DSTX, parent_txid);
40324033
pfrom.AddKnownInventory(_inv2.hash);
4033-
if (!AlreadyHave(_inv2)) RequestObject(State(pfrom.GetId()), _inv2, current_time);
4034+
if (!AlreadyHave(_inv2)) RequestObject(State(pfrom.GetId()), _inv2, current_time, is_masternode);
40344035
}
40354036
AddOrphanTx(ptx, pfrom.GetId());
40364037

@@ -4743,7 +4744,7 @@ void PeerManagerImpl::ProcessMessage(
47434744
ProcessPeerMsgRet(m_govman.ProcessMessage(pfrom, m_connman, *this, msg_type, vRecv), pfrom);
47444745
ProcessPeerMsgRet(CMNAuth::ProcessMessage(pfrom, m_connman, m_mn_metaman, m_mn_activeman, m_mn_sync, m_dmnman->GetListAtChainTip(), msg_type, vRecv), pfrom);
47454746
ProcessPeerMsgRet(m_llmq_ctx->quorum_block_processor->ProcessMessage(pfrom, msg_type, vRecv), pfrom);
4746-
ProcessPeerMsgRet(m_llmq_ctx->qdkgsman->ProcessMessage(pfrom, this, /* is_masternode = */ m_mn_activeman != nullptr, msg_type, vRecv), pfrom);
4747+
ProcessPeerMsgRet(m_llmq_ctx->qdkgsman->ProcessMessage(pfrom, this, is_masternode, msg_type, vRecv), pfrom);
47474748
ProcessPeerMsgRet(m_llmq_ctx->qman->ProcessMessage(pfrom, msg_type, vRecv), pfrom);
47484749
m_llmq_ctx->shareman->ProcessMessage(pfrom, m_sporkman, msg_type, vRecv);
47494750
ProcessPeerMsgRet(m_llmq_ctx->sigman->ProcessMessage(pfrom, this, msg_type, vRecv), pfrom);
@@ -5203,6 +5204,8 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
52035204
{
52045205
assert(m_llmq_ctx);
52055206

5207+
const bool is_masternode = m_mn_activeman != nullptr;
5208+
52065209
PeerRef peer = GetPeerRef(pto->GetId());
52075210
if (!peer) return false;
52085211
const Consensus::Params& consensusParams = m_chainparams.GetConsensus();
@@ -5463,7 +5466,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
54635466
// Check whether periodic sends should happen
54645467
// Note: If this node is running in a Masternode mode, it makes no sense to delay outgoing txes
54655468
// because we never produce any txes ourselves i.e. no privacy is lost in this case.
5466-
bool fSendTrickle = pto->HasPermission(NetPermissionFlags::NoBan) || fMasternodeMode;
5469+
bool fSendTrickle = pto->HasPermission(NetPermissionFlags::NoBan) || is_masternode;
54675470
if (pto->m_tx_relay->nNextInvSend < current_time) {
54685471
fSendTrickle = true;
54695472
if (pto->IsInboundConn()) {
@@ -5731,7 +5734,7 @@ bool PeerManagerImpl::SendMessages(CNode* pto)
57315734
// up processing to happen after the download times out
57325735
// (with a slight delay for inbound peers, to prefer
57335736
// requests to outbound peers).
5734-
const auto next_process_time = CalculateObjectGetDataTime(inv, current_time, !state.fPreferredDownload);
5737+
const auto next_process_time = CalculateObjectGetDataTime(inv, current_time, is_masternode, !state.fPreferredDownload);
57355738
object_process_time.emplace(next_process_time, inv);
57365739
LogPrint(BCLog::NET, "%s -- GETDATA re-queue inv=(%s), next_process_time=%d, delta=%d, peer=%d\n", __func__, inv.ToString(), next_process_time.count(), (next_process_time - current_time).count(), pto->GetId());
57375740
}

src/node/blockstorage.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ void ThreadImport(ChainstateManager& chainman, CDeterministicMNManager& dmnman,
209209
LogPrintf("Filling coin cache with masternode UTXOs: done in %dms\n", GetTimeMillis() - nStart);
210210
}
211211

212-
if (fMasternodeMode) {
213-
Assert(mn_activeman)->Init(::ChainActive().Tip());
212+
if (mn_activeman != nullptr) {
213+
mn_activeman->Init(::ChainActive().Tip());
214214
}
215215

216216
g_wallet_init_interface.AutoLockMasternodeCollaterals();

0 commit comments

Comments
 (0)