mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-15 12:51:00 +02:00
Merge 1f14130cb0 into merged_master (Bitcoin PR #21575)
This commit is contained in:
commit
a9ef79acbc
19 changed files with 330 additions and 260 deletions
95
src/init.cpp
95
src/init.cpp
|
|
@ -16,7 +16,6 @@
|
|||
#include <chain.h>
|
||||
#include <chainparams.h>
|
||||
#include <compat/sanity.h>
|
||||
#include <consensus/validation.h>
|
||||
#include <fs.h>
|
||||
#include <hash.h>
|
||||
#include <httprpc.h>
|
||||
|
|
@ -33,6 +32,7 @@
|
|||
#include <net_permissions.h>
|
||||
#include <net_processing.h>
|
||||
#include <netbase.h>
|
||||
#include <node/blockstorage.h>
|
||||
#include <node/context.h>
|
||||
#include <node/ui_interface.h>
|
||||
#include <policy/feerate.h>
|
||||
|
|
@ -62,6 +62,7 @@
|
|||
#include <util/system.h>
|
||||
#include <util/threadnames.h>
|
||||
#include <util/translation.h>
|
||||
#include <validation.h>
|
||||
#include <validationinterface.h>
|
||||
#include <walletinitinterface.h>
|
||||
|
||||
|
|
@ -93,7 +94,6 @@
|
|||
|
||||
static const bool DEFAULT_PROXYRANDOMIZE = true;
|
||||
static const bool DEFAULT_REST_ENABLE = false;
|
||||
static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false;
|
||||
|
||||
#ifdef WIN32
|
||||
// Win32 LevelDB doesn't use filedescriptors, and the ones used for
|
||||
|
|
@ -162,8 +162,6 @@ static fs::path GetPidFile(const ArgsManager& args)
|
|||
|
||||
static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle;
|
||||
|
||||
static std::thread g_load_block;
|
||||
|
||||
void Interrupt(NodeContext& node)
|
||||
{
|
||||
InterruptHTTPServer();
|
||||
|
|
@ -228,7 +226,7 @@ void Shutdown(NodeContext& node)
|
|||
// CScheduler/checkqueue, scheduler and load block thread.
|
||||
if (node.scheduler) node.scheduler->stop();
|
||||
if (node.reverification_scheduler) node.reverification_scheduler->stop();
|
||||
if (g_load_block.joinable()) g_load_block.join();
|
||||
if (node.chainman && node.chainman->m_load_block.joinable()) node.chainman->m_load_block.join();
|
||||
StopScriptCheckWorkerThreads();
|
||||
|
||||
// After the threads that potentially access these pointers have been stopped,
|
||||
|
|
@ -680,20 +678,6 @@ static void BlockNotifyGenesisWait(const CBlockIndex* pBlockIndex)
|
|||
}
|
||||
}
|
||||
|
||||
struct CImportingNow
|
||||
{
|
||||
CImportingNow() {
|
||||
assert(fImporting == false);
|
||||
fImporting = true;
|
||||
}
|
||||
|
||||
~CImportingNow() {
|
||||
assert(fImporting == true);
|
||||
fImporting = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// If we're using -prune with -reindex, then delete block files that will be ignored by the
|
||||
// reindex. Since reindexing works by starting at block file 0 and looping until a blockfile
|
||||
// is missing, do the same here to delete any later block files after a gap. Also delete all
|
||||
|
|
@ -746,77 +730,6 @@ static void StartupNotify(const ArgsManager& args)
|
|||
}
|
||||
#endif
|
||||
|
||||
static void ThreadImport(ChainstateManager& chainman, std::vector<fs::path> vImportFiles, const ArgsManager& args)
|
||||
{
|
||||
const CChainParams& chainparams = Params();
|
||||
ScheduleBatchPriority();
|
||||
|
||||
{
|
||||
CImportingNow imp;
|
||||
|
||||
// -reindex
|
||||
if (fReindex) {
|
||||
int nFile = 0;
|
||||
while (true) {
|
||||
FlatFilePos pos(nFile, 0);
|
||||
if (!fs::exists(GetBlockPosFilename(pos)))
|
||||
break; // No block files left to reindex
|
||||
FILE *file = OpenBlockFile(pos, true);
|
||||
if (!file)
|
||||
break; // This error is logged in OpenBlockFile
|
||||
LogPrintf("Reindexing block file blk%05u.dat...\n", (unsigned int)nFile);
|
||||
::ChainstateActive().LoadExternalBlockFile(chainparams, file, &pos);
|
||||
if (ShutdownRequested()) {
|
||||
LogPrintf("Shutdown requested. Exit %s\n", __func__);
|
||||
return;
|
||||
}
|
||||
nFile++;
|
||||
}
|
||||
pblocktree->WriteReindexing(false);
|
||||
fReindex = false;
|
||||
LogPrintf("Reindexing finished\n");
|
||||
// To avoid ending up in a situation without genesis block, re-try initializing (no-op if reindexing worked):
|
||||
::ChainstateActive().LoadGenesisBlock(chainparams);
|
||||
}
|
||||
|
||||
// -loadblock=
|
||||
for (const fs::path& path : vImportFiles) {
|
||||
FILE *file = fsbridge::fopen(path, "rb");
|
||||
if (file) {
|
||||
LogPrintf("Importing blocks file %s...\n", path.string());
|
||||
::ChainstateActive().LoadExternalBlockFile(chainparams, file);
|
||||
if (ShutdownRequested()) {
|
||||
LogPrintf("Shutdown requested. Exit %s\n", __func__);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
LogPrintf("Warning: Could not open blocks file %s\n", path.string());
|
||||
}
|
||||
}
|
||||
|
||||
// scan for better chains in the block chain database, that are not yet connected in the active best chain
|
||||
|
||||
// We can't hold cs_main during ActivateBestChain even though we're accessing
|
||||
// the chainman unique_ptrs since ABC requires us not to be holding cs_main, so retrieve
|
||||
// the relevant pointers before the ABC call.
|
||||
for (CChainState* chainstate : WITH_LOCK(::cs_main, return chainman.GetAll())) {
|
||||
BlockValidationState state;
|
||||
if (!chainstate->ActivateBestChain(state, chainparams, nullptr)) {
|
||||
LogPrintf("Failed to connect best block (%s)\n", state.ToString());
|
||||
StartShutdown();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.GetBoolArg("-stopafterblockimport", DEFAULT_STOPAFTERBLOCKIMPORT)) {
|
||||
LogPrintf("Stopping after block import\n");
|
||||
StartShutdown();
|
||||
return;
|
||||
}
|
||||
} // End scope of CImportingNow
|
||||
chainman.ActiveChainstate().LoadMempool(args);
|
||||
}
|
||||
|
||||
/** Sanity checks
|
||||
* Ensure that Bitcoin is running in a usable environment with all
|
||||
* necessary library support.
|
||||
|
|
@ -1938,7 +1851,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
|||
vImportFiles.push_back(strFile);
|
||||
}
|
||||
|
||||
g_load_block = std::thread(&TraceThread<std::function<void()>>, "loadblk", [=, &chainman, &args] {
|
||||
chainman.m_load_block = std::thread(&TraceThread<std::function<void()>>, "loadblk", [=, &chainman, &args] {
|
||||
ThreadImport(chainman, vImportFiles, args);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue