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

fixed issue with default minting address; more verbose output #86

Merged
merged 1 commit into from
Nov 2, 2020
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
31 changes: 19 additions & 12 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1931,21 +1931,28 @@ bool AppInitMain(InitInterfaces& interfaces)
return false;
}

CTxDestination rewardAddress;

auto myIDs = pcustomcsview->AmIOperator();
if(myIDs) {
CMasternode const node = *pcustomcsview->GetMasternode(myIDs->second);
rewardAddress = node.ownerType == 1 ? CTxDestination(PKHash(node.ownerAuthAddress)) : CTxDestination(WitnessV0KeyHash(node.ownerAuthAddress));
// determine coinbase script for minting thread
CTxDestination ownerDest;
auto optMasternodeID = pcustomcsview->GetMasternodeIdByOperator(operatorId);
if (optMasternodeID) {
auto nodePtr = pcustomcsview->GetMasternode(*optMasternodeID);
assert(nodePtr); // this should not happen if MN was found by operator's id
ownerDest = nodePtr->ownerType == 1 ? CTxDestination(PKHash(nodePtr->ownerAuthAddress)) : CTxDestination(WitnessV0KeyHash(nodePtr->ownerAuthAddress));
}

CTxDestination const mintToAddress = DecodeDestination(gArgs.GetArg("-rewardaddress", ""), Params());
if (IsValidDestination(mintToAddress))
rewardAddress = mintToAddress;

CScript coinbaseScript = GetScriptForDestination(rewardAddress);
CTxDestination const rewardAddress = DecodeDestination(gArgs.GetArg("-rewardaddress", ""), Params());
if (IsValidDestination(rewardAddress)) {
LogPrintf("Default minting address was overlapped by -rewardaddress=%s\n", gArgs.GetArg("-rewardaddress", "").c_str());
stakerParams.coinbaseScript = GetScriptForDestination(rewardAddress);
}
else if (IsValidDestination(ownerDest)) {
LogPrintf("Minting thread will start with default address %s\n", EncodeDestination(ownerDest).c_str());
stakerParams.coinbaseScript = GetScriptForDestination(ownerDest);
}
else {
LogPrintf("Minting thread will start with empty coinbase address cause masternode does not exist yet. Correct address will be resolved later.\n");
}

stakerParams.coinbaseScript = coinbaseScript;
stakerParams.minterKey = minterKey;
stakerParams.operatorID = operatorId;
}
Expand Down
7 changes: 6 additions & 1 deletion src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ namespace pos {
/// @todo is 'tip' can be changed here? is it possible to pull 'getTip()' and mnview access to the upper (calling 'stake()') block?
uint32_t mintedBlocks(0);
uint256 masternodeID{};
CScript defaultScript;
{
LOCK(cs_main);
auto optMasternodeID = pcustomcsview->GetMasternodeIdByOperator(args.operatorID);
Expand All @@ -621,6 +622,10 @@ namespace pos {
return Status::initWaiting;
}
mintedBlocks = nodePtr->mintedBlocks;
if (args.coinbaseScript.empty()) {
// this is safe cause MN was found
defaultScript = GetScriptForDestination(nodePtr->ownerType == 1 ? CTxDestination(PKHash(nodePtr->ownerAuthAddress)) : CTxDestination(WitnessV0KeyHash(nodePtr->ownerAuthAddress)));
}
}

withSearchInterval([&](int64_t coinstakeTime, int64_t nSearchInterval) {
Expand All @@ -640,7 +645,7 @@ namespace pos {
//
// Create block template
//
std::unique_ptr<CBlockTemplate> pblocktemplate(BlockAssembler(chainparams).CreateNewBlock(args.coinbaseScript));
std::unique_ptr<CBlockTemplate> pblocktemplate(BlockAssembler(chainparams).CreateNewBlock(args.coinbaseScript.empty() ? defaultScript : args.coinbaseScript));
if (!pblocktemplate.get()) {
throw std::runtime_error("Error in WalletStaker: Keypool ran out, please call keypoolrefill before restarting the staking thread");
}
Expand Down