MCPcopy Create free account
hub / github.com/LUX-Core/lux / PrepareShutdown

Function PrepareShutdown

src/init.cpp:195–281  ·  view source on GitHub ↗

Preparing steps before shutting down or restarting the wallet */

Source from the content-addressed store, hash-verified

193
194/** Preparing steps before shutting down or restarting the wallet */
195void PrepareShutdown()
196{
197 LogPrintf("%s: In progress...\n", __func__);
198 static CCriticalSection cs_Shutdown;
199 TRY_LOCK(cs_Shutdown, lockShutdown);
200 if (!lockShutdown)
201 return;
202
203 /// Note: Shutdown() must be able to handle cases in which AppInit2() failed part of the way,
204 /// for example if the data directory was found to be locked.
205 /// Be sure that anything that writes files or flushes caches only does this if the respective
206 /// module was initialized.
207 RenameThread("lux-shutoff");
208 mempool.AddTransactionsUpdated(1);
209
210 StopHTTPRPC();
211 StopREST();
212 StopRPC();
213 StopHTTPServer();
214#ifdef ENABLE_WALLET
215 if (pwalletMain)
216 bitdb.Flush(false);
217// GenerateBitcoins(NULL, 0);
218#endif
219 StopNode();
220 UnregisterNodeSignals(GetNodeSignals());
221
222 // After everything has been shut down, but before things get flushed, stop the
223 // CScheduler/checkqueue threadGroup
224 threadGroup.interrupt_all();
225 threadGroup.join_all();
226
227 if (fFeeEstimatesInitialized) {
228 boost::filesystem::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME;
229 CAutoFile est_fileout(fopen(est_path.string().c_str(), "wb"), SER_DISK, CLIENT_VERSION);
230 if (!est_fileout.IsNull())
231 mempool.WriteFeeEstimates(est_fileout);
232 else
233 LogPrintf("%s: Failed to write fee estimates to %s\n", __func__, est_path.string());
234 fFeeEstimatesInitialized = false;
235 }
236
237 {
238 LOCK(cs_main);
239 if (pcoinsTip != NULL) {
240 FlushStateToDisk();
241
242 //record that client took the proper shutdown procedure
243 pblocktree->WriteFlag("shutdown", true);
244 }
245 delete pcoinsTip;
246 pcoinsTip = NULL;
247 delete pcoinscatcher;
248 pcoinscatcher = NULL;
249 delete pcoinsdbview;
250 pcoinsdbview = NULL;
251 delete pblocktree;
252 pblocktree = NULL;

Callers 2

ShutdownFunction · 0.85
restartMethod · 0.85

Calls 15

RenameThreadFunction · 0.85
StopHTTPRPCFunction · 0.85
StopRESTFunction · 0.85
StopRPCFunction · 0.85
StopHTTPServerFunction · 0.85
StopNodeFunction · 0.85
UnregisterNodeSignalsFunction · 0.85
FlushStateToDiskFunction · 0.85
GetPidFileFunction · 0.85

Tested by

no test coverage detected