|
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 |
3 | 3 | // Distributed under the MIT/X11 software license, see the accompanying
|
4 | 4 | // file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
5 | 5 |
|
@@ -108,7 +108,7 @@ class TxPriorityCompare
|
108 | 108 | CBlock* CreateNewBlock(CReserveKey& reservekey, bool fProofOfStake, int64_t* pFees)
|
109 | 109 | {
|
110 | 110 | // Create new block
|
111 |
| - auto_ptr<CBlock> pblock(new CBlock()); |
| 111 | + unique_ptr<CBlock> pblock(new CBlock()); |
112 | 112 | if (!pblock.get())
|
113 | 113 | return NULL;
|
114 | 114 |
|
@@ -581,25 +581,51 @@ void ThreadStakeMiner(CWallet *pwallet)
|
581 | 581 |
|
582 | 582 | void static BitcoinMiner(CWallet *pwallet)
|
583 | 583 | {
|
584 |
| - printf("BitcoinMiner started\n"); |
585 | 584 | SetThreadPriority(THREAD_PRIORITY_LOWEST);
|
| 585 | + |
| 586 | + // Make this thread recognisable as the mining thread |
586 | 587 | RenameThread("LiteDoge Miner");
|
| 588 | + printf("BitcoinMiner started\n"); |
| 589 | + |
| 590 | + |
587 | 591 |
|
588 | 592 | // Each thread has its own key and counter
|
589 | 593 | CReserveKey reservekey(pwallet);
|
590 | 594 | unsigned int nExtraNonce = 0;
|
591 | 595 |
|
592 |
| - try { for(;;) { |
593 |
| - while (vNodes.empty()) |
| 596 | + while (true) |
| 597 | + { |
| 598 | + while (pwallet->IsLocked()) |
| 599 | + { |
| 600 | + nLastCoinStakeSearchInterval = 0; |
594 | 601 | MilliSleep(1000);
|
| 602 | + } |
| 603 | + |
| 604 | + while (vNodes.empty() || IsInitialBlockDownload()) |
| 605 | + { |
| 606 | + nLastCoinStakeSearchInterval = 0; |
| 607 | + fTryToSync = true; |
| 608 | + MilliSleep(1000); |
| 609 | + } |
595 | 610 |
|
| 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 | + |
596 | 621 | //
|
597 | 622 | // Create new block
|
598 | 623 | //
|
599 | 624 | unsigned int nTransactionsUpdatedLast = mempool.GetTransactionsUpdated();
|
600 | 625 | CBlockIndex* pindexPrev = pindexBest;
|
601 | 626 |
|
602 |
| - auto_ptr<CBlock> pblock(CreateNewBlock(reservekey)); |
| 627 | + int64_t nFees; |
| 628 | + unique_ptr<CBlock> pblock(CreateNewBlock(reservekey, true, &nFees)); |
603 | 629 | if (!pblock.get())
|
604 | 630 | return;
|
605 | 631 |
|
@@ -641,16 +667,18 @@ void static BitcoinMiner(CWallet *pwallet)
|
641 | 667 |
|
642 | 668 | if (hash <= hashTarget)
|
643 | 669 | {
|
644 |
| - // Found a solution |
| 670 | + // Trying to sign a block |
645 | 671 | pblock->nNonce = ByteReverse(nNonceFound);
|
646 |
| - assert(hash == pblock->GetHash()); |
647 |
| - |
| 672 | + { |
648 | 673 | SetThreadPriority(THREAD_PRIORITY_NORMAL);
|
649 | 674 | CheckWork(pblock.get(), *pwallet, reservekey);
|
650 | 675 | SetThreadPriority(THREAD_PRIORITY_LOWEST);
|
651 |
| - break; |
652 |
| - } |
653 |
| - } |
| 676 | + MilliSleep(500); |
| 677 | + } |
| 678 | + else |
| 679 | + MilliSleep(nMinerSleep); |
| 680 | + } |
| 681 | +} |
654 | 682 |
|
655 | 683 | // Meter hashes/sec
|
656 | 684 | static int64_t nHashCounter;
|
|
0 commit comments