Skip to content

Commit

Permalink
Don't allow non-ProTx masternode collaterals after DIP3 activation
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Aug 30, 2018
1 parent 5461e92 commit 2c17287
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/governance-object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ bool CGovernanceObject::IsValidLocally(std::string& strError, bool& fMissingMast
CMasternode::CollateralStatus err = CMasternode::CheckCollateral(masternodeOutpoint, CKeyID());
if (err == CMasternode::COLLATERAL_UTXO_NOT_FOUND) {
strError = "Failed to find Masternode UTXO, missing masternode=" + strOutpoint + "\n";
} else if (err == CMasternode::COLLATERAL_UTXO_NOT_PROTX) {
strError = "Masternode UTXO is not a ProTx, missing masternode=" + strOutpoint + "\n";
} else if (err == CMasternode::COLLATERAL_INVALID_AMOUNT) {
strError = "Masternode UTXO should have 1000 DASH, missing masternode=" + strOutpoint + "\n";
} else if (err == CMasternode::COLLATERAL_INVALID_PUBKEY) {
Expand Down
21 changes: 21 additions & 0 deletions src/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,22 @@ CMasternode::CollateralStatus CMasternode::CheckCollateral(const COutPoint& outp
return COLLATERAL_INVALID_PUBKEY;
}

CTransactionRef tx;
uint256 hashBlock;
if (!GetTransaction(outpoint.hash, tx, Params().GetConsensus(), hashBlock, true)) {
// should not happen
return COLLATERAL_UTXO_NOT_FOUND;
}
if (tx->nType != TRANSACTION_PROVIDER_REGISTER) {
assert(mapBlockIndex.count(hashBlock));

CBlockIndex *pindex = mapBlockIndex[hashBlock];
if (VersionBitsState(pindex->pprev, Params().GetConsensus(), Consensus::DEPLOYMENT_DIP0003, versionbitscache) == THRESHOLD_ACTIVE) {
LogPrintf("CMasternode::CheckCollateral -- ERROR: Collateral of masternode %s was created after DIP3 activation and is not a ProTx\n", outpoint.ToStringShort());
return COLLATERAL_UTXO_NOT_PROTX;
}
}

nHeightRet = coin.nHeight;
return COLLATERAL_OK;
}
Expand Down Expand Up @@ -554,6 +570,11 @@ bool CMasternodeBroadcast::CheckOutpoint(int& nDos)
return false;
}

if (err == COLLATERAL_UTXO_NOT_PROTX) {
LogPrint("masternode", "CMasternodeBroadcast::CheckOutpoint -- Masternode UTXO should be a ProTx, masternode=%s\n", outpoint.ToStringShort());
return false;
}

if (err == COLLATERAL_INVALID_AMOUNT) {
LogPrint("masternode", "CMasternodeBroadcast::CheckOutpoint -- Masternode UTXO should have 1000 DASH, masternode=%s\n", outpoint.ToStringShort());
nDos = 33;
Expand Down
3 changes: 2 additions & 1 deletion src/masternode.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ class CMasternode : public masternode_info_t
COLLATERAL_OK,
COLLATERAL_UTXO_NOT_FOUND,
COLLATERAL_INVALID_AMOUNT,
COLLATERAL_INVALID_PUBKEY
COLLATERAL_INVALID_PUBKEY,
COLLATERAL_UTXO_NOT_PROTX,
};


Expand Down

0 comments on commit 2c17287

Please sign in to comment.