Skip to content

Commit

Permalink
GetMasternodeInfo with payee argument should do nothing when DIP3 is …
Browse files Browse the repository at this point in the history
…active

Also change ComputeBlockVersion to directly use mnList.GetMNPayee()
  • Loading branch information
codablock committed Nov 14, 2018
1 parent 927e8bd commit 5ccf556
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 28 deletions.
26 changes: 17 additions & 9 deletions src/masternodeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,18 +605,26 @@ bool CMasternodeMan::GetMasternodeInfo(const CKeyID& keyIDOperator, masternode_i

bool CMasternodeMan::GetMasternodeInfo(const CScript& payee, masternode_info_t& mnInfoRet)
{
CTxDestination dest;
if (!ExtractDestination(payee, dest) || !boost::get<CKeyID>(&dest))
if (deterministicMNManager->IsDeterministicMNsSporkActive()) {
// we can't reliably search by payee as there might be duplicates. Also, keyIDCollateralAddress is not
// always the payout address as DIP3 allows using different keys for collateral and payouts
// this method is only used from ComputeBlockVersion, which has a different logic for deterministic MNs
// this method won't be reimplemented when removing the compatibility code
return false;
CKeyID keyId = *boost::get<CKeyID>(&dest);
LOCK(cs);
for (const auto& mnpair : mapMasternodes) {
if (mnpair.second.keyIDCollateralAddress == keyId) {
mnInfoRet = mnpair.second.GetInfo();
return true;
} else {
CTxDestination dest;
if (!ExtractDestination(payee, dest) || !boost::get<CKeyID>(&dest))
return false;
CKeyID keyId = *boost::get<CKeyID>(&dest);
LOCK(cs);
for (const auto& mnpair : mapMasternodes) {
if (mnpair.second.keyIDCollateralAddress == keyId) {
mnInfoRet = mnpair.second.GetInfo();
return true;
}
}
return false;
}
return false;
}

bool CMasternodeMan::Has(const COutPoint& outpoint)
Expand Down
46 changes: 27 additions & 19 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1807,26 +1807,34 @@ int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Para
ThresholdState state = VersionBitsState(pindexPrev, params, pos, versionbitscache);
const struct BIP9DeploymentInfo& vbinfo = VersionBitsDeploymentInfo[pos];
if (vbinfo.check_mn_protocol && state == THRESHOLD_STARTED && fCheckMasternodesUpgraded) {
std::vector<CTxOut> voutMasternodePayments;
masternode_info_t mnInfo;
if (!mnpayments.GetBlockTxOuts(pindexPrev->nHeight + 1, 0, voutMasternodePayments)) {
// no votes for this block
continue;
}
bool mnKnown = false;
for (const auto& txout : voutMasternodePayments) {
if (mnodeman.GetMasternodeInfo(txout.scriptPubKey, mnInfo)) {
mnKnown = true;
break;
if (deterministicMNManager->IsDeterministicMNsSporkActive()) {
auto mnList = deterministicMNManager->GetListForBlock(pindexPrev->GetBlockHash());
auto payee = mnList.GetMNPayee();
if (!payee) {
continue;
}
} else {
std::vector<CTxOut> voutMasternodePayments;
masternode_info_t mnInfo;
if (!mnpayments.GetBlockTxOuts(pindexPrev->nHeight + 1, 0, voutMasternodePayments)) {
// no votes for this block
continue;
}
bool mnKnown = false;
for (const auto& txout : voutMasternodePayments) {
if (mnodeman.GetMasternodeInfo(txout.scriptPubKey, mnInfo)) {
mnKnown = true;
break;
}
}
if (!mnKnown) {
// unknown masternode
continue;
}
if (mnInfo.nProtocolVersion < DMN_PROTO_VERSION) {
// masternode is not upgraded yet
continue;
}
}
if (!mnKnown) {
// unknown masternode
continue;
}
if (mnInfo.nProtocolVersion < DMN_PROTO_VERSION) {
// masternode is not upgraded yet
continue;
}
}
if (state == THRESHOLD_LOCKED_IN || state == THRESHOLD_STARTED) {
Expand Down

0 comments on commit 5ccf556

Please sign in to comment.