Skip to content

Commit c9faf42

Browse files
Merge #6894: refactor: drop mutex and atomic from CMasternodeMetaInfo, access to object directly without shared_ptr
572bafd refactor: rename IsDsqOver to IsMixingThresholdExceeded (Konstantin Akimov) 16915ff fixup: lock annotation for CMasternodeMetaMan::nDsqCount (Konstantin Akimov) 982b68e fix: usage of ResetPlatformBan in CDeterministicMNList (Konstantin Akimov) f860031 refactoring: apply code review suggestions (Konstantin Akimov) fe3966d fix: removed leftover annotation, as follow-up conflict resolving with #6880 (Konstantin Akimov) 969b841 refactor: drop return bool from AddGovernanceVote which is always true (Konstantin Akimov) 04ab976 refactor: remove unused CConnMan from meta.h (Konstantin Akimov) ed27d90 refactor: use GetMetaInfoOrDefault widely, final (Konstantin Akimov) b79dd90 refactor: use a helper GetMetaInfo and GetMetaInfoOrDefault internally (Konstantin Akimov) 69ed5f5 refactor: remove useless helpers of CMasternodeMetaInfo (Konstantin Akimov) 1bfd6ff refactor: drop mutex and atomics from CMasternodeMetaInfo (Konstantin Akimov) d5e693f refactor: drop shared_ptr from CMasternodeMetaMan and make GetMetaInfo a private member (Konstantin Akimov) c0e146f refactor: hide direct usages of GetMetaInfo for net_processing (Konstantin Akimov) b1a03e6 refactor: hide direct usages of GetMetaInfo from net module (Konstantin Akimov) a40c418 refactor: hide direct calls of GetMetaInfo from llmq/utils (Konstantin Akimov) 7ba51ec refactor: remove direct usages of GetMetaInfo for dkgsession (Konstantin Akimov) 7ec239b refactor: replace direct usages of GetMetaInfo when platform unban node in mn-list (Konstantin Akimov) 16abbed refactor: replace direct usages of GetMetaInfo while calculating dsq threshold (Konstantin Akimov) 6cb2344 refactor: replace direct call of MetaInfo from rpc/evo code to helper (Konstantin Akimov) Pull request description: ## Issue being fixed or feature implemented Current implementation: 1. every access to `CMasternodeMetaInfo` is done by accessing `GetMetaInfo` under mutex `CMasternodeMetaMan::cs` 2. `GetMetaInfo` returns shared_ptr to object 3. every read or write of `GetMetaInfo` is protected by atomic, second mutex `CMasternodeMetaInfo::cs`; access to object is done indirectly by one more memory hop (because shared_ptr) It is not efficient, because `GetMetaInfo` is spread all over code base and not a single case need shared_ptr here; all accesses are brief and short (single read or single write; except RPC where all structure is serialized). ## What was done? This PR is follow-up for PR #6868 with further improvements and simplification of code. Instead returning shared_ptr with `CMasternodeMetaInfo` directly access to members of `CMasternodeMetaMan` under its mutex; all mutexes, atomic and shared_ptr itself are removed from `CMasternodeMetaInfo` accesses. It simplified implementation significantly, removed big amount of thread-safety annotations. Performance is probably improved, but improvement is unmeasurable, because `CMasternodeMetaInfo` and `CMasternodeMetaMan` has not been spotted as hot spot in profiler neither hot spot in lock contentions logs. Also this PR removes duplicated code between coinjoin/client and coinjoin/server by creating a helper in `CMasternodeMetaMan` ## How Has This Been Tested? Run unit & functional tests ## Breaking Changes N/A ## Checklist: - [x] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have added or updated relevant unit/integration/functional/e2e tests - [ ] I have made corresponding changes to the documentation - [x] I have assigned this pull request to a milestone ACKs for top commit: UdjinM6: utACK 572bafd Tree-SHA512: a9a955a6d2d5d9c18f35bd900a4d2064217974c44277572cdaf10d729cafa4e937b4fc361d64a5132439227fcc7fd3fff98358e20aa7adcbfbbe2a399f9e5052
2 parents a3118c1 + 572bafd commit c9faf42

File tree

12 files changed

+192
-181
lines changed

12 files changed

+192
-181
lines changed

src/coinjoin/client.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,17 +124,11 @@ MessageProcessingResult CCoinJoinClientQueueManager::ProcessMessage(NodeId from,
124124
LogPrint(BCLog::COINJOIN, "DSQUEUE -- CoinJoin queue is ready, masternode=%s, queue=%s\n", dmn->proTxHash.ToString(), dsq.ToString());
125125
return ret;
126126
} else {
127-
int64_t nLastDsq = m_mn_metaman.GetMetaInfo(dmn->proTxHash)->GetLastDsq();
128-
int64_t nDsqThreshold = m_mn_metaman.GetDsqThreshold(dmn->proTxHash, tip_mn_list.GetValidMNsCount());
129-
LogPrint(BCLog::COINJOIN, "DSQUEUE -- nLastDsq: %d nDsqThreshold: %d nDsqCount: %d\n", nLastDsq,
130-
nDsqThreshold, m_mn_metaman.GetDsqCount());
131-
// don't allow a few nodes to dominate the queuing process
132-
if (nLastDsq != 0 && nDsqThreshold > m_mn_metaman.GetDsqCount()) {
127+
if (m_mn_metaman.IsMixingThresholdExceeded(dmn->proTxHash, tip_mn_list.GetValidMNsCount())) {
133128
LogPrint(BCLog::COINJOIN, "DSQUEUE -- Masternode %s is sending too many dsq messages\n",
134129
dmn->proTxHash.ToString());
135130
return ret;
136131
}
137-
138132
m_mn_metaman.AllowMixing(dmn->proTxHash);
139133

140134
LogPrint(BCLog::COINJOIN, "DSQUEUE -- new CoinJoin queue, masternode=%s, queue=%s\n", dmn->proTxHash.ToString(), dsq.ToString());
@@ -1180,13 +1174,10 @@ bool CCoinJoinClientSession::StartNewQueue(CAmount nBalanceNeedsAnonymized, CCon
11801174
continue;
11811175
}
11821176

1183-
int64_t nLastDsq = m_mn_metaman.GetMetaInfo(dmn->proTxHash)->GetLastDsq();
1184-
int64_t nDsqThreshold = m_mn_metaman.GetDsqThreshold(dmn->proTxHash, nMnCount);
1185-
if (nLastDsq != 0 && nDsqThreshold > m_mn_metaman.GetDsqCount()) {
1177+
if (m_mn_metaman.IsMixingThresholdExceeded(dmn->proTxHash, nMnCount)) {
11861178
WalletCJLogPrint(m_wallet, /* Continued */
1187-
"CCoinJoinClientSession::StartNewQueue -- too early to mix with node," /* Continued */
1188-
" masternode=%s, nLastDsq=%d, nDsqThreshold=%d, nDsqCount=%d\n",
1189-
dmn->proTxHash.ToString(), nLastDsq, nDsqThreshold, m_mn_metaman.GetDsqCount());
1179+
"CCoinJoinClientSession::StartNewQueue -- too early to mix with node masternode=%s\n",
1180+
dmn->proTxHash.ToString());
11901181
nTries++;
11911182
continue;
11921183
}

src/coinjoin/server.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ void CCoinJoinServer::ProcessDSACCEPT(CNode& peer, CDataStream& vRecv)
9999
}
100100
}
101101

102-
int64_t nLastDsq = m_mn_metaman.GetMetaInfo(dmn->proTxHash)->GetLastDsq();
103-
int64_t nDsqThreshold = m_mn_metaman.GetDsqThreshold(dmn->proTxHash, mnList.GetValidMNsCount());
104-
if (nLastDsq != 0 && nDsqThreshold > m_mn_metaman.GetDsqCount()) {
102+
if (m_mn_metaman.IsMixingThresholdExceeded(dmn->proTxHash, mnList.GetValidMNsCount())) {
105103
if (fLogIPs) {
106104
LogPrint(BCLog::COINJOIN, "DSACCEPT -- last dsq too recent, must wait: peer=%d, addr=%s\n",
107105
peer.GetId(), peer.addr.ToStringAddrPort());
@@ -194,11 +192,8 @@ MessageProcessingResult CCoinJoinServer::ProcessDSQUEUE(NodeId from, CDataStream
194192
}
195193

196194
if (!dsq.fReady) {
197-
int64_t nLastDsq = m_mn_metaman.GetMetaInfo(dmn->proTxHash)->GetLastDsq();
198-
int64_t nDsqThreshold = m_mn_metaman.GetDsqThreshold(dmn->proTxHash, tip_mn_list.GetValidMNsCount());
199-
LogPrint(BCLog::COINJOIN, "DSQUEUE -- nLastDsq: %d nDsqThreshold: %d nDsqCount: %d\n", nLastDsq, nDsqThreshold, m_mn_metaman.GetDsqCount());
200195
//don't allow a few nodes to dominate the queuing process
201-
if (nLastDsq != 0 && nDsqThreshold > m_mn_metaman.GetDsqCount()) {
196+
if (m_mn_metaman.IsMixingThresholdExceeded(dmn->proTxHash, tip_mn_list.GetValidMNsCount())) {
202197
LogPrint(BCLog::COINJOIN, "DSQUEUE -- node sending too many dsq messages, masternode=%s\n", dmn->proTxHash.ToString());
203198
return ret;
204199
}

src/evo/deterministicmns.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,7 @@ bool CDeterministicMNManager::ProcessBlock(const CBlock& block, gsl::not_null<co
677677
const auto opt_proTx = GetTxPayload<CProUpServTx>(tx);
678678
if (!opt_proTx) continue; // should not happen but does not matter
679679

680-
if (auto meta_info = m_mn_metaman.GetMetaInfo(opt_proTx->proTxHash, false);
681-
!meta_info || !meta_info->SetPlatformBan(false, nHeight)) {
680+
if (!m_mn_metaman.ResetPlatformBan(opt_proTx->proTxHash, nHeight)) {
682681
LogPrint(BCLog::LLMQ, "%s -- MN %s is failed to Platform revived at height %d\n", __func__,
683682
opt_proTx->proTxHash.ToString(), nHeight);
684683
}

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/governance/object.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,7 @@ bool CGovernanceObject::ProcessVote(CMasternodeMetaMan& mn_metaman, CGovernanceM
147147
return false;
148148
}
149149

150-
if (!mn_metaman.AddGovernanceVote(dmn->proTxHash, vote.GetParentHash())) {
151-
std::string msg{strprintf("CGovernanceObject::%s -- Unable to add governance vote, MN outpoint = %s, "
152-
"governance object hash = %s",
153-
__func__, vote.GetMasternodeOutpoint().ToStringShort(), GetHash().ToString())};
154-
LogPrint(BCLog::GOBJECT, "%s\n", msg);
155-
exception = CGovernanceException(msg, GOVERNANCE_EXCEPTION_PERMANENT_ERROR);
156-
return false;
157-
}
150+
mn_metaman.AddGovernanceVote(dmn->proTxHash, vote.GetParentHash());
158151

159152
voteInstanceRef = vote_instance_t(vote.GetOutcome(), nVoteTimeUpdate, vote.GetTimestamp());
160153
fileVotes.AddVote(vote);

src/llmq/dkgsession.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -492,12 +492,11 @@ void CDKGSession::VerifyConnectionAndMinProtoVersions(CConnman& connman) const
492492
m->badConnection = true;
493493
logger.Batch("%s does not have min proto version %d (has %d)", m->dmn->proTxHash.ToString(), MIN_MASTERNODE_PROTO_VERSION, it->second);
494494
}
495-
const auto meta_info = m_mn_metaman.GetMetaInfo(m->dmn->proTxHash);
496-
if (meta_info->OutboundFailedTooManyTimes()) {
495+
if (m_mn_metaman.OutboundFailedTooManyTimes(m->dmn->proTxHash)) {
497496
m->badConnection = true;
498497
logger.Batch("%s failed to connect to it too many times", m->dmn->proTxHash.ToString());
499498
}
500-
if (meta_info->IsPlatformBanned()) {
499+
if (m_mn_metaman.IsPlatformBanned(m->dmn->proTxHash)) {
501500
m->badConnection = true;
502501
logger.Batch("%s is Platform PoSe banned", m->dmn->proTxHash.ToString());
503502
}

src/llmq/utils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ void AddQuorumProbeConnections(const Consensus::LLMQParams& llmqParams, CConnman
912912
if (dmn->proTxHash == myProTxHash) {
913913
continue;
914914
}
915-
auto lastOutbound = mn_metaman.GetMetaInfo(dmn->proTxHash)->GetLastOutboundSuccess();
915+
auto lastOutbound = mn_metaman.GetLastOutboundSuccess(dmn->proTxHash);
916916
if (curTime - lastOutbound < 10 * 60) {
917917
// avoid re-probing nodes too often
918918
continue;

src/masternode/meta.cpp

Lines changed: 120 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@
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+
16+
namespace {
17+
static const CMasternodeMetaInfo default_meta_info{};
18+
} // anonymous namespace
19+
1320
CMasternodeMetaMan::CMasternodeMetaMan() :
1421
m_db{std::make_unique<db_type>("mncache.dat", "magicMasternodeCache")}
1522
{
@@ -30,29 +37,24 @@ bool CMasternodeMetaMan::LoadCache(bool load_cache)
3037

3138
UniValue CMasternodeMetaInfo::ToJson() const
3239
{
33-
UniValue ret(UniValue::VOBJ);
34-
3540
int64_t now = GetTime<std::chrono::seconds>().count();
3641

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-
}
42+
UniValue ret(UniValue::VOBJ);
43+
ret.pushKV("lastDSQ", m_last_dsq);
44+
ret.pushKV("mixingTxCount", m_mixing_tx_count);
45+
ret.pushKV("outboundAttemptCount", outboundAttemptCount);
46+
ret.pushKV("lastOutboundAttempt", lastOutboundAttempt);
47+
ret.pushKV("lastOutboundAttemptElapsed", now - lastOutboundAttempt);
48+
ret.pushKV("lastOutboundSuccess", lastOutboundSuccess);
49+
ret.pushKV("lastOutboundSuccessElapsed", now - lastOutboundSuccess);
50+
ret.pushKV("is_platform_banned", m_platform_ban);
51+
ret.pushKV("platform_ban_height_updated", m_platform_ban_updated);
4952

5053
return ret;
5154
}
5255

5356
void CMasternodeMetaInfo::AddGovernanceVote(const uint256& nGovernanceObjectHash)
5457
{
55-
LOCK(cs);
5658
// Insert a zero value, or not. Then increment the value regardless. This
5759
// ensures the value is in the map.
5860
const auto& pair = mapGovernanceObjectsVotedOn.emplace(nGovernanceObjectHash, 0);
@@ -61,65 +63,81 @@ void CMasternodeMetaInfo::AddGovernanceVote(const uint256& nGovernanceObjectHash
6163

6264
void CMasternodeMetaInfo::RemoveGovernanceObject(const uint256& nGovernanceObjectHash)
6365
{
64-
LOCK(cs);
6566
// Whether or not the govobj hash exists in the map first is irrelevant.
6667
mapGovernanceObjectsVotedOn.erase(nGovernanceObjectHash);
6768
}
6869

69-
CMasternodeMetaInfoPtr CMasternodeMetaMan::GetMetaInfo(const uint256& proTxHash, bool fCreate)
70+
const CMasternodeMetaInfo& CMasternodeMetaMan::GetMetaInfoOrDefault(const uint256& protx_hash) const
71+
{
72+
const auto it = metaInfos.find(protx_hash);
73+
if (it == metaInfos.end()) return default_meta_info;
74+
return it->second;
75+
}
76+
77+
CMasternodeMetaInfo CMasternodeMetaMan::GetInfo(const uint256& proTxHash) const
7078
{
7179
LOCK(cs);
80+
return GetMetaInfoOrDefault(proTxHash);
81+
}
82+
83+
CMasternodeMetaInfo& CMasternodeMetaMan::GetMetaInfo(const uint256& proTxHash)
84+
{
7285
auto it = metaInfos.find(proTxHash);
7386
if (it != metaInfos.end()) {
7487
return it->second;
7588
}
76-
if (!fCreate) {
77-
return nullptr;
78-
}
79-
it = metaInfos.emplace(proTxHash, std::make_shared<CMasternodeMetaInfo>(proTxHash)).first;
89+
it = metaInfos.emplace(proTxHash, CMasternodeMetaInfo{proTxHash}).first;
8090
return it->second;
8191
}
8292

83-
// We keep track of dsq (mixing queues) count to avoid using same masternodes for mixing too often.
84-
// This threshold is calculated as the last dsq count this specific masternode was used in a mixing
85-
// session plus a margin of 20% of masternode count. In other words we expect at least 20% of unique
86-
// masternodes before we ever see a masternode that we know already mixed someone's funds earlier.
87-
int64_t CMasternodeMetaMan::GetDsqThreshold(const uint256& proTxHash, int nMnCount)
93+
bool CMasternodeMetaMan::IsMixingThresholdExceeded(const uint256& protx_hash, int mn_count) const
8894
{
89-
auto metaInfo = GetMetaInfo(proTxHash);
90-
if (metaInfo == nullptr) {
91-
// return a threshold which is slightly above nDsqCount i.e. a no-go
92-
return nDsqCount + 1;
95+
LOCK(cs);
96+
auto it = metaInfos.find(protx_hash);
97+
if (it == metaInfos.end()) {
98+
LogPrint(BCLog::COINJOIN, "DSQUEUE -- node %s is logged\n", protx_hash.ToString());
99+
return false;
93100
}
94-
return metaInfo->GetLastDsq() + nMnCount / 5;
101+
const auto& meta_info = it->second;
102+
int64_t last_dsq = meta_info.m_last_dsq;
103+
int64_t threshold = last_dsq + mn_count / 5;
104+
105+
LogPrint(BCLog::COINJOIN, "DSQUEUE -- mn: %s last_dsq: %d dsq_threshold: %d nDsqCount: %d\n",
106+
protx_hash.ToString(), last_dsq, threshold, nDsqCount);
107+
return last_dsq != 0 && threshold > nDsqCount;
95108
}
96109

97110
void CMasternodeMetaMan::AllowMixing(const uint256& proTxHash)
98111
{
99-
auto mm = GetMetaInfo(proTxHash);
100-
nDsqCount++;
101-
mm->nLastDsq = nDsqCount.load();
102-
mm->nMixingTxCount = 0;
112+
LOCK(cs);
113+
auto& mm = GetMetaInfo(proTxHash);
114+
mm.m_last_dsq = ++nDsqCount;
115+
mm.m_mixing_tx_count = 0;
103116
}
104117

105118
void CMasternodeMetaMan::DisallowMixing(const uint256& proTxHash)
106119
{
107-
auto mm = GetMetaInfo(proTxHash);
108-
mm->nMixingTxCount++;
120+
LOCK(cs);
121+
GetMetaInfo(proTxHash).m_mixing_tx_count++;
109122
}
110123

111-
bool CMasternodeMetaMan::AddGovernanceVote(const uint256& proTxHash, const uint256& nGovernanceObjectHash)
124+
bool CMasternodeMetaMan::IsValidForMixingTxes(const uint256& protx_hash) const
112125
{
113-
auto mm = GetMetaInfo(proTxHash);
114-
mm->AddGovernanceVote(nGovernanceObjectHash);
115-
return true;
126+
LOCK(cs);
127+
return GetMetaInfoOrDefault(protx_hash).m_mixing_tx_count <= MASTERNODE_MAX_MIXING_TXES;
128+
}
129+
130+
void CMasternodeMetaMan::AddGovernanceVote(const uint256& proTxHash, const uint256& nGovernanceObjectHash)
131+
{
132+
LOCK(cs);
133+
GetMetaInfo(proTxHash).AddGovernanceVote(nGovernanceObjectHash);
116134
}
117135

118136
void CMasternodeMetaMan::RemoveGovernanceObject(const uint256& nGovernanceObjectHash)
119137
{
120138
LOCK(cs);
121-
for(const auto& p : metaInfos) {
122-
p.second->RemoveGovernanceObject(nGovernanceObjectHash);
139+
for (auto& [_, meta_info] : metaInfos) {
140+
meta_info.RemoveGovernanceObject(nGovernanceObjectHash);
123141
}
124142
}
125143

@@ -130,6 +148,65 @@ std::vector<uint256> CMasternodeMetaMan::GetAndClearDirtyGovernanceObjectHashes(
130148
return vecTmp;
131149
}
132150

151+
void CMasternodeMetaMan::SetLastOutboundAttempt(const uint256& protx_hash, int64_t t)
152+
{
153+
LOCK(cs);
154+
GetMetaInfo(protx_hash).SetLastOutboundAttempt(t);
155+
}
156+
157+
void CMasternodeMetaMan::SetLastOutboundSuccess(const uint256& protx_hash, int64_t t)
158+
{
159+
LOCK(cs);
160+
GetMetaInfo(protx_hash).SetLastOutboundSuccess(t);
161+
}
162+
163+
int64_t CMasternodeMetaMan::GetLastOutboundAttempt(const uint256& protx_hash) const
164+
{
165+
LOCK(cs);
166+
return GetMetaInfoOrDefault(protx_hash).lastOutboundAttempt;
167+
}
168+
169+
int64_t CMasternodeMetaMan::GetLastOutboundSuccess(const uint256& protx_hash) const
170+
{
171+
LOCK(cs);
172+
return GetMetaInfoOrDefault(protx_hash).lastOutboundSuccess;
173+
}
174+
175+
bool CMasternodeMetaMan::OutboundFailedTooManyTimes(const uint256& protx_hash) const
176+
{
177+
LOCK(cs);
178+
return GetMetaInfoOrDefault(protx_hash).outboundAttemptCount > MASTERNODE_MAX_FAILED_OUTBOUND_ATTEMPTS;
179+
}
180+
181+
bool CMasternodeMetaMan::IsPlatformBanned(const uint256& protx_hash) const
182+
{
183+
LOCK(cs);
184+
return GetMetaInfoOrDefault(protx_hash).m_platform_ban;
185+
}
186+
187+
bool CMasternodeMetaMan::ResetPlatformBan(const uint256& protx_hash, int height)
188+
{
189+
LOCK(cs);
190+
191+
auto it = metaInfos.find(protx_hash);
192+
if (it == metaInfos.end()) return false;
193+
194+
return it->second.SetPlatformBan(false, height);
195+
}
196+
197+
bool CMasternodeMetaMan::SetPlatformBan(const uint256& inv_hash, PlatformBanMessage&& ban_msg)
198+
{
199+
LOCK(cs);
200+
201+
const uint256& protx_hash = ban_msg.m_protx_hash;
202+
203+
bool ret = GetMetaInfo(protx_hash).SetPlatformBan(true, ban_msg.m_requested_height);
204+
if (ret) {
205+
m_seen_platform_bans.insert(inv_hash, std::move(ban_msg));
206+
}
207+
return ret;
208+
}
209+
133210
bool CMasternodeMetaMan::AlreadyHavePlatformBan(const uint256& inv_hash) const
134211
{
135212
LOCK(cs);
@@ -147,12 +224,6 @@ std::optional<PlatformBanMessage> CMasternodeMetaMan::GetPlatformBan(const uint2
147224
return ret;
148225
}
149226

150-
void CMasternodeMetaMan::RememberPlatformBan(const uint256& inv_hash, PlatformBanMessage&& msg)
151-
{
152-
LOCK(cs);
153-
m_seen_platform_bans.insert(inv_hash, std::move(msg));
154-
}
155-
156227
void CMasternodeMetaMan::AddUsedMasternode(const uint256& proTxHash)
157228
{
158229
LOCK(cs);

0 commit comments

Comments
 (0)