Skip to content

Commit 1bfd6ff

Browse files
committed
refactor: drop mutex and atomics from CMasternodeMetaInfo
It is already guarded by CMasternodeMetaMan::cs
1 parent d5e693f commit 1bfd6ff

File tree

2 files changed

+25
-58
lines changed

2 files changed

+25
-58
lines changed

src/masternode/meta.cpp

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,24 @@ bool CMasternodeMetaMan::LoadCache(bool load_cache)
3030

3131
UniValue CMasternodeMetaInfo::ToJson() const
3232
{
33-
UniValue ret(UniValue::VOBJ);
34-
3533
int64_t now = GetTime<std::chrono::seconds>().count();
3634

37-
ret.pushKV("lastDSQ", nLastDsq.load());
38-
ret.pushKV("mixingTxCount", nMixingTxCount.load());
39-
ret.pushKV("outboundAttemptCount", outboundAttemptCount.load());
40-
ret.pushKV("lastOutboundAttempt", lastOutboundAttempt.load());
41-
ret.pushKV("lastOutboundAttemptElapsed", now - lastOutboundAttempt.load());
42-
ret.pushKV("lastOutboundSuccess", lastOutboundSuccess.load());
43-
ret.pushKV("lastOutboundSuccessElapsed", now - lastOutboundSuccess.load());
44-
{
45-
LOCK(cs);
46-
ret.pushKV("is_platform_banned", m_platform_ban);
47-
ret.pushKV("platform_ban_height_updated", m_platform_ban_updated);
48-
}
35+
UniValue ret(UniValue::VOBJ);
36+
ret.pushKV("lastDSQ", nLastDsq);
37+
ret.pushKV("mixingTxCount", nMixingTxCount);
38+
ret.pushKV("outboundAttemptCount", outboundAttemptCount);
39+
ret.pushKV("lastOutboundAttempt", lastOutboundAttempt);
40+
ret.pushKV("lastOutboundAttemptElapsed", now - lastOutboundAttempt);
41+
ret.pushKV("lastOutboundSuccess", lastOutboundSuccess);
42+
ret.pushKV("lastOutboundSuccessElapsed", now - lastOutboundSuccess);
43+
ret.pushKV("is_platform_banned", m_platform_ban);
44+
ret.pushKV("platform_ban_height_updated", m_platform_ban_updated);
4945

5046
return ret;
5147
}
5248

5349
void CMasternodeMetaInfo::AddGovernanceVote(const uint256& nGovernanceObjectHash)
5450
{
55-
LOCK(cs);
5651
// Insert a zero value, or not. Then increment the value regardless. This
5752
// ensures the value is in the map.
5853
const auto& pair = mapGovernanceObjectsVotedOn.emplace(nGovernanceObjectHash, 0);
@@ -61,14 +56,12 @@ void CMasternodeMetaInfo::AddGovernanceVote(const uint256& nGovernanceObjectHash
6156

6257
void CMasternodeMetaInfo::RemoveGovernanceObject(const uint256& nGovernanceObjectHash)
6358
{
64-
LOCK(cs);
6559
// Whether or not the govobj hash exists in the map first is irrelevant.
6660
mapGovernanceObjectsVotedOn.erase(nGovernanceObjectHash);
6761
}
6862

6963
CMasternodeMetaInfo CMasternodeMetaMan::GetInfo(const uint256& proTxHash)
7064
{
71-
LOCK(cs);
7265
auto it = metaInfos.find(proTxHash);
7366
if (it == metaInfos.end()) return CMasternodeMetaInfo{};
7467

src/masternode/meta.h

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -32,66 +32,42 @@ static constexpr int MASTERNODE_MAX_FAILED_OUTBOUND_ATTEMPTS{5};
3232
// This is mostly local information, e.g. about mixing and governance
3333
class CMasternodeMetaInfo
3434
{
35-
friend class CMasternodeMetaMan;
36-
37-
private:
38-
mutable Mutex cs;
39-
40-
uint256 proTxHash GUARDED_BY(cs);
35+
public:
36+
uint256 proTxHash;
4137

4238
//the dsq count from the last dsq broadcast of this node
43-
std::atomic<int64_t> nLastDsq{0};
44-
std::atomic<int> nMixingTxCount{0};
39+
int64_t nLastDsq{0};
40+
int nMixingTxCount{0};
4541

4642
// KEEP TRACK OF GOVERNANCE ITEMS EACH MASTERNODE HAS VOTE UPON FOR RECALCULATION
47-
std::map<uint256, int> mapGovernanceObjectsVotedOn GUARDED_BY(cs);
43+
std::map<uint256, int> mapGovernanceObjectsVotedOn;
4844

49-
std::atomic<int> outboundAttemptCount{0};
50-
std::atomic<int64_t> lastOutboundAttempt{0};
51-
std::atomic<int64_t> lastOutboundSuccess{0};
45+
int outboundAttemptCount{0};
46+
int64_t lastOutboundAttempt{0};
47+
int64_t lastOutboundSuccess{0};
5248

5349
//! bool flag is node currently under platform ban by p2p message
54-
bool m_platform_ban GUARDED_BY(cs){false};
50+
bool m_platform_ban{false};
5551
//! height at which platform ban has been applied or removed
56-
int m_platform_ban_updated GUARDED_BY(cs){0};
52+
int m_platform_ban_updated{0};
5753

5854
public:
5955
CMasternodeMetaInfo() = default;
6056
explicit CMasternodeMetaInfo(const uint256& _proTxHash) : proTxHash(_proTxHash) {}
61-
CMasternodeMetaInfo(const CMasternodeMetaInfo& ref) :
62-
proTxHash(ref.proTxHash),
63-
nLastDsq(ref.nLastDsq.load()),
64-
nMixingTxCount(ref.nMixingTxCount.load()),
65-
mapGovernanceObjectsVotedOn(ref.mapGovernanceObjectsVotedOn),
66-
lastOutboundAttempt(ref.lastOutboundAttempt.load()),
67-
lastOutboundSuccess(ref.lastOutboundSuccess.load()),
68-
m_platform_ban(ref.m_platform_ban),
69-
m_platform_ban_updated(ref.m_platform_ban_updated)
70-
{
71-
}
57+
CMasternodeMetaInfo(const CMasternodeMetaInfo& ref) = default;
7258

73-
template <typename Stream>
74-
void Serialize(Stream& s) const EXCLUSIVE_LOCKS_REQUIRED(!cs)
59+
SERIALIZE_METHODS(CMasternodeMetaInfo, obj)
7560
{
76-
LOCK(cs);
77-
s << proTxHash << nLastDsq << nMixingTxCount << mapGovernanceObjectsVotedOn << outboundAttemptCount
78-
<< lastOutboundAttempt << lastOutboundSuccess << m_platform_ban << m_platform_ban_updated;
79-
}
80-
81-
template <typename Stream>
82-
void Unserialize(Stream& s) EXCLUSIVE_LOCKS_REQUIRED(!cs)
83-
{
84-
LOCK(cs);
85-
s >> proTxHash >> nLastDsq >> nMixingTxCount >> mapGovernanceObjectsVotedOn >> outboundAttemptCount >>
86-
lastOutboundAttempt >> lastOutboundSuccess >> m_platform_ban >> m_platform_ban_updated;
61+
READWRITE(obj.proTxHash, obj.nLastDsq, obj.nMixingTxCount, obj.mapGovernanceObjectsVotedOn,
62+
obj.outboundAttemptCount, obj.lastOutboundAttempt, obj.lastOutboundSuccess, obj.m_platform_ban,
63+
obj.m_platform_ban_updated);
8764
}
8865

8966
UniValue ToJson() const EXCLUSIVE_LOCKS_REQUIRED(!cs);
9067

9168
public:
9269
const uint256 GetProTxHash() const EXCLUSIVE_LOCKS_REQUIRED(!cs)
9370
{
94-
LOCK(cs);
9571
return proTxHash;
9672
}
9773
int64_t GetLastDsq() const { return nLastDsq; }
@@ -111,7 +87,6 @@ class CMasternodeMetaInfo
11187
int64_t GetLastOutboundSuccess() const { return lastOutboundSuccess; }
11288
bool SetPlatformBan(bool is_banned, int height) EXCLUSIVE_LOCKS_REQUIRED(!cs)
11389
{
114-
LOCK(cs);
11590
if (height < m_platform_ban_updated) {
11691
return false;
11792
}
@@ -124,7 +99,6 @@ class CMasternodeMetaInfo
12499
}
125100
bool IsPlatformBanned() const EXCLUSIVE_LOCKS_REQUIRED(!cs)
126101
{
127-
LOCK(cs);
128102
return m_platform_ban;
129103
}
130104
};

0 commit comments

Comments
 (0)