Skip to content

Commit

Permalink
Mocknet create MN on start (#1399)
Browse files Browse the repository at this point in the history
  • Loading branch information
Bushstar authored Jul 29, 2022
1 parent fb294de commit 7568a27
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
41 changes: 39 additions & 2 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -2134,7 +2166,12 @@ bool AppInitMain(InitInterfaces& interfaces)

std::set<std::string> 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<pos::ThreadStaker::Args> stakersParams;
for (auto const & op : operators) {
Expand Down
5 changes: 5 additions & 0 deletions src/pos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down

0 comments on commit 7568a27

Please sign in to comment.