Changeset View
Changeset View
Standalone View
Standalone View
src/init.cpp
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | bool Open(const CChainParams &chainParams) const override { | ||||
return true; | return true; | ||||
} | } | ||||
void Start(CScheduler &scheduler) const override {} | void Start(CScheduler &scheduler) const override {} | ||||
void Flush() const override {} | void Flush() const override {} | ||||
void Stop() const override {} | void Stop() const override {} | ||||
void Close() const override {} | void Close() const override {} | ||||
}; | }; | ||||
static DummyWalletInit g_dummy_wallet_init; | const WalletInitInterface &g_wallet_init_interface = DummyWalletInit(); | ||||
WalletInitInterface *const g_wallet_init_interface = &g_dummy_wallet_init; | |||||
#endif | #endif | ||||
#if ENABLE_ZMQ | #if ENABLE_ZMQ | ||||
static CZMQNotificationInterface *pzmqNotificationInterface = nullptr; | static CZMQNotificationInterface *pzmqNotificationInterface = nullptr; | ||||
#endif | #endif | ||||
#ifdef WIN32 | #ifdef WIN32 | ||||
// Win32 LevelDB doesn't use filedescriptors, and the ones used for accessing | // Win32 LevelDB doesn't use filedescriptors, and the ones used for accessing | ||||
▲ Show 20 Lines • Show All 95 Lines • ▼ Show 20 Lines | void Shutdown() { | ||||
/// only does this if the respective module was initialized. | /// only does this if the respective module was initialized. | ||||
RenameThread("bitcoin-shutoff"); | RenameThread("bitcoin-shutoff"); | ||||
g_mempool.AddTransactionsUpdated(1); | g_mempool.AddTransactionsUpdated(1); | ||||
StopHTTPRPC(); | StopHTTPRPC(); | ||||
StopREST(); | StopREST(); | ||||
StopRPC(); | StopRPC(); | ||||
StopHTTPServer(); | StopHTTPServer(); | ||||
g_wallet_init_interface->Flush(); | g_wallet_init_interface.Flush(); | ||||
StopMapPort(); | StopMapPort(); | ||||
// Because these depend on each-other, we make sure that neither can be | // Because these depend on each-other, we make sure that neither can be | ||||
// using the other before destroying them. | // using the other before destroying them. | ||||
if (peerLogic) { | if (peerLogic) { | ||||
UnregisterValidationInterface(peerLogic.get()); | UnregisterValidationInterface(peerLogic.get()); | ||||
} | } | ||||
if (g_connman) { | if (g_connman) { | ||||
Show All 35 Lines | // cases and make next startup faster by avoiding rescan. | ||||
if (pcoinsTip != nullptr) { | if (pcoinsTip != nullptr) { | ||||
FlushStateToDisk(); | FlushStateToDisk(); | ||||
} | } | ||||
pcoinsTip.reset(); | pcoinsTip.reset(); | ||||
pcoinscatcher.reset(); | pcoinscatcher.reset(); | ||||
pcoinsdbview.reset(); | pcoinsdbview.reset(); | ||||
pblocktree.reset(); | pblocktree.reset(); | ||||
} | } | ||||
g_wallet_init_interface->Stop(); | g_wallet_init_interface.Stop(); | ||||
#if ENABLE_ZMQ | #if ENABLE_ZMQ | ||||
if (pzmqNotificationInterface) { | if (pzmqNotificationInterface) { | ||||
UnregisterValidationInterface(pzmqNotificationInterface); | UnregisterValidationInterface(pzmqNotificationInterface); | ||||
delete pzmqNotificationInterface; | delete pzmqNotificationInterface; | ||||
pzmqNotificationInterface = nullptr; | pzmqNotificationInterface = nullptr; | ||||
} | } | ||||
#endif | #endif | ||||
#ifndef WIN32 | #ifndef WIN32 | ||||
try { | try { | ||||
fs::remove(GetPidFile()); | fs::remove(GetPidFile()); | ||||
} catch (const fs::filesystem_error &e) { | } catch (const fs::filesystem_error &e) { | ||||
LogPrintf("%s: Unable to remove pidfile: %s\n", __func__, e.what()); | LogPrintf("%s: Unable to remove pidfile: %s\n", __func__, e.what()); | ||||
} | } | ||||
#endif | #endif | ||||
UnregisterAllValidationInterfaces(); | UnregisterAllValidationInterfaces(); | ||||
GetMainSignals().UnregisterBackgroundSignalScheduler(); | GetMainSignals().UnregisterBackgroundSignalScheduler(); | ||||
GetMainSignals().UnregisterWithMempoolSignals(g_mempool); | GetMainSignals().UnregisterWithMempoolSignals(g_mempool); | ||||
g_wallet_init_interface->Close(); | g_wallet_init_interface.Close(); | ||||
globalVerifyHandle.reset(); | globalVerifyHandle.reset(); | ||||
ECC_Stop(); | ECC_Stop(); | ||||
LogPrintf("%s: done\n", __func__); | LogPrintf("%s: done\n", __func__); | ||||
} | } | ||||
/** | /** | ||||
* Signal handlers are very limited in what they are allowed to do. | * Signal handlers are very limited in what they are allowed to do. | ||||
* The execution context the handler is invoked in is not guaranteed, | * The execution context the handler is invoked in is not guaranteed, | ||||
▲ Show 20 Lines • Show All 337 Lines • ▼ Show 20 Lines | strUsage += HelpMessageOpt( | ||||
"if they violate local relay policy (default: %d)"), | "if they violate local relay policy (default: %d)"), | ||||
DEFAULT_WHITELISTFORCERELAY)); | DEFAULT_WHITELISTFORCERELAY)); | ||||
strUsage += HelpMessageOpt( | strUsage += HelpMessageOpt( | ||||
"-maxuploadtarget=<n>", | "-maxuploadtarget=<n>", | ||||
strprintf(_("Tries to keep outbound traffic under the given target (in " | strprintf(_("Tries to keep outbound traffic under the given target (in " | ||||
"MiB per 24h), 0 = no limit (default: %d)"), | "MiB per 24h), 0 = no limit (default: %d)"), | ||||
DEFAULT_MAX_UPLOAD_TARGET)); | DEFAULT_MAX_UPLOAD_TARGET)); | ||||
strUsage += g_wallet_init_interface->GetHelpString(showDebug); | strUsage += g_wallet_init_interface.GetHelpString(showDebug); | ||||
#if ENABLE_ZMQ | #if ENABLE_ZMQ | ||||
strUsage += HelpMessageGroup(_("ZeroMQ notification options:")); | strUsage += HelpMessageGroup(_("ZeroMQ notification options:")); | ||||
strUsage += HelpMessageOpt("-zmqpubhashblock=<address>", | strUsage += HelpMessageOpt("-zmqpubhashblock=<address>", | ||||
_("Enable publish hash block in <address>")); | _("Enable publish hash block in <address>")); | ||||
strUsage += | strUsage += | ||||
HelpMessageOpt("-zmqpubhashtx=<address>", | HelpMessageOpt("-zmqpubhashtx=<address>", | ||||
_("Enable publish hash transaction in <address>")); | _("Enable publish hash transaction in <address>")); | ||||
▲ Show 20 Lines • Show All 1,025 Lines • ▼ Show 20 Lines | fRequireStandard = | ||||
!gArgs.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard()); | !gArgs.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard()); | ||||
if (chainparams.RequireStandard() && !fRequireStandard) { | if (chainparams.RequireStandard() && !fRequireStandard) { | ||||
return InitError( | return InitError( | ||||
strprintf("acceptnonstdtxn is not currently supported for %s chain", | strprintf("acceptnonstdtxn is not currently supported for %s chain", | ||||
chainparams.NetworkIDString())); | chainparams.NetworkIDString())); | ||||
} | } | ||||
nBytesPerSigOp = gArgs.GetArg("-bytespersigop", nBytesPerSigOp); | nBytesPerSigOp = gArgs.GetArg("-bytespersigop", nBytesPerSigOp); | ||||
if (!g_wallet_init_interface->ParameterInteraction()) { | if (!g_wallet_init_interface.ParameterInteraction()) { | ||||
return false; | return false; | ||||
} | } | ||||
fIsBareMultisigStd = | fIsBareMultisigStd = | ||||
gArgs.GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG); | gArgs.GetBoolArg("-permitbaremultisig", DEFAULT_PERMIT_BAREMULTISIG); | ||||
fAcceptDatacarrier = | fAcceptDatacarrier = | ||||
gArgs.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER); | gArgs.GetBoolArg("-datacarrier", DEFAULT_ACCEPT_DATACARRIER); | ||||
▲ Show 20 Lines • Show All 135 Lines • ▼ Show 20 Lines | #endif | ||||
GetMainSignals().RegisterBackgroundSignalScheduler(scheduler); | GetMainSignals().RegisterBackgroundSignalScheduler(scheduler); | ||||
GetMainSignals().RegisterWithMempoolSignals(g_mempool); | GetMainSignals().RegisterWithMempoolSignals(g_mempool); | ||||
/** | /** | ||||
* Register RPC commands regardless of -server setting so they will be | * Register RPC commands regardless of -server setting so they will be | ||||
* available in the GUI RPC console even if external calls are disabled. | * available in the GUI RPC console even if external calls are disabled. | ||||
*/ | */ | ||||
RegisterAllRPCCommands(config, rpcServer, tableRPC); | RegisterAllRPCCommands(config, rpcServer, tableRPC); | ||||
g_wallet_init_interface->RegisterRPC(tableRPC); | g_wallet_init_interface.RegisterRPC(tableRPC); | ||||
/** | /** | ||||
* 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)) { | ||||
return false; | return false; | ||||
} | } | ||||
// Step 6: network initialization | // Step 6: network initialization | ||||
// Note that we absolutely cannot open any actual connections | // Note that we absolutely cannot open any actual connections | ||||
// until the very end ("start node") as the UTXO/block state | // until the very end ("start node") as the UTXO/block state | ||||
// is not yet setup and may end up being set up twice if we | // is not yet setup and may end up being set up twice if we | ||||
▲ Show 20 Lines • Show All 382 Lines • ▼ Show 20 Lines | #endif | ||||
LogPrintf(" block index %15dms\n", GetTimeMillis() - nStart); | LogPrintf(" block index %15dms\n", GetTimeMillis() - nStart); | ||||
// Encoded addresses using cashaddr instead of base58 | // Encoded addresses using cashaddr instead of base58 | ||||
// Activates by default on Jan, 14 | // Activates by default on Jan, 14 | ||||
config.SetCashAddrEncoding( | config.SetCashAddrEncoding( | ||||
gArgs.GetBoolArg("-usecashaddr", GetAdjustedTime() > 1515900000)); | gArgs.GetBoolArg("-usecashaddr", GetAdjustedTime() > 1515900000)); | ||||
// Step 8: load wallet | // Step 8: load wallet | ||||
if (!g_wallet_init_interface->Open(chainparams)) { | if (!g_wallet_init_interface.Open(chainparams)) { | ||||
return false; | return false; | ||||
} | } | ||||
// Step 9: data directory maintenance | // Step 9: data directory maintenance | ||||
// if pruning, unset the service bit and perform the initial blockstore | // if pruning, unset the service bit and perform the initial blockstore | ||||
// prune after any wallet rescanning has taken place. | // prune after any wallet rescanning has taken place. | ||||
if (fPruneMode) { | if (fPruneMode) { | ||||
▲ Show 20 Lines • Show All 140 Lines • ▼ Show 20 Lines | if (!connman.Start(scheduler, connOptions)) { | ||||
return false; | return false; | ||||
} | } | ||||
// Step 12: finished | // Step 12: finished | ||||
SetRPCWarmupFinished(); | SetRPCWarmupFinished(); | ||||
uiInterface.InitMessage(_("Done loading")); | uiInterface.InitMessage(_("Done loading")); | ||||
g_wallet_init_interface->Start(scheduler); | g_wallet_init_interface.Start(scheduler); | ||||
return true; | return true; | ||||
} | } |