Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor mocknet and add more params #1292

Merged
merged 3 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 36 additions & 27 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#include <boost/algorithm/string/case_conv.hpp>

bool fMockNetwork = false;
std::string sMockFoundationPubKey;
uint64_t nMockBlockTimeSecs = 0;

std::vector<CTransactionRef> CChainParams::CreateGenesisMasternodes()
{
Expand Down Expand Up @@ -945,8 +943,7 @@ boost::optional<int> UpdateHeightValidation(const std::string& argName, const st
return {};
}

void CRegTestParams::UpdateActivationParametersFromArgs()
{
void SetupCommonArgActivationParams(Consensus::Params &consensus) {
UpdateHeightValidation("Segwit", "-segwitheight", consensus.SegwitHeight);
UpdateHeightValidation("AMK", "-amkheight", consensus.AMKHeight);
UpdateHeightValidation("Bayfront", "-bayfrontheight", consensus.BayfrontHeight);
Expand All @@ -972,7 +969,42 @@ void CRegTestParams::UpdateActivationParametersFromArgs()
consensus.pos.nTargetSpacing = 30; // seconds
consensus.pos.nTargetTimespanV2 = 1008 * consensus.pos.nTargetSpacing; // 1008 blocks
}
}


void CMainParams::UpdateActivationParametersFromArgs() {
fMockNetwork = gArgs.IsArgSet("-mocknet");
if (fMockNetwork) {
LogPrintf("============================================\n");
LogPrintf("WARNING: MOCKNET ACTIVE. THIS IS NOT MAINNET\n");
LogPrintf("============================================\n");
auto sMockFoundationPubKey = gArgs.GetArg("-mocknet-key", "");
auto nMockBlockTimeSecs = gArgs.GetArg("-mocknet-blocktime", 10);
if (!gArgs.IsArgSet("-maxtipage")) {
gArgs.ForceSetArg("-maxtipage", "2207520000"); // 10 years
}

// End of args. Perform sane set below.
consensus.pos.nTargetSpacing = nMockBlockTimeSecs;
consensus.pos.nTargetTimespanV2 = 10 * consensus.pos.nTargetSpacing;
consensus.pos.allowMintingWithoutPeers = true;

SetupCommonArgActivationParams(consensus);

LogPrintf("mocknet: block-time: %s secs\n", consensus.pos.nTargetSpacing);

// Add additional foundation members here for testing
if (!sMockFoundationPubKey.empty()) {
consensus.foundationMembers.insert(GetScriptForDestination(DecodeDestination(sMockFoundationPubKey, *this)));
LogPrintf("mocknet: key: %s\n", sMockFoundationPubKey);
}
}
}


void CRegTestParams::UpdateActivationParametersFromArgs()
{
SetupCommonArgActivationParams(consensus);
if (!gArgs.IsArgSet("-vbparams")) return;

for (const std::string& strDeployment : gArgs.GetArgs("-vbparams")) {
Expand Down Expand Up @@ -1003,29 +1035,6 @@ void CRegTestParams::UpdateActivationParametersFromArgs()
}
}

void CMainParams::UpdateActivationParametersFromArgs() {
fMockNetwork = gArgs.IsArgSet("-mocknet");
if (fMockNetwork) {
LogPrintf("============================================\n");
LogPrintf("WARNING: MOCKNET ACTIVE. THIS IS NOT MAINNET\n");
LogPrintf("============================================\n");
sMockFoundationPubKey = gArgs.GetArg("-mocknet-key", "");
nMockBlockTimeSecs = gArgs.GetArg("-mocknet-blocktime", 10);
}

if (fMockNetwork) {
consensus.pos.nTargetSpacing = nMockBlockTimeSecs;
consensus.pos.nTargetTimespanV2 = 10 * consensus.pos.nTargetSpacing;
LogPrintf("mocknet: block-time: %s secs\n", nMockBlockTimeSecs);
// Add additional foundation members here for testing
if (!sMockFoundationPubKey.empty()) {
consensus.foundationMembers.insert(GetScriptForDestination(DecodeDestination(sMockFoundationPubKey, *this)));
LogPrintf("mocknet: key: %s\n", sMockFoundationPubKey);
}
}
}


static std::unique_ptr<const CChainParams> globalChainParams;

const CChainParams &Params() {
Expand Down
2 changes: 0 additions & 2 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

/** Used for mocking network with low difficulty for testing */
extern bool fMockNetwork;
extern std::string sMockFoundationPubKey;
extern uint64_t nMockBlockTimeSecs;

struct SeedSpec6 {
uint8_t addr[16];
Expand Down