Skip to content

Commit 69ed5f5

Browse files
committed
refactor: remove useless helpers of CMasternodeMetaInfo
1 parent 1bfd6ff commit 69ed5f5

File tree

2 files changed

+23
-36
lines changed

2 files changed

+23
-36
lines changed

src/masternode/meta.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
const std::string MasternodeMetaStore::SERIALIZATION_VERSION_STRING = "CMasternodeMetaMan-Version-5";
1212

13+
static constexpr int MASTERNODE_MAX_FAILED_OUTBOUND_ATTEMPTS{5};
14+
static constexpr int MASTERNODE_MAX_MIXING_TXES{5};
15+
1316
CMasternodeMetaMan::CMasternodeMetaMan() :
1417
m_db{std::make_unique<db_type>("mncache.dat", "magicMasternodeCache")}
1518
{
@@ -33,8 +36,8 @@ UniValue CMasternodeMetaInfo::ToJson() const
3336
int64_t now = GetTime<std::chrono::seconds>().count();
3437

3538
UniValue ret(UniValue::VOBJ);
36-
ret.pushKV("lastDSQ", nLastDsq);
37-
ret.pushKV("mixingTxCount", nMixingTxCount);
39+
ret.pushKV("lastDSQ", m_last_dsq);
40+
ret.pushKV("mixingTxCount", m_mixing_tx_count);
3841
ret.pushKV("outboundAttemptCount", outboundAttemptCount);
3942
ret.pushKV("lastOutboundAttempt", lastOutboundAttempt);
4043
ret.pushKV("lastOutboundAttemptElapsed", now - lastOutboundAttempt);
@@ -87,7 +90,7 @@ bool CMasternodeMetaMan::IsDsqOver(const uint256& protx_hash, int mn_count) cons
8790
return false;
8891
}
8992
const auto& meta_info = it->second;
90-
int64_t last_dsq = meta_info.GetLastDsq();
93+
int64_t last_dsq = meta_info.m_last_dsq;
9194
int64_t threshold = last_dsq + mn_count / 5;
9295

9396
LogPrint(BCLog::COINJOIN, "DSQUEUE -- mn: %s last_dsq: %d dsq_threshold: %d nDsqCount: %d\n",
@@ -100,15 +103,15 @@ void CMasternodeMetaMan::AllowMixing(const uint256& proTxHash)
100103
LOCK(cs);
101104
auto& mm = GetMetaInfo(proTxHash);
102105
nDsqCount++;
103-
mm.nLastDsq = nDsqCount.load();
104-
mm.nMixingTxCount = 0;
106+
mm.m_last_dsq = nDsqCount.load();
107+
mm.m_mixing_tx_count = 0;
105108
}
106109

107110
void CMasternodeMetaMan::DisallowMixing(const uint256& proTxHash)
108111
{
109112
LOCK(cs);
110113
auto& mm = GetMetaInfo(proTxHash);
111-
mm.nMixingTxCount++;
114+
mm.m_mixing_tx_count++;
112115
}
113116

114117
bool CMasternodeMetaMan::IsValidForMixingTxes(const uint256& protx_hash) const
@@ -118,7 +121,7 @@ bool CMasternodeMetaMan::IsValidForMixingTxes(const uint256& protx_hash) const
118121
auto it = metaInfos.find(protx_hash);
119122
if (it == metaInfos.end()) return true;
120123

121-
return it->second.IsValidForMixingTxes();
124+
return it->second.m_mixing_tx_count <= MASTERNODE_MAX_MIXING_TXES;
122125
}
123126

124127
bool CMasternodeMetaMan::AddGovernanceVote(const uint256& proTxHash, const uint256& nGovernanceObjectHash)
@@ -175,7 +178,7 @@ int64_t CMasternodeMetaMan::GetLastOutboundAttempt(const uint256& protx_hash) co
175178
auto it = metaInfos.find(protx_hash);
176179
if (it == metaInfos.end()) return 0;
177180

178-
return it->second.GetLastOutboundAttempt();
181+
return it->second.lastOutboundAttempt;
179182
}
180183

181184
int64_t CMasternodeMetaMan::GetLastOutboundSuccess(const uint256& protx_hash) const
@@ -185,7 +188,7 @@ int64_t CMasternodeMetaMan::GetLastOutboundSuccess(const uint256& protx_hash) co
185188
auto it = metaInfos.find(protx_hash);
186189
if (it == metaInfos.end()) return 0;
187190

188-
return it->second.GetLastOutboundSuccess();
191+
return it->second.lastOutboundSuccess;
189192
}
190193

191194
bool CMasternodeMetaMan::OutboundFailedTooManyTimes(const uint256& protx_hash) const
@@ -195,7 +198,7 @@ bool CMasternodeMetaMan::OutboundFailedTooManyTimes(const uint256& protx_hash) c
195198
auto it = metaInfos.find(protx_hash);
196199
if (it == metaInfos.end()) return false;
197200

198-
return it->second.OutboundFailedTooManyTimes();
201+
return it->second.outboundAttemptCount > MASTERNODE_MAX_FAILED_OUTBOUND_ATTEMPTS;
199202
}
200203

201204
bool CMasternodeMetaMan::IsPlatformBanned(const uint256& protx_hash) const
@@ -205,7 +208,7 @@ bool CMasternodeMetaMan::IsPlatformBanned(const uint256& protx_hash) const
205208
auto it = metaInfos.find(protx_hash);
206209
if (it == metaInfos.end()) return false;
207210

208-
return it->second.IsPlatformBanned();
211+
return it->second.m_platform_ban;
209212
}
210213

211214
bool CMasternodeMetaMan::ResetPlatformBan(const uint256& protx_hash, int height)

src/masternode/meta.h

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,16 @@ class UniValue;
2525
template<typename T>
2626
class CFlatDB;
2727

28-
static constexpr int MASTERNODE_MAX_MIXING_TXES{5};
29-
static constexpr int MASTERNODE_MAX_FAILED_OUTBOUND_ATTEMPTS{5};
30-
3128
// Holds extra (non-deterministic) information about masternodes
3229
// This is mostly local information, e.g. about mixing and governance
3330
class CMasternodeMetaInfo
3431
{
3532
public:
36-
uint256 proTxHash;
33+
uint256 m_protx_hash;
3734

3835
//the dsq count from the last dsq broadcast of this node
39-
int64_t nLastDsq{0};
40-
int nMixingTxCount{0};
36+
int64_t m_last_dsq{0};
37+
int m_mixing_tx_count{0};
4138

4239
// KEEP TRACK OF GOVERNANCE ITEMS EACH MASTERNODE HAS VOTE UPON FOR RECALCULATION
4340
std::map<uint256, int> mapGovernanceObjectsVotedOn;
@@ -53,38 +50,29 @@ class CMasternodeMetaInfo
5350

5451
public:
5552
CMasternodeMetaInfo() = default;
56-
explicit CMasternodeMetaInfo(const uint256& _proTxHash) : proTxHash(_proTxHash) {}
53+
explicit CMasternodeMetaInfo(const uint256& protx_hash) :
54+
m_protx_hash(protx_hash)
55+
{
56+
}
5757
CMasternodeMetaInfo(const CMasternodeMetaInfo& ref) = default;
5858

5959
SERIALIZE_METHODS(CMasternodeMetaInfo, obj)
6060
{
61-
READWRITE(obj.proTxHash, obj.nLastDsq, obj.nMixingTxCount, obj.mapGovernanceObjectsVotedOn,
61+
READWRITE(obj.m_protx_hash, obj.m_last_dsq, obj.m_mixing_tx_count, obj.mapGovernanceObjectsVotedOn,
6262
obj.outboundAttemptCount, obj.lastOutboundAttempt, obj.lastOutboundSuccess, obj.m_platform_ban,
6363
obj.m_platform_ban_updated);
6464
}
6565

6666
UniValue ToJson() const EXCLUSIVE_LOCKS_REQUIRED(!cs);
6767

6868
public:
69-
const uint256 GetProTxHash() const EXCLUSIVE_LOCKS_REQUIRED(!cs)
70-
{
71-
return proTxHash;
72-
}
73-
int64_t GetLastDsq() const { return nLastDsq; }
74-
int GetMixingTxCount() const { return nMixingTxCount; }
75-
76-
bool IsValidForMixingTxes() const { return GetMixingTxCount() <= MASTERNODE_MAX_MIXING_TXES; }
77-
7869
// KEEP TRACK OF EACH GOVERNANCE ITEM IN CASE THIS NODE GOES OFFLINE, SO WE CAN RECALCULATE THEIR STATUS
7970
void AddGovernanceVote(const uint256& nGovernanceObjectHash) EXCLUSIVE_LOCKS_REQUIRED(!cs);
8071

8172
void RemoveGovernanceObject(const uint256& nGovernanceObjectHash) EXCLUSIVE_LOCKS_REQUIRED(!cs);
8273

83-
bool OutboundFailedTooManyTimes() const { return outboundAttemptCount > MASTERNODE_MAX_FAILED_OUTBOUND_ATTEMPTS; }
8474
void SetLastOutboundAttempt(int64_t t) { lastOutboundAttempt = t; ++outboundAttemptCount; }
85-
int64_t GetLastOutboundAttempt() const { return lastOutboundAttempt; }
8675
void SetLastOutboundSuccess(int64_t t) { lastOutboundSuccess = t; outboundAttemptCount = 0; }
87-
int64_t GetLastOutboundSuccess() const { return lastOutboundSuccess; }
8876
bool SetPlatformBan(bool is_banned, int height) EXCLUSIVE_LOCKS_REQUIRED(!cs)
8977
{
9078
if (height < m_platform_ban_updated) {
@@ -97,10 +85,6 @@ class CMasternodeMetaInfo
9785
m_platform_ban_updated = height;
9886
return true;
9987
}
100-
bool IsPlatformBanned() const EXCLUSIVE_LOCKS_REQUIRED(!cs)
101-
{
102-
return m_platform_ban;
103-
}
10488
};
10589

10690
class MasternodeMetaStore
@@ -146,7 +130,7 @@ class MasternodeMetaStore
146130
std::vector<uint256> tmpUsedMasternodes;
147131
s >> tmpMetaInfo >> nDsqCount >> tmpUsedMasternodes;
148132
for (auto& mm : tmpMetaInfo) {
149-
metaInfos.emplace(mm.GetProTxHash(), CMasternodeMetaInfo{std::move(mm)});
133+
metaInfos.emplace(mm.m_protx_hash, CMasternodeMetaInfo{std::move(mm)});
150134
}
151135

152136
// Convert vector to deque and build unordered_set for O(1) lookups

0 commit comments

Comments
 (0)