Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mocknet create MN on start #1399

Merged
merged 2 commits into from
Jul 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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