Some useful commits from the DIP3 PR in regard to integration tests (#2218)
* Allow changing budget parameters for regtest * Lift some limitations for local addresses for masternodes in regtest Needed to make masternodes works in regtest mode * Add "masternode check" RPC to force invocation of CheckAndRemove Useful in integration tests where MN lists must be predictable
This commit is contained in:
parent
a959f60aa7
commit
2d4e18537c
@ -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,6 +188,7 @@ void CActiveMasternode::ManageStateInitial(CConnman& connman)
|
||||
return;
|
||||
}
|
||||
|
||||
if(Params().NetworkIDString() != CBaseChainParams::REGTEST) {
|
||||
// Check socket connectivity
|
||||
LogPrintf("CActiveMasternode::ManageStateInitial -- Checking inbound connection to '%s'\n", service.ToString());
|
||||
SOCKET hSocket;
|
||||
@ -193,7 +201,7 @@ void CActiveMasternode::ManageStateInitial(CConnman& connman)
|
||||
LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
// Default to REMOTE
|
||||
eType = MASTERNODE_REMOTE;
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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
|
||||
|
25
src/init.cpp
25
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<std::string> 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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user