MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / ThreadBlockProducing

Function ThreadBlockProducing

src/miner/miner.cpp:730–853  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

728}
729
730void static ThreadBlockProducing(CWallet *pWallet, int32_t targetHeight) {
731 LogPrint(BCLog::INFO, "started\n");
732
733 RenameThread("coin-miner");
734
735 auto HaveMinerKey = [&]() {
736 LOCK2(cs_main, pWalletMain->cs_wallet);
737
738 set<CKeyID> setMineKey;
739 setMineKey.clear();
740 pWalletMain->GetKeys(setMineKey, true);
741 return !setMineKey.empty();
742 };
743
744 if (!HaveMinerKey()) {
745 LogPrint(BCLog::ERROR, "terminated due to lack of miner key\n");
746 return;
747 }
748
749 auto GetCurrHeight = [&]() {
750 LOCK(cs_main);
751 return chainActive.Height();
752 };
753
754 g_isMiningTimeLimit = SysCfg().GetBoolArg("-isminingtimelimit", true);
755 targetHeight += GetCurrHeight();
756 bool needSleep = false;
757 int64_t nextSlotTime = 0;
758 int64_t sleepSeconds = 100;
759
760 try {
761 SetMinerStatus(true);
762
763 while (true) {
764 boost::this_thread::interruption_point();
765
766 CBlockIndex *pPrevIndex = nullptr;
767 sleepSeconds = 100; // set sleep seconds default value
768 if (!needSleep && (SysCfg().NetworkID() != REGTEST_NET)) {
769
770 LOCK(cs_main);
771 pPrevIndex = chainActive.Tip();
772
773 if (vNodes.empty() || (pPrevIndex && pPrevIndex->height > 1 &&
774 GetAdjustedTime() - pPrevIndex->nTime > 60 * 60 &&
775 !SysCfg().GetBoolArg("-genblockforce", false))) {
776 // Busy-wait for the network to come online so we don't waste time mining
777 // on an obsolete chain. In regtest mode we expect to fly solo.
778 sleepSeconds = 1000;
779 needSleep = true;
780 }
781 }
782
783 if (needSleep) {
784 MilliSleep(sleepSeconds);
785 needSleep = false;
786 continue;
787 }

Callers

nothing calls this directly

Calls 15

RenameThreadFunction · 0.85
SetMinerStatusFunction · 0.85
GetAdjustedTimeFunction · 0.85
MilliSleepFunction · 0.85
GetBlockIntervalFunction · 0.85
GetMinerFunction · 0.85
ProduceBlockFunction · 0.85
HeightMethod · 0.80
GetBoolArgMethod · 0.80
TipMethod · 0.80
IsReindexMethod · 0.80
CheckPermsMethod · 0.80

Tested by

no test coverage detected