Skip to content

Commit

Permalink
Remove a few uses of mnodeman from governance code
Browse files Browse the repository at this point in the history
And remove them with direct use of deterministicMNManager
  • Loading branch information
codablock committed Dec 31, 2018
1 parent 14d8ce0 commit 2b2e4f4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 25 deletions.
24 changes: 8 additions & 16 deletions src/governance-object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ bool CGovernanceObject::ProcessVote(CNode* pfrom,
ostr << "CGovernanceObject::ProcessVote -- Masternode " << vote.GetMasternodeOutpoint().ToStringShort() << " not found";
exception = CGovernanceException(ostr.str(), GOVERNANCE_EXCEPTION_WARNING);
if (cmmapOrphanVotes.Insert(vote.GetMasternodeOutpoint(), vote_time_pair_t(vote, GetAdjustedTime() + GOVERNANCE_ORPHAN_EXPIRATION_TIME))) {
if (pfrom) {
mnodeman.AskForMN(pfrom, vote.GetMasternodeOutpoint(), connman);
}
LogPrintf("%s\n", ostr.str());
} else {
LogPrint("gobject", "%s\n", ostr.str());
Expand Down Expand Up @@ -556,9 +553,11 @@ bool CGovernanceObject::IsValidLocally(std::string& strError, bool& fMissingMast
return true;
}

auto mnList = deterministicMNManager->GetListAtChainTip();

std::string strOutpoint = masternodeOutpoint.ToStringShort();
masternode_info_t infoMn;
if (!mnodeman.GetMasternodeInfo(masternodeOutpoint, infoMn)) {
auto dmn = mnList.GetValidMNByCollateral(masternodeOutpoint);
if (!dmn) {
CMasternode::CollateralStatus err = CMasternode::CheckCollateral(masternodeOutpoint, CKeyID());
if (err == CMasternode::COLLATERAL_UTXO_NOT_FOUND) {
strError = "Failed to find Masternode UTXO, missing masternode=" + strOutpoint + "\n";
Expand All @@ -576,16 +575,9 @@ bool CGovernanceObject::IsValidLocally(std::string& strError, bool& fMissingMast
}

// Check that we have a valid MN signature
if (deterministicMNManager->IsDIP3Active()) {
if (!CheckSignature(infoMn.blsPubKeyOperator)) {
strError = "Invalid masternode signature for: " + strOutpoint + ", pubkey id = " + infoMn.blsPubKeyOperator.ToString();
return false;
}
} else {
if (!CheckSignature(infoMn.legacyKeyIDOperator)) {
strError = "Invalid masternode signature for: " + strOutpoint + ", pubkey id = " + infoMn.legacyKeyIDOperator.ToString();
return false;
}
if (!CheckSignature(dmn->pdmnState->pubKeyOperator)) {
strError = "Invalid masternode signature for: " + strOutpoint + ", pubkey = " + dmn->pdmnState->pubKeyOperator.ToString();
return false;
}

return true;
Expand Down Expand Up @@ -783,7 +775,7 @@ void CGovernanceObject::UpdateSentinelVariables()
{
// CALCULATE MINIMUM SUPPORT LEVELS REQUIRED

int nMnCount = mnodeman.CountEnabled();
int nMnCount = (int)deterministicMNManager->GetListAtChainTip().GetValidMNsCount();
if (nMnCount == 0) return;

// CALCULATE THE MINUMUM VOTE COUNT REQUIRED FOR FULL SIGNAL
Expand Down
12 changes: 4 additions & 8 deletions src/governance-vote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,20 +256,16 @@ bool CGovernanceVote::IsValid(bool useVotingKey) const
return false;
}

masternode_info_t infoMn;
if (!mnodeman.GetMasternodeInfo(masternodeOutpoint, infoMn)) {
auto dmn = deterministicMNManager->GetListAtChainTip().GetValidMNByCollateral(masternodeOutpoint);
if (!dmn) {
LogPrint("gobject", "CGovernanceVote::IsValid -- Unknown Masternode - %s\n", masternodeOutpoint.ToStringShort());
return false;
}

if (useVotingKey) {
return CheckSignature(infoMn.keyIDVoting);
return CheckSignature(dmn->pdmnState->keyIDVoting);
} else {
if (deterministicMNManager->IsDIP3Active()) {
return CheckSignature(infoMn.blsPubKeyOperator);
} else {
return CheckSignature(infoMn.legacyKeyIDOperator);
}
return CheckSignature(dmn->pdmnState->pubKeyOperator);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ int CGovernanceManager::RequestGovernanceObjectVotes(const std::vector<CNode*>&
int nMaxObjRequestsPerNode = 1;
size_t nProjectedVotes = 2000;
if (Params().NetworkIDString() != CBaseChainParams::MAIN) {
nMaxObjRequestsPerNode = std::max(1, int(nProjectedVotes / std::max(1, mnodeman.size())));
nMaxObjRequestsPerNode = std::max(1, int(nProjectedVotes / std::max(1, (int)deterministicMNManager->GetListAtChainTip().GetValidMNsCount())));
}

{
Expand Down

0 comments on commit 2b2e4f4

Please sign in to comment.