aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-10-14 11:32:12 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-10-14 11:35:17 +0200
commit992ab87114b8c9ea8230e97a9c8d8bd71939074d (patch)
tree0ee6087b370083783b41aa6362034e631c797b20 /src
parent2e4f6127bf6e9f01ea5eb0f711b275270c489e9d (diff)
parent94064710b9123dfb3df8cfd6c32efae349aec281 (diff)
downloadbitcoin-992ab87114b8c9ea8230e97a9c8d8bd71939074d.tar.xz
Merge pull request #4942
9406471 Write fee estimate and peers files only when initialized (Wladimir J. van der Laan)
Diffstat (limited to 'src')
-rw-r--r--src/init.cpp27
-rw-r--r--src/net.cpp20
2 files changed, 29 insertions, 18 deletions
diff --git a/src/init.cpp b/src/init.cpp
index 8dcd35fb8f..8772be5539 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -47,6 +47,7 @@ using namespace std;
#ifdef ENABLE_WALLET
CWallet* pwalletMain = NULL;
#endif
+bool fFeeEstimatesInitialized = false;
#ifdef WIN32
// Win32 LevelDB doesn't use filedescriptors, and the ones used for
@@ -119,6 +120,10 @@ void Shutdown()
if (!lockShutdown)
return;
+ /// Note: Shutdown() must be able to handle cases in which AppInit2() failed part of the way,
+ /// for example if the data directory was found to be locked.
+ /// Be sure that anything that writes files or flushes caches only does this if the respective
+ /// module was initialized.
RenameThread("bitcoin-shutoff");
mempool.AddTransactionsUpdated(1);
StopRPCThreads();
@@ -130,6 +135,7 @@ void Shutdown()
StopNode();
UnregisterNodeSignals(GetNodeSignals());
+ if (fFeeEstimatesInitialized)
{
boost::filesystem::path est_path = GetDataDir() / FEE_ESTIMATES_FILENAME;
CAutoFile est_fileout(fopen(est_path.string().c_str(), "wb"), SER_DISK, CLIENT_VERSION);
@@ -137,6 +143,7 @@ void Shutdown()
mempool.WriteFeeEstimates(est_fileout);
else
LogPrintf("%s: Failed to write fee estimates to %s\n", __func__, est_path.string());
+ fFeeEstimatesInitialized = false;
}
{
@@ -1059,6 +1066,7 @@ bool AppInit2(boost::thread_group& threadGroup)
// Allowed to fail as this file IS missing on first startup.
if (est_filein)
mempool.ReadFeeEstimates(est_filein);
+ fFeeEstimatesInitialized = true;
// ********************************************************* Step 8: load wallet
#ifdef ENABLE_WALLET
@@ -1215,22 +1223,7 @@ bool AppInit2(boost::thread_group& threadGroup)
}
threadGroup.create_thread(boost::bind(&ThreadImport, vImportFiles));
- // ********************************************************* Step 10: load peers
-
- uiInterface.InitMessage(_("Loading addresses..."));
-
- nStart = GetTimeMillis();
-
- {
- CAddrDB adb;
- if (!adb.Read(addrman))
- LogPrintf("Invalid or missing peers.dat; recreating\n");
- }
-
- LogPrintf("Loaded %i addresses from peers.dat %dms\n",
- addrman.size(), GetTimeMillis() - nStart);
-
- // ********************************************************* Step 11: start node
+ // ********************************************************* Step 10: start node
if (!CheckDiskSpace())
return false;
@@ -1259,7 +1252,7 @@ bool AppInit2(boost::thread_group& threadGroup)
GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain, GetArg("-genproclimit", -1));
#endif
- // ********************************************************* Step 12: finished
+ // ********************************************************* Step 11: finished
uiInterface.InitMessage(_("Done loading"));
diff --git a/src/net.cpp b/src/net.cpp
index 866bac2c0e..dd5cb480cc 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -78,6 +78,7 @@ uint64_t nLocalHostNonce = 0;
static std::vector<ListenSocket> vhListenSocket;
CAddrMan addrman;
int nMaxConnections = 125;
+bool fAddressesInitialized = false;
vector<CNode*> vNodes;
CCriticalSection cs_vNodes;
@@ -1739,6 +1740,18 @@ void static Discover(boost::thread_group& threadGroup)
void StartNode(boost::thread_group& threadGroup)
{
+ uiInterface.InitMessage(_("Loading addresses..."));
+ // Load addresses for peers.dat
+ int64_t nStart = GetTimeMillis();
+ {
+ CAddrDB adb;
+ if (!adb.Read(addrman))
+ LogPrintf("Invalid or missing peers.dat; recreating\n");
+ }
+ LogPrintf("Loaded %i addresses from peers.dat %dms\n",
+ addrman.size(), GetTimeMillis() - nStart);
+ fAddressesInitialized = true;
+
if (semOutbound == NULL) {
// initialize semaphore
int nMaxOutbound = min(MAX_OUTBOUND_CONNECTIONS, nMaxConnections);
@@ -1785,7 +1798,12 @@ bool StopNode()
if (semOutbound)
for (int i=0; i<MAX_OUTBOUND_CONNECTIONS; i++)
semOutbound->post();
- DumpAddresses();
+
+ if (fAddressesInitialized)
+ {
+ DumpAddresses();
+ fAddressesInitialized = false;
+ }
return true;
}