From 0cc1530f288f3602b0d9bb3e0de1d5587c43efe6 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Tue, 24 May 2022 13:20:21 +0530 Subject: [PATCH 1/2] Add mocknet helpers --- .gitignore | 1 + contrib/devtools/mocknet.patch | 38 ++++++++++++++++++++++++++++++++++ src/chainparams.cpp | 13 ++++++++++++ src/chainparams.h | 6 ++++++ src/init.cpp | 9 +++++++- test/lint/check-doc.py | 2 +- 6 files changed, 67 insertions(+), 2 deletions(-) create mode 100644 contrib/devtools/mocknet.patch diff --git a/.gitignore b/.gitignore index 807436234b1..a77db6d536e 100644 --- a/.gitignore +++ b/.gitignore @@ -79,6 +79,7 @@ src/univalue/gen # Only ignore unexpected patches *.patch !depends/patches/**/*.patch +!contrib/devtools/*.patch #libtool object files *.lo diff --git a/contrib/devtools/mocknet.patch b/contrib/devtools/mocknet.patch new file mode 100644 index 00000000000..4e0bc2fe253 --- /dev/null +++ b/contrib/devtools/mocknet.patch @@ -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 diff --git a/src/chainparams.cpp b/src/chainparams.cpp index fe5f9fac6b0..3f5c3557dcf 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -19,6 +19,10 @@ #include #include +bool fMockNetwork = false; +std::string sMockFoundationPubKey; +uint64_t nMockBlockTimeSecs = 8; + std::vector CChainParams::CreateGenesisMasternodes() { std::vector mnTxs; @@ -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))); + } + } } }; diff --git a/src/chainparams.h b/src/chainparams.h index 1e0c243cce3..c5a252f06f7 100644 --- a/src/chainparams.h +++ b/src/chainparams.h @@ -15,6 +15,12 @@ #include #include + +/** 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; diff --git a/src/init.cpp b/src/init.cpp index 78cb828fcdf..311aaddb234 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -375,7 +375,9 @@ void SetupServerArgs() // Hidden Options std::vector hidden_args = { - "-dbcrashratio", "-forcecompactdb", "-interrupt-block=", "-stop-block=", + "-dbcrashratio", "-forcecompactdb", + "-interrupt-block=", "-stop-block=", + "-mocknet", "-mocknet-blocktime=", "-mocknet-key=" // GUI args. These will be overwritten by SetupUIArgs for the GUI "-choosedatadir", "-lang=", "-min", "-resetguisettings", "-splash"}; @@ -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; } diff --git a/test/lint/check-doc.py b/test/lint/check-doc.py index 9788a10ed30..3f1b15729ca 100755 --- a/test/lint/check-doc.py +++ b/test/lint/check-doc.py @@ -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(): From 90830f6f9642283780bf570d1448e90121674522 Mon Sep 17 00:00:00 2001 From: Prasanna Loganathar Date: Tue, 24 May 2022 13:38:17 +0530 Subject: [PATCH 2/2] Update chainparams.cpp --- src/chainparams.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 3f5c3557dcf..156f9b9807e 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -21,7 +21,7 @@ bool fMockNetwork = false; std::string sMockFoundationPubKey; -uint64_t nMockBlockTimeSecs = 8; +uint64_t nMockBlockTimeSecs = 0; std::vector CChainParams::CreateGenesisMasternodes() {