Skip to content

Commit

Permalink
Merge pull request #86 from DeFiCh/fix/minting_again
Browse files Browse the repository at this point in the history
fixed issue with default minting address; more verbose output
  • Loading branch information
monstrobishi authored Nov 2, 2020
2 parents 51f976e + a3ace9d commit 3b75cc6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
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

0 comments on commit 3b75cc6

Please sign in to comment.