diff --git a/src/activemasternode.cpp b/src/activemasternode.cpp index 726acfa0e..7b262d6bb 100644 --- a/src/activemasternode.cpp +++ b/src/activemasternode.cpp @@ -8,6 +8,7 @@ #include "masternodeman.h" #include "netbase.h" #include "protocol.h" +#include "netbase.h" // Keep track of the active Masternode CActiveMasternode activeMasternode; @@ -159,6 +160,12 @@ void CActiveMasternode::ManageStateInitial(CConnman& connman) } } + if (!fFoundLocal && Params().NetworkIDString() == CBaseChainParams::REGTEST) { + if (Lookup("127.0.0.1", activeMasternode.service, GetListenPort(), false)) { + fFoundLocal = true; + } + } + if(!fFoundLocal) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = "Can't detect valid external address. Please consider using the externalip configuration option if problem persists. Make sure to use IPv4 address only."; @@ -181,19 +188,20 @@ void CActiveMasternode::ManageStateInitial(CConnman& connman) return; } - // Check socket connectivity - LogPrintf("CActiveMasternode::ManageStateInitial -- Checking inbound connection to '%s'\n", service.ToString()); - SOCKET hSocket; - bool fConnected = ConnectSocket(service, hSocket, nConnectTimeout) && IsSelectableSocket(hSocket); - CloseSocket(hSocket); + if(Params().NetworkIDString() != CBaseChainParams::REGTEST) { + // Check socket connectivity + LogPrintf("CActiveMasternode::ManageStateInitial -- Checking inbound connection to '%s'\n", service.ToString()); + SOCKET hSocket; + bool fConnected = ConnectSocket(service, hSocket, nConnectTimeout) && IsSelectableSocket(hSocket); + CloseSocket(hSocket); - if (!fConnected) { - nState = ACTIVE_MASTERNODE_NOT_CAPABLE; - strNotCapableReason = "Could not connect to " + service.ToString(); - LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); - return; + if (!fConnected) { + nState = ACTIVE_MASTERNODE_NOT_CAPABLE; + strNotCapableReason = "Could not connect to " + service.ToString(); + LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); + return; + } } - // Default to REMOTE eType = MASTERNODE_REMOTE; diff --git a/src/chainparams.cpp b/src/chainparams.cpp index f98388947..c605d7d60 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -639,6 +639,13 @@ public: consensus.vDeployments[d].nStartTime = nStartTime; consensus.vDeployments[d].nTimeout = nTimeout; } + + void UpdateBudgetParameters(int nMasternodePaymentsStartBlock, int nBudgetPaymentsStartBlock, int nSuperblockStartBlock) + { + consensus.nMasternodePaymentsStartBlock = nMasternodePaymentsStartBlock; + consensus.nBudgetPaymentsStartBlock = nBudgetPaymentsStartBlock; + consensus.nSuperblockStartBlock = nSuperblockStartBlock; + } }; static CRegTestParams regTestParams; @@ -678,3 +685,8 @@ void UpdateRegtestBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, { regTestParams.UpdateBIP9Parameters(d, nStartTime, nTimeout); } + +void UpdateRegtestBudgetParameters(int nMasternodePaymentsStartBlock, int nBudgetPaymentsStartBlock, int nSuperblockStartBlock) +{ + regTestParams.UpdateBudgetParameters(nMasternodePaymentsStartBlock, nBudgetPaymentsStartBlock, nSuperblockStartBlock); +} diff --git a/src/chainparams.h b/src/chainparams.h index a0e0b07b3..fa67c9b73 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -141,4 +141,9 @@ void SelectParams(const std::string& chain); */ void UpdateRegtestBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout); +/** + * Allows modifying the budget regtest parameters. + */ +void UpdateRegtestBudgetParameters(int nMasternodePaymentsStartBlock, int nBudgetPaymentsStartBlock, int nSuperblockStartBlock); + #endif // BITCOIN_CHAINPARAMS_H diff --git a/src/init.cpp b/src/init.cpp index cc6f38b7f..b6430790e 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1277,6 +1277,31 @@ bool AppInitParameterInteraction() } } + if (IsArgSet("-budgetparams")) { + // Allow overriding budget parameters for testing + if (!chainparams.MineBlocksOnDemand()) { + return InitError("Budget parameters may only be overridden on regtest."); + } + + std::string strBudgetParams = GetArg("-budgetparams", ""); + std::vector vBudgetParams; + boost::split(vBudgetParams, strBudgetParams, boost::is_any_of(":")); + if (vBudgetParams.size() != 3) { + return InitError("Budget parameters malformed, expecting masternodePaymentsStartBlock:budgetPaymentsStartBlock:superblockStartBlock"); + } + int nMasternodePaymentsStartBlock, nBudgetPaymentsStartBlock, nSuperblockStartBlock; + if (!ParseInt32(vBudgetParams[0], &nMasternodePaymentsStartBlock)) { + return InitError(strprintf("Invalid nMasternodePaymentsStartBlock (%s)", vBudgetParams[0])); + } + if (!ParseInt32(vBudgetParams[1], &nBudgetPaymentsStartBlock)) { + return InitError(strprintf("Invalid nBudgetPaymentsStartBlock (%s)", vBudgetParams[1])); + } + if (!ParseInt32(vBudgetParams[2], &nSuperblockStartBlock)) { + return InitError(strprintf("Invalid nSuperblockStartBlock (%s)", vBudgetParams[2])); + } + UpdateRegtestBudgetParameters(nMasternodePaymentsStartBlock, nBudgetPaymentsStartBlock, nSuperblockStartBlock); + } + return true; } diff --git a/src/rpc/masternode.cpp b/src/rpc/masternode.cpp index d6dd81c50..6508df0d9 100644 --- a/src/rpc/masternode.cpp +++ b/src/rpc/masternode.cpp @@ -135,13 +135,14 @@ UniValue masternode(const JSONRPCRequest& request) #endif // ENABLE_WALLET strCommand != "list" && strCommand != "list-conf" && strCommand != "count" && strCommand != "debug" && strCommand != "current" && strCommand != "winner" && strCommand != "winners" && strCommand != "genkey" && - strCommand != "connect" && strCommand != "status")) + strCommand != "connect" && strCommand != "status" && strCommand != "check")) throw std::runtime_error( "masternode \"command\"...\n" "Set of commands to execute masternode related actions\n" "\nArguments:\n" "1. \"command\" (string or set of strings, required) The command to execute\n" "\nAvailable commands:\n" + " check - Force check all masternodes and remove invalid ones\n" " count - Get information about number of masternodes (DEPRECATED options: 'total', 'ps', 'enabled', 'qualify', 'all')\n" " current - Print info on current masternode winner to be paid the next block (calculated locally)\n" " genkey - Generate new masternodeprivkey\n" @@ -477,6 +478,26 @@ UniValue masternode(const JSONRPCRequest& request) return obj; } + if (strCommand == "check") { + int countBeforeCheck = mnodeman.CountMasternodes(); + int countEnabledBeforeCheck = mnodeman.CountEnabled(); + + mnodeman.CheckAndRemove(*g_connman); + + int countAfterCheck = mnodeman.CountMasternodes(); + int countEnabledAfterCheck = mnodeman.CountEnabled(); + int removedCount = std::max(0, countBeforeCheck - countAfterCheck); + int removedEnabledCount = std::max(0, countEnabledBeforeCheck - countEnabledAfterCheck); + + UniValue obj(UniValue::VOBJ); + obj.push_back(Pair("removedTotalCount", removedCount)); + obj.push_back(Pair("removedEnabledCount", removedEnabledCount)); + obj.push_back(Pair("totalCount", countAfterCheck)); + obj.push_back(Pair("enabledCount", countEnabledAfterCheck)); + + return obj; + } + return NullUniValue; }