From c41dd7c457a777301ebecd7ab3e355dbbcc4c322 Mon Sep 17 00:00:00 2001 From: random-zebra Date: Tue, 10 Sep 2019 14:51:15 +0200 Subject: [PATCH] [Refactor] refactor/fix CSporkManager and CSporkMessage classes - move ProcessSpork, GetSporkValue, IsSporkActive, ExecuteSpork and mapSporksActive to CSporkManager - move Sign, CheckSignature, Relay to CSporkMessage - move ReprocessBlocks out of sporks to main.cpp - rename DisconnectBlocksAndReprocess to DisconnectBlocks - bugfix: only set strMasterPrivKey if spork signature produced by that key was verified successfully - few log format changes, cleaned up includes --- src/activemasternode.cpp | 4 +- src/init.cpp | 2 +- src/main.cpp | 49 +++++-- src/main.h | 3 +- src/masternode-payments.cpp | 16 +-- src/masternode-sync.cpp | 4 +- src/masternodeman.cpp | 8 +- src/miner.cpp | 2 +- src/qt/pivx/privacywidget.cpp | 2 +- src/qt/pivx/send.cpp | 2 +- src/qt/privacydialog.cpp | 6 +- src/qt/walletmodel.cpp | 8 +- src/rpc/misc.cpp | 4 +- src/rpc/rawtransaction.cpp | 2 +- src/spork.cpp | 234 ++++++++++++++-------------------- src/spork.h | 45 ++++--- src/swifttx.cpp | 6 +- src/wallet/rpcwallet.cpp | 8 +- src/wallet/wallet.cpp | 6 +- 19 files changed, 201 insertions(+), 210 deletions(-) diff --git a/src/activemasternode.cpp b/src/activemasternode.cpp index 58ed547e112c5..c57da3da49f66 100644 --- a/src/activemasternode.cpp +++ b/src/activemasternode.cpp @@ -198,7 +198,7 @@ bool CActiveMasternode::SendMasternodePing(std::string& errorMessage) * AFTER MIGRATION TO V12 IS DONE */ - if (IsSporkActive(SPORK_10_MASTERNODE_PAY_UPDATED_NODES)) return true; + if (sporkManager.IsSporkActive(SPORK_10_MASTERNODE_PAY_UPDATED_NODES)) return true; // for migration purposes ping our node on old masternodes network too std::string retErrorMessage; std::vector vchMasterNodeSignature; @@ -300,7 +300,7 @@ bool CActiveMasternode::CreateBroadcast(CTxIn vin, CService service, CKey keyCol * AFTER MIGRATION TO V12 IS DONE */ - if (IsSporkActive(SPORK_10_MASTERNODE_PAY_UPDATED_NODES)) return true; + if (sporkManager.IsSporkActive(SPORK_10_MASTERNODE_PAY_UPDATED_NODES)) return true; // for migration purposes inject our node in old masternodes' list too std::string retErrorMessage; std::vector vchMasterNodeSignature; diff --git a/src/init.cpp b/src/init.cpp index 90830083301ff..1fd3963ba0a82 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1442,7 +1442,7 @@ bool AppInit2() // PIVX: load previous sessions sporks if we have them. uiInterface.InitMessage(_("Loading sporks...")); - LoadSporksFromDB(); + sporkManager.LoadSporksFromDB(); uiInterface.InitMessage(_("Loading block index...")); std::string strBlockIndexError = ""; diff --git a/src/main.cpp b/src/main.cpp index bc682af7154cd..cd7b33d300e77 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1338,7 +1338,7 @@ bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState& state, const CTransa *pfMissingInputs = false; //Temporarily disable zerocoin for maintenance - if (GetAdjustedTime() > GetSporkValue(SPORK_16_ZEROCOIN_MAINTENANCE_MODE) && tx.ContainsZerocoins()) + if (sporkManager.IsSporkActive(SPORK_16_ZEROCOIN_MAINTENANCE_MODE) && tx.ContainsZerocoins()) return state.DoS(10, error("AcceptToMemoryPool : Zerocoin transactions are temporarily disabled for maintenance"), REJECT_INVALID, "bad-tx"); int chainHeight = chainActive.Height(); @@ -2044,7 +2044,7 @@ CAmount GetSeeSaw(const CAmount& blockValue, int nMasternodeCount, int nHeight) { //if a mn count is inserted into the function we are looking for a specific result for a masternode count if (nMasternodeCount < 1){ - if (IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)) + if (sporkManager.IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)) nMasternodeCount = mnodeman.stable_size(); else nMasternodeCount = mnodeman.size(); @@ -3241,7 +3241,7 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin return state.DoS(100, error("ConnectBlock() : too many sigops"), REJECT_INVALID, "bad-blk-sigops"); //Temporarily disable zerocoin transactions for maintenance - if (block.nTime > GetSporkValue(SPORK_16_ZEROCOIN_MAINTENANCE_MODE) && !IsInitialBlockDownload() && tx.ContainsZerocoins()) { + if (block.nTime > sporkManager.GetSporkValue(SPORK_16_ZEROCOIN_MAINTENANCE_MODE) && !IsInitialBlockDownload() && tx.ContainsZerocoins()) { return state.DoS(100, error("ConnectBlock() : zerocoin transactions are currently in maintenance mode")); } @@ -3756,19 +3756,50 @@ bool static ConnectTip(CValidationState& state, CBlockIndex* pindexNew, CBlock* return true; } -bool DisconnectBlocksAndReprocess(int blocks) +bool DisconnectBlocks(int blocks) { LOCK(cs_main); CValidationState state; - LogPrintf("DisconnectBlocksAndReprocess: Got command to replay %d blocks\n", blocks); + LogPrintf("%s: Got command to replay %d blocks\n", __func__, blocks); for (int i = 0; i <= blocks; i++) DisconnectTip(state); return true; } +void ReprocessBlocks(int nBlocks) +{ + std::map::iterator it = mapRejectedBlocks.begin(); + while (it != mapRejectedBlocks.end()) { + //use a window twice as large as is usual for the nBlocks we want to reset + if ((*it).second > GetTime() - (nBlocks * 60 * 5)) { + BlockMap::iterator mi = mapBlockIndex.find((*it).first); + if (mi != mapBlockIndex.end() && (*mi).second) { + LOCK(cs_main); + + CBlockIndex* pindex = (*mi).second; + LogPrintf("%s - %s\n", __func__, (*it).first.ToString()); + + CValidationState state; + ReconsiderBlock(state, pindex); + } + } + ++it; + } + + CValidationState state; + { + LOCK(cs_main); + DisconnectBlocks(nBlocks); + } + + if (state.IsValid()) { + ActivateBestChain(state); + } +} + /* DisconnectBlockAndInputs @@ -4404,7 +4435,7 @@ bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW, bo } // ----------- swiftTX transaction scanning ----------- - if (IsSporkActive(SPORK_3_SWIFTTX_BLOCK_FILTERING)) { + if (sporkManager.IsSporkActive(SPORK_3_SWIFTTX_BLOCK_FILTERING)) { for (const CTransaction& tx : block.vtx) { if (!tx.IsCoinBase()) { //only reject blocks when it's based on complete consensus @@ -7048,7 +7079,7 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR budget.ProcessMessage(pfrom, strCommand, vRecv); masternodePayments.ProcessMessageMasternodePayments(pfrom, strCommand, vRecv); ProcessMessageSwiftTX(pfrom, strCommand, vRecv); - ProcessSpork(pfrom, strCommand, vRecv); + sporkManager.ProcessSpork(pfrom, strCommand, vRecv); masternodeSync.ProcessMessage(pfrom, strCommand, vRecv); } @@ -7063,11 +7094,11 @@ bool static ProcessMessage(CNode* pfrom, std::string strCommand, CDataStream& vR int ActiveProtocol() { // SPORK_14 is used for 70917 (v3.4+) - if (IsSporkActive(SPORK_14_NEW_PROTOCOL_ENFORCEMENT)) + if (sporkManager.IsSporkActive(SPORK_14_NEW_PROTOCOL_ENFORCEMENT)) return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT; // SPORK_15 was used for 70916 (v3.3+), commented out now. - //if (IsSporkActive(SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2)) + //if (sporkManager.IsSporkActive(SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2)) // return MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT; return MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT; diff --git a/src/main.h b/src/main.h index 25a63ee803947..b691fa0c6f63e 100644 --- a/src/main.h +++ b/src/main.h @@ -461,7 +461,8 @@ bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex); bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, bool* pfClean = NULL); /** Reprocess a number of blocks to try and get on the correct chain again **/ -bool DisconnectBlocksAndReprocess(int blocks); +bool DisconnectBlocks(int blocks); +void ReprocessBlocks(int nBlocks); /** Apply the effects of this block (with given index) on the UTXO set represented by coins */ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins, bool fJustCheck, bool fAlreadyChecked = false); diff --git a/src/masternode-payments.cpp b/src/masternode-payments.cpp index 393bf746f9326..d510f0c48b481 100644 --- a/src/masternode-payments.cpp +++ b/src/masternode-payments.cpp @@ -205,7 +205,7 @@ bool IsBlockValueValid(const CBlock& block, CAmount nExpectedValue, CAmount nMin } else { // we're synced and have data so check the budget schedule //are these blocks even enabled - if (!IsSporkActive(SPORK_13_ENABLE_SUPERBLOCKS)) { + if (!sporkManager.IsSporkActive(SPORK_13_ENABLE_SUPERBLOCKS)) { return nMinted <= nExpectedValue; } @@ -234,7 +234,7 @@ bool IsBlockPayeeValid(const CBlock& block, int nBlockHeight) const CTransaction& txNew = (nBlockHeight > Params().LAST_POW_BLOCK() ? block.vtx[1] : block.vtx[0]); //check if it's a budget block - if (IsSporkActive(SPORK_13_ENABLE_SUPERBLOCKS)) { + if (sporkManager.IsSporkActive(SPORK_13_ENABLE_SUPERBLOCKS)) { if (budget.IsBudgetPaymentBlock(nBlockHeight)) { transactionStatus = budget.IsTransactionValid(txNew, nBlockHeight); if (transactionStatus == TrxValidationStatus::Valid) { @@ -243,7 +243,7 @@ bool IsBlockPayeeValid(const CBlock& block, int nBlockHeight) if (transactionStatus == TrxValidationStatus::InValid) { LogPrint("masternode","Invalid budget payment detected %s\n", txNew.ToString().c_str()); - if (IsSporkActive(SPORK_9_MASTERNODE_BUDGET_ENFORCEMENT)) + if (sporkManager.IsSporkActive(SPORK_9_MASTERNODE_BUDGET_ENFORCEMENT)) return false; LogPrint("masternode","Budget enforcement is disabled, accepting block\n"); @@ -261,7 +261,7 @@ bool IsBlockPayeeValid(const CBlock& block, int nBlockHeight) return true; LogPrint("masternode","Invalid mn payment detected %s\n", txNew.ToString().c_str()); - if (IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)) + if (sporkManager.IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)) return false; LogPrint("masternode","Masternode payment enforcement is disabled, accepting block\n"); @@ -274,7 +274,7 @@ void FillBlockPayee(CMutableTransaction& txNew, CAmount nFees, bool fProofOfStak CBlockIndex* pindexPrev = chainActive.Tip(); if (!pindexPrev) return; - if (IsSporkActive(SPORK_13_ENABLE_SUPERBLOCKS) && budget.IsBudgetPaymentBlock(pindexPrev->nHeight + 1)) { + if (sporkManager.IsSporkActive(SPORK_13_ENABLE_SUPERBLOCKS) && budget.IsBudgetPaymentBlock(pindexPrev->nHeight + 1)) { budget.FillBlockPayee(txNew, nFees, fProofOfStake); } else { masternodePayments.FillBlockPayee(txNew, nFees, fProofOfStake, fZPIVStake); @@ -283,7 +283,7 @@ void FillBlockPayee(CMutableTransaction& txNew, CAmount nFees, bool fProofOfStak std::string GetRequiredPaymentsString(int nBlockHeight) { - if (IsSporkActive(SPORK_13_ENABLE_SUPERBLOCKS) && budget.IsBudgetPaymentBlock(nBlockHeight)) { + if (sporkManager.IsSporkActive(SPORK_13_ENABLE_SUPERBLOCKS) && budget.IsBudgetPaymentBlock(nBlockHeight)) { return budget.GetRequiredPaymentsString(nBlockHeight); } else { return masternodePayments.GetRequiredPaymentsString(nBlockHeight); @@ -359,7 +359,7 @@ void CMasternodePayments::FillBlockPayee(CMutableTransaction& txNew, int64_t nFe int CMasternodePayments::GetMinMasternodePaymentsProto() { - if (IsSporkActive(SPORK_10_MASTERNODE_PAY_UPDATED_NODES)) + if (sporkManager.IsSporkActive(SPORK_10_MASTERNODE_PAY_UPDATED_NODES)) return ActiveProtocol(); // Allow only updated peers else return MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT; // Also allow old peers as long as they are allowed to run @@ -547,7 +547,7 @@ bool CMasternodeBlockPayees::IsTransactionValid(const CTransaction& txNew) CAmount nReward = GetBlockValue(nBlockHeight); - if (IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)) { + if (sporkManager.IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)) { // Get a stable number of masternodes by ignoring newly activated (< 8000 sec old) masternodes nMasternode_Drift_Count = mnodeman.stable_size() + Params().MasternodeCountDrift(); } diff --git a/src/masternode-sync.cpp b/src/masternode-sync.cpp index d23f1bd46be23..a765b5e325f2e 100644 --- a/src/masternode-sync.cpp +++ b/src/masternode-sync.cpp @@ -308,7 +308,7 @@ void CMasternodeSync::Process() // timeout if (lastMasternodeList == 0 && (RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD * 3 || GetTime() - nAssetSyncStarted > MASTERNODE_SYNC_TIMEOUT * 5)) { - if (IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)) { + if (sporkManager.IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)) { LogPrintf("CMasternodeSync::Process - ERROR - Sync has failed, will retry later\n"); RequestedMasternodeAssets = MASTERNODE_SYNC_FAILED; RequestedMasternodeAttempt = 0; @@ -339,7 +339,7 @@ void CMasternodeSync::Process() // timeout if (lastMasternodeWinner == 0 && (RequestedMasternodeAttempt >= MASTERNODE_SYNC_THRESHOLD * 3 || GetTime() - nAssetSyncStarted > MASTERNODE_SYNC_TIMEOUT * 5)) { - if (IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)) { + if (sporkManager.IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)) { LogPrintf("CMasternodeSync::Process - ERROR - Sync has failed, will retry later\n"); RequestedMasternodeAssets = MASTERNODE_SYNC_FAILED; RequestedMasternodeAttempt = 0; diff --git a/src/masternodeman.cpp b/src/masternodeman.cpp index 04f6ad3a8bc0c..856245adb918f 100644 --- a/src/masternodeman.cpp +++ b/src/masternodeman.cpp @@ -358,7 +358,7 @@ int CMasternodeMan::stable_size () if (mn.protocolVersion < nMinProtocol) { continue; // Skip obsolete versions } - if (IsSporkActive (SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)) { + if (sporkManager.IsSporkActive (SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)) { nMasternode_Age = GetAdjustedTime() - mn.sigTime; if ((nMasternode_Age) < nMasternode_Min_Age) { continue; // Skip masternodes younger than (default) 8000 sec (MUST be > MASTERNODE_REMOVAL_SECONDS) @@ -607,7 +607,7 @@ int CMasternodeMan::GetMasternodeRank(const CTxIn& vin, int64_t nBlockHeight, in continue; // Skip obsolete versions } - if (IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)) { + if (sporkManager.IsSporkActive(SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT)) { nMasternode_Age = GetAdjustedTime() - mn.sigTime; if ((nMasternode_Age) < nMasternode_Min_Age) { if (fDebug) LogPrint("masternode","Skipping just activated Masternode. Age: %ld\n", nMasternode_Age); @@ -856,7 +856,7 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData // Light version for OLD MASSTERNODES - fake pings, no self-activation else if (strCommand == "dsee") { //ObfuScation Election Entry - if (IsSporkActive(SPORK_10_MASTERNODE_PAY_UPDATED_NODES)) return; + if (sporkManager.IsSporkActive(SPORK_10_MASTERNODE_PAY_UPDATED_NODES)) return; CTxIn vin; CService addr; @@ -1061,7 +1061,7 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData else if (strCommand == "dseep") { //ObfuScation Election Entry Ping - if (IsSporkActive(SPORK_10_MASTERNODE_PAY_UPDATED_NODES)) return; + if (sporkManager.IsSporkActive(SPORK_10_MASTERNODE_PAY_UPDATED_NODES)) return; CTxIn vin; std::vector vchSig; diff --git a/src/miner.cpp b/src/miner.cpp index 540bafece6d40..63562578c872e 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -213,7 +213,7 @@ CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn, CWallet* pwallet, if (tx.IsCoinBase() || tx.IsCoinStake() || !IsFinalTx(tx, nHeight)){ continue; } - if(GetAdjustedTime() > GetSporkValue(SPORK_16_ZEROCOIN_MAINTENANCE_MODE) && tx.ContainsZerocoins()){ + if(sporkManager.IsSporkActive(SPORK_16_ZEROCOIN_MAINTENANCE_MODE) && tx.ContainsZerocoins()){ continue; } diff --git a/src/qt/pivx/privacywidget.cpp b/src/qt/pivx/privacywidget.cpp index 451fb29f0e529..88a0e34d163df 100644 --- a/src/qt/pivx/privacywidget.cpp +++ b/src/qt/pivx/privacywidget.cpp @@ -234,7 +234,7 @@ void PrivacyWidget::onSendClicked(){ if (!walletModel || !walletModel->getOptionsModel()) return; - if(GetAdjustedTime() > GetSporkValue(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) { + if(sporkManager.IsSporkActive(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) { warn(tr("Zerocoin"), tr("zPIV is currently undergoing maintenance")); return; } diff --git a/src/qt/pivx/send.cpp b/src/qt/pivx/send.cpp index 5e94edd3de2af..64a859d9abde2 100644 --- a/src/qt/pivx/send.cpp +++ b/src/qt/pivx/send.cpp @@ -380,7 +380,7 @@ bool SendWidget::sendZpiv(QList recipients){ if (!walletModel || !walletModel->getOptionsModel()) return false; - if(GetAdjustedTime() > GetSporkValue(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) { + if(sporkManager.IsSporkActive(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) { emit message(tr("Spend Zerocoin"), tr("zPIV is currently undergoing maintenance."), CClientUIInterface::MSG_ERROR); return false; } diff --git a/src/qt/privacydialog.cpp b/src/qt/privacydialog.cpp index 47b6ccdd8ea45..a4acfe0174b47 100644 --- a/src/qt/privacydialog.cpp +++ b/src/qt/privacydialog.cpp @@ -164,7 +164,7 @@ void PrivacyDialog::on_pushButtonMintzPIV_clicked() if (!walletModel || !walletModel->getOptionsModel()) return; - if(GetAdjustedTime() > GetSporkValue(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) { + if(sporkManager.IsSporkActive(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) { QMessageBox::information(this, tr("Mint Zerocoin"), tr("zPIV is currently undergoing maintenance."), QMessageBox::Ok, QMessageBox::Ok); @@ -276,7 +276,7 @@ void PrivacyDialog::on_pushButtonSpendzPIV_clicked() if (!walletModel || !walletModel->getOptionsModel() || !pwalletMain) return; - if(GetAdjustedTime() > GetSporkValue(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) { + if(sporkManager.IsSporkActive(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) { QMessageBox::information(this, tr("Mint Zerocoin"), tr("zPIV is currently undergoing maintenance."), QMessageBox::Ok, QMessageBox::Ok); return; @@ -808,7 +808,7 @@ void PrivacyDialog::updateSPORK16Status() // Update/enable labels, buttons and tooltips depending on the current SPORK_16 status //bool fButtonsEnabled = ui->pushButtonMintzPIV->isEnabled(); bool fButtonsEnabled = false; - bool fMaintenanceMode = GetAdjustedTime() > GetSporkValue(SPORK_16_ZEROCOIN_MAINTENANCE_MODE); + bool fMaintenanceMode = sporkManager.IsSporkActive(SPORK_16_ZEROCOIN_MAINTENANCE_MODE); if (fMaintenanceMode && fButtonsEnabled) { // Mint zPIV //ui->pushButtonMintzPIV->setEnabled(false); diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 612d1344beff7..6a7670497947a 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -358,8 +358,8 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact CReserveKey* keyChange = transaction.getPossibleKeyChange(); - if (recipients[0].useSwiftTX && total > GetSporkValue(SPORK_5_MAX_VALUE) * COIN) { - emit message(tr("Send Coins"), tr("SwiftX doesn't support sending values that high yet. Transactions are currently limited to %1 PIV.").arg(GetSporkValue(SPORK_5_MAX_VALUE)), + if (recipients[0].useSwiftTX && total > sporkManager.GetSporkValue(SPORK_5_MAX_VALUE) * COIN) { + emit message(tr("Send Coins"), tr("SwiftX doesn't support sending values that high yet. Transactions are currently limited to %1 PIV.").arg(sporkManager.GetSporkValue(SPORK_5_MAX_VALUE)), CClientUIInterface::MSG_ERROR); return TransactionCreationFailed; } @@ -367,8 +367,8 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact bool fCreated = wallet->CreateTransaction(vecSend, *newTx, *keyChange, nFeeRequired, strFailReason, coinControl, recipients[0].inputType, recipients[0].useSwiftTX); transaction.setTransactionFee(nFeeRequired); - if (recipients[0].useSwiftTX && newTx->GetValueOut() > GetSporkValue(SPORK_5_MAX_VALUE) * COIN) { - emit message(tr("Send Coins"), tr("SwiftX doesn't support sending values that high yet. Transactions are currently limited to %1 PIV.").arg(GetSporkValue(SPORK_5_MAX_VALUE)), + if (recipients[0].useSwiftTX && newTx->GetValueOut() > sporkManager.GetSporkValue(SPORK_5_MAX_VALUE) * COIN) { + emit message(tr("Send Coins"), tr("SwiftX doesn't support sending values that high yet. Transactions are currently limited to %1 PIV.").arg(sporkManager.GetSporkValue(SPORK_5_MAX_VALUE)), CClientUIInterface::MSG_ERROR); return TransactionCreationFailed; } diff --git a/src/rpc/misc.cpp b/src/rpc/misc.cpp index 22e8c5d05f66a..c42e135b9a858 100644 --- a/src/rpc/misc.cpp +++ b/src/rpc/misc.cpp @@ -293,14 +293,14 @@ UniValue spork(const UniValue& params, bool fHelp) UniValue ret(UniValue::VOBJ); for (int nSporkID = SPORK_START; nSporkID <= SPORK_END; nSporkID++) { if (sporkManager.GetSporkNameByID(nSporkID) != "Unknown") - ret.push_back(Pair(sporkManager.GetSporkNameByID(nSporkID), GetSporkValue(nSporkID))); + ret.push_back(Pair(sporkManager.GetSporkNameByID(nSporkID), sporkManager.GetSporkValue(nSporkID))); } return ret; } else if (params.size() == 1 && params[0].get_str() == "active") { UniValue ret(UniValue::VOBJ); for (int nSporkID = SPORK_START; nSporkID <= SPORK_END; nSporkID++) { if (sporkManager.GetSporkNameByID(nSporkID) != "Unknown") - ret.push_back(Pair(sporkManager.GetSporkNameByID(nSporkID), IsSporkActive(nSporkID))); + ret.push_back(Pair(sporkManager.GetSporkNameByID(nSporkID), sporkManager.IsSporkActive(nSporkID))); } return ret; } else if (params.size() == 2) { diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 300fd8eed9317..d1cad1f73d609 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -934,7 +934,7 @@ UniValue createrawzerocoinstake(const UniValue& params, bool fHelp) assert(pwalletMain != NULL); LOCK2(cs_main, pwalletMain->cs_wallet); - if(GetAdjustedTime() > GetSporkValue(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) + if(sporkManager.IsSporkActive(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) throw JSONRPCError(RPC_WALLET_ERROR, "zPIV is currently disabled due to maintenance."); std::string serial_hash = params[0].get_str(); diff --git a/src/spork.cpp b/src/spork.cpp index b4f852fb83888..093f3025d9134 100644 --- a/src/spork.cpp +++ b/src/spork.cpp @@ -3,17 +3,11 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include "spork.h" -#include "base58.h" -#include "key.h" #include "main.h" #include "masternode-budget.h" #include "net.h" -#include "protocol.h" -#include "sync.h" +#include "spork.h" #include "sporkdb.h" -#include "util.h" - class CSporkMessage; class CSporkManager; @@ -21,10 +15,9 @@ class CSporkManager; CSporkManager sporkManager; std::map mapSporks; -std::map mapSporksActive; // PIVX: on startup load spork values from previous session if they exist in the sporkDB -void LoadSporksFromDB() +void CSporkManager::LoadSporksFromDB() { for (int i = SPORK_START; i <= SPORK_END; ++i) { // Since not all spork IDs are in use, we have to exclude undefined IDs @@ -54,16 +47,17 @@ void LoadSporksFromDB() } } -void ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStream& vRecv) +void CSporkManager::ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStream& vRecv) { - if (fLiteMode) return; //disable all obfuscation/masternode related functionality + if (fLiteMode) return; // disable all obfuscation/masternode related functionality if (strCommand == "spork") { - //LogPrintf("ProcessSpork::spork\n"); + //LogPrintf("CSporkManager::spork\n"); CDataStream vMsg(vRecv); CSporkMessage spork; vRecv >> spork; + LOCK(cs_main); if (chainActive.Tip() == NULL) return; // Ignore spork messages about unknown/deleted sporks @@ -83,7 +77,7 @@ void ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStream& vRecv) LogPrintf("%s : new %s ID %d Time %d bestHeight %d\n", __func__, hash.ToString(), spork.nSporkID, spork.nValue, chainActive.Tip()->nHeight); bool fRequireNew = spork.nTimeSigned >= Params().NewSporkStart(); - if (!sporkManager.CheckSignature(spork, fRequireNew)) { + if (!spork.CheckSignature(fRequireNew)) { LogPrintf("%s : Invalid Signature\n", __func__); Misbehaving(pfrom->GetId(), 100); return; @@ -91,7 +85,7 @@ void ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStream& vRecv) mapSporks[hash] = spork; mapSporksActive[spork.nSporkID] = spork; - sporkManager.Relay(spork); + spork.Relay(); // PIVX: add to spork database. pSporkDB->WriteSpork(spork.nSporkID, spork); @@ -106,9 +100,31 @@ void ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStream& vRecv) } } +bool CSporkManager::UpdateSpork(int nSporkID, int64_t nValue) +{ + + CSporkMessage spork = CSporkMessage(nSporkID, nValue, GetTime()); + + if(spork.Sign(strMasterPrivKey)){ + spork.Relay(); + mapSporks[spork.GetHash()] = spork; + mapSporksActive[nSporkID] = spork; + return true; + } + + return false; +} + +// grab the spork value, and see if it's off +bool CSporkManager::IsSporkActive(int nSporkID) +{ + int64_t r = GetSporkValue(nSporkID); + if (r == -1) return false; + return r < GetAdjustedTime(); +} // grab the value of the spork on the network, or the default -int64_t GetSporkValue(int nSporkID) +int64_t CSporkManager::GetSporkValue(int nSporkID) { int64_t r = -1; @@ -133,164 +149,104 @@ int64_t GetSporkValue(int nSporkID) return r; } -// grab the spork value, and see if it's off -bool IsSporkActive(int nSporkID) +int CSporkManager::GetSporkIDByName(std::string strName) { - int64_t r = GetSporkValue(nSporkID); - if (r == -1) return false; - return r < GetTime(); -} + if (strName == "SPORK_2_SWIFTTX") return SPORK_2_SWIFTTX; + if (strName == "SPORK_3_SWIFTTX_BLOCK_FILTERING") return SPORK_3_SWIFTTX_BLOCK_FILTERING; + if (strName == "SPORK_5_MAX_VALUE") return SPORK_5_MAX_VALUE; + if (strName == "SPORK_7_MASTERNODE_SCANNING") return SPORK_7_MASTERNODE_SCANNING; + if (strName == "SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT") return SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT; + if (strName == "SPORK_9_MASTERNODE_BUDGET_ENFORCEMENT") return SPORK_9_MASTERNODE_BUDGET_ENFORCEMENT; + if (strName == "SPORK_10_MASTERNODE_PAY_UPDATED_NODES") return SPORK_10_MASTERNODE_PAY_UPDATED_NODES; + if (strName == "SPORK_13_ENABLE_SUPERBLOCKS") return SPORK_13_ENABLE_SUPERBLOCKS; + if (strName == "SPORK_14_NEW_PROTOCOL_ENFORCEMENT") return SPORK_14_NEW_PROTOCOL_ENFORCEMENT; + if (strName == "SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2") return SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2; + if (strName == "SPORK_16_ZEROCOIN_MAINTENANCE_MODE") return SPORK_16_ZEROCOIN_MAINTENANCE_MODE; + return -1; +} -void ReprocessBlocks(int nBlocks) +std::string CSporkManager::GetSporkNameByID(int id) { - std::map::iterator it = mapRejectedBlocks.begin(); - while (it != mapRejectedBlocks.end()) { - //use a window twice as large as is usual for the nBlocks we want to reset - if ((*it).second > GetTime() - (nBlocks * 60 * 5)) { - BlockMap::iterator mi = mapBlockIndex.find((*it).first); - if (mi != mapBlockIndex.end() && (*mi).second) { - LOCK(cs_main); - - CBlockIndex* pindex = (*mi).second; - LogPrintf("ReprocessBlocks - %s\n", (*it).first.ToString()); - - CValidationState state; - ReconsiderBlock(state, pindex); - } - } - ++it; - } - - CValidationState state; - { - LOCK(cs_main); - DisconnectBlocksAndReprocess(nBlocks); - } + if (id == SPORK_2_SWIFTTX) return "SPORK_2_SWIFTTX"; + if (id == SPORK_3_SWIFTTX_BLOCK_FILTERING) return "SPORK_3_SWIFTTX_BLOCK_FILTERING"; + if (id == SPORK_5_MAX_VALUE) return "SPORK_5_MAX_VALUE"; + if (id == SPORK_7_MASTERNODE_SCANNING) return "SPORK_7_MASTERNODE_SCANNING"; + if (id == SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT) return "SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT"; + if (id == SPORK_9_MASTERNODE_BUDGET_ENFORCEMENT) return "SPORK_9_MASTERNODE_BUDGET_ENFORCEMENT"; + if (id == SPORK_10_MASTERNODE_PAY_UPDATED_NODES) return "SPORK_10_MASTERNODE_PAY_UPDATED_NODES"; + if (id == SPORK_13_ENABLE_SUPERBLOCKS) return "SPORK_13_ENABLE_SUPERBLOCKS"; + if (id == SPORK_14_NEW_PROTOCOL_ENFORCEMENT) return "SPORK_14_NEW_PROTOCOL_ENFORCEMENT"; + if (id == SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2) return "SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2"; + if (id == SPORK_16_ZEROCOIN_MAINTENANCE_MODE) return "SPORK_16_ZEROCOIN_MAINTENANCE_MODE"; - if (state.IsValid()) { - ActivateBestChain(state); - } + return "Unknown"; } -bool CSporkManager::CheckSignature(CSporkMessage& spork, bool fRequireNew) +bool CSporkManager::SetPrivKey(std::string strPrivKey) { - //note: need to investigate why this is failing - std::string strMessage = std::to_string(spork.nSporkID) + std::to_string(spork.nValue) + std::to_string(spork.nTimeSigned); - CPubKey pubkeynew(ParseHex(Params().SporkPubKey())); - std::string errorMessage = ""; + CSporkMessage spork; - bool fValidWithNewKey = obfuScationSigner.VerifyMessage(pubkeynew, spork.vchSig,strMessage, errorMessage); + spork.Sign(strPrivKey); - if (fRequireNew && !fValidWithNewKey) - return false; - - // See if window is open that allows for old spork key to sign messages - if (!fValidWithNewKey && GetAdjustedTime() < Params().RejectOldSporkKey()) { - CPubKey pubkeyold(ParseHex(Params().SporkPubKeyOld())); - return obfuScationSigner.VerifyMessage(pubkeyold, spork.vchSig, strMessage, errorMessage); + const bool fRequireNew = GetTime() >= Params().NewSporkStart(); + if (spork.CheckSignature(fRequireNew)) { + // Test signing successful, proceed + LogPrintf("%s : -- Successfully initialized as spork signer\n", __func__); + strMasterPrivKey = strPrivKey; + return true; } - return fValidWithNewKey; + return false; } -bool CSporkManager::Sign(CSporkMessage& spork) +bool CSporkMessage::Sign(std::string strSignKey) { - std::string strMessage = std::to_string(spork.nSporkID) + std::to_string(spork.nValue) + std::to_string(spork.nTimeSigned); + std::string strMessage = std::to_string(nSporkID) + std::to_string(nValue) + std::to_string(nTimeSigned); - CKey key2; - CPubKey pubkey2; + CKey key; + CPubKey pubkey; std::string errorMessage = ""; - if (!obfuScationSigner.SetKey(strMasterPrivKey, errorMessage, key2, pubkey2)) { - LogPrintf("CMasternodePayments::Sign - ERROR: Invalid masternodeprivkey: '%s'\n", errorMessage); - return false; + if (!obfuScationSigner.SetKey(strSignKey, errorMessage, key, pubkey)) { + return error("%s : SetKey error: '%s'\n", __func__, errorMessage); } - if (!obfuScationSigner.SignMessage(strMessage, errorMessage, spork.vchSig, key2)) { - LogPrintf("CMasternodePayments::Sign - Sign message failed"); - return false; + if (!obfuScationSigner.SignMessage(strMessage, errorMessage, vchSig, key)) { + return error("%s : Sign message failed", __func__); } - if (!obfuScationSigner.VerifyMessage(pubkey2, spork.vchSig, strMessage, errorMessage)) { - LogPrintf("CMasternodePayments::Sign - Verify message failed"); - return false; + if (!obfuScationSigner.VerifyMessage(pubkey, vchSig, strMessage, errorMessage)) { + return error("%s : Verify message failed", __func__); } return true; } -bool CSporkManager::UpdateSpork(int nSporkID, int64_t nValue) +bool CSporkMessage::CheckSignature(bool fRequireNew) { - CSporkMessage msg; - msg.nSporkID = nSporkID; - msg.nValue = nValue; - msg.nTimeSigned = GetTime(); - - if (Sign(msg)) { - Relay(msg); - mapSporks[msg.GetHash()] = msg; - mapSporksActive[nSporkID] = msg; - return true; - } - - return false; -} - -void CSporkManager::Relay(CSporkMessage& msg) -{ - CInv inv(MSG_SPORK, msg.GetHash()); - RelayInv(inv); -} - -bool CSporkManager::SetPrivKey(std::string strPrivKey) -{ - CSporkMessage msg; - - // Test signing successful, proceed - strMasterPrivKey = strPrivKey; + //note: need to investigate why this is failing + std::string strMessage = std::to_string(nSporkID) + std::to_string(nValue) + std::to_string(nTimeSigned); + CPubKey pubkeynew(ParseHex(Params().SporkPubKey())); + std::string errorMessage = ""; - Sign(msg); + bool fValidWithNewKey = obfuScationSigner.VerifyMessage(pubkeynew, vchSig, strMessage, errorMessage); - bool fRequireNew = GetTime() >= Params().NewSporkStart(); - if (CheckSignature(msg, fRequireNew)) { - LogPrintf("CSporkManager::SetPrivKey - Successfully initialized as spork signer\n"); - return true; - } else { + if (fRequireNew && !fValidWithNewKey) return false; - } -} -int CSporkManager::GetSporkIDByName(std::string strName) -{ - if (strName == "SPORK_2_SWIFTTX") return SPORK_2_SWIFTTX; - if (strName == "SPORK_3_SWIFTTX_BLOCK_FILTERING") return SPORK_3_SWIFTTX_BLOCK_FILTERING; - if (strName == "SPORK_5_MAX_VALUE") return SPORK_5_MAX_VALUE; - if (strName == "SPORK_7_MASTERNODE_SCANNING") return SPORK_7_MASTERNODE_SCANNING; - if (strName == "SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT") return SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT; - if (strName == "SPORK_9_MASTERNODE_BUDGET_ENFORCEMENT") return SPORK_9_MASTERNODE_BUDGET_ENFORCEMENT; - if (strName == "SPORK_10_MASTERNODE_PAY_UPDATED_NODES") return SPORK_10_MASTERNODE_PAY_UPDATED_NODES; - if (strName == "SPORK_13_ENABLE_SUPERBLOCKS") return SPORK_13_ENABLE_SUPERBLOCKS; - if (strName == "SPORK_14_NEW_PROTOCOL_ENFORCEMENT") return SPORK_14_NEW_PROTOCOL_ENFORCEMENT; - if (strName == "SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2") return SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2; - if (strName == "SPORK_16_ZEROCOIN_MAINTENANCE_MODE") return SPORK_16_ZEROCOIN_MAINTENANCE_MODE; + // See if window is open that allows for old spork key to sign messages + if (!fValidWithNewKey && GetAdjustedTime() < Params().RejectOldSporkKey()) { + CPubKey pubkeyold(ParseHex(Params().SporkPubKeyOld())); + return obfuScationSigner.VerifyMessage(pubkeyold, vchSig, strMessage, errorMessage); + } - return -1; + return fValidWithNewKey; } -std::string CSporkManager::GetSporkNameByID(int id) +void CSporkMessage::Relay() { - if (id == SPORK_2_SWIFTTX) return "SPORK_2_SWIFTTX"; - if (id == SPORK_3_SWIFTTX_BLOCK_FILTERING) return "SPORK_3_SWIFTTX_BLOCK_FILTERING"; - if (id == SPORK_5_MAX_VALUE) return "SPORK_5_MAX_VALUE"; - if (id == SPORK_7_MASTERNODE_SCANNING) return "SPORK_7_MASTERNODE_SCANNING"; - if (id == SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT) return "SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT"; - if (id == SPORK_9_MASTERNODE_BUDGET_ENFORCEMENT) return "SPORK_9_MASTERNODE_BUDGET_ENFORCEMENT"; - if (id == SPORK_10_MASTERNODE_PAY_UPDATED_NODES) return "SPORK_10_MASTERNODE_PAY_UPDATED_NODES"; - if (id == SPORK_13_ENABLE_SUPERBLOCKS) return "SPORK_13_ENABLE_SUPERBLOCKS"; - if (id == SPORK_14_NEW_PROTOCOL_ENFORCEMENT) return "SPORK_14_NEW_PROTOCOL_ENFORCEMENT"; - if (id == SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2) return "SPORK_15_NEW_PROTOCOL_ENFORCEMENT_2"; - if (id == SPORK_16_ZEROCOIN_MAINTENANCE_MODE) return "SPORK_16_ZEROCOIN_MAINTENANCE_MODE"; - - return "Unknown"; + CInv inv(MSG_SPORK, GetHash()); + RelayInv(inv); } + diff --git a/src/spork.h b/src/spork.h index e7c068ebcc4d0..8d42fdf055b9d 100644 --- a/src/spork.h +++ b/src/spork.h @@ -7,6 +7,7 @@ #define SPORK_H #include "base58.h" +#include "hash.h" #include "key.h" #include "main.h" #include "net.h" @@ -57,33 +58,31 @@ class CSporkMessage; class CSporkManager; extern std::map mapSporks; -extern std::map mapSporksActive; extern CSporkManager sporkManager; -void LoadSporksFromDB(); -void ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); -int64_t GetSporkValue(int nSporkID); -bool IsSporkActive(int nSporkID); -void ReprocessBlocks(int nBlocks); - // -// Spork Class -// Keeps track of all of the network spork settings +// Spork Classes +// Keep track of all of the network spork settings // class CSporkMessage { +private: + + public: std::vector vchSig; int nSporkID; int64_t nValue; int64_t nTimeSigned; - uint256 GetHash() - { - uint256 n = HashQuark(BEGIN(nSporkID), END(nTimeSigned)); - return n; - } + CSporkMessage(int nSporkID, int64_t nValue, int64_t nTimeSigned) : nSporkID(nSporkID), nValue(nValue), nTimeSigned(nTimeSigned) {} + CSporkMessage() : nSporkID(0), nValue(0), nTimeSigned(0) {} + + uint256 GetHash() { return HashQuark(BEGIN(nSporkID), END(nTimeSigned)); } + bool Sign(std::string strSignKey); + bool CheckSignature(bool fRequireNew = false); + void Relay(); ADD_SERIALIZE_METHODS; @@ -103,19 +102,23 @@ class CSporkManager private: std::vector vchSig; std::string strMasterPrivKey; + std::map mapSporksActive; public: - CSporkManager() - { - } + CSporkManager() {} + void LoadSporksFromDB(); + + void ProcessSpork(CNode* pfrom, std::string& strCommand, CDataStream& vRecv); + int64_t GetSporkValue(int nSporkID); + void ExecuteSpork(int nSporkID, int nValue); + bool UpdateSpork(int nSporkID, int64_t nValue); + + bool IsSporkActive(int nSporkID); std::string GetSporkNameByID(int id); int GetSporkIDByName(std::string strName); - bool UpdateSpork(int nSporkID, int64_t nValue); + bool SetPrivKey(std::string strPrivKey); - bool CheckSignature(CSporkMessage& spork, bool fRequireNew = false); - bool Sign(CSporkMessage& spork); - void Relay(CSporkMessage& msg); }; #endif diff --git a/src/swifttx.cpp b/src/swifttx.cpp index 1d7f4ca306a27..225942d63779e 100644 --- a/src/swifttx.cpp +++ b/src/swifttx.cpp @@ -37,7 +37,7 @@ int nCompleteTXLocks; void ProcessMessageSwiftTX(CNode* pfrom, std::string& strCommand, CDataStream& vRecv) { if (fLiteMode) return; //disable all obfuscation/masternode related functionality - if (!IsSporkActive(SPORK_2_SWIFTTX)) return; + if (!sporkManager.IsSporkActive(SPORK_2_SWIFTTX)) return; if (!masternodeSync.IsBlockchainSynced()) return; if (strCommand == "ix") { @@ -197,7 +197,7 @@ bool IsIXTXValid(const CTransaction& txCollateral) } } - if (nValueOut > GetSporkValue(SPORK_5_MAX_VALUE) * COIN) { + if (nValueOut > sporkManager.GetSporkValue(SPORK_5_MAX_VALUE) * COIN) { LogPrint("swiftx", "IsIXTXValid - Transaction value too high - %s\n", txCollateral.ToString().c_str()); return false; } @@ -461,7 +461,7 @@ void CleanTransactionLocksList() int GetTransactionLockSignatures(uint256 txHash) { if(fLargeWorkForkFound || fLargeWorkInvalidChainFound) return -2; - if (!IsSporkActive(SPORK_2_SWIFTTX)) return -1; + if (!sporkManager.IsSporkActive(SPORK_2_SWIFTTX)) return -1; std::map::iterator it = mapTxLocks.find(txHash); if(it != mapTxLocks.end()) return it->second.CountSignatures(); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index a616e6f846c34..79c957c774e44 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -2782,7 +2782,7 @@ UniValue mintzerocoin(const UniValue& params, bool fHelp) } int64_t nTime = GetTimeMillis(); - if(GetAdjustedTime() > GetSporkValue(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) + if(sporkManager.IsSporkActive(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) throw JSONRPCError(RPC_WALLET_ERROR, "zPIV is currently disabled due to maintenance."); EnsureWalletIsUnlocked(true); @@ -2886,7 +2886,7 @@ UniValue spendzerocoin(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); - if(GetAdjustedTime() > GetSporkValue(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) + if(sporkManager.IsSporkActive(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) throw JSONRPCError(RPC_WALLET_ERROR, "zPIV is currently disabled due to maintenance."); EnsureWalletIsUnlocked(); @@ -2950,7 +2950,7 @@ UniValue spendzerocoinmints(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); - if(GetAdjustedTime() > GetSporkValue(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) + if(sporkManager.IsSporkActive(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) throw JSONRPCError(RPC_WALLET_ERROR, "zPIV is currently disabled due to maintenance."); std::string address_str = ""; @@ -3739,7 +3739,7 @@ UniValue spendrawzerocoin(const UniValue& params, bool fHelp) LOCK2(cs_main, pwalletMain->cs_wallet); - if (GetAdjustedTime() > GetSporkValue(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) + if (sporkManager.IsSporkActive(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) throw JSONRPCError(RPC_WALLET_ERROR, "zPIV is currently disabled due to maintenance."); CBigNum serial; diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index aa5349ce40d65..49d26c3b19c44 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1845,7 +1845,7 @@ bool CWallet::SelectStakeCoins(std::list >& listInp /* Disable zPIV Staking //zPIV - if ((GetBoolArg("-zpivstake", true) || fPrecompute) && chainActive.Height() > Params().Zerocoin_Block_V2_Start() && !IsSporkActive(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) { + if ((GetBoolArg("-zpivstake", true) || fPrecompute) && chainActive.Height() > Params().Zerocoin_Block_V2_Start() && !sporkManager.IsSporkActive(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) { //Only update zPIV set once per update interval bool fUpdate = false; static int64_t nTimeLastUpdate = 0; @@ -3312,7 +3312,7 @@ void CWallet::CreateAutoMintTransaction(const CAmount& nMintAmount, CCoinControl void CWallet::AutoZeromint() { // Don't bother Autominting if Zerocoin Protocol isn't active - if (GetAdjustedTime() > GetSporkValue(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) return; + if (sporkManager.IsSporkActive(SPORK_16_ZEROCOIN_MAINTENANCE_MODE)) return; // Wait until blockchain + masternodes are fully synced and wallet is unlocked. if (IsInitialBlockDownload() || IsLocked()){ @@ -3727,7 +3727,7 @@ bool CMerkleTx::AcceptToMemoryPool(bool fLimitFree, bool fRejectInsaneFee, bool int CMerkleTx::GetTransactionLockSignatures() const { if (fLargeWorkForkFound || fLargeWorkInvalidChainFound) return -2; - if (!IsSporkActive(SPORK_2_SWIFTTX)) return -3; + if (!sporkManager.IsSporkActive(SPORK_2_SWIFTTX)) return -3; if (!fEnableSwiftTX) return -1; //compile consessus vote