Skip to content

Commit

Permalink
Add mocknet to all networks (#3103)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar authored Oct 28, 2024
1 parent a2c4958 commit f1c38f4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 20 deletions.
19 changes: 16 additions & 3 deletions src/chainparams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,10 @@ class CTestNetParams : public CChainParams {
/* nTxCount */ 178351,
/* dTxRate */ 0.03842042178237066
};

UpdateActivationParametersFromArgs();
}
void UpdateActivationParametersFromArgs();
};

/**
Expand Down Expand Up @@ -1378,8 +1381,7 @@ void SetupCommonArgActivationParams(Consensus::Params &consensus) {
}
}


void CMainParams::UpdateActivationParametersFromArgs() {
bool SetMocknet(const CChainParams &params, Consensus::Params& consensus) {
fMockNetwork = gArgs.IsArgSet("-mocknet");
if (fMockNetwork) {
LogPrintf("============================================\n");
Expand All @@ -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");
Expand All @@ -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");
Expand Down
46 changes: 34 additions & 12 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
}

Expand Down
5 changes: 0 additions & 5 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1526,11 +1526,6 @@ namespace pos {
void stakingManagerThread(std::vector<std::shared_ptr<CWallet>> wallets, const int subnodeCount) {
auto operators = gArgs.GetArgs("-masternode_operator");

if (fMockNetwork) {
auto mocknet_operator = "df1qu04hcpd3untnm453mlkgc0g9mr9ap39lyx4ajc";
operators.push_back(mocknet_operator);
}

std::map<CKeyID, CKey> minterKeyMap;

while (!ShutdownRequested()) {
Expand Down

0 comments on commit f1c38f4

Please sign in to comment.