Skip to content

Commit c7f6cc8

Browse files
authored
Update miner.cpp
1 parent 4970529 commit c7f6cc8

File tree

1 file changed

+41
-13
lines changed

1 file changed

+41
-13
lines changed

src/miner.cpp

+41-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Copyright (c) 2009-2022 The Bitcoin developers
2-
// Copyright (c) 2015-2021 The LiteDogecoin developers
1+
// Copyright (c) 2009-8888 The Bitcoin developers
2+
// Copyright (c) 2015-8888 The LiteDogecoin developers
33
// Distributed under the MIT/X11 software license, see the accompanying
44
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
55

@@ -108,7 +108,7 @@ class TxPriorityCompare
108108
CBlock* CreateNewBlock(CReserveKey& reservekey, bool fProofOfStake, int64_t* pFees)
109109
{
110110
// Create new block
111-
auto_ptr<CBlock> pblock(new CBlock());
111+
unique_ptr<CBlock> pblock(new CBlock());
112112
if (!pblock.get())
113113
return NULL;
114114

@@ -581,25 +581,51 @@ void ThreadStakeMiner(CWallet *pwallet)
581581

582582
void static BitcoinMiner(CWallet *pwallet)
583583
{
584-
printf("BitcoinMiner started\n");
585584
SetThreadPriority(THREAD_PRIORITY_LOWEST);
585+
586+
// Make this thread recognisable as the mining thread
586587
RenameThread("LiteDoge Miner");
588+
printf("BitcoinMiner started\n");
589+
590+
587591

588592
// Each thread has its own key and counter
589593
CReserveKey reservekey(pwallet);
590594
unsigned int nExtraNonce = 0;
591595

592-
try { for(;;) {
593-
while (vNodes.empty())
596+
while (true)
597+
{
598+
while (pwallet->IsLocked())
599+
{
600+
nLastCoinStakeSearchInterval = 0;
594601
MilliSleep(1000);
602+
}
603+
604+
while (vNodes.empty() || IsInitialBlockDownload())
605+
{
606+
nLastCoinStakeSearchInterval = 0;
607+
fTryToSync = true;
608+
MilliSleep(1000);
609+
}
595610

611+
if (fTryToSync)
612+
{
613+
fTryToSync = false;
614+
if (vNodes.size() < 3 || pindexBest->GetBlockTime() < GetTime() - 10 * 60)
615+
{
616+
MilliSleep(60000);
617+
continue;
618+
}
619+
}
620+
596621
//
597622
// Create new block
598623
//
599624
unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
600625
CBlockIndex* pindexPrev = pindexBest;
601626

602-
auto_ptr<CBlock> pblock(CreateNewBlock(reservekey));
627+
int64_t nFees;
628+
unique_ptr<CBlock> pblock(CreateNewBlock(reservekey, true, &nFees));
603629
if (!pblock.get())
604630
return;
605631

@@ -641,16 +667,18 @@ void static BitcoinMiner(CWallet *pwallet)
641667

642668
if (hash <= hashTarget)
643669
{
644-
// Found a solution
670+
// Trying to sign a block
645671
pblock->nNonce = ByteReverse(nNonceFound);
646-
assert(hash == pblock->GetHash());
647-
672+
{
648673
SetThreadPriority(THREAD_PRIORITY_NORMAL);
649674
CheckWork(pblock.get(), *pwallet, reservekey);
650675
SetThreadPriority(THREAD_PRIORITY_LOWEST);
651-
break;
652-
}
653-
}
676+
MilliSleep(500);
677+
}
678+
else
679+
MilliSleep(nMinerSleep);
680+
}
681+
}
654682

655683
// Meter hashes/sec
656684
static int64_t nHashCounter;

0 commit comments

Comments
 (0)