Skip to content

Commit

Permalink
[BUG] Prevent StartAll from starting mns with immature collateral
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Apr 9, 2020
1 parent 3dddd25 commit 7830c17
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/qt/pivx/masternodeswidget.cpp
Expand Up @@ -269,7 +269,8 @@ void MasterNodesWidget::onStartAllClicked(int type)
inform(tr("Cannot perform Mastenodes start, wallet locked"));
return;
}
if (!checkMNsNetwork()) return;
if (!Params().IsRegTestNet() && !checkMNsNetwork()) return; // skip on RegNet: so we can test even if tier two not synced

if (isLoading) {
inform(tr("Background task is being executed, please wait"));
} else {
Expand All @@ -294,6 +295,11 @@ bool MasterNodesWidget::startAll(QString& failText, bool onlyMissing)
continue;
}

if(!mnModel->isMNCollateralMature(mnAlias)) {
amountOfMnFailed++;
continue;
}

std::string strError;
if (!startMN(mne, strError)) {
amountOfMnFailed++;
Expand Down
7 changes: 7 additions & 0 deletions src/qt/pivx/mnmodel.cpp
Expand Up @@ -174,6 +174,13 @@ bool MNModel::isMNActive(QString mnAlias)
return activeState == CMasternode::MASTERNODE_PRE_ENABLED || activeState == CMasternode::MASTERNODE_ENABLED;
}

bool MNModel::isMNCollateralMature(QString mnAlias)
{
QMap<QString, std::pair<QString, CMasternode*>>::const_iterator it = nodes.find(mnAlias);
if (it != nodes.end()) return collateralTxAccepted.value(it.value().second->vin.prevout.hash.GetHex());
throw std::runtime_error(std::string("Masternode alias not found"));
}

bool MNModel::isMNsNetworkSynced()
{
return masternodeSync.IsSynced();
Expand Down
2 changes: 2 additions & 0 deletions src/qt/pivx/mnmodel.h
Expand Up @@ -49,6 +49,8 @@ class MNModel : public QAbstractTableModel
bool isMNInactive(QString mnAlias);
// Masternode is active if it's in PRE_ENABLED OR ENABLED state
bool isMNActive(QString mnAlias);
// Masternode collateral has enough confirmations
bool isMNCollateralMature(QString mnAlias);


private:
Expand Down

0 comments on commit 7830c17

Please sign in to comment.