Skip to content

Commit c0e146f

Browse files
committed
refactor: hide direct usages of GetMetaInfo for net_processing
1 parent b1a03e6 commit c0e146f

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

src/masternode/meta.cpp

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,16 @@ void CMasternodeMetaMan::DisallowMixing(const uint256& proTxHash)
119119
mm->nMixingTxCount++;
120120
}
121121

122+
bool CMasternodeMetaMan::IsValidForMixingTxes(const uint256& protx_hash) const
123+
{
124+
LOCK(cs);
125+
126+
auto it = metaInfos.find(protx_hash);
127+
if (it == metaInfos.end()) return true;
128+
129+
return it->second->IsValidForMixingTxes();
130+
}
131+
122132
bool CMasternodeMetaMan::AddGovernanceVote(const uint256& proTxHash, const uint256& nGovernanceObjectHash)
123133
{
124134
auto mm = GetMetaInfo(proTxHash);
@@ -215,6 +225,24 @@ bool CMasternodeMetaMan::ResetPlatformBan(const uint256& protx_hash, int height)
215225
return it->second->SetPlatformBan(false, height);
216226
}
217227

228+
bool CMasternodeMetaMan::SetPlatformBan(const uint256& inv_hash, PlatformBanMessage&& ban_msg)
229+
{
230+
LOCK(cs);
231+
232+
const uint256& protx_hash = ban_msg.m_protx_hash;
233+
234+
auto it = metaInfos.find(protx_hash);
235+
if (it == metaInfos.end()) {
236+
it = metaInfos.emplace(protx_hash, std::make_shared<CMasternodeMetaInfo>(protx_hash)).first;
237+
}
238+
239+
bool ret = it->second->SetPlatformBan(true, ban_msg.m_requested_height);
240+
if (ret) {
241+
m_seen_platform_bans.insert(inv_hash, std::move(ban_msg));
242+
}
243+
return ret;
244+
}
245+
218246
bool CMasternodeMetaMan::AlreadyHavePlatformBan(const uint256& inv_hash) const
219247
{
220248
LOCK(cs);
@@ -232,12 +260,6 @@ std::optional<PlatformBanMessage> CMasternodeMetaMan::GetPlatformBan(const uint2
232260
return ret;
233261
}
234262

235-
void CMasternodeMetaMan::RememberPlatformBan(const uint256& inv_hash, PlatformBanMessage&& msg)
236-
{
237-
LOCK(cs);
238-
m_seen_platform_bans.insert(inv_hash, std::move(msg));
239-
}
240-
241263
void CMasternodeMetaMan::AddUsedMasternode(const uint256& proTxHash)
242264
{
243265
LOCK(cs);

src/masternode/meta.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ class CMasternodeMetaMan : public MasternodeMetaStore
270270

271271
void AllowMixing(const uint256& proTxHash);
272272
void DisallowMixing(const uint256& proTxHash);
273+
bool IsValidForMixingTxes(const uint256& protx_hash) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
273274

274275
bool AddGovernanceVote(const uint256& proTxHash, const uint256& nGovernanceObjectHash);
275276
void RemoveGovernanceObject(const uint256& nGovernanceObjectHash) EXCLUSIVE_LOCKS_REQUIRED(!cs);
@@ -284,9 +285,9 @@ class CMasternodeMetaMan : public MasternodeMetaStore
284285

285286
bool IsPlatformBanned(const uint256& protx_hash) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
286287
bool ResetPlatformBan(const uint256& protx_hash, int height) EXCLUSIVE_LOCKS_REQUIRED(!cs);
288+
bool SetPlatformBan(const uint256& inv_hash, PlatformBanMessage&& msg) EXCLUSIVE_LOCKS_REQUIRED(!cs);
287289
bool AlreadyHavePlatformBan(const uint256& inv_hash) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
288290
std::optional<PlatformBanMessage> GetPlatformBan(const uint256& inv_hash) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
289-
void RememberPlatformBan(const uint256& inv_hash, PlatformBanMessage&& msg) EXCLUSIVE_LOCKS_REQUIRED(!cs);
290291

291292
// CoinJoin masternode tracking
292293
void AddUsedMasternode(const uint256& proTxHash) EXCLUSIVE_LOCKS_REQUIRED(!cs);

src/net_processing.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3471,7 +3471,7 @@ std::pair<bool /*ret*/, bool /*do_return*/> static ValidateDSTX(CDeterministicMN
34713471
return {false, true};
34723472
}
34733473

3474-
if (!mn_metaman.GetMetaInfo(dmn->proTxHash)->IsValidForMixingTxes()) {
3474+
if (!mn_metaman.IsValidForMixingTxes(dmn->proTxHash)) {
34753475
LogPrint(BCLog::COINJOIN, "DSTX -- Masternode %s is sending too many transactions %s\n", dstx.masternodeOutpoint.ToStringShort(), hashTx.ToString());
34763476
return {true, true};
34773477
// TODO: Not an error? Could it be that someone is relaying old DSTXes
@@ -3602,10 +3602,8 @@ MessageProcessingResult PeerManagerImpl::ProcessPlatformBanMessage(NodeId node,
36023602
}
36033603

36043604
// At this point, the outgoing message serialization version can't change.
3605-
const auto meta_info = m_mn_metaman.GetMetaInfo(ban_msg.m_protx_hash);
3606-
if (meta_info->SetPlatformBan(true, ban_msg.m_requested_height)) {
3607-
LogPrintf("PLATFORMBAN -- forward message to other nodes\n");
3608-
m_mn_metaman.RememberPlatformBan(hash, std::move(ban_msg));
3605+
if (m_mn_metaman.SetPlatformBan(hash, std::move(ban_msg))) {
3606+
LogPrintf("PLATFORMBAN -- hash: %s forward message to other nodes\n", hash.ToString());
36093607
ret.m_inventory.emplace_back(MSG_PLATFORM_BAN, hash);
36103608
}
36113609
return ret;

0 commit comments

Comments
 (0)