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

Add mocknet helpers #1273

Merged
merged 3 commits into from
May 24, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ src/univalue/gen
# Only ignore unexpected patches
*.patch
!depends/patches/**/*.patch
!contrib/devtools/*.patch

#libtool object files
*.lo
Expand Down
38 changes: 38 additions & 0 deletions contrib/devtools/mocknet.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
diff --git a/src/pos.cpp b/src/pos.cpp
index 1ad8d066d..01b13b8aa 100644
--- a/src/pos.cpp
+++ b/src/pos.cpp
@@ -140,6 +140,11 @@ unsigned int GetNextWorkRequired(const CBlockIndex* pindexLast, int64_t blockTim

unsigned int nProofOfWorkLimit = UintToArith256(params.pos.diffLimit).GetCompact();

+ // Lower difficulty fork for mock network testing
+ if (fMockNetwork) {
+ return nProofOfWorkLimit;
+ }
+
int nHeight{pindexLast->nHeight + 1};
bool newDifficultyAdjust{nHeight > params.EunosHeight};

diff --git a/src/version.h b/src/version.h
index 3ab303d56..fb84cea92 100644
--- a/src/version.h
+++ b/src/version.h
@@ -9,7 +9,7 @@
* network protocol versioning
*/

-static const int PROTOCOL_VERSION = 70029;
+static const int PROTOCOL_VERSION = 100000;

//! initial proto version, to be increased after version/verack negotiation
static const int INIT_PROTO_VERSION = 209;
@@ -18,7 +18,7 @@ static const int INIT_PROTO_VERSION = 209;
static const int GETHEADERS_VERSION = 31800;

//! disconnect from peers older than this proto version
-static const int MIN_PEER_PROTO_VERSION = 70023;
+static const int MIN_PEER_PROTO_VERSION = 100000;

//! nTime field added to CAddress, starting with this version;
//! if possible, avoid requesting addresses nodes older than this
13 changes: 13 additions & 0 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/case_conv.hpp>

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

std::vector<CTransactionRef> CChainParams::CreateGenesisMasternodes()
{
std::vector<CTransactionRef> mnTxs;
Expand Down Expand Up @@ -325,6 +329,15 @@ class CMainParams : public CChainParams {
/* nTxCount */ 1091894,
/* dTxRate */ 0.1841462153145931
};

if (fMockNetwork) {
consensus.pos.nTargetSpacing = nMockBlockTimeSecs;
consensus.pos.nTargetTimespanV2 = 10 * consensus.pos.nTargetSpacing;
// Add additional foundation members here for testing
if (!sMockFoundationPubKey.empty()) {
consensus.foundationMembers.insert(GetScriptForDestination(DecodeDestination(sMockFoundationPubKey, *this)));
}
}
}
};

Expand Down
6 changes: 6 additions & 0 deletions src/chainparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
#include <memory>
#include <vector>


/** 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];
uint16_t port;
Expand Down
9 changes: 8 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,9 @@ void SetupServerArgs()

// Hidden Options
std::vector<std::string> hidden_args = {
"-dbcrashratio", "-forcecompactdb", "-interrupt-block=<hash|height>", "-stop-block=<hash|height>",
"-dbcrashratio", "-forcecompactdb",
"-interrupt-block=<hash|height>", "-stop-block=<hash|height>",
"-mocknet", "-mocknet-blocktime=<secs>", "-mocknet-key=<pubkey>"
// GUI args. These will be overwritten by SetupUIArgs for the GUI
"-choosedatadir", "-lang=<lang>", "-min", "-resetguisettings", "-splash"};

Expand Down Expand Up @@ -1218,6 +1220,11 @@ bool AppInitParameterInteraction()
fIsFakeNet = Params().NetworkIDString() == "regtest" && gArgs.GetArg("-dummypos", false);
CTxOut::SERIALIZE_FORCED_TO_OLD_IN_TESTS = Params().NetworkIDString() == "regtest" && gArgs.GetArg("-txnotokens", false);

fMockNetwork = gArgs.IsArgSet("-mocknet");
if (fMockNetwork) {
sMockFoundationPubKey = gArgs.GetArg("-mocknet-key", "");
nMockBlockTimeSecs = gArgs.GetArg("-mocknet-blocktime", 10);
}
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion test/lint/check-doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
CMD_GREP_WALLET_HIDDEN_ARGS = r"git grep --function-context 'void DummyWalletInit::AddWalletOptions' -- {}".format(CMD_ROOT_DIR)
CMD_GREP_DOCS = r"git grep --perl-regexp '{}' {}".format(REGEX_DOC, CMD_ROOT_DIR)
# list unsupported, deprecated and duplicate args as they need no documentation
SET_DOC_OPTIONAL = set(['-h', '-help', '-dbcrashratio', '-forcecompactdb', '-interrupt-block', '-stop-block'])
SET_DOC_OPTIONAL = set(['-h', '-help', '-dbcrashratio', '-forcecompactdb', '-interrupt-block', '-stop-block', '-mocknet', '-mocknet-key', '-mocknet-blocktime'])


def lint_missing_argument_documentation():
Expand Down