Skip to content
23 changes: 12 additions & 11 deletions src/activemasternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,8 @@ void CActiveDeterministicMasternodeManager::Init()
return;
}

if (!mnList.IsMNValid(dmn->proTxHash)) {
if (mnList.IsMNPoSeBanned(dmn->proTxHash)) {
state = MASTERNODE_POSE_BANNED;
} else {
state = MASTERNODE_REMOVED;
}
if (dmn->IsPoSeBanned()) {
state = MASTERNODE_POSE_BANNED;
return;
}

Expand Down Expand Up @@ -181,16 +177,21 @@ void CActiveDeterministicMasternodeManager::UpdatedBlockTip(const CBlockIndex* p
return;

if (state == MASTERNODE_READY) {
auto oldMNList = deterministicMNManager->GetListForBlock(pindexNew->pprev);
auto newMNList = deterministicMNManager->GetListForBlock(pindexNew);
if (!newMNList.IsMNValid(info.proTxHash)) {
auto newDmn = deterministicMNManager->GetListForBlock(pindexNew).GetValidMN(info.proTxHash);
if (newDmn == nullptr) {
// MN disappeared from MN list
Reset(MASTERNODE_REMOVED);
return;
}

auto oldDmn = oldMNList.GetMN(info.proTxHash);
auto newDmn = newMNList.GetMN(info.proTxHash);
auto oldDmn = deterministicMNManager->GetListForBlock(pindexNew->pprev).GetMN(info.proTxHash);
if (oldDmn == nullptr) {
// should never happen if state is MASTERNODE_READY
LogPrintf("%s: WARNING: unable to find active mn %s in prev block list %s\n",
__func__, info.proTxHash.ToString(), pindexNew->pprev->GetBlockHash().ToString());
return;
}

if (newDmn->pdmnState->keyIDOperator != oldDmn->pdmnState->keyIDOperator) {
// MN operator key changed or revoked
Reset(MASTERNODE_OPERATOR_KEY_CHANGED);
Expand Down
14 changes: 7 additions & 7 deletions src/budget/budgetmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ bool CBudgetManager::GetFinalizedBudget(const uint256& nHash, CFinalizedBudget&
bool CBudgetManager::IsBudgetPaymentBlock(int nBlockHeight, int& nCountThreshold) const
{
int nHighestCount = GetHighestVoteCount(nBlockHeight);
int nCountEnabled = mnodeman.CountEnabled(ActiveProtocol());
int nCountEnabled = mnodeman.CountEnabled();
int nFivePercent = nCountEnabled / 20;
// threshold for highest finalized budgets (highest vote count - 10% of active masternodes)
nCountThreshold = nHighestCount - (nCountEnabled / 10);
Expand Down Expand Up @@ -712,7 +712,7 @@ std::vector<CBudgetProposal> CBudgetManager::GetBudget()
const int nBlocksPerCycle = Params().GetConsensus().nBudgetCycleBlocks;
int nBlockStart = nHeight - nHeight % nBlocksPerCycle + nBlocksPerCycle;
int nBlockEnd = nBlockStart + nBlocksPerCycle - 1;
int mnCount = mnodeman.CountEnabled(ActiveProtocol());
int mnCount = mnodeman.CountEnabled();
CAmount nTotalBudget = GetTotalBudget(nBlockStart);

for (CBudgetProposal* pbudgetProposal: vBudgetPorposalsSort) {
Expand All @@ -736,7 +736,7 @@ std::vector<CBudgetProposal> CBudgetManager::GetBudget()
} else {
LogPrint(BCLog::MNBUDGET,"%s: - Check 1 failed: valid=%d | %ld <= %ld | %ld >= %ld | Yeas=%d Nays=%d Count=%d | established=%d\n",
__func__, pbudgetProposal->IsValid(), pbudgetProposal->GetBlockStart(), nBlockStart, pbudgetProposal->GetBlockEnd(),
nBlockEnd, pbudgetProposal->GetYeas(), pbudgetProposal->GetNays(), mnodeman.CountEnabled(ActiveProtocol()) / 10,
nBlockEnd, pbudgetProposal->GetYeas(), pbudgetProposal->GetNays(), mnodeman.CountEnabled() / 10,
pbudgetProposal->IsEstablished());
}

Expand Down Expand Up @@ -821,7 +821,7 @@ void CBudgetManager::RemoveStaleVotesOnProposal(CBudgetProposal* prop)
auto mnList = deterministicMNManager->GetListAtChainTip();
auto dmn = mnList.GetMNByCollateral(it->first);
if (dmn) {
(*it).second.SetValid(mnList.IsMNValid(dmn));
(*it).second.SetValid(!dmn->IsPoSeBanned());
} else {
// -- Legacy System (!TODO: remove after enforcement) --
CMasternode* pmn = mnodeman.Find(it->first);
Expand All @@ -845,7 +845,7 @@ void CBudgetManager::RemoveStaleVotesOnFinalBudget(CFinalizedBudget* fbud)
auto mnList = deterministicMNManager->GetListAtChainTip();
auto dmn = mnList.GetMNByCollateral(it->first);
if (dmn) {
(*it).second.SetValid(mnList.IsMNValid(dmn));
(*it).second.SetValid(!dmn->IsPoSeBanned());
} else {
// -- Legacy System (!TODO: remove after enforcement) --
CMasternode* pmn = mnodeman.Find(it->first);
Expand Down Expand Up @@ -1020,7 +1020,7 @@ bool CBudgetManager::ProcessProposalVote(CBudgetVote& vote, CNode* pfrom, CValid

AddSeenProposalVote(vote);

if (!mnList.IsMNValid(dmn)) {
if (dmn->IsPoSeBanned()) {
err = strprintf("masternode (%s) not valid or PoSe banned", mn_protx_id);
return state.DoS(0, false, REJECT_INVALID, "bad-mvote", false, err);
}
Expand Down Expand Up @@ -1116,7 +1116,7 @@ bool CBudgetManager::ProcessFinalizedBudgetVote(CFinalizedBudgetVote& vote, CNod

AddSeenFinalizedBudgetVote(vote);

if (!mnList.IsMNValid(dmn)) {
if (dmn->IsPoSeBanned()) {
err = strprintf("masternode (%s) not valid or PoSe banned", mn_protx_id);
return state.DoS(0, false, REJECT_INVALID, "bad-fbvote", false, err);
}
Expand Down
2 changes: 2 additions & 0 deletions src/budget/budgetmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ class CBudgetManager : public CValidationInterface
// Only initialized masternodes: sign and submit votes on valid finalized budgets
void VoteOnFinalizedBudgets();

int CountProposals() { LOCK(cs_proposals); return mapProposals.size(); }

void CheckOrphanVotes();
void Clear()
{
Expand Down
2 changes: 1 addition & 1 deletion src/budget/budgetproposal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void CBudgetProposal::SyncVotes(CNode* pfrom, bool fPartial, int& nInvCount) con

bool CBudgetProposal::IsHeavilyDownvoted(bool fNewRules)
{
if (GetNays() - GetYeas() > (fNewRules ? 3 : 1) * mnodeman.CountEnabled(ActiveProtocol()) / 10) {
if (GetNays() - GetYeas() > (fNewRules ? 3 : 1) * mnodeman.CountEnabled() / 10) {
strInvalid = "Heavily Downvoted";
return true;
}
Expand Down
34 changes: 2 additions & 32 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,36 +105,6 @@ void CDeterministicMN::ToJson(UniValue& obj) const
obj.pushKV("dmnstate", stateObj);
}

bool CDeterministicMNList::IsMNValid(const uint256& proTxHash) const
{
auto p = mnMap.find(proTxHash);
if (p == nullptr) {
return false;
}
return IsMNValid(*p);
}

bool CDeterministicMNList::IsMNPoSeBanned(const uint256& proTxHash) const
{
auto p = mnMap.find(proTxHash);
if (p == nullptr) {
return false;
}
return IsMNPoSeBanned(*p);
}

bool CDeterministicMNList::IsMNValid(const CDeterministicMNCPtr& dmn) const
{
return !IsMNPoSeBanned(dmn);
}

bool CDeterministicMNList::IsMNPoSeBanned(const CDeterministicMNCPtr& dmn) const
{
assert(dmn);
const CDeterministicMNState& state = *dmn->pdmnState;
return state.nPoSeBanHeight != -1;
}

CDeterministicMNCPtr CDeterministicMNList::GetMN(const uint256& proTxHash) const
{
auto p = mnMap.find(proTxHash);
Expand All @@ -147,7 +117,7 @@ CDeterministicMNCPtr CDeterministicMNList::GetMN(const uint256& proTxHash) const
CDeterministicMNCPtr CDeterministicMNList::GetValidMN(const uint256& proTxHash) const
{
auto dmn = GetMN(proTxHash);
if (dmn && !IsMNValid(dmn)) {
if (dmn && dmn->IsPoSeBanned()) {
return nullptr;
}
return dmn;
Expand All @@ -171,7 +141,7 @@ CDeterministicMNCPtr CDeterministicMNList::GetMNByCollateral(const COutPoint& co
CDeterministicMNCPtr CDeterministicMNList::GetValidMNByCollateral(const COutPoint& collateralOutpoint) const
{
auto dmn = GetMNByCollateral(collateralOutpoint);
if (dmn && !IsMNValid(dmn)) {
if (dmn && dmn->IsPoSeBanned()) {
return nullptr;
}
return dmn;
Expand Down
10 changes: 3 additions & 7 deletions src/evo/deterministicmns.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class CDeterministicMN
}

uint64_t GetInternalId() const;
bool IsPoSeBanned() const { return pdmnState->nPoSeBanHeight != -1; }

std::string ToString() const;
void ToJson(UniValue& obj) const;
Expand Down Expand Up @@ -321,7 +322,7 @@ class CDeterministicMNList
{
size_t count = 0;
for (const auto& p : mnMap) {
if (IsMNValid(p.second)) {
if (!p.second->IsPoSeBanned()) {
count++;
}
}
Expand All @@ -332,7 +333,7 @@ class CDeterministicMNList
void ForEachMN(bool onlyValid, Callback&& cb) const
{
for (const auto& p : mnMap) {
if (!onlyValid || IsMNValid(p.second)) {
if (!onlyValid || !p.second->IsPoSeBanned()) {
cb(p.second);
}
}
Expand All @@ -345,11 +346,6 @@ class CDeterministicMNList
void SetHeight(int _height) { nHeight = _height; }
void SetBlockHash(const uint256& _blockHash) { blockHash = _blockHash; }

bool IsMNValid(const uint256& proTxHash) const;
bool IsMNPoSeBanned(const uint256& proTxHash) const;
bool IsMNValid(const CDeterministicMNCPtr& dmn) const;
bool IsMNPoSeBanned(const CDeterministicMNCPtr& dmn) const;

bool HasMN(const uint256& proTxHash) const
{
return GetMN(proTxHash) != nullptr;
Expand Down
17 changes: 11 additions & 6 deletions src/masternode-sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,13 +274,18 @@ void CMasternodeSync::Process()
if (tick++ % MASTERNODE_SYNC_TIMEOUT != 0) return;

if (IsSynced()) {
/*
Resync if we lose all masternodes from sleep/wake or failure to sync originally
*/
if (mnodeman.CountEnabled() == 0 && !isRegTestNet) {
if (isRegTestNet) {
return;
}
bool legacy_obsolete = deterministicMNManager->LegacyMNObsolete();
// Check if we lost all masternodes from sleep/wake or failure to sync originally (after
// spork 21, check if we lost all proposals instead). If we did, resync from scratch.
if ((!legacy_obsolete && mnodeman.CountEnabled(true /* only_legacy */) == 0) ||
(legacy_obsolete && g_budgetman.CountProposals() == 0)) {
Comment thread
furszy marked this conversation as resolved.
Reset();
} else
} else {
return;
}
}

//try syncing again
Expand Down Expand Up @@ -401,7 +406,7 @@ bool CMasternodeSync::SyncWithNode(CNode* pnode, bool fLegacyMnObsolete)
if (pnode->HasFulfilledRequest("mnwsync")) return true;
pnode->FulfilledRequest("mnwsync");

int nMnCount = mnodeman.CountEnabled();
int nMnCount = mnodeman.CountEnabled(true /* only_legacy */);
g_connman->PushMessage(pnode, msgMaker.Make(NetMsgType::GETMNWINNERS, nMnCount)); //sync payees
RequestedMasternodeAttempt++;
return false;
Expand Down
Loading