Skip to content

Commit 470cb9d

Browse files
Merge #6679: refactor: drop static IsMNPoSeBanned and IsMNValid which are confusing
9e636d0 refactor: drop static IsMNPoSeBanned and IsMNValid which are confusing (Konstantin Akimov) Pull request description: ## Issue being fixed or feature implemented This methods are static, but they are confusing, because their usage such as `IsMNValid(*p.second);` or `mnList.IsMNValid(dmn)` looks like it does something with CDeterministicMNList; but all data contained inside CDeterministicMNState (dmn) object. ## What was done? Dropped static methods `IsMNValid` and `IsMNPoSeBanned` from CDeterministicMNList. Non-static methods with same name that uses proTx still exist and are not changed. ## 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: kwvg: utACK 9e636d0 UdjinM6: utACK 9e636d0 Tree-SHA512: ef7c60fa9b74904dcc86567d7144edb41ef66f1bcbcc74ac4cc704e32d1a23d65049b488d7462b26761859e6d57159737b479f96964f6e8bc7d9061410c27957
2 parents 7520644 + 9e636d0 commit 470cb9d

File tree

3 files changed

+14
-28
lines changed

3 files changed

+14
-28
lines changed

src/evo/deterministicmns.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ bool CDeterministicMNList::IsMNValid(const uint256& proTxHash) const
6969
if (p == nullptr) {
7070
return false;
7171
}
72-
return IsMNValid(**p);
72+
return !(*p)->pdmnState->IsBanned();
7373
}
7474

7575
bool CDeterministicMNList::IsMNPoSeBanned(const uint256& proTxHash) const
@@ -78,17 +78,7 @@ bool CDeterministicMNList::IsMNPoSeBanned(const uint256& proTxHash) const
7878
if (p == nullptr) {
7979
return false;
8080
}
81-
return IsMNPoSeBanned(**p);
82-
}
83-
84-
bool CDeterministicMNList::IsMNValid(const CDeterministicMN& dmn)
85-
{
86-
return !IsMNPoSeBanned(dmn);
87-
}
88-
89-
bool CDeterministicMNList::IsMNPoSeBanned(const CDeterministicMN& dmn)
90-
{
91-
return dmn.pdmnState->IsBanned();
81+
return (*p)->pdmnState->IsBanned();
9282
}
9383

9484
CDeterministicMNCPtr CDeterministicMNList::GetMN(const uint256& proTxHash) const
@@ -103,7 +93,7 @@ CDeterministicMNCPtr CDeterministicMNList::GetMN(const uint256& proTxHash) const
10393
CDeterministicMNCPtr CDeterministicMNList::GetValidMN(const uint256& proTxHash) const
10494
{
10595
auto dmn = GetMN(proTxHash);
106-
if (dmn && !IsMNValid(*dmn)) {
96+
if (dmn && dmn->pdmnState->IsBanned()) {
10797
return nullptr;
10898
}
10999
return dmn;
@@ -127,7 +117,7 @@ CDeterministicMNCPtr CDeterministicMNList::GetMNByCollateral(const COutPoint& co
127117
CDeterministicMNCPtr CDeterministicMNList::GetValidMNByCollateral(const COutPoint& collateralOutpoint) const
128118
{
129119
auto dmn = GetMNByCollateral(collateralOutpoint);
130-
if (dmn && !IsMNValid(*dmn)) {
120+
if (dmn && dmn->pdmnState->IsBanned()) {
131121
return nullptr;
132122
}
133123
return dmn;

src/evo/deterministicmns.h

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class CDeterministicMNList
221221

222222
[[nodiscard]] size_t GetValidMNsCount() const
223223
{
224-
return ranges::count_if(mnMap, [](const auto& p) { return IsMNValid(*p.second); });
224+
return ranges::count_if(mnMap, [](const auto& p) { return !p.second->pdmnState->IsBanned(); });
225225
}
226226

227227
[[nodiscard]] size_t GetAllEvoCount() const
@@ -231,14 +231,15 @@ class CDeterministicMNList
231231

232232
[[nodiscard]] size_t GetValidEvoCount() const
233233
{
234-
return ranges::count_if(mnMap,
235-
[](const auto& p) { return p.second->nType == MnType::Evo && IsMNValid(*p.second); });
234+
return ranges::count_if(mnMap, [](const auto& p) {
235+
return p.second->nType == MnType::Evo && !p.second->pdmnState->IsBanned();
236+
});
236237
}
237238

238239
[[nodiscard]] size_t GetValidWeightedMNsCount() const
239240
{
240241
return std::accumulate(mnMap.begin(), mnMap.end(), 0, [](auto res, const auto& p) {
241-
if (!IsMNValid(*p.second)) return res;
242+
if (p.second->pdmnState->IsBanned()) return res;
242243
return res + GetMnType(p.second->nType).voting_weight;
243244
});
244245
}
@@ -253,7 +254,7 @@ class CDeterministicMNList
253254
void ForEachMN(bool onlyValid, Callback&& cb) const
254255
{
255256
for (const auto& p : mnMap) {
256-
if (!onlyValid || IsMNValid(*p.second)) {
257+
if (!onlyValid || !p.second->pdmnState->IsBanned()) {
257258
cb(*p.second);
258259
}
259260
}
@@ -270,7 +271,7 @@ class CDeterministicMNList
270271
void ForEachMNShared(bool onlyValid, Callback&& cb) const
271272
{
272273
for (const auto& p : mnMap) {
273-
if (!onlyValid || IsMNValid(*p.second)) {
274+
if (!onlyValid || !p.second->pdmnState->IsBanned()) {
274275
cb(p.second);
275276
}
276277
}
@@ -301,8 +302,6 @@ class CDeterministicMNList
301302

302303
[[nodiscard]] bool IsMNValid(const uint256& proTxHash) const;
303304
[[nodiscard]] bool IsMNPoSeBanned(const uint256& proTxHash) const;
304-
static bool IsMNValid(const CDeterministicMN& dmn);
305-
static bool IsMNPoSeBanned(const CDeterministicMN& dmn);
306305

307306
[[nodiscard]] bool HasMN(const uint256& proTxHash) const
308307
{

src/rpc/masternode.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,13 +517,10 @@ static RPCHelpMan masternodelist_helper(bool is_composite)
517517

518518
const auto mnList = CHECK_NONFATAL(node.dmnman)->GetListAtChainTip();
519519
const auto dmnToStatus = [&](const auto& dmn) {
520-
if (mnList.IsMNValid(dmn)) {
521-
return "ENABLED";
522-
}
523-
if (mnList.IsMNPoSeBanned(dmn)) {
520+
if (dmn.pdmnState->IsBanned()) {
524521
return "POSE_BANNED";
525522
}
526-
return "UNKNOWN";
523+
return "ENABLED";
527524
};
528525
const auto dmnToLastPaidTime = [&](const auto& dmn) {
529526
if (dmn.pdmnState->nLastPaidHeight == 0) {
@@ -539,7 +536,7 @@ static RPCHelpMan masternodelist_helper(bool is_composite)
539536
const bool showEvoOnly = strMode == "evo";
540537
const int tipHeight = WITH_LOCK(cs_main, return chainman.ActiveChain().Tip()->nHeight);
541538
mnList.ForEachMN(false, [&](auto& dmn) {
542-
if (showRecentMnsOnly && mnList.IsMNPoSeBanned(dmn)) {
539+
if (showRecentMnsOnly && dmn.pdmnState->IsBanned()) {
543540
if (tipHeight - dmn.pdmnState->GetBannedHeight() > Params().GetConsensus().nSuperblockCycle) {
544541
return;
545542
}

0 commit comments

Comments
 (0)