Skip to content

Commit

Permalink
Backport Bitcoin Qt/Gui changes up to 0.14.x part 3 (#1617)
Browse files Browse the repository at this point in the history
* Merge bitcoin#8996: Network activity toggle

19f46f1 Qt: New network_disabled icon (Luke Dashjr)
54cf997 RPC/Net: Use boolean consistently for networkactive, and remove from getinfo (Luke Dashjr)
b2b33d9 Overhaul network activity toggle (Jonas Schnelli)
32efa79 Qt: Add GUI feedback and control of network activity state. (Jon Lund Steffensen)
e38993b RPC: Add "togglenetwork" method to toggle network activity temporarily (Jon Lund Steffensen)
7c9a98a Allow network activity to be temporarily suspended. (Jon Lund Steffensen)

* Revert on-click behavior of network status icon to showing peers list

Stay with the way Dash handled clicking on the status icon

* Add theme support for network disabled icon

* Merge bitcoin#8874: Multiple Selection for peer and ban tables

1077577 Fix auto-deselection of peers (Andrew Chow)
addfdeb Multiple Selection for peer and ban tables (Andrew Chow)

* Merge bitcoin#9190: qt: Plug many memory leaks

ed998ea qt: Avoid OpenSSL certstore-related memory leak (Wladimir J. van der Laan)
5204598 qt: Avoid shutdownwindow-related memory leak (Wladimir J. van der Laan)
e4f126a qt: Avoid splash-screen related memory leak (Wladimir J. van der Laan)
693384e qt: Prevent thread/memory leak on exiting RPCConsole (Wladimir J. van der Laan)
47db075 qt: Plug many memory leaks (Wladimir J. van der Laan)

* Merge bitcoin#9218: qt: Show progress overlay when clicking spinner icon

042f9fa qt: Show progress overlay when clicking spinner icon (Wladimir J. van der Laan)
827d9a3 qt: Replace NetworkToggleStatusBarControl with generic ClickableLabel (Wladimir J. van der Laan)

* Merge bitcoin#9266: Bugfix: Qt/RPCConsole: Put column enum in the right places

df17fe0 Bugfix: Qt/RPCConsole: Put column enum in the right places (Luke Dashjr)

* Merge bitcoin#9255: qt: layoutAboutToChange signal is called layoutAboutToBeChanged

f36349e qt: Remove on_toggleNetworkActiveButton_clicked from RPCConsole (Wladimir J. van der Laan)
297cc20 qt: layoutAboutToChange signal is called layoutAboutToBeChanged (Wladimir J. van der Laan)

* Use UniValue until bitcoin PR bitcoin#8788 is backported

Network active toggle was already based on
"[RPC] Give RPC commands more information about the RPC request"
We need to use the old UniValue style until that one is backported

* Merge bitcoin#8906: [qt] sync-overlay: Don't show progress twice

fafeec3 [qt] sync-overlay: Don't show progress twice (MarcoFalke)

* Merge bitcoin#8985: Use pindexBestHeader instead of setBlockIndexCandidates for NotifyHeaderTip()

3154d6e [Qt] use NotifyHeaderTip's height and date for the progress update (Jonas Schnelli)
0a261b6 Use pindexBestHeader instead of setBlockIndexCandidates for NotifyHeaderTip() (Jonas Schnelli)

* Merge bitcoin#9280: [Qt] Show ModalOverlay by pressing the progress bar, allow hiding

89a3723 [Qt] Show ModalOverlay by pressing the progress bar, disabled show() in sync mode (Jonas Schnelli)

* Merge bitcoin#9461: [Qt] Improve progress display during headers-sync and peer-finding

40ec7c7 [Qt] Improve progress display during headers-sync and peer-finding (Jonas Schnelli)

* Merge bitcoin#9588: qt: Use nPowTargetSpacing constant

fa4d478 qt: Use nPowTargetSpacing constant (MarcoFalke)

* Hide modal overlay forever when syncing has catched up

Don't allow to open it again by clicking on the progress bar and spinner
icon. Currently the overlay does not show meaningful information about
masternode sync and it gives the impression of being stuck after the block
chain sync is done.

* Don't include chainparams.h in sendcoinsdialog.cpp

This was just a remainder of a backported PR which meant to change some
calculation in this file which does not apply to Dash.

* Also check for fNetworkActive in ConnectNode

* Merge bitcoin#9528: [qt] Rename formateNiceTimeOffset(qint64) to formatNiceTimeOffset(qint64)

988d300 [qt] Rename formateNiceTimeOffset(qint64) to formatNiceTimeOffset(qint64) (practicalswift)

* Merge bitcoin#11237: qt: Fixing division by zero in time remaining

c8d38ab Refactor tipUpdate as per style guide (MeshCollider)
3b69a08 Fix division by zero in time remaining (MeshCollider)

Pull request description:

  Fixes bitcoin#10291, bitcoin#11265

  progressDelta may be 0 (or even negative according to 11265), this checks for that and prints unknown if it is, because we cannot calculate an estimate for the time remaining (would be infinite or negative).

Tree-SHA512: bc5708e5ed6e4670d008219558c5fbb25709bd99a32c98ec39bb74f94a0b7fa058f3d03389ccdd39e6723e6b5b48e34b13ceee7c051c2db631e51d8ec3e1d68c
  • Loading branch information
codablock authored and UdjinM6 committed Sep 11, 2017
1 parent 9707ca5 commit 91d99fc
Show file tree
Hide file tree
Showing 46 changed files with 578 additions and 190 deletions.
3 changes: 3 additions & 0 deletions contrib/debian/copyright
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ Comment: Site: https://github.com/stephenhutchings/typicons.font

Files: src/qt/res/icons/connect*.png
src/qt/res/src/connect-*.svg
src/qt/res/icons/*/network_disabled.png
src/qt/res/src/network_disabled.svg
Copyright: Marco Falke
Luke Dashjr
License: Expat
Comment: Inspired by Stephan Hutchings Typicons

Expand Down
6 changes: 5 additions & 1 deletion src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ RES_ICONS = \
qt/res/icons/drkblue/fontbigger.png \
qt/res/icons/drkblue/fontsmaller.png \
qt/res/icons/drkblue/transaction_abandoned.png \
qt/res/icons/drkblue/network_disabled.png \
qt/res/icons/crownium/add.png \
qt/res/icons/crownium/address-book.png \
qt/res/icons/crownium/browse.png \
Expand Down Expand Up @@ -278,6 +279,7 @@ RES_ICONS = \
qt/res/icons/crownium/fontbigger.png \
qt/res/icons/crownium/fontsmaller.png \
qt/res/icons/crownium/transaction_abandoned.png \
qt/res/icons/crownium/network_disabled.png \
qt/res/icons/light/add.png \
qt/res/icons/light/address-book.png \
qt/res/icons/light/browse.png \
Expand Down Expand Up @@ -331,6 +333,7 @@ RES_ICONS = \
qt/res/icons/light/fontbigger.png \
qt/res/icons/light/fontsmaller.png \
qt/res/icons/light/transaction_abandoned.png \
qt/res/icons/light/network_disabled.png \
qt/res/icons/trad/add.png \
qt/res/icons/trad/address-book.png \
qt/res/icons/trad/browse.png \
Expand Down Expand Up @@ -383,7 +386,8 @@ RES_ICONS = \
qt/res/icons/trad/verify.png \
qt/res/icons/trad/fontbigger.png \
qt/res/icons/trad/fontsmaller.png \
qt/res/icons/trad/transaction_abandoned.png
qt/res/icons/trad/transaction_abandoned.png \
qt/res/icons/trad/network_disabled.png

BITCOIN_QT_CPP = \
qt/bantablemodel.cpp \
Expand Down
37 changes: 37 additions & 0 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@ bool CConnman::CheckIncomingNonce(uint64_t nonce)

CNode* CConnman::ConnectNode(CAddress addrConnect, const char *pszDest, bool fConnectToMasternode)
{
// TODO: This is different from what we have in Bitcoin which only calls ConnectNode from OpenNetworkConnection
// If we ever switch to using OpenNetworkConnection for MNs as well, this can be removed
if (!fNetworkActive) {
return NULL;
}

if (pszDest == NULL) {
// we clean masternode connections in CMasternodeMan::ProcessMasternodeConnections()
// so should be safe to skip this and connect to local Hot MN on CActiveMasternode::ManageState()
Expand Down Expand Up @@ -1042,6 +1048,12 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
return;
}

if (!fNetworkActive) {
LogPrintf("connection from %s dropped: not accepting new connections\n", addr.ToString());
CloseSocket(hSocket);
return;
}

if (!IsSelectableSocket(hSocket))
{
LogPrintf("connection from %s dropped: non-selectable socket\n", addr.ToString());
Expand Down Expand Up @@ -1878,6 +1890,9 @@ bool CConnman::OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGran
if (interruptNet) {
return false;
}
if (!fNetworkActive) {
return false;
}
if (!pszDest) {
if (IsLocal(addrConnect) ||
FindNode((CNetAddr)addrConnect) || IsBanned(addrConnect) ||
Expand Down Expand Up @@ -2094,8 +2109,30 @@ void Discover(boost::thread_group& threadGroup)
#endif
}

void CConnman::SetNetworkActive(bool active)
{
if (fDebug) {
LogPrint("net", "SetNetworkActive: %s\n", active);
}

if (!active) {
fNetworkActive = false;

LOCK(cs_vNodes);
// Close sockets to all nodes
BOOST_FOREACH(CNode* pnode, vNodes) {
pnode->CloseSocketDisconnect();
}
} else {
fNetworkActive = true;
}

uiInterface.NotifyNetworkActiveChanged(fNetworkActive);
}

CConnman::CConnman()
{
fNetworkActive = true;
setBannedIsDirty = false;
fAddressesInitialized = false;
nLastNodeId = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ class CConnman
void Stop();
void Interrupt();
bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
bool GetNetworkActive() const { return fNetworkActive; };
void SetNetworkActive(bool active);
bool OpenNetworkConnection(const CAddress& addrConnect, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false, bool fFeeler = false);
bool CheckIncomingNonce(uint64_t nonce);

Expand Down Expand Up @@ -459,6 +461,7 @@ class CConnman
unsigned int nReceiveFloodSize;

std::vector<ListenSocket> vhListenSocket;
bool fNetworkActive;
banmap_t setBanned;
CCriticalSection cs_setBanned;
bool setBannedIsDirty;
Expand Down
2 changes: 1 addition & 1 deletion src/qt/addressbookpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ AddressBookPage::AddressBookPage(const PlatformStyle *platformStyle, Mode mode,
deleteAction = new QAction(ui->deleteAddress->text(), this);

// Build context menu
contextMenu = new QMenu();
contextMenu = new QMenu(this);
contextMenu->addAction(copyAddressAction);
contextMenu->addAction(copyLabelAction);
contextMenu->addAction(editAction);
Expand Down
7 changes: 6 additions & 1 deletion src/qt/bantablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,19 @@ BanTableModel::BanTableModel(ClientModel *parent) :
clientModel(parent)
{
columns << tr("IP/Netmask") << tr("Banned Until");
priv = new BanTablePriv();
priv.reset(new BanTablePriv());
// default to unsorted
priv->sortColumn = -1;

// load initial data
refresh();
}

BanTableModel::~BanTableModel()
{
// Intentionally left empty
}

int BanTableModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent);
Expand Down
3 changes: 2 additions & 1 deletion src/qt/bantablemodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class BanTableModel : public QAbstractTableModel

public:
explicit BanTableModel(ClientModel *parent = 0);
~BanTableModel();
void startAutoRefresh();
void stopAutoRefresh();

Expand All @@ -66,7 +67,7 @@ public Q_SLOTS:
private:
ClientModel *clientModel;
QStringList columns;
BanTablePriv *priv;
std::unique_ptr<BanTablePriv> priv;
};

#endif // BITCOIN_QT_BANTABLEMODEL_H
94 changes: 68 additions & 26 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "macdockiconhandler.h"
#endif

#include "chainparams.h"
#include "init.h"
#include "ui_interface.h"
#include "util.h"
Expand All @@ -45,7 +46,6 @@
#include <QMenuBar>
#include <QMessageBox>
#include <QMimeData>
#include <QProgressBar>
#include <QProgressDialog>
#include <QSettings>
#include <QShortcut>
Expand Down Expand Up @@ -205,14 +205,9 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *platformStyle, const NetworkStyle *n
unitDisplayControl = new UnitDisplayStatusBarControl(platformStyle);
labelEncryptionIcon = new QLabel();
labelWalletHDStatusIcon = new QLabel();
labelConnectionsIcon = new QPushButton();
labelConnectionsIcon->setFlat(true); // Make the button look like a label, but clickable
labelConnectionsIcon->setStyleSheet(".QPushButton { background-color: rgba(255, 255, 255, 0);}");
labelConnectionsIcon->setMaximumSize(STATUSBAR_ICONSIZE, STATUSBAR_ICONSIZE);
// Jump to peers tab by clicking on connections icon
connect(labelConnectionsIcon, SIGNAL(clicked()), this, SLOT(showPeers()));
labelConnectionsIcon = new GUIUtil::ClickableLabel();

labelBlocksIcon = new QLabel();
labelBlocksIcon = new GUIUtil::ClickableLabel();
if(enableWallet)
{
frameBlocksLayout->addStretch();
Expand Down Expand Up @@ -256,10 +251,16 @@ BitcoinGUI::BitcoinGUI(const PlatformStyle *platformStyle, const NetworkStyle *n
// Subscribe to notifications from core
subscribeToCoreSignals();

// Jump to peers tab by clicking on connections icon
connect(labelConnectionsIcon, SIGNAL(clicked(QPoint)), this, SLOT(showPeers()));

modalOverlay = new ModalOverlay(this->centralWidget());
#ifdef ENABLE_WALLET
if(enableWallet)
if(enableWallet) {
connect(walletFrame, SIGNAL(requestedSyncWarningInfo()), this, SLOT(showModalOverlay()));
connect(labelBlocksIcon, SIGNAL(clicked(QPoint)), this, SLOT(showModalOverlay()));
connect(progressBar, SIGNAL(clicked(QPoint)), this, SLOT(showModalOverlay()));
}
#endif
}

Expand Down Expand Up @@ -610,8 +611,9 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel)
}

// Keep up to date with client
setNumConnections(clientModel->getNumConnections());
updateNetworkState();
connect(clientModel, SIGNAL(numConnectionsChanged(int)), this, SLOT(setNumConnections(int)));
connect(clientModel, SIGNAL(networkActiveChanged(bool)), this, SLOT(setNetworkActive(bool)));

setNumBlocks(clientModel->getNumBlocks(), clientModel->getLastBlockDate(), clientModel->getVerificationProgress(NULL), false);
connect(clientModel, SIGNAL(numBlocksChanged(int,QDateTime,double,bool)), this, SLOT(setNumBlocks(int,QDateTime,double,bool)));
Expand Down Expand Up @@ -652,6 +654,13 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel)
// Disable context menu on tray icon
trayIconMenu->clear();
}
// Propagate cleared model to child objects
rpcConsole->setClientModel(nullptr);
#ifdef ENABLE_WALLET
walletFrame->setClientModel(nullptr);
#endif // ENABLE_WALLET
unitDisplayControl->setOptionsModel(nullptr);

#ifdef Q_OS_MAC
if(dockIconMenu)
{
Expand Down Expand Up @@ -897,8 +906,9 @@ void BitcoinGUI::gotoVerifyMessageTab(QString addr)
}
#endif // ENABLE_WALLET

void BitcoinGUI::setNumConnections(int count)
void BitcoinGUI::updateNetworkState()
{
int count = clientModel->getNumConnections();
QString icon;
QString theme = GUIUtil::getThemeName();
switch(count)
Expand All @@ -909,22 +919,44 @@ void BitcoinGUI::setNumConnections(int count)
case 7: case 8: case 9: icon = ":/icons/" + theme + "/connect_3"; break;
default: icon = ":/icons/" + theme + "/connect_4"; break;
}
QIcon connectionItem = QIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE);
labelConnectionsIcon->setIcon(connectionItem);
labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Dash network", "", count));

if (clientModel->getNetworkActive()) {
labelConnectionsIcon->setToolTip(tr("%n active connection(s) to Dash network", "", count));
} else {
labelConnectionsIcon->setToolTip(tr("Network activity disabled"));
icon = ":/icons/" + theme + "/network_disabled";
}

labelConnectionsIcon->setPixmap(platformStyle->SingleColorIcon(icon).pixmap(STATUSBAR_ICONSIZE,STATUSBAR_ICONSIZE));
}

void BitcoinGUI::setNumConnections(int count)
{
updateNetworkState();
}

void BitcoinGUI::setNetworkActive(bool networkActive)
{
updateNetworkState();
}

void BitcoinGUI::updateHeadersSyncProgressLabel()
{
int64_t headersTipTime = clientModel->getHeaderTipTime();
int headersTipHeight = clientModel->getHeaderTipHeight();
int estHeadersLeft = (GetTime() - headersTipTime) / Params().GetConsensus().nPowTargetSpacing;
if (estHeadersLeft > HEADER_HEIGHT_DELTA_SYNC)
progressBarLabel->setText(tr("Syncing Headers (%1%)...").arg(QString::number(100.0 / (headersTipHeight+estHeadersLeft)*headersTipHeight, 'f', 1)));
}

void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVerificationProgress, bool header)
{
if (modalOverlay)
{
if (header) {
/* use clientmodels getHeaderTipHeight and getHeaderTipTime because the NotifyHeaderTip signal does not fire when updating the best header */
modalOverlay->setKnownBestHeight(clientModel->getHeaderTipHeight(), QDateTime::fromTime_t(clientModel->getHeaderTipTime()));
}
else {
if (header)
modalOverlay->setKnownBestHeight(count, blockDate);
else
modalOverlay->tipUpdate(count, blockDate, nVerificationProgress);
}
}
if (!clientModel)
return;
Expand All @@ -937,9 +969,11 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
switch (blockSource) {
case BLOCK_SOURCE_NETWORK:
if (header) {
updateHeadersSyncProgressLabel();
return;
}
progressBarLabel->setText(tr("Synchronizing with network..."));
updateHeadersSyncProgressLabel();
break;
case BLOCK_SOURCE_DISK:
if (header) {
Expand All @@ -955,8 +989,7 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
if (header) {
return;
}
// Case: not Importing, not Reindexing and no network connection
progressBarLabel->setText(tr("No block source available..."));
progressBarLabel->setText(tr("Connecting to peers..."));
break;
}

Expand All @@ -976,6 +1009,8 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer
if(secs < 25*60) // 90*60 in bitcoin
{
modalOverlay->showHide(true, true);
// TODO instead of hiding it forever, we should add meaningful information about MN sync to the overlay
modalOverlay->hideForever();
}
else
{
Expand All @@ -986,7 +1021,7 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, double nVer

if(!masternodeSync.IsBlockchainSynced())
{
QString timeBehindText = GUIUtil::formateNiceTimeOffset(secs);
QString timeBehindText = GUIUtil::formatNiceTimeOffset(secs);

progressBarLabel->setVisible(true);
progressBar->setFormat(tr("%1 behind").arg(timeBehindText));
Expand Down Expand Up @@ -1375,8 +1410,8 @@ void BitcoinGUI::setTrayIconVisible(bool fHideTrayIcon)

void BitcoinGUI::showModalOverlay()
{
if (modalOverlay)
modalOverlay->showHide(false, true);
if (modalOverlay && (progressBar->isVisible() || modalOverlay->isLayerVisible()))
modalOverlay->toggleVisibility();
}

static bool ThreadSafeMessageBox(BitcoinGUI *gui, const std::string& message, const std::string& caption, unsigned int style)
Expand Down Expand Up @@ -1410,6 +1445,13 @@ void BitcoinGUI::unsubscribeFromCoreSignals()
uiInterface.ThreadSafeQuestion.disconnect(boost::bind(ThreadSafeMessageBox, this, _1, _3, _4));
}

void BitcoinGUI::toggleNetworkActive()
{
if (clientModel) {
clientModel->setNetworkActive(!clientModel->getNetworkActive());
}
}

/** Get restart command-line parameters and request restart */
void BitcoinGUI::handleRestart(QStringList args)
{
Expand Down Expand Up @@ -1444,7 +1486,7 @@ void UnitDisplayStatusBarControl::mousePressEvent(QMouseEvent *event)
/** Creates context menu, its actions, and wires up all the relevant signals for mouse events. */
void UnitDisplayStatusBarControl::createContextMenu()
{
menu = new QMenu();
menu = new QMenu(this);
Q_FOREACH(BitcoinUnits::Unit u, BitcoinUnits::availableUnits())
{
QAction *menuAction = new QAction(QString(BitcoinUnits::name(u)), this);
Expand Down
Loading

0 comments on commit 91d99fc

Please sign in to comment.