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:
Alexander Block 2018-08-11 00:36:17 +02:00 committed by UdjinM6
parent a959f60aa7
commit 2d4e18537c
5 changed files with 83 additions and 12 deletions

View File

@ -8,6 +8,7 @@
#include "masternodeman.h" #include "masternodeman.h"
#include "netbase.h" #include "netbase.h"
#include "protocol.h" #include "protocol.h"
#include "netbase.h"
// Keep track of the active Masternode // Keep track of the active Masternode
CActiveMasternode activeMasternode; 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) { if(!fFoundLocal) {
nState = ACTIVE_MASTERNODE_NOT_CAPABLE; 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."; 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; return;
} }
if(Params().NetworkIDString() != CBaseChainParams::REGTEST) {
// Check socket connectivity // Check socket connectivity
LogPrintf("CActiveMasternode::ManageStateInitial -- Checking inbound connection to '%s'\n", service.ToString()); LogPrintf("CActiveMasternode::ManageStateInitial -- Checking inbound connection to '%s'\n", service.ToString());
SOCKET hSocket; SOCKET hSocket;
@ -193,7 +201,7 @@ void CActiveMasternode::ManageStateInitial(CConnman& connman)
LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason);
return; return;
} }
}
// Default to REMOTE // Default to REMOTE
eType = MASTERNODE_REMOTE; eType = MASTERNODE_REMOTE;

View File

@ -639,6 +639,13 @@ public:
consensus.vDeployments[d].nStartTime = nStartTime; consensus.vDeployments[d].nStartTime = nStartTime;
consensus.vDeployments[d].nTimeout = nTimeout; 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; static CRegTestParams regTestParams;
@ -678,3 +685,8 @@ void UpdateRegtestBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime,
{ {
regTestParams.UpdateBIP9Parameters(d, nStartTime, nTimeout); regTestParams.UpdateBIP9Parameters(d, nStartTime, nTimeout);
} }
void UpdateRegtestBudgetParameters(int nMasternodePaymentsStartBlock, int nBudgetPaymentsStartBlock, int nSuperblockStartBlock)
{
regTestParams.UpdateBudgetParameters(nMasternodePaymentsStartBlock, nBudgetPaymentsStartBlock, nSuperblockStartBlock);
}

View File

@ -141,4 +141,9 @@ void SelectParams(const std::string& chain);
*/ */
void UpdateRegtestBIP9Parameters(Consensus::DeploymentPos d, int64_t nStartTime, int64_t nTimeout); 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 #endif // BITCOIN_CHAINPARAMS_H

View File

@ -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; return true;
} }

View File

@ -135,13 +135,14 @@ UniValue masternode(const JSONRPCRequest& request)
#endif // ENABLE_WALLET #endif // ENABLE_WALLET
strCommand != "list" && strCommand != "list-conf" && strCommand != "count" && strCommand != "list" && strCommand != "list-conf" && strCommand != "count" &&
strCommand != "debug" && strCommand != "current" && strCommand != "winner" && strCommand != "winners" && strCommand != "genkey" && strCommand != "debug" && strCommand != "current" && strCommand != "winner" && strCommand != "winners" && strCommand != "genkey" &&
strCommand != "connect" && strCommand != "status")) strCommand != "connect" && strCommand != "status" && strCommand != "check"))
throw std::runtime_error( throw std::runtime_error(
"masternode \"command\"...\n" "masternode \"command\"...\n"
"Set of commands to execute masternode related actions\n" "Set of commands to execute masternode related actions\n"
"\nArguments:\n" "\nArguments:\n"
"1. \"command\" (string or set of strings, required) The command to execute\n" "1. \"command\" (string or set of strings, required) The command to execute\n"
"\nAvailable commands:\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" " 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" " current - Print info on current masternode winner to be paid the next block (calculated locally)\n"
" genkey - Generate new masternodeprivkey\n" " genkey - Generate new masternodeprivkey\n"
@ -477,6 +478,26 @@ UniValue masternode(const JSONRPCRequest& request)
return obj; 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; return NullUniValue;
} }