Skip to content

Commit

Permalink
Move-only: Move MN collateral min conf value to chainparams
Browse files Browse the repository at this point in the history
This field is used for both types, legacy and deterministic.
  • Loading branch information
furszy committed Jan 18, 2022
1 parent 1d2a830 commit c748402
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 43 deletions.
3 changes: 3 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ class CMainParams : public CChainParams
consensus.nMaxMoneyOut = 21000000 * COIN;
consensus.nMNCollateralAmt = 10000 * COIN;
consensus.nMNBlockReward = 3 * COIN;
consensus.nMNCollateralMinConf = 15;
consensus.nProposalEstablishmentTime = 60 * 60 * 24; // must be at least a day old to make it into a budget
consensus.nStakeMinAge = 60 * 60;
consensus.nStakeMinDepth = 600;
Expand Down Expand Up @@ -375,6 +376,7 @@ class CTestNetParams : public CChainParams
consensus.nMaxMoneyOut = 21000000 * COIN;
consensus.nMNCollateralAmt = 10000 * COIN;
consensus.nMNBlockReward = 3 * COIN;
consensus.nMNCollateralMinConf = 15;
consensus.nProposalEstablishmentTime = 60 * 5; // at least 5 min old to make it into a budget
consensus.nStakeMinAge = 60 * 60;
consensus.nStakeMinDepth = 100;
Expand Down Expand Up @@ -506,6 +508,7 @@ class CRegTestParams : public CChainParams
consensus.nMaxMoneyOut = 43199500 * COIN;
consensus.nMNCollateralAmt = 100 * COIN;
consensus.nMNBlockReward = 3 * COIN;
consensus.nMNCollateralMinConf = 1;
consensus.nProposalEstablishmentTime = 60 * 5; // at least 5 min old to make it into a budget
consensus.nStakeMinAge = 0;
consensus.nStakeMinDepth = 20;
Expand Down
2 changes: 2 additions & 0 deletions src/consensus/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ struct Params {
int nFutureTimeDriftPoS;
CAmount nMaxMoneyOut;
CAmount nMNCollateralAmt;
int nMNCollateralMinConf;
CAmount nMNBlockReward;
int64_t nProposalEstablishmentTime;
int nStakeMinAge;
Expand Down Expand Up @@ -209,6 +210,7 @@ struct Params {
uint256 ProofOfStakeLimit(const bool fV2) const { return fV2 ? posLimitV2 : posLimitV1; }
bool MoneyRange(const CAmount& nValue) const { return (nValue >= 0 && nValue <= nMaxMoneyOut); }
bool IsTimeProtocolV2(const int nHeight) const { return NetworkUpgradeActive(nHeight, UPGRADE_V4_0); }
int MasternodeCollateralMinConf() const { return nMNCollateralMinConf; }

int FutureBlockTimeDrift(const int nHeight) const
{
Expand Down
7 changes: 3 additions & 4 deletions src/evo/deterministicmns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "key_io.h"
#include "guiinterface.h"
#include "llmq/quorums_utils.h"
#include "masternode.h" // for MasternodeCollateralMinConf
#include "masternodeman.h" // for mnodeman (!TODO: remove)
#include "script/standard.h"
#include "spork.h"
Expand Down Expand Up @@ -568,7 +567,7 @@ void CDeterministicMNManager::SetTipIndex(const CBlockIndex* pindex)
bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const CBlockIndex* pindexPrev, CValidationState& _state, CDeterministicMNList& mnListRet, bool debugLogs)
{
AssertLockHeld(cs);

const auto& consensus = Params().GetConsensus();
int nHeight = pindexPrev->nHeight + 1;

CDeterministicMNList oldList = GetListForBlock(pindexPrev);
Expand All @@ -589,7 +588,7 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C
// this works on the previous block, so confirmation will happen one block after nMasternodeMinimumConfirmations
// has been reached, but the block hash will then point to the block at nMasternodeMinimumConfirmations
int nConfirmations = pindexPrev->nHeight - dmn->pdmnState->nRegisteredHeight;
if (nConfirmations >= MasternodeCollateralMinConf()) {
if (nConfirmations >= consensus.MasternodeCollateralMinConf()) {
auto newState = std::make_shared<CDeterministicMNState>(*dmn->pdmnState);
newState->UpdateConfirmedHash(dmn->proTxHash, pindexPrev->GetBlockHash());
newList.UpdateMN(dmn->proTxHash, newState);
Expand Down Expand Up @@ -762,7 +761,7 @@ bool CDeterministicMNManager::BuildNewListFromBlock(const CBlock& block, const C
}
if (!pl.commitment.IsNull()) {
// Double-check that the quorum index is in the active chain
const auto& params = Params().GetConsensus().llmqs.at((Consensus::LLMQType)pl.commitment.llmqType);
const auto& params = consensus.llmqs.at((Consensus::LLMQType)pl.commitment.llmqType);
uint32_t quorumHeight = pl.nHeight - (pl.nHeight % params.dkgInterval);
auto quorumIndex = pindexPrev->GetAncestor(quorumHeight);
if (!quorumIndex || quorumIndex->GetBlockHash() != pl.commitment.quorumHash) {
Expand Down
11 changes: 0 additions & 11 deletions src/masternode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,19 @@
#include "tiertwo/tiertwo_sync_state.h"
#include "wallet/wallet.h"

#define MASTERNODE_MIN_CONFIRMATIONS_REGTEST 1
#define MASTERNODE_MIN_MNP_SECONDS_REGTEST 90
#define MASTERNODE_MIN_MNB_SECONDS_REGTEST 25
#define MASTERNODE_PING_SECONDS_REGTEST 25
#define MASTERNODE_EXPIRATION_SECONDS_REGTEST 12 * 60
#define MASTERNODE_REMOVAL_SECONDS_REGTEST 13 * 60

#define MASTERNODE_MIN_CONFIRMATIONS 15
#define MASTERNODE_MIN_MNP_SECONDS (10 * 60)
#define MASTERNODE_MIN_MNB_SECONDS (5 * 60)
#define MASTERNODE_PING_SECONDS (5 * 60)
#define MASTERNODE_EXPIRATION_SECONDS (120 * 60)
#define MASTERNODE_REMOVAL_SECONDS (130 * 60)
#define MASTERNODE_CHECK_SECONDS 5

// keep track of the scanning errors I've seen
std::map<uint256, int> mapSeenMasternodeScanningErrors;


int MasternodeMinPingSeconds()
{
return Params().IsRegTestNet() ? MASTERNODE_MIN_MNP_SECONDS_REGTEST : MASTERNODE_MIN_MNP_SECONDS;
Expand All @@ -41,11 +35,6 @@ int MasternodeBroadcastSeconds()
return Params().IsRegTestNet() ? MASTERNODE_MIN_MNB_SECONDS_REGTEST : MASTERNODE_MIN_MNB_SECONDS;
}

int MasternodeCollateralMinConf()
{
return Params().IsRegTestNet() ? MASTERNODE_MIN_CONFIRMATIONS_REGTEST : MASTERNODE_MIN_CONFIRMATIONS;
}

int MasternodePingSeconds()
{
return Params().IsRegTestNet() ? MASTERNODE_PING_SECONDS_REGTEST : MASTERNODE_PING_SECONDS;
Expand Down
1 change: 0 additions & 1 deletion src/masternode.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ typedef std::shared_ptr<const CDeterministicMN> CDeterministicMNCPtr;

int MasternodeMinPingSeconds();
int MasternodeBroadcastSeconds();
int MasternodeCollateralMinConf();
int MasternodePingSeconds();
int MasternodeExpirationSeconds();
int MasternodeRemovalSeconds();
Expand Down
11 changes: 6 additions & 5 deletions src/masternodeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,7 @@ std::vector<std::pair<int64_t, MasternodeRef>> CMasternodeMan::GetMasternodeRank

bool CMasternodeMan::CheckInputs(CMasternodeBroadcast& mnb, int nChainHeight, int& nDoS)
{
const auto& consensus = Params().GetConsensus();
// incorrect ping or its sigTime
if(mnb.lastPing.IsNull() || !mnb.lastPing.CheckAndUpdate(nDoS, false, true)) {
return false;
Expand All @@ -766,7 +767,7 @@ bool CMasternodeMan::CheckInputs(CMasternodeBroadcast& mnb, int nChainHeight, in
}

// Check collateral value
if (collateralUtxo.out.nValue != Params().GetConsensus().nMNCollateralAmt) {
if (collateralUtxo.out.nValue != consensus.nMNCollateralAmt) {
LogPrint(BCLog::MASTERNODE,"mnb - invalid amount for mnb collateral %s\n", mnb.vin.prevout.ToString());
nDoS = 33;
return false;
Expand All @@ -783,8 +784,8 @@ bool CMasternodeMan::CheckInputs(CMasternodeBroadcast& mnb, int nChainHeight, in
LogPrint(BCLog::MASTERNODE, "mnb - Accepted Masternode entry\n");
const int utxoHeight = (int) collateralUtxo.nHeight;
int collateralUtxoDepth = nChainHeight - utxoHeight + 1;
if (collateralUtxoDepth < MasternodeCollateralMinConf()) {
LogPrint(BCLog::MASTERNODE,"mnb - Input must have at least %d confirmations\n", MasternodeCollateralMinConf());
if (collateralUtxoDepth < consensus.MasternodeCollateralMinConf()) {
LogPrint(BCLog::MASTERNODE,"mnb - Input must have at least %d confirmations\n", consensus.MasternodeCollateralMinConf());
// maybe we miss few blocks, let this mnb to be checked again later
mapSeenMasternodeBroadcast.erase(mnb.GetHash());
g_tiertwo_sync_state.EraseSeenMNB(mnb.GetHash());
Expand All @@ -793,10 +794,10 @@ bool CMasternodeMan::CheckInputs(CMasternodeBroadcast& mnb, int nChainHeight, in

// verify that sig time is legit in past
// should be at least not earlier than block when 1000 PIV tx got MASTERNODE_MIN_CONFIRMATIONS
CBlockIndex* pConfIndex = WITH_LOCK(cs_main, return chainActive[utxoHeight + MasternodeCollateralMinConf() - 1]); // block where tx got MASTERNODE_MIN_CONFIRMATIONS
CBlockIndex* pConfIndex = WITH_LOCK(cs_main, return chainActive[utxoHeight + consensus.MasternodeCollateralMinConf() - 1]); // block where tx got MASTERNODE_MIN_CONFIRMATIONS
if (pConfIndex->GetBlockTime() > mnb.sigTime) {
LogPrint(BCLog::MASTERNODE,"mnb - Bad sigTime %d for Masternode %s (%i conf block is at %d)\n",
mnb.sigTime, mnb.vin.prevout.hash.ToString(), MasternodeCollateralMinConf(), pConfIndex->GetBlockTime());
mnb.sigTime, mnb.vin.prevout.hash.ToString(), consensus.MasternodeCollateralMinConf(), pConfIndex->GetBlockTime());
return false;
}

Expand Down
16 changes: 1 addition & 15 deletions src/qt/pivx/masternodeswidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,25 +204,11 @@ void MasterNodesWidget::onEditMNClicked()
}
} else {
inform(tr("Cannot start masternode, the collateral transaction has not been confirmed by the network yet.\n"
"Please wait few more minutes (masternode collaterals require %1 confirmations).").arg(MasternodeCollateralMinConf()));
"Please wait few more minutes (masternode collaterals require %1 confirmations).").arg(mnModel->getMasternodeCollateralMinConf()));
}
}
}

static bool startMN(const CMasternodeConfig::CMasternodeEntry& mne, int chainHeight, std::string& strError)
{
CMasternodeBroadcast mnb;
if (!CMasternodeBroadcast::Create(mne.getIp(), mne.getPrivKey(), mne.getTxHash(), mne.getOutputIndex(), strError, mnb, false, chainHeight))
return false;

mnodeman.UpdateMasternodeList(mnb);
if (activeMasternode.pubKeyMasternode == mnb.GetPubKey()) {
activeMasternode.EnableHotColdMasterNode(mnb.vin, mnb.addr);
}
mnb.Relay();
return true;
}

void MasterNodesWidget::startAlias(const QString& strAlias)
{
QString strStatusHtml;
Expand Down
2 changes: 1 addition & 1 deletion src/qt/pivx/masternodewizarddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ bool MasterNodeWizardDialog::createMN()
return false;
}

returnStr = tr("Masternode created! Wait %1 confirmations before starting it.").arg(MasternodeCollateralMinConf());
returnStr = tr("Masternode created! Wait %1 confirmations before starting it.").arg(mnModel->getMasternodeCollateralMinConf());
return true;
}

Expand Down
10 changes: 8 additions & 2 deletions src/qt/pivx/mnmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "qt/pivx/mnmodel.h"

#include "activemasternode.h"
#include "masternode.h"
#include "masternodeman.h"
#include "net.h" // for validateMasternodeIP
#include "tiertwo/tiertwo_sync_state.h"
Expand All @@ -27,6 +27,7 @@ void MNModel::init()

void MNModel::updateMNList()
{
int mnMinConf = getMasternodeCollateralMinConf();
int end = nodes.size();
nodes.clear();
collateralTxAccepted.clear();
Expand All @@ -43,7 +44,7 @@ void MNModel::updateMNList()
}
nodes.insert(QString::fromStdString(mne.getAlias()), std::make_pair(QString::fromStdString(mne.getIp()), pmn));
if (walletModel) {
collateralTxAccepted.insert(mne.getTxHash(), walletModel->getWalletTxDepth(txHash) >= MasternodeCollateralMinConf());
collateralTxAccepted.insert(mne.getTxHash(), walletModel->getWalletTxDepth(txHash) >= mnMinConf);
}
}
Q_EMIT dataChanged(index(0, 0, QModelIndex()), index(end, 5, QModelIndex()) );
Expand Down Expand Up @@ -199,6 +200,11 @@ CAmount MNModel::getMNCollateralRequiredAmount()
return Params().GetConsensus().nMNCollateralAmt;
}

int MNModel::getMasternodeCollateralMinConf()
{
return Params().GetConsensus().MasternodeCollateralMinConf();
}

bool MNModel::createMNCollateral(
const QString& alias,
const QString& addr,
Expand Down
5 changes: 4 additions & 1 deletion src/qt/pivx/mnmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
#define MNMODEL_H

#include <QAbstractTableModel>
#include "masternode.h"
#include "masternodeconfig.h"
#include "qt/walletmodel.h"

class CMasternode;

class MNModel : public QAbstractTableModel
{
Q_OBJECT
Expand Down Expand Up @@ -59,6 +60,8 @@ class MNModel : public QAbstractTableModel

// Return the specific chain amount value for the MN collateral output.
CAmount getMNCollateralRequiredAmount();
// Return the specific chain min conf for the collateral tx
int getMasternodeCollateralMinConf();
// Generates the collateral transaction
bool createMNCollateral(const QString& alias, const QString& addr, COutPoint& ret_outpoint, QString& ret_error);

Expand Down
7 changes: 4 additions & 3 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2451,7 +2451,8 @@ bool CWallet::GetMasternodeVinAndKeys(CTxIn& txinRet, CPubKey& pubKeyRet, CKey&
CTxOut txOut = wtx->tx->vout[nOutputIndex];

// Masternode collateral value
if (txOut.nValue != Params().GetConsensus().nMNCollateralAmt) {
const auto& consensus = Params().GetConsensus();
if (txOut.nValue != consensus.nMNCollateralAmt) {
strError = strprintf("Invalid collateral tx value, must be %s PIV", FormatMoney(Params().GetConsensus().nMNCollateralAmt));
return error("%s: tx %s, index %d not a masternode collateral", __func__, strTxHash, nOutputIndex);
}
Expand All @@ -2474,8 +2475,8 @@ bool CWallet::GetMasternodeVinAndKeys(CTxIn& txinRet, CPubKey& pubKeyRet, CKey&
}

// Depth must be at least MASTERNODE_MIN_CONFIRMATIONS
if (nDepth < MasternodeCollateralMinConf()) {
strError = strprintf("Collateral tx must have at least %d confirmations, has %d", MasternodeCollateralMinConf(), nDepth);
if (nDepth < consensus.MasternodeCollateralMinConf()) {
strError = strprintf("Collateral tx must have at least %d confirmations, has %d", consensus.MasternodeCollateralMinConf(), nDepth);
return error("%s: %s", __func__, strError);
}

Expand Down

0 comments on commit c748402

Please sign in to comment.