Skip to content

Commit b1a03e6

Browse files
committed
refactor: hide direct usages of GetMetaInfo from net module
1 parent a40c418 commit b1a03e6

File tree

4 files changed

+44
-6
lines changed

4 files changed

+44
-6
lines changed

src/evo/mnauth.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ MessageProcessingResult CMNAuth::ProcessMessage(CNode& peer, ServiceFlags node_s
103103
}
104104

105105
if (!peer.IsInboundConn()) {
106-
mn_metaman.GetMetaInfo(mnauth.proRegTxHash)->SetLastOutboundSuccess(GetTime<std::chrono::seconds>().count());
106+
mn_metaman.SetLastOutboundSuccess(mnauth.proRegTxHash, GetTime<std::chrono::seconds>().count());
107107
if (peer.m_masternode_probe_connection) {
108108
LogPrint(BCLog::NET_NETCONN, "CMNAuth::ProcessMessage -- Masternode probe successful for %s, disconnecting. peer=%d\n",
109109
mnauth.proRegTxHash.ToString(), peer.GetId());

src/masternode/meta.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,40 @@ std::vector<uint256> CMasternodeMetaMan::GetAndClearDirtyGovernanceObjectHashes(
141141
return vecTmp;
142142
}
143143

144+
void CMasternodeMetaMan::SetLastOutboundAttempt(const uint256& protx_hash, int64_t t)
145+
{
146+
LOCK(cs);
147+
148+
auto it = metaInfos.find(protx_hash);
149+
if (it == metaInfos.end()) {
150+
it = metaInfos.emplace(protx_hash, std::make_shared<CMasternodeMetaInfo>(protx_hash)).first;
151+
}
152+
153+
return it->second->SetLastOutboundAttempt(t);
154+
}
155+
156+
void CMasternodeMetaMan::SetLastOutboundSuccess(const uint256& protx_hash, int64_t t)
157+
{
158+
LOCK(cs);
159+
160+
auto it = metaInfos.find(protx_hash);
161+
if (it == metaInfos.end()) {
162+
it = metaInfos.emplace(protx_hash, std::make_shared<CMasternodeMetaInfo>(protx_hash)).first;
163+
}
164+
165+
return it->second->SetLastOutboundSuccess(t);
166+
}
167+
168+
int64_t CMasternodeMetaMan::GetLastOutboundAttempt(const uint256& protx_hash) const
169+
{
170+
LOCK(cs);
171+
172+
auto it = metaInfos.find(protx_hash);
173+
if (it == metaInfos.end()) return 0;
174+
175+
return it->second->GetLastOutboundAttempt();
176+
}
177+
144178
int64_t CMasternodeMetaMan::GetLastOutboundSuccess(const uint256& protx_hash) const
145179
{
146180
LOCK(cs);

src/masternode/meta.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,12 @@ class CMasternodeMetaMan : public MasternodeMetaStore
276276

277277
std::vector<uint256> GetAndClearDirtyGovernanceObjectHashes() EXCLUSIVE_LOCKS_REQUIRED(!cs);
278278

279+
void SetLastOutboundAttempt(const uint256& protx_hash, int64_t t) EXCLUSIVE_LOCKS_REQUIRED(!cs);
280+
void SetLastOutboundSuccess(const uint256& protx_hash, int64_t t) EXCLUSIVE_LOCKS_REQUIRED(!cs);
281+
int64_t GetLastOutboundAttempt(const uint256& protx_hash) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
279282
int64_t GetLastOutboundSuccess(const uint256& protx_hash) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
280283
bool OutboundFailedTooManyTimes(const uint256& protx_hash) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
284+
281285
bool IsPlatformBanned(const uint256& protx_hash) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
282286
bool ResetPlatformBan(const uint256& protx_hash, int height) EXCLUSIVE_LOCKS_REQUIRED(!cs);
283287
bool AlreadyHavePlatformBan(const uint256& inv_hash) const EXCLUSIVE_LOCKS_REQUIRED(!cs);

src/net.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3403,7 +3403,7 @@ void CConnman::ThreadOpenMasternodeConnections(CDeterministicMNManager& dmnman,
34033403
continue;
34043404
}
34053405
// back off connecting to an address if we already tried recently
3406-
int64_t last_attempt = mn_metaman.GetMetaInfo(dmn->proTxHash)->GetLastOutboundAttempt();
3406+
int64_t last_attempt = mn_metaman.GetLastOutboundAttempt(dmn->proTxHash);
34073407
if (nANow - last_attempt < chainParams.LLMQConnectionRetryTimeout()) {
34083408
continue;
34093409
}
@@ -3426,14 +3426,14 @@ void CConnman::ThreadOpenMasternodeConnections(CDeterministicMNManager& dmnman,
34263426
bool connectedAndOutbound = connectedProRegTxHashes.count(dmn->proTxHash) && !connectedProRegTxHashes[dmn->proTxHash];
34273427
if (connectedAndOutbound) {
34283428
// we already have an outbound connection to this MN so there is no theed to probe it again
3429-
mn_metaman.GetMetaInfo(dmn->proTxHash)->SetLastOutboundSuccess(nANow);
3429+
mn_metaman.SetLastOutboundSuccess(dmn->proTxHash, nANow);
34303430
it = masternodePendingProbes.erase(it);
34313431
continue;
34323432
}
34333433

34343434
++it;
34353435

3436-
int64_t lastAttempt = mn_metaman.GetMetaInfo(dmn->proTxHash)->GetLastOutboundAttempt();
3436+
int64_t lastAttempt = mn_metaman.GetLastOutboundAttempt(dmn->proTxHash);
34373437
// back off trying connecting to an address if we already tried recently
34383438
if (nANow - lastAttempt < chainParams.LLMQConnectionRetryTimeout()) {
34393439
continue;
@@ -3493,7 +3493,7 @@ void CConnman::ThreadOpenMasternodeConnections(CDeterministicMNManager& dmnman,
34933493

34943494
didConnect = true;
34953495

3496-
mn_metaman.GetMetaInfo(connectToDmn->proTxHash)->SetLastOutboundAttempt(nANow);
3496+
mn_metaman.SetLastOutboundAttempt(connectToDmn->proTxHash, nANow);
34973497

34983498
OpenMasternodeConnection(CAddress(connectToDmn->pdmnState->netInfo->GetPrimary(), NODE_NETWORK), /*use_v2transport=*/GetLocalServices() & NODE_P2P_V2, isProbe);
34993499
// should be in the list now if connection was opened
@@ -3506,7 +3506,7 @@ void CConnman::ThreadOpenMasternodeConnections(CDeterministicMNManager& dmnman,
35063506
if (!connected) {
35073507
LogPrint(BCLog::NET_NETCONN, "CConnman::%s -- connection failed for masternode %s, service=%s\n", __func__, connectToDmn->proTxHash.ToString(), connectToDmn->pdmnState->netInfo->GetPrimary().ToStringAddrPort());
35083508
// Will take a few consequent failed attempts to PoSe-punish a MN.
3509-
if (mn_metaman.GetMetaInfo(connectToDmn->proTxHash)->OutboundFailedTooManyTimes()) {
3509+
if (mn_metaman.OutboundFailedTooManyTimes(connectToDmn->proTxHash)) {
35103510
LogPrint(BCLog::NET_NETCONN, "CConnman::%s -- failed to connect to masternode %s too many times\n", __func__, connectToDmn->proTxHash.ToString());
35113511
}
35123512
}

0 commit comments

Comments
 (0)