Skip to content

Commit

Permalink
fix DIP0001 implementation (#1639)
Browse files Browse the repository at this point in the history
According to DIP0001 description we should be using payment queue to select current masternode:
>As a block is mined the version number is determined by the miner who mined it and the masternode that is selected for that block.
>...
>The selection of a round consisting of 4032 blocks is made based on masternodes not being randomly selected, rather they are in a queue.

https://github.com/dashpay/dips/blob/master/dip-0001.md
  • Loading branch information
UdjinM6 authored Sep 20, 2017
1 parent cd76f2a commit 25fa44d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/masternodeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,19 @@ bool CMasternodeMan::GetMasternodeInfo(const CPubKey& pubKeyMasternode, masterno
return false;
}

bool CMasternodeMan::GetMasternodeInfo(const CScript& payee, masternode_info_t& mnInfoRet)
{
LOCK(cs);
for (auto& mnpair : mapMasternodes) {
CScript scriptCollateralAddress = GetScriptForDestination(mnpair.second.pubKeyCollateralAddress.GetID());
if (scriptCollateralAddress == payee) {
mnInfoRet = mnpair.second.GetInfo();
return true;
}
}
return false;
}

bool CMasternodeMan::Has(const COutPoint& outpoint)
{
LOCK(cs);
Expand Down
2 changes: 1 addition & 1 deletion src/masternodeman.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ class CMasternodeMan
bool Has(const COutPoint& outpoint);

bool GetMasternodeInfo(const COutPoint& outpoint, masternode_info_t& mnInfoRet);

bool GetMasternodeInfo(const CPubKey& pubKeyMasternode, masternode_info_t& mnInfoRet);
bool GetMasternodeInfo(const CScript& payee, masternode_info_t& mnInfoRet);

/// Find an entry in the masternode list that is next to be paid
bool GetNextMasternodeInQueueForPayment(int nBlockHeight, bool fFilterSigTime, int& nCountRet, masternode_info_t& mnInfoRet);
Expand Down
14 changes: 11 additions & 3 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1885,10 +1885,18 @@ 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 && !fAssumeMasternodeIsUpgraded) {
CScript payee;
masternode_info_t mnInfo;
bool fFound = mnodeman.GetMasternodeByRank(1, mnInfo, pindexPrev->nHeight);
if (!fFound || mnInfo.nProtocolVersion < PROTOCOL_VERSION) {
// no masternodes(?) or masternode is not upgraded yet
if (!mnpayments.GetBlockPayee(pindexPrev->nHeight + 1, payee)) {
// no votes for this block
continue;
}
if (!mnodeman.GetMasternodeInfo(payee, mnInfo)) {
// unknown masternode
continue;
}
if (mnInfo.nProtocolVersion < DIP0001_PROTOCOL_VERSION) {
// masternode is not upgraded yet
continue;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ extern bool fAlerts;
extern bool fEnableReplacement;

extern std::map<uint256, int64_t> mapRejectedBlocks;

static const int DIP0001_PROTOCOL_VERSION = 70208;
extern std::atomic<bool> fDIP0001LockedInAtTip;
extern std::atomic<bool> fDIP0001ActiveAtTip;

Expand Down

0 comments on commit 25fa44d

Please sign in to comment.