aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcontrib/gitian-build.sh2
-rw-r--r--doc/build-osx.md17
-rw-r--r--src/chainparamsbase.cpp44
-rw-r--r--src/chainparamsbase.h5
-rw-r--r--src/init.cpp17
-rw-r--r--src/net.cpp86
-rw-r--r--src/net.h10
-rw-r--r--src/net_processing.cpp4
-rw-r--r--src/qt/README.md95
-rw-r--r--src/qt/optionsmodel.cpp7
-rw-r--r--src/torcontrol.cpp6
-rw-r--r--src/torcontrol.h2
-rw-r--r--src/validation.cpp3
-rw-r--r--src/wallet/wallet.cpp4
14 files changed, 181 insertions, 121 deletions
diff --git a/contrib/gitian-build.sh b/contrib/gitian-build.sh
index 631fba9089..d334c1642f 100755
--- a/contrib/gitian-build.sh
+++ b/contrib/gitian-build.sh
@@ -47,7 +47,7 @@ Options:
-j Number of processes to use. Default 2
-m Memory to allocate in MiB. Default 2000
--kvm Use KVM instead of LXC
---setup Set up the Gitian building environment. Uses KVM. If you want to use lxc, use the --lxc option. Only works on Debian-based systems (Ubuntu, Debian)
+--setup Set up the Gitian building environment. Uses LXC. If you want to use KVM, use the --kvm option. Only works on Debian-based systems (Ubuntu, Debian)
--detach-sign Create the assert file for detached signing. Will not commit anything.
--no-commit Do not commit anything to git
-h|--help Print this help message
diff --git a/doc/build-osx.md b/doc/build-osx.md
index 3e243933c8..2b84c7cc2c 100644
--- a/doc/build-osx.md
+++ b/doc/build-osx.md
@@ -90,23 +90,6 @@ Other commands:
./src/bitcoin-cli --help # Outputs a list of command-line options.
./src/bitcoin-cli help # Outputs a list of RPC commands when the daemon is running.
-Using Qt Creator as IDE
-------------------------
-You can use Qt Creator as an IDE, for bitcoin development.
-Download and install the community edition of [Qt Creator](https://www.qt.io/download/).
-Uncheck everything except Qt Creator during the installation process.
-
-1. Make sure you installed everything through Homebrew mentioned above
-2. Do a proper ./configure --enable-debug
-3. In Qt Creator do "New Project" -> Import Project -> Import Existing Project
-4. Enter "bitcoin-qt" as project name, enter src/qt as location
-5. Leave the file selection as it is
-6. Confirm the "summary page"
-7. In the "Projects" tab select "Manage Kits..."
-8. Select the default "Desktop" kit and select "Clang (x86 64bit in /usr/bin)" as compiler
-9. Select LLDB as debugger (you might need to set the path to your installation)
-10. Start debugging with Qt Creator
-
Notes
-----
diff --git a/src/chainparamsbase.cpp b/src/chainparamsbase.cpp
index 89dd8549b9..a04258fd40 100644
--- a/src/chainparamsbase.cpp
+++ b/src/chainparamsbase.cpp
@@ -24,44 +24,6 @@ void AppendParamsHelpMessages(std::string& strUsage, bool debugHelp)
strUsage += HelpMessageOpt("-testnet", _("Use the test chain"));
}
-/**
- * Main network
- */
-class CBaseMainParams : public CBaseChainParams
-{
-public:
- CBaseMainParams()
- {
- nRPCPort = 8332;
- }
-};
-
-/**
- * Testnet (v3)
- */
-class CBaseTestNetParams : public CBaseChainParams
-{
-public:
- CBaseTestNetParams()
- {
- nRPCPort = 18332;
- strDataDir = "testnet3";
- }
-};
-
-/*
- * Regression test
- */
-class CBaseRegTestParams : public CBaseChainParams
-{
-public:
- CBaseRegTestParams()
- {
- nRPCPort = 18443;
- strDataDir = "regtest";
- }
-};
-
static std::unique_ptr<CBaseChainParams> globalChainBaseParams;
const CBaseChainParams& BaseParams()
@@ -73,11 +35,11 @@ const CBaseChainParams& BaseParams()
std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain)
{
if (chain == CBaseChainParams::MAIN)
- return std::unique_ptr<CBaseChainParams>(new CBaseMainParams());
+ return MakeUnique<CBaseChainParams>("", 8332);
else if (chain == CBaseChainParams::TESTNET)
- return std::unique_ptr<CBaseChainParams>(new CBaseTestNetParams());
+ return MakeUnique<CBaseChainParams>("testnet3", 18332);
else if (chain == CBaseChainParams::REGTEST)
- return std::unique_ptr<CBaseChainParams>(new CBaseRegTestParams());
+ return MakeUnique<CBaseChainParams>("regtest", 18443);
else
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
}
diff --git a/src/chainparamsbase.h b/src/chainparamsbase.h
index b4d2bb4f08..2cb860380e 100644
--- a/src/chainparamsbase.h
+++ b/src/chainparamsbase.h
@@ -24,9 +24,10 @@ public:
const std::string& DataDir() const { return strDataDir; }
int RPCPort() const { return nRPCPort; }
-protected:
- CBaseChainParams() {}
+ CBaseChainParams() = delete;
+ CBaseChainParams(const std::string& data_dir, int rpc_port) : nRPCPort(rpc_port), strDataDir(data_dir) {}
+private:
int nRPCPort;
std::string strDataDir;
};
diff --git a/src/init.cpp b/src/init.cpp
index 84398d978c..b28baba779 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -165,6 +165,7 @@ void Interrupt()
InterruptRPC();
InterruptREST();
InterruptTorControl();
+ InterruptMapPort();
if (g_connman)
g_connman->Interrupt();
}
@@ -191,7 +192,7 @@ void Shutdown()
#ifdef ENABLE_WALLET
FlushWallets();
#endif
- MapPort(false);
+ StopMapPort();
// Because these depend on each-other, we make sure that neither can be
// using the other before destroying them.
@@ -545,7 +546,8 @@ static void BlockNotifyCallback(bool initialSync, const CBlockIndex *pBlockIndex
std::string strCmd = gArgs.GetArg("-blocknotify", "");
if (!strCmd.empty()) {
boost::replace_all(strCmd, "%s", pBlockIndex->GetBlockHash().GetHex());
- boost::thread t(runCommand, strCmd); // thread runs free
+ std::thread t(runCommand, strCmd);
+ t.detach(); // thread runs free
}
}
@@ -1425,6 +1427,9 @@ bool AppInitMain()
pcoinsTip.reset();
pcoinsdbview.reset();
pcoinscatcher.reset();
+ // new CBlockTreeDB tries to delete the existing file, which
+ // fails if it's still open from the previous loop. Close it first:
+ pblocktree.reset();
pblocktree.reset(new CBlockTreeDB(nBlockTreeDBCache, false, fReset));
if (fReset) {
@@ -1671,12 +1676,14 @@ bool AppInitMain()
LogPrintf("nBestHeight = %d\n", chain_active_height);
if (gArgs.GetBoolArg("-listenonion", DEFAULT_LISTEN_ONION))
- StartTorControl(threadGroup, scheduler);
+ StartTorControl();
- Discover(threadGroup);
+ Discover();
// Map ports with UPnP
- MapPort(gArgs.GetBoolArg("-upnp", DEFAULT_UPNP));
+ if (gArgs.GetBoolArg("-upnp", DEFAULT_UPNP)) {
+ StartMapPort();
+ }
CConnman::Options connOptions;
connOptions.nLocalServices = nLocalServices;
diff --git a/src/net.cpp b/src/net.cpp
index 03ed7e7fc1..201914685c 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -1459,6 +1459,8 @@ void CConnman::WakeMessageHandler()
#ifdef USE_UPNP
+static CThreadInterrupt g_upnp_interrupt;
+static std::thread g_upnp_thread;
void ThreadMapPort()
{
std::string port = strprintf("%u", GetListenPort());
@@ -1509,35 +1511,29 @@ void ThreadMapPort()
std::string strDesc = "Bitcoin " + FormatFullVersion();
- try {
- while (true) {
+ do {
#ifndef UPNPDISCOVER_SUCCESS
- /* miniupnpc 1.5 */
- r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,
- port.c_str(), port.c_str(), lanaddr, strDesc.c_str(), "TCP", 0);
+ /* miniupnpc 1.5 */
+ r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,
+ port.c_str(), port.c_str(), lanaddr, strDesc.c_str(), "TCP", 0);
#else
- /* miniupnpc 1.6 */
- r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,
- port.c_str(), port.c_str(), lanaddr, strDesc.c_str(), "TCP", 0, "0");
+ /* miniupnpc 1.6 */
+ r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,
+ port.c_str(), port.c_str(), lanaddr, strDesc.c_str(), "TCP", 0, "0");
#endif
- if(r!=UPNPCOMMAND_SUCCESS)
- LogPrintf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n",
- port, port, lanaddr, r, strupnperror(r));
- else
- LogPrintf("UPnP Port Mapping successful.\n");
-
- MilliSleep(20*60*1000); // Refresh every 20 minutes
- }
- }
- catch (const boost::thread_interrupted&)
- {
- r = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port.c_str(), "TCP", 0);
- LogPrintf("UPNP_DeletePortMapping() returned: %d\n", r);
- freeUPNPDevlist(devlist); devlist = nullptr;
- FreeUPNPUrls(&urls);
- throw;
+ if(r!=UPNPCOMMAND_SUCCESS)
+ LogPrintf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n",
+ port, port, lanaddr, r, strupnperror(r));
+ else
+ LogPrintf("UPnP Port Mapping successful.\n");
}
+ while(g_upnp_interrupt.sleep_for(std::chrono::minutes(20)));
+
+ r = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port.c_str(), "TCP", 0);
+ LogPrintf("UPNP_DeletePortMapping() returned: %d\n", r);
+ freeUPNPDevlist(devlist); devlist = nullptr;
+ FreeUPNPUrls(&urls);
} else {
LogPrintf("No valid UPnP IGDs found\n");
freeUPNPDevlist(devlist); devlist = nullptr;
@@ -1546,27 +1542,39 @@ void ThreadMapPort()
}
}
-void MapPort(bool fUseUPnP)
+void StartMapPort()
{
- static std::unique_ptr<boost::thread> upnp_thread;
+ if (!g_upnp_thread.joinable()) {
+ assert(!g_upnp_interrupt);
+ g_upnp_thread = std::thread((std::bind(&TraceThread<void (*)()>, "upnp", &ThreadMapPort)));
+ }
+}
- if (fUseUPnP)
- {
- if (upnp_thread) {
- upnp_thread->interrupt();
- upnp_thread->join();
- }
- upnp_thread.reset(new boost::thread(boost::bind(&TraceThread<void (*)()>, "upnp", &ThreadMapPort)));
+void InterruptMapPort()
+{
+ if(g_upnp_thread.joinable()) {
+ g_upnp_interrupt();
}
- else if (upnp_thread) {
- upnp_thread->interrupt();
- upnp_thread->join();
- upnp_thread.reset();
+}
+
+void StopMapPort()
+{
+ if(g_upnp_thread.joinable()) {
+ g_upnp_thread.join();
+ g_upnp_interrupt.reset();
}
}
#else
-void MapPort(bool)
+void StartMapPort()
+{
+ // Intentionally left blank.
+}
+void InterruptMapPort()
+{
+ // Intentionally left blank.
+}
+void StopMapPort()
{
// Intentionally left blank.
}
@@ -2121,7 +2129,7 @@ bool CConnman::BindListenPort(const CService &addrBind, std::string& strError, b
return true;
}
-void Discover(boost::thread_group& threadGroup)
+void Discover()
{
if (!fDiscover)
return;
diff --git a/src/net.h b/src/net.h
index 0542ec1aaa..8378a303b8 100644
--- a/src/net.h
+++ b/src/net.h
@@ -37,10 +37,6 @@
class CScheduler;
class CNode;
-namespace boost {
- class thread_group;
-} // namespace boost
-
/** Time between pings automatically sent out for latency probing and keepalive (in seconds). */
static const int PING_INTERVAL = 2 * 60;
/** Time after which to disconnect, after waiting for a ping response (or inactivity). */
@@ -441,8 +437,10 @@ private:
friend struct CConnmanTest;
};
extern std::unique_ptr<CConnman> g_connman;
-void Discover(boost::thread_group& threadGroup);
-void MapPort(bool fUseUPnP);
+void Discover();
+void StartMapPort();
+void InterruptMapPort();
+void StopMapPort();
unsigned short GetListenPort();
bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index fc0ba82d8b..bf9307727a 100644
--- a/src/net_processing.cpp
+++ b/src/net_processing.cpp
@@ -1226,10 +1226,10 @@ void static ProcessGetData(CNode* pfrom, const Consensus::Params& consensusParam
}
} // release cs_main
- if (it != pfrom->vRecvGetData.end()) {
+ if (it != pfrom->vRecvGetData.end() && !pfrom->fPauseSend) {
const CInv &inv = *it;
- it++;
if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK || inv.type == MSG_CMPCT_BLOCK || inv.type == MSG_WITNESS_BLOCK) {
+ it++;
ProcessGetBlockData(pfrom, consensusParams, inv, connman, interruptMsgProc);
}
}
diff --git a/src/qt/README.md b/src/qt/README.md
new file mode 100644
index 0000000000..7ffea98170
--- /dev/null
+++ b/src/qt/README.md
@@ -0,0 +1,95 @@
+This directory contains the BitcoinQT graphical user interface (GUI). It uses the cross platform framework [QT](https://www1.qt.io/developers/).
+
+The current precise version for QT 5 is specified in [qt.mk](/depends/packages/qt.mk). QT 4 is also supported (see [#8263](https://github.com/bitcoin/bitcoin/issues/8263)).
+
+## Compile and run
+
+See build instructions ([OSX](/doc/build-osx.md), [Windows](/doc/build-windows.md), [Unix](/doc/build-unix.md), etc).
+
+To run:
+
+```sh
+./src/qt/bitcoin-qt
+```
+
+## Files and directories
+
+### forms
+
+Contains [Designer UI](http://doc.qt.io/qt-5.9/designer-using-a-ui-file.html) files. They are created with [Qt Creator](#use-qt-Creator-as IDE), but can be edited using any text editor.
+
+### locale
+
+Contains translations. They are periodically updated. The process is described [here](/doc/translation_process.md).
+
+### res
+
+Resources such as the icon.
+
+### test
+
+Tests.
+
+### bitcoingui.(h/cpp)
+
+Represents the main window of the Bitcoin UI.
+
+### \*model.(h/cpp)
+
+The model. When it has a corresponding controller, it generally inherits from [QAbstractTableModel](http://doc.qt.io/qt-5/qabstracttablemodel.html). Models that are used by controllers as helpers inherit from other QT classes like [QValidator](http://doc.qt.io/qt-5/qvalidator.html).
+
+ClientModel is used by the main application `bitcoingui` and several models like `peertablemodel`.
+
+### \*page.(h/cpp)
+
+A controller. `:NAMEpage.cpp` generally includes `:NAMEmodel.h` and `forms/:NAME.page.ui` with a similar `:NAME`.
+
+### \*dialog.(h/cpp)
+
+Various dialogs, e.g. to open a URL. Inherit from [QDialog](http://doc.qt.io/qt-4.8/qdialog.html).
+
+### paymentserver.(h/cpp)
+
+Used to process BIP21 and BIP70 (see https://github.com/bitcoin/bitcoin/pull/11622) payment URI / requests. Also handles URI based application switching (e.g. when following a bitcoin:... link from a browser).
+
+### walletview.(h/cpp)
+
+Represents the view to a single wallet.
+
+### Other .h/cpp files
+
+* UI elements like BitcoinAmountField, which inherit from QWidget.
+* `bitcoinstrings.cpp`: automatically generated
+* `bitcoinunits.(h/cpp)`: BTC / mBTC / etc handling
+* `callback.h`
+* `guiconstants.h`: UI colors, app name, etc
+* `guiutil.h`: several helper functions
+* `macdockiconhandler.(h/cpp)`
+* `macdockiconhandler.(h/cpp)`: display notifications in OSX
+
+## Contribute
+
+See [CONTRIBUTING.md](/CONTRIBUTING.md) for general guidelines. Specifically for QT:
+
+* don't change `local/bitcoin_en.ts`; this happens [automatically](/doc/translation_process.md#writing-code-with-translations)
+
+## Using Qt Creator as IDE
+
+You can use Qt Creator as an IDE. This is especially useful if you want to change
+the UI layout.
+
+Download and install the community edition of [Qt Creator](https://www.qt.io/download/).
+Uncheck everything except Qt Creator during the installation process.
+
+Instructions for OSX:
+
+1. Make sure you installed everything through Homebrew mentioned in the [OSX build instructions](/docs/build-osx.md)
+2. Use `./configure` with the `--enable-debug` flag
+3. In Qt Creator do "New Project" -> Import Project -> Import Existing Project
+4. Enter "bitcoin-qt" as project name, enter src/qt as location
+5. Leave the file selection as it is
+6. Confirm the "summary page"
+7. In the "Projects" tab select "Manage Kits..."
+8. Select the default "Desktop" kit and select "Clang (x86 64bit in /usr/bin)" as compiler
+9. Select LLDB as debugger (you might need to set the path to your installation)
+10. Start debugging with Qt Creator (you might need to the executable to "bitcoin-qt" under "Run", which is where you can also add command line arguments)
diff --git a/src/qt/optionsmodel.cpp b/src/qt/optionsmodel.cpp
index 4ade88d843..909be1c264 100644
--- a/src/qt/optionsmodel.cpp
+++ b/src/qt/optionsmodel.cpp
@@ -315,7 +315,12 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
break;
case MapPortUPnP: // core option - can be changed on-the-fly
settings.setValue("fUseUPnP", value.toBool());
- MapPort(value.toBool());
+ if (value.toBool()) {
+ StartMapPort();
+ } else {
+ InterruptMapPort();
+ StopMapPort();
+ }
break;
case MinimizeOnClose:
fMinimizeOnClose = value.toBool();
diff --git a/src/torcontrol.cpp b/src/torcontrol.cpp
index d875008ef2..717d1cf7e5 100644
--- a/src/torcontrol.cpp
+++ b/src/torcontrol.cpp
@@ -731,7 +731,7 @@ void TorController::reconnect_cb(evutil_socket_t fd, short what, void *arg)
/****** Thread ********/
static struct event_base *gBase;
-static boost::thread torControlThread;
+static std::thread torControlThread;
static void TorControlThread()
{
@@ -740,7 +740,7 @@ static void TorControlThread()
event_base_dispatch(gBase);
}
-void StartTorControl(boost::thread_group& threadGroup, CScheduler& scheduler)
+void StartTorControl()
{
assert(!gBase);
#ifdef WIN32
@@ -754,7 +754,7 @@ void StartTorControl(boost::thread_group& threadGroup, CScheduler& scheduler)
return;
}
- torControlThread = boost::thread(boost::bind(&TraceThread<void (*)()>, "torcontrol", &TorControlThread));
+ torControlThread = std::thread(std::bind(&TraceThread<void (*)()>, "torcontrol", &TorControlThread));
}
void InterruptTorControl()
diff --git a/src/torcontrol.h b/src/torcontrol.h
index 20514f7bbf..2be6701fa5 100644
--- a/src/torcontrol.h
+++ b/src/torcontrol.h
@@ -13,7 +13,7 @@
extern const std::string DEFAULT_TOR_CONTROL;
static const bool DEFAULT_LISTEN_ONION = true;
-void StartTorControl(boost::thread_group& threadGroup, CScheduler& scheduler);
+void StartTorControl();
void InterruptTorControl();
void StopTorControl();
diff --git a/src/validation.cpp b/src/validation.cpp
index 978aaf7d06..371460a6f0 100644
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -1182,7 +1182,8 @@ static void AlertNotify(const std::string& strMessage)
safeStatus = singleQuote+safeStatus+singleQuote;
boost::replace_all(strCmd, "%s", safeStatus);
- boost::thread t(runCommand, strCmd); // thread runs free
+ std::thread t(runCommand, strCmd);
+ t.detach(); // thread runs free
}
static void CheckForkWarningConditions()
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 7f36aefeaf..513819606b 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -34,7 +34,6 @@
#include <future>
#include <boost/algorithm/string/replace.hpp>
-#include <boost/thread.hpp>
std::vector<CWalletRef> vpwallets;
/** Transaction fee set by the user */
@@ -976,7 +975,8 @@ bool CWallet::AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose)
if (!strCmd.empty())
{
boost::replace_all(strCmd, "%s", wtxIn.GetHash().GetHex());
- boost::thread t(runCommand, strCmd); // thread runs free
+ std::thread t(runCommand, strCmd);
+ t.detach(); // thread runs free
}
return true;