|
16 | 16 | #include <chain.h>
|
17 | 17 | #include <chainparams.h>
|
18 | 18 | #include <compat/sanity.h>
|
19 |
| -#include <consensus/validation.h> |
20 | 19 | #include <fs.h>
|
21 | 20 | #include <hash.h>
|
22 | 21 | #include <httprpc.h>
|
|
32 | 31 | #include <net_permissions.h>
|
33 | 32 | #include <net_processing.h>
|
34 | 33 | #include <netbase.h>
|
| 34 | +#include <node/blockstorage.h> |
35 | 35 | #include <node/context.h>
|
36 | 36 | #include <node/ui_interface.h>
|
37 | 37 | #include <policy/feerate.h>
|
|
61 | 61 | #include <util/threadnames.h>
|
62 | 62 | #include <util/translation.h>
|
63 | 63 | #include <validation.h>
|
64 |
| - |
65 | 64 | #include <validationinterface.h>
|
66 | 65 | #include <walletinitinterface.h>
|
67 | 66 |
|
|
90 | 89 |
|
91 | 90 | static const bool DEFAULT_PROXYRANDOMIZE = true;
|
92 | 91 | static const bool DEFAULT_REST_ENABLE = false;
|
93 |
| -static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false; |
94 | 92 |
|
95 | 93 | #ifdef WIN32
|
96 | 94 | // Win32 LevelDB doesn't use filedescriptors, and the ones used for
|
@@ -155,8 +153,6 @@ static fs::path GetPidFile(const ArgsManager& args)
|
155 | 153 |
|
156 | 154 | static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle;
|
157 | 155 |
|
158 |
| -static std::thread g_load_block; |
159 |
| - |
160 | 156 | void Interrupt(NodeContext& node)
|
161 | 157 | {
|
162 | 158 | InterruptHTTPServer();
|
@@ -220,7 +216,7 @@ void Shutdown(NodeContext& node)
|
220 | 216 | // After everything has been shut down, but before things get flushed, stop the
|
221 | 217 | // CScheduler/checkqueue, scheduler and load block thread.
|
222 | 218 | if (node.scheduler) node.scheduler->stop();
|
223 |
| - if (g_load_block.joinable()) g_load_block.join(); |
| 219 | + if (node.chainman && node.chainman->m_load_block.joinable()) node.chainman->m_load_block.join(); |
224 | 220 | StopScriptCheckWorkerThreads();
|
225 | 221 |
|
226 | 222 | // After the threads that potentially access these pointers have been stopped,
|
@@ -627,20 +623,6 @@ static void BlockNotifyGenesisWait(const CBlockIndex* pBlockIndex)
|
627 | 623 | }
|
628 | 624 | }
|
629 | 625 |
|
630 |
| -struct CImportingNow |
631 |
| -{ |
632 |
| - CImportingNow() { |
633 |
| - assert(fImporting == false); |
634 |
| - fImporting = true; |
635 |
| - } |
636 |
| - |
637 |
| - ~CImportingNow() { |
638 |
| - assert(fImporting == true); |
639 |
| - fImporting = false; |
640 |
| - } |
641 |
| -}; |
642 |
| - |
643 |
| - |
644 | 626 | // If we're using -prune with -reindex, then delete block files that will be ignored by the
|
645 | 627 | // reindex. Since reindexing works by starting at block file 0 and looping until a blockfile
|
646 | 628 | // is missing, do the same here to delete any later block files after a gap. Also delete all
|
@@ -693,77 +675,6 @@ static void StartupNotify(const ArgsManager& args)
|
693 | 675 | }
|
694 | 676 | #endif
|
695 | 677 |
|
696 |
| -static void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const ArgsManager& args) |
697 |
| -{ |
698 |
| - const CChainParams& chainparams = Params(); |
699 |
| - ScheduleBatchPriority(); |
700 |
| - |
701 |
| - { |
702 |
| - CImportingNow imp; |
703 |
| - |
704 |
| - // -reindex |
705 |
| - if (fReindex) { |
706 |
| - int nFile = 0; |
707 |
| - while (true) { |
708 |
| - FlatFilePos pos(nFile, 0); |
709 |
| - if (!fs::exists(GetBlockPosFilename(pos))) |
710 |
| - break; // No block files left to reindex |
711 |
| - FILE *file = OpenBlockFile(pos, true); |
712 |
| - if (!file) |
713 |
| - break; // This error is logged in OpenBlockFile |
714 |
| - LogPrintf("Reindexing block file blk%05u.dat...\n", (unsigned int)nFile); |
715 |
| - ::ChainstateActive().LoadExternalBlockFile(chainparams, file, &pos); |
716 |
| - if (ShutdownRequested()) { |
717 |
| - LogPrintf("Shutdown requested. Exit %s\n", __func__); |
718 |
| - return; |
719 |
| - } |
720 |
| - nFile++; |
721 |
| - } |
722 |
| - pblocktree->WriteReindexing(false); |
723 |
| - fReindex = false; |
724 |
| - LogPrintf("Reindexing finished\n"); |
725 |
| - // To avoid ending up in a situation without genesis block, re-try initializing (no-op if reindexing worked): |
726 |
| - ::ChainstateActive().LoadGenesisBlock(chainparams); |
727 |
| - } |
728 |
| - |
729 |
| - // -loadblock= |
730 |
| - for (const fs::path& path : vImportFiles) { |
731 |
| - FILE *file = fsbridge::fopen(path, "rb"); |
732 |
| - if (file) { |
733 |
| - LogPrintf("Importing blocks file %s...\n", path.string()); |
734 |
| - ::ChainstateActive().LoadExternalBlockFile(chainparams, file); |
735 |
| - if (ShutdownRequested()) { |
736 |
| - LogPrintf("Shutdown requested. Exit %s\n", __func__); |
737 |
| - return; |
738 |
| - } |
739 |
| - } else { |
740 |
| - LogPrintf("Warning: Could not open blocks file %s\n", path.string()); |
741 |
| - } |
742 |
| - } |
743 |
| - |
744 |
| - // scan for better chains in the block chain database, that are not yet connected in the active best chain |
745 |
| - |
746 |
| - // We can't hold cs_main during ActivateBestChain even though we're accessing |
747 |
| - // the chainman unique_ptrs since ABC requires us not to be holding cs_main, so retrieve |
748 |
| - // the relevant pointers before the ABC call. |
749 |
| - for (CChainState* chainstate : WITH_LOCK(::cs_main, return chainman.GetAll())) { |
750 |
| - BlockValidationState state; |
751 |
| - if (!chainstate->ActivateBestChain(state, chainparams, nullptr)) { |
752 |
| - LogPrintf("Failed to connect best block (%s)\n", state.ToString()); |
753 |
| - StartShutdown(); |
754 |
| - return; |
755 |
| - } |
756 |
| - } |
757 |
| - |
758 |
| - if (args.GetBoolArg("-stopafterblockimport", DEFAULT_STOPAFTERBLOCKIMPORT)) { |
759 |
| - LogPrintf("Stopping after block import\n"); |
760 |
| - StartShutdown(); |
761 |
| - return; |
762 |
| - } |
763 |
| - } // End scope of CImportingNow |
764 |
| - chainman.ActiveChainstate().LoadMempool(args); |
765 |
| -} |
766 |
| - |
767 | 678 | /** Sanity checks
|
768 | 679 | * Ensure that Bitcoin is running in a usable environment with all
|
769 | 680 | * necessary library support.
|
@@ -1880,7 +1791,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
1880 | 1791 | vImportFiles.push_back(strFile);
|
1881 | 1792 | }
|
1882 | 1793 |
|
1883 |
| - g_load_block = std::thread(&TraceThread<std::function<void()>>, "loadblk", [=, &chainman, &args] { |
| 1794 | + chainman.m_load_block = std::thread(&TraceThread<std::function<void()>>, "loadblk", [=, &chainman, &args] { |
1884 | 1795 | ThreadImport(chainman, vImportFiles, args);
|
1885 | 1796 | });
|
1886 | 1797 |
|
|
0 commit comments