diff --git a/src/miner.cpp b/src/miner.cpp index 5c40b1a02..aaa9f4d5e 100644 --- a/src/miner.cpp +++ b/src/miner.cpp @@ -906,7 +906,6 @@ void static MeritMiner(const CChainParams& chainparams, uint8_t nThreads) unsigned int nExtraNonce = 0; std::shared_ptr coinbaseScript; - GetMainSignals().ScriptForMining(coinbaseScript); ctpl::thread_pool pool{nThreads}; @@ -915,9 +914,8 @@ void static MeritMiner(const CChainParams& chainparams, uint8_t nThreads) // due to some internal error but also if the keypool is empty. // In the latter case, already the pointer is NULL. if (!coinbaseScript || coinbaseScript->reserveScript.empty()) { - throw std::runtime_error( - "No coinbase script available " - "(mining requires confirmed wallet)"); + LogPrintf("No coinbase script available (mining requires confirmed wallet)." + " Blockchain might be not fully synced.\n"); } while (true) { @@ -940,6 +938,24 @@ void static MeritMiner(const CChainParams& chainparams, uint8_t nThreads) } while (true); } + while (IsInitialBlockDownload()) { + LogPrintf("Initial blockchain download is active.\n"); + MilliSleep(1000); + } + + if (!coinbaseScript || coinbaseScript->reserveScript.empty()) { + LogPrintf("No coinbase script found, generating new.\n"); + GetMainSignals().ScriptForMining(coinbaseScript); + } + + + if (!coinbaseScript || coinbaseScript->reserveScript.empty()) { + throw std::runtime_error( + "No coinbase script available" + " (mining requires confirmed wallet)." + " Miner will be stopped.\n"); + } + // // Create new block // @@ -1052,9 +1068,11 @@ void static MeritMiner(const CChainParams& chainparams, uint8_t nThreads) } } catch (const boost::thread_interrupted&) { LogPrintf("MeritMiner terminated\n"); + gArgs.ForceSetArg("-mine", 0); throw; } catch (const std::runtime_error& e) { LogPrintf("MeritMiner runtime error: %s\n", e.what()); + gArgs.ForceSetArg("-mine", 0); return; } } diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index 736da6a8a..f96ea07cf 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -559,7 +559,7 @@ UniValue getblocktemplate(const JSONRPCRequest& request) static std::unique_ptr pblocktemplate; if (pindexPrev != chainActive.Tip() || (mempool.GetTransactionsUpdated() != nTransactionsUpdatedLast && GetTime() - nStart > 5)) { - // Clear pindexPrev so future calls make a new block, despite any failures from here on + // Clear pindexPrev so future calls make a new block, despite any failures from here on pindexPrev = nullptr; // Store the pindexBest used before CreateNewBlock, to avoid races @@ -1030,7 +1030,7 @@ UniValue setmining(const JSONRPCRequest& request) GenerateMerit(mine, nThreads, Params()); - return NullUniValue; + return gArgs.GetBoolArg("-mine", DEFAULT_MINING); } UniValue getmining(const JSONRPCRequest& request) diff --git a/src/validation.cpp b/src/validation.cpp index 950c8fede..dc79f32f1 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2138,24 +2138,36 @@ bool AreExpectedInvitesRewarded(const pog::InviteRewards& expected_invites, cons bool IsInitialBlockDownload() { // Once this function has returned false, it must remain false. - static std::atomic latchToFalse{false}; + // static std::atomic latchToFalse{false}; // Optimization: pre-test latch before taking the lock. - if (latchToFalse.load(std::memory_order_relaxed)) - return false; + // if (latchToFalse.load(std::memory_order_relaxed)) { + // LogPrintf("Pre: Latched to false\n"); + // return false; + // } LOCK(cs_main); - if (latchToFalse.load(std::memory_order_relaxed)) - return false; - if (fImporting || fReindex) + // if (latchToFalse.load(std::memory_order_relaxed)) { + // LogPrintf("Latched to false\n"); + // return false; + // } + if (fImporting || fReindex) { + LogPrintf("Importing or reindex\n"); return true; - if (chainActive.Tip() == nullptr) + } + if (chainActive.Tip() == nullptr) { + LogPrintf("Tip is null\n"); return true; - if (chainActive.Tip()->nChainWork < nMinimumChainWork) + } + if (chainActive.Tip()->nChainWork < nMinimumChainWork) { + LogPrintf("Tip chainwork is less than minimum chainwork\n"); return true; - if (chainActive.Tip()->GetBlockTime() < (GetTime() - nMaxTipAge)) + } + if (chainActive.Tip()->GetBlockTime() < (GetTime() - nMaxTipAge)) { + LogPrintf("Time check triggered\n"); return true; + } LogPrintf("Leaving InitialBlockDownload (latching to false)\n"); - latchToFalse.store(true, std::memory_order_relaxed); + // latchToFalse.store(true, std::memory_order_relaxed); return false; } diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index 1d353e8af..28dcbb9be 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -1499,8 +1499,8 @@ isminetype CWallet::IsMine(const referral::Referral& ref) const { LOCK(cs_wallet); const auto root = GetRootReferral(); - return - mapWalletRTx.count(ref.GetHash()) || + return + mapWalletRTx.count(ref.GetHash()) || (root && ref.parentAddress == root->GetAddress()) ? ISMINE_ALL : ISMINE_NO; } @@ -4110,7 +4110,7 @@ void CWallet::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool) CWalletDB walletdb(*dbw); - + auto it = setKeyPool.begin(); while(it != setKeyPool.end()) { nIndex = *it; @@ -4133,6 +4133,10 @@ void CWallet::ReserveKeyFromKeyPool(int64_t& nIndex, CKeyPool& keypool) it++; } + // if (it == setKeyPool.end()) { + // throw std::runtime_error(std::string(__func__) + ": beconed key was not found"); + // } + // do not remove key from pool if (Daedalus()) { return;