Changeset View
Changeset View
Standalone View
Standalone View
src/init.cpp
Show First 20 Lines • Show All 309 Lines • ▼ Show 20 Lines | static void registerSignalHandler(int signal, void (*handler)(int)) { | ||||
sa.sa_handler = handler; | sa.sa_handler = handler; | ||||
sigemptyset(&sa.sa_mask); | sigemptyset(&sa.sa_mask); | ||||
sa.sa_flags = 0; | sa.sa_flags = 0; | ||||
sigaction(signal, &sa, NULL); | sigaction(signal, &sa, NULL); | ||||
} | } | ||||
#endif | #endif | ||||
static void OnRPCStarted() { | static void OnRPCStarted() { | ||||
uiInterface.NotifyBlockTip.connect(&RPCNotifyBlockChange); | uiInterface.NotifyBlockTip_connect(&RPCNotifyBlockChange); | ||||
} | } | ||||
static void OnRPCStopped() { | static void OnRPCStopped() { | ||||
uiInterface.NotifyBlockTip.disconnect(&RPCNotifyBlockChange); | uiInterface.NotifyBlockTip_disconnect(&RPCNotifyBlockChange); | ||||
RPCNotifyBlockChange(false, nullptr); | RPCNotifyBlockChange(false, nullptr); | ||||
g_best_block_cv.notify_all(); | g_best_block_cv.notify_all(); | ||||
LogPrint(BCLog::RPC, "RPC stopped.\n"); | LogPrint(BCLog::RPC, "RPC stopped.\n"); | ||||
} | } | ||||
void SetupServerArgs() { | void SetupServerArgs() { | ||||
const auto defaultBaseParams = | const auto defaultBaseParams = | ||||
CreateBaseChainParams(CBaseChainParams::MAIN); | CreateBaseChainParams(CBaseChainParams::MAIN); | ||||
▲ Show 20 Lines • Show All 1,572 Lines • ▼ Show 20 Lines | #endif | ||||
/** | /** | ||||
* Start the RPC server. It will be started in "warmup" mode and not | * Start the RPC server. It will be started in "warmup" mode and not | ||||
* process calls yet (but it will verify that the server is there and will | * process calls yet (but it will verify that the server is there and will | ||||
* be ready later). Warmup mode will be completed when initialisation is | * be ready later). Warmup mode will be completed when initialisation is | ||||
* finished. | * finished. | ||||
*/ | */ | ||||
if (gArgs.GetBoolArg("-server", false)) { | if (gArgs.GetBoolArg("-server", false)) { | ||||
uiInterface.InitMessage.connect(SetRPCWarmupStatus); | uiInterface.InitMessage_connect(SetRPCWarmupStatus); | ||||
if (!AppInitServers(config, httpRPCRequestProcessor)) { | if (!AppInitServers(config, httpRPCRequestProcessor)) { | ||||
return InitError( | return InitError( | ||||
_("Unable to start HTTP server. See debug log for details.")); | _("Unable to start HTTP server. See debug log for details.")); | ||||
} | } | ||||
} | } | ||||
// Step 5: verify wallet database integrity | // Step 5: verify wallet database integrity | ||||
if (!g_wallet_init_interface.Verify(chainparams)) { | if (!g_wallet_init_interface.Verify(chainparams)) { | ||||
▲ Show 20 Lines • Show All 418 Lines • ▼ Show 20 Lines | if (!CheckDiskSpace(GetBlocksDir())) { | ||||
strprintf(_("Error: Disk space is low for %s"), GetBlocksDir())); | strprintf(_("Error: Disk space is low for %s"), GetBlocksDir())); | ||||
return false; | return false; | ||||
} | } | ||||
// Either install a handler to notify us when genesis activates, or set | // Either install a handler to notify us when genesis activates, or set | ||||
// fHaveGenesis directly. | // fHaveGenesis directly. | ||||
// No locking, as this happens before any background thread is started. | // No locking, as this happens before any background thread is started. | ||||
if (chainActive.Tip() == nullptr) { | if (chainActive.Tip() == nullptr) { | ||||
uiInterface.NotifyBlockTip.connect(BlockNotifyGenesisWait); | uiInterface.NotifyBlockTip_connect(BlockNotifyGenesisWait); | ||||
} else { | } else { | ||||
fHaveGenesis = true; | fHaveGenesis = true; | ||||
} | } | ||||
if (gArgs.IsArgSet("-blocknotify")) { | if (gArgs.IsArgSet("-blocknotify")) { | ||||
uiInterface.NotifyBlockTip.connect(BlockNotifyCallback); | uiInterface.NotifyBlockTip_connect(BlockNotifyCallback); | ||||
} | } | ||||
std::vector<fs::path> vImportFiles; | std::vector<fs::path> vImportFiles; | ||||
for (const std::string &strFile : gArgs.GetArgs("-loadblock")) { | for (const std::string &strFile : gArgs.GetArgs("-loadblock")) { | ||||
vImportFiles.push_back(strFile); | vImportFiles.push_back(strFile); | ||||
} | } | ||||
threadGroup.create_thread( | threadGroup.create_thread( | ||||
std::bind(&ThreadImport, std::ref(config), vImportFiles)); | std::bind(&ThreadImport, std::ref(config), vImportFiles)); | ||||
// Wait for genesis block to be processed | // Wait for genesis block to be processed | ||||
{ | { | ||||
WAIT_LOCK(g_genesis_wait_mutex, lock); | WAIT_LOCK(g_genesis_wait_mutex, lock); | ||||
// We previously could hang here if StartShutdown() is called prior to | // We previously could hang here if StartShutdown() is called prior to | ||||
// ThreadImport getting started, so instead we just wait on a timer to | // ThreadImport getting started, so instead we just wait on a timer to | ||||
// check ShutdownRequested() regularly. | // check ShutdownRequested() regularly. | ||||
while (!fHaveGenesis && !ShutdownRequested()) { | while (!fHaveGenesis && !ShutdownRequested()) { | ||||
g_genesis_wait_cv.wait_for(lock, std::chrono::milliseconds(500)); | g_genesis_wait_cv.wait_for(lock, std::chrono::milliseconds(500)); | ||||
} | } | ||||
uiInterface.NotifyBlockTip.disconnect(BlockNotifyGenesisWait); | uiInterface.NotifyBlockTip_disconnect(BlockNotifyGenesisWait); | ||||
} | } | ||||
if (ShutdownRequested()) { | if (ShutdownRequested()) { | ||||
return false; | return false; | ||||
} | } | ||||
// Step 12: start node | // Step 12: start node | ||||
▲ Show 20 Lines • Show All 101 Lines • Show Last 20 Lines |