aboutsummaryrefslogtreecommitdiff
path: root/src/init.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/init.cpp')
-rw-r--r--src/init.cpp34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/init.cpp b/src/init.cpp
index d317209346..f4136f09e9 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -40,7 +40,9 @@
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/replace.hpp>
+#include <boost/bind.hpp>
#include <boost/filesystem.hpp>
+#include <boost/function.hpp>
#include <boost/interprocess/sync/file_lock.hpp>
#include <boost/thread.hpp>
#include <openssl/crypto.h>
@@ -189,7 +191,11 @@ void Shutdown()
pwalletMain->Flush(true);
#endif
#ifndef WIN32
- boost::filesystem::remove(GetPidFile());
+ try {
+ boost::filesystem::remove(GetPidFile());
+ } catch (const boost::filesystem::filesystem_error& e) {
+ LogPrintf("%s: Unable to remove pidfile: %s\n", __func__, e.what());
+ }
#endif
UnregisterAllValidationInterfaces();
#ifdef ENABLE_WALLET
@@ -334,7 +340,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-salvagewallet", _("Attempt to recover private keys from a corrupt wallet.dat") + " " + _("on startup"));
strUsage += HelpMessageOpt("-sendfreetransactions", strprintf(_("Send transactions as zero-fee transactions if possible (default: %u)"), 0));
strUsage += HelpMessageOpt("-spendzeroconfchange", strprintf(_("Spend unconfirmed change when sending transactions (default: %u)"), 1));
- strUsage += HelpMessageOpt("-txconfirmtarget=<n>", strprintf(_("If paytxfee is not set, include enough fee so transactions begin confirmation on average within n blocks (default: %u)"), 1));
+ strUsage += HelpMessageOpt("-txconfirmtarget=<n>", strprintf(_("If paytxfee is not set, include enough fee so transactions begin confirmation on average within n blocks (default: %u)"), DEFAULT_TX_CONFIRM_TARGET));
strUsage += HelpMessageOpt("-maxtxfee=<amt>", strprintf(_("Maximum total fees to use in a single wallet transaction; setting this too low may abort large transactions (default: %s)"),
FormatMoney(maxTxFee)));
strUsage += HelpMessageOpt("-upgradewallet", _("Upgrade wallet to latest format") + " " + _("on startup"));
@@ -662,6 +668,10 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
// to protect privacy, do not listen by default if a default proxy server is specified
if (SoftSetBoolArg("-listen", false))
LogPrintf("%s: parameter interaction: -proxy set -> setting -listen=0\n", __func__);
+ // to protect privacy, do not use UPNP when a proxy is set. The user may still specify -listen=1
+ // to listen locally, so don't rely on this happening through -listen below.
+ if (SoftSetBoolArg("-upnp", false))
+ LogPrintf("%s: parameter interaction: -proxy set -> setting -upnp=0\n", __func__);
// to protect privacy, do not discover addresses by default
if (SoftSetBoolArg("-discover", false))
LogPrintf("%s: parameter interaction: -proxy set -> setting -discover=0\n", __func__);
@@ -835,7 +845,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
mapArgs["-maxtxfee"], ::minRelayTxFee.ToString()));
}
}
- nTxConfirmTarget = GetArg("-txconfirmtarget", 1);
+ nTxConfirmTarget = GetArg("-txconfirmtarget", DEFAULT_TX_CONFIRM_TARGET);
bSpendZeroConfChange = GetBoolArg("-spendzeroconfchange", true);
fSendFreeTransactions = GetBoolArg("-sendfreetransactions", false);
@@ -864,9 +874,15 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
boost::filesystem::path pathLockFile = GetDataDir() / ".lock";
FILE* file = fopen(pathLockFile.string().c_str(), "a"); // empty lock file; created if it doesn't exist.
if (file) fclose(file);
- static boost::interprocess::file_lock lock(pathLockFile.string().c_str());
- if (!lock.try_lock())
- return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin Core is probably already running."), strDataDir));
+
+ try {
+ static boost::interprocess::file_lock lock(pathLockFile.string().c_str());
+ if (!lock.try_lock())
+ return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin Core is probably already running."), strDataDir));
+ } catch(const boost::interprocess::interprocess_exception& e) {
+ return InitError(strprintf(_("Cannot obtain a lock on data directory %s. Bitcoin Core is probably already running.") + " %s.", strDataDir, e.what()));
+ }
+
#ifndef WIN32
CreatePidFile(GetPidFile(), getpid());
#endif
@@ -1383,6 +1399,12 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
StartNode(threadGroup, scheduler);
+ // Monitor the chain, and alert if we get blocks much quicker or slower than expected
+ int64_t nPowTargetSpacing = Params().GetConsensus().nPowTargetSpacing;
+ CScheduler::Function f = boost::bind(&PartitionCheck, &IsInitialBlockDownload,
+ boost::ref(cs_main), boost::cref(chainActive), nPowTargetSpacing);
+ scheduler.scheduleEvery(f, nPowTargetSpacing);
+
#ifdef ENABLE_WALLET
// Generate coins in the background
if (pwalletMain)