| 153 | } |
| 154 | |
| 155 | void Shutdown() |
| 156 | { |
| 157 | LogPrintf("%s: In progress...\n", __func__); |
| 158 | static CCriticalSection cs_Shutdown; |
| 159 | TRY_LOCK(cs_Shutdown, lockShutdown); |
| 160 | if (!lockShutdown) |
| 161 | return; |
| 162 | |
| 163 | /// Note: Shutdown() must be able to handle cases in which AppInit2() failed part of the way, |
| 164 | /// for example if the data directory was found to be locked. |
| 165 | /// Be sure that anything that writes files or flushes caches only does this if the respective |
| 166 | /// module was initialized. |
| 167 | RenameThread("bitcoin-shutoff"); |
| 168 | mempool.AddTransactionsUpdated(1); |
| 169 | |
| 170 | StopHTTPRPC(); |
| 171 | StopREST(); |
| 172 | StopRPC(); |
| 173 | StopHTTPServer(); |
| 174 | #ifdef ENABLE_WALLET |
| 175 | if (pwalletMain) |
| 176 | pwalletMain->Flush(false); |
| 177 | GenerateBitcoins(false, NULL, 0); |
| 178 | #endif |
| 179 | StopNode(); |
| 180 | UnregisterNodeSignals(GetNodeSignals()); |
| 181 | |
| 182 | if (fFeeEstimatesInitialized) |
| 183 | { |
| 184 | boost::filesystem::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME; |
| 185 | CAutoFile est_fileout(fopen(est_path.string().c_str(), "wb"), SER_DISK, CLIENT_VERSION); |
| 186 | if (!est_fileout.IsNull()) |
| 187 | mempool.WriteFeeEstimates(est_fileout); |
| 188 | else |
| 189 | LogPrintf("%s: Failed to write fee estimates to %s\n", __func__, est_path.string()); |
| 190 | fFeeEstimatesInitialized = false; |
| 191 | } |
| 192 | |
| 193 | { |
| 194 | LOCK(cs_main); |
| 195 | if (pcoinsTip != NULL) { |
| 196 | FlushStateToDisk(); |
| 197 | } |
| 198 | delete pcoinsTip; |
| 199 | pcoinsTip = NULL; |
| 200 | delete pcoinscatcher; |
| 201 | pcoinscatcher = NULL; |
| 202 | delete pcoinsdbview; |
| 203 | pcoinsdbview = NULL; |
| 204 | delete pblocktree; |
| 205 | pblocktree = NULL; |
| 206 | } |
| 207 | #ifdef ENABLE_WALLET |
| 208 | if (pwalletMain) |
| 209 | pwalletMain->Flush(true); |
| 210 | #endif |
| 211 | #ifndef WIN32 |
| 212 | try { |
no test coverage detected