From a3ace9d02e50c45be749b4798b8d565db3fbfbc1 Mon Sep 17 00:00:00 2001 From: DeFiDev M Date: Mon, 2 Nov 2020 17:08:58 +0700 Subject: [PATCH] fixed issue with default minting address; more verbose output --- src/init.cpp | 31 +++++++++++++++++++------------ src/miner.cpp | 7 ++++++- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 0dddf13ba4..bec69433e6 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -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; } diff --git a/src/miner.cpp b/src/miner.cpp index c0947a86bd..eef2ca8d84 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -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); @@ -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) { @@ -640,7 +645,7 @@ namespace pos { // // Create block template // - std::unique_ptr pblocktemplate(BlockAssembler(chainparams).CreateNewBlock(args.coinbaseScript)); + std::unique_ptr 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"); }