From 1e6eba297c240bdcfeba6df4aed0a38d2da2fd31 Mon Sep 17 00:00:00 2001 From: Peter Bushnell Date: Wed, 27 Jul 2022 09:46:06 +0100 Subject: [PATCH 1/2] Mocknet create MN on start --- src/init.cpp | 34 +++++++++++++++++++++++++++++++++- src/pos.cpp | 5 +++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index ac461bce05..4cfb0c1aa5 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -2116,7 +2116,39 @@ bool AppInitMain(InitInterfaces& interfaces) g_banman->DumpBanlist(); }, DUMP_BANS_INTERVAL * 1000); - // ********************************************************* Step XX: start spv + // ********************************************************* Step XX.a: create mocknet MN + // MN: 0000000000000000000000000000000000000000000000000000000000000000 + // Owner/Operator Address: df1qu04hcpd3untnm453mlkgc0g9mr9ap39lyx4ajc + // Owner/Operator Privkey: L5DhrVPhA2FbJ1ezpN3JijHVnnH1sVcbdcAcp3nE373ooGH6LEz6 + + if (fMockNetwork && HasWallets()) { + + // Import privkey + const auto key = DecodeSecret("L5DhrVPhA2FbJ1ezpN3JijHVnnH1sVcbdcAcp3nE373ooGH6LEz6"); + const auto pubkey = key.GetPubKey(); + const auto dest = WitnessV0KeyHash(PKHash{pubkey}); + const auto keyID = pubkey.GetID(); + const auto time{std::time(nullptr)}; + + auto pwallet = GetWallets()[0]; + pwallet->SetAddressBook(dest, "", "receive"); + pwallet->ImportPrivKeys({{keyID, key}}, time); + + // Create masternode + CMasternode node; + node.creationHeight = chain_active_height - Params().GetConsensus().mn.newActivationDelay; + node.ownerType = WitV0KeyHashType; + node.ownerAuthAddress = keyID; + node.operatorType = WitV0KeyHashType; + node.operatorAuthAddress = keyID; + node.version = CMasternode::VERSION0; + pcustomcsview->CreateMasternode(uint256S(std::string{64, '0'}), node, CMasternode::ZEROYEAR); + for (uint8_t i{0}; i < SUBNODE_COUNT; ++i) { + pcustomcsview->SetSubNodesBlockTime(node.operatorAuthAddress, chain_active_height, i, time); + } + } + + // ********************************************************* Step XX.b: start spv if (spv::pspv) { spv::pspv->Connect(); diff --git a/src/pos.cpp b/src/pos.cpp index 81cd0a856e..dddcaf8b18 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}; From b4e293a335fa330b84fea04fb79b9db6a5a4b2cb Mon Sep 17 00:00:00 2001 From: jouzo Date: Thu, 28 Jul 2022 13:46:34 +0100 Subject: [PATCH 2/2] Add mocknet operator address to masternode_operator args --- src/init.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index 4cfb0c1aa5..cd568b4f05 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -2166,7 +2166,12 @@ bool AppInitMain(InitInterfaces& interfaces) std::set operatorsSet; bool atLeastOneRunningOperator = false; - auto const operators = gArgs.GetArgs("-masternode_operator"); + auto operators = gArgs.GetArgs("-masternode_operator"); + + if (fMockNetwork) { + auto mocknet_operator = "df1qu04hcpd3untnm453mlkgc0g9mr9ap39lyx4ajc"; + operators.push_back(mocknet_operator); + } std::vector stakersParams; for (auto const & op : operators) {