diff --git a/src/chainparams.cpp b/src/chainparams.cpp index 38b466dbf0..c9ad109df1 100644 --- a/src/chainparams.cpp +++ b/src/chainparams.cpp @@ -613,7 +613,10 @@ class CTestNetParams : public CChainParams { /* nTxCount */ 178351, /* dTxRate */ 0.03842042178237066 }; + + UpdateActivationParametersFromArgs(); } + void UpdateActivationParametersFromArgs(); }; /** @@ -1378,8 +1381,7 @@ void SetupCommonArgActivationParams(Consensus::Params &consensus) { } } - -void CMainParams::UpdateActivationParametersFromArgs() { +bool SetMocknet(const CChainParams ¶ms, Consensus::Params& consensus) { fMockNetwork = gArgs.IsArgSet("-mocknet"); if (fMockNetwork) { LogPrintf("============================================\n"); @@ -1400,16 +1402,26 @@ void CMainParams::UpdateActivationParametersFromArgs() { // Add additional foundation members here for testing if (!sMockFoundationPubKey.empty()) { - consensus.foundationMembers.insert(GetScriptForDestination(DecodeDestination(sMockFoundationPubKey, *this))); + consensus.foundationMembers.insert(GetScriptForDestination(DecodeDestination(sMockFoundationPubKey, params))); LogPrintf("mocknet: key: %s\n", sMockFoundationPubKey); } // Do this at the end, to ensure simualte mainnet overrides are in place. SetupCommonArgActivationParams(consensus); } + return fMockNetwork; +} + +void CMainParams::UpdateActivationParametersFromArgs() { + SetMocknet(*this, consensus); +} + +void CTestNetParams::UpdateActivationParametersFromArgs() { + SetMocknet(*this, consensus); } void CChangiParams::UpdateActivationParametersFromArgs() { + if (SetMocknet(*this, consensus)) { return; } if (gArgs.IsArgSet("-changi-bootstrap")) { nDefaultPort = 18555; vSeeds.emplace_back("changi-seed.defichain.io"); @@ -1421,6 +1433,7 @@ void CChangiParams::UpdateActivationParametersFromArgs() { } void CDevNetParams::UpdateActivationParametersFromArgs() { + if (SetMocknet(*this, consensus)) { return; } if (gArgs.IsArgSet("-devnet-bootstrap")) { nDefaultPort = 18555; vSeeds.emplace_back("testnet-seed.defichain.io"); diff --git a/src/init.cpp b/src/init.cpp index d49f36daab..1def0f90e8 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -2503,20 +2503,36 @@ bool AppInitMain(InitInterfaces& interfaces) // ********************************************************* Step XX.a: create mocknet MN // MN: 0000000000000000000000000000000000000000000000000000000000000000 - // Owner/Operator Address: df1qu04hcpd3untnm453mlkgc0g9mr9ap39lyx4ajc - // Owner/Operator Privkey: L5DhrVPhA2FbJ1ezpN3JijHVnnH1sVcbdcAcp3nE373ooGH6LEz6 if (fMockNetwork && HasWallets()) { + CKeyID keyID; + CTxDestination dest; + + { + auto pwallet = GetWallets()[0]; + LOCK(pwallet->cs_wallet); + + if (!pwallet->CanGetAddresses()) { + return InitError("Wallet not able to generate address for mocknet"); + } + + std::string error; + + if (!pwallet->GetNewDestination(OutputType::BECH32, "", dest, error)) { + return InitError("Wallet not able to get new destination for mocknet"); + } + } + // Import privkey - const auto key = DecodeSecret("L5DhrVPhA2FbJ1ezpN3JijHVnnH1sVcbdcAcp3nE373ooGH6LEz6"); - const auto keyID = key.GetPubKey().GetID(); - const auto dest = WitnessV0KeyHash(PKHash{keyID}); - const auto time{std::time(nullptr)}; + const auto optKeyID = CKeyID::TryFromDestination(dest, KeyType::WPKHashKeyType); + if (!optKeyID) { + return InitError("Not able to get new keyID for mocknet"); + } + keyID = *optKeyID; - auto pwallet = GetWallets()[0]; - pwallet->SetAddressBook(dest, "receive", "receive"); - pwallet->ImportPrivKeys({{keyID, key}}, time); + // Set operator for mining + gArgs.ForceSetArg("-masternode_operator", EncodeDestination(dest)); // Create masternode CMasternode node; @@ -2526,9 +2542,15 @@ bool AppInitMain(InitInterfaces& interfaces) 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); + + const auto time{std::time(nullptr)}; + + { + LOCK(cs_main); + 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); + } } } diff --git a/src/miner.cpp b/src/miner.cpp index dc408eba94..d01bdc03d1 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -1526,11 +1526,6 @@ namespace pos { void stakingManagerThread(std::vector> wallets, const int subnodeCount) { auto operators = gArgs.GetArgs("-masternode_operator"); - if (fMockNetwork) { - auto mocknet_operator = "df1qu04hcpd3untnm453mlkgc0g9mr9ap39lyx4ajc"; - operators.push_back(mocknet_operator); - } - std::map minterKeyMap; while (!ShutdownRequested()) {