From 1e165bf1c9bc439546e2fcdf3671864429d521f5 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Tue, 10 Jan 2017 18:24:56 +0100 Subject: [PATCH 1/8] Add fAutoRequestBlocks to disabled/enable the verification progress --- src/net_processing.cpp | 6 ++++++ src/net_processing.h | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 4d832f37113..5d3c5d21132 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -60,6 +60,8 @@ static std::vector> vExtraTxnForCompact GUAR static const uint64_t RANDOMIZER_ID_ADDRESS_RELAY = 0x3cac0035b5866b90ULL; // SHA256("main address relay")[0:8] +std::atomic fAutoRequestBlocks(DEFAULT_AUTOMATIC_BLOCK_REQUESTS); + // Internal stuff namespace { /** Number of nodes with fSyncStarted. */ @@ -465,6 +467,10 @@ void FindNextBlocksToDownload(NodeId nodeid, unsigned int count, std::vectorpindexBestKnownBlock == NULL || state->pindexBestKnownBlock->nChainWork < chainActive.Tip()->nChainWork || state->pindexBestKnownBlock->nChainWork < UintToArith256(consensusParams.nMinimumChainWork)) { // This peer has nothing interesting. return; diff --git a/src/net_processing.h b/src/net_processing.h index db6d81e6b67..1f5874dde37 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -27,6 +27,10 @@ void RegisterNodeSignals(CNodeSignals& nodeSignals); /** Unregister a network node */ void UnregisterNodeSignals(CNodeSignals& nodeSignals); +/** if disabled, blocks will not be requested automatically, useful for low-resources-available mode */ +static const bool DEFAULT_AUTOMATIC_BLOCK_REQUESTS = true; +extern std::atomic fAutoRequestBlocks; + class PeerLogicValidation : public CValidationInterface { private: CConnman* connman; From b30c8a1ce12a481d447bf29e37b139f8c275ddeb Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Tue, 10 Jan 2017 18:24:15 +0100 Subject: [PATCH 2/8] [Qt] update header-syncing progress when not processing a block --- src/qt/modaloverlay.cpp | 16 +++++++++++----- src/qt/modaloverlay.h | 1 + 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/qt/modaloverlay.cpp b/src/qt/modaloverlay.cpp index a83f285034f..6351eae4b11 100644 --- a/src/qt/modaloverlay.cpp +++ b/src/qt/modaloverlay.cpp @@ -71,6 +71,7 @@ void ModalOverlay::setKnownBestHeight(int count, const QDateTime& blockDate) if (count > bestHeaderHeight) { bestHeaderHeight = count; bestHeaderDate = blockDate; + eventuallyShowHeaderSyncing(count); } } @@ -125,15 +126,20 @@ void ModalOverlay::tipUpdate(int count, const QDateTime& blockDate, double nVeri // not syncing return; + // show remaining number of blocks + ui->numberOfBlocksLeft->setText(QString::number(bestHeaderHeight - count)); + eventuallyShowHeaderSyncing(count); +} + +void ModalOverlay::eventuallyShowHeaderSyncing(int count) +{ // estimate the number of headers left based on nPowTargetSpacing // and check if the gui is not aware of the best header (happens rarely) - int estimateNumHeadersLeft = bestHeaderDate.secsTo(currentDate) / Params().GetConsensus().nPowTargetSpacing; + int estimateNumHeadersLeft = bestHeaderDate.secsTo(QDateTime::currentDateTime()) / Params().GetConsensus().nPowTargetSpacing; bool hasBestHeader = bestHeaderHeight >= count; - // show remaining number of blocks - if (estimateNumHeadersLeft < HEADER_HEIGHT_DELTA_SYNC && hasBestHeader) { - ui->numberOfBlocksLeft->setText(QString::number(bestHeaderHeight - count)); - } else { + // show headers-syncing progress if we still sync headers + if (estimateNumHeadersLeft >= HEADER_HEIGHT_DELTA_SYNC || !hasBestHeader) { ui->numberOfBlocksLeft->setText(tr("Unknown. Syncing Headers (%1)...").arg(bestHeaderHeight)); ui->expectedTimeLeft->setText(tr("Unknown...")); } diff --git a/src/qt/modaloverlay.h b/src/qt/modaloverlay.h index 21ccdbd8397..cdff18c62ba 100644 --- a/src/qt/modaloverlay.h +++ b/src/qt/modaloverlay.h @@ -45,6 +45,7 @@ public Q_SLOTS: QVector > blockProcessTime; bool layerIsVisible; bool userClosed; + void eventuallyShowHeaderSyncing(int count); }; #endif // BITCOIN_QT_MODALOVERLAY_H From 5702c49a544d91ac446473d564b65392114b7922 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Tue, 10 Jan 2017 18:31:08 +0100 Subject: [PATCH 3/8] [Qt] Add option to pause/resume block downloads --- src/qt/bitcoingui.cpp | 5 +++++ src/qt/clientmodel.cpp | 17 +++++++++++++++++ src/qt/clientmodel.h | 7 +++++++ src/qt/forms/modaloverlay.ui | 7 +++++++ src/qt/modaloverlay.cpp | 11 +++++++++++ src/qt/modaloverlay.h | 7 +++++++ 6 files changed, 54 insertions(+) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index 429c18cba85..f0940824002 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -479,6 +479,10 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel) connect(_clientModel, SIGNAL(networkActiveChanged(bool)), this, SLOT(setNetworkActive(bool))); modalOverlay->setKnownBestHeight(_clientModel->getHeaderTipHeight(), QDateTime::fromTime_t(_clientModel->getHeaderTipTime())); + modalOverlay->setPauseResumeState(!clientModel->isAutorequestBlocks()); + connect(modalOverlay, SIGNAL(requestVerificationPauseOrResume()), _clientModel, SLOT(toggleAutorequestBlocks())); + connect(_clientModel, SIGNAL(verificationProgressPauseStateHasChanged(bool)), modalOverlay, SLOT(setPauseResumeState(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))); @@ -506,6 +510,7 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel) // initialize the disable state of the tray icon with the current value in the model. setTrayIconVisible(optionsModel->getHideTrayIcon()); } + } else { // Disable possibility to show main window via action toggleHideAction->setEnabled(false); diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index 33f4535ee22..892b396db36 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -15,6 +15,7 @@ #include "clientversion.h" #include "validation.h" #include "net.h" +#include "net_processing.h" #include "txmempool.h" #include "ui_interface.h" #include "util.h" @@ -245,6 +246,22 @@ QString ClientModel::dataDir() const return GUIUtil::boostPathToQString(GetDataDir()); } +bool ClientModel::isAutorequestBlocks() const +{ + return fAutoRequestBlocks; +} + +void ClientModel::setAutorequestBlocks(bool state) +{ + fAutoRequestBlocks = state; + Q_EMIT verificationProgressPauseStateHasChanged(!fAutoRequestBlocks); +} + +void ClientModel::toggleAutorequestBlocks() +{ + setAutorequestBlocks(!fAutoRequestBlocks); +} + void ClientModel::updateBanlist() { banTableModel->refresh(); diff --git a/src/qt/clientmodel.h b/src/qt/clientmodel.h index 6447cae1bb4..1f002b4795f 100644 --- a/src/qt/clientmodel.h +++ b/src/qt/clientmodel.h @@ -84,6 +84,10 @@ class ClientModel : public QObject mutable std::atomic cachedBestHeaderHeight; mutable std::atomic cachedBestHeaderTime; + // get/set state about autorequesting-blocks during IBD + bool isAutorequestBlocks() const; + void setAutorequestBlocks(bool state); + private: OptionsModel *optionsModel; PeerTableModel *peerTableModel; @@ -108,12 +112,15 @@ class ClientModel : public QObject // Show progress dialog e.g. for verifychain void showProgress(const QString &title, int nProgress); + void verificationProgressPauseStateHasChanged(bool pauseActive); + public Q_SLOTS: void updateTimer(); void updateNumConnections(int numConnections); void updateNetworkActive(bool networkActive); void updateAlert(); void updateBanlist(); + void toggleAutorequestBlocks(); }; #endif // BITCOIN_QT_CLIENTMODEL_H diff --git a/src/qt/forms/modaloverlay.ui b/src/qt/forms/modaloverlay.ui index 65a7a6c77ee..fce0db128a6 100644 --- a/src/qt/forms/modaloverlay.ui +++ b/src/qt/forms/modaloverlay.ui @@ -334,6 +334,13 @@ QLabel { color: rgb(40,40,40); } 10 + + + Pause downloading blocks + + + + Qt::Horizontal diff --git a/src/qt/modaloverlay.cpp b/src/qt/modaloverlay.cpp index 6351eae4b11..e0b9931fe9c 100644 --- a/src/qt/modaloverlay.cpp +++ b/src/qt/modaloverlay.cpp @@ -22,6 +22,7 @@ userClosed(false) { ui->setupUi(this); connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(closeClicked())); + connect(ui->pauseResumeVerification, SIGNAL(clicked()), this, SLOT(pauseClicked())); if (parent) { parent->installEventFilter(this); raise(); @@ -176,3 +177,13 @@ void ModalOverlay::closeClicked() showHide(true); userClosed = true; } + +void ModalOverlay::pauseClicked() +{ + Q_EMIT requestVerificationPauseOrResume(); +} + +void ModalOverlay::setPauseResumeState(bool pauseActive) +{ + ui->pauseResumeVerification->setText((pauseActive ? "Resume downloading blocks": "Pause downloading blocks")); +} diff --git a/src/qt/modaloverlay.h b/src/qt/modaloverlay.h index cdff18c62ba..cad59dbd5af 100644 --- a/src/qt/modaloverlay.h +++ b/src/qt/modaloverlay.h @@ -32,8 +32,14 @@ public Q_SLOTS: // will show or hide the modal layer void showHide(bool hide = false, bool userRequested = false); void closeClicked(); + void pauseClicked(); + void setPauseResumeState(bool pauseActive); bool isLayerVisible() { return layerIsVisible; } +Q_SIGNALS: + // Fired when the user requested a block download pause or resume + void requestVerificationPauseOrResume(); + protected: bool eventFilter(QObject * obj, QEvent * ev); bool event(QEvent* ev); @@ -45,6 +51,7 @@ public Q_SLOTS: QVector > blockProcessTime; bool layerIsVisible; bool userClosed; + bool verificationPauseActive; void eventuallyShowHeaderSyncing(int count); }; From 0ac2217b332eac76c4ed34cc85b894e3cfebd0bf Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Wed, 19 Apr 2017 16:36:52 +0200 Subject: [PATCH 4/8] Rename autorequest blocks methods --- src/qt/bitcoingui.cpp | 4 ++-- src/qt/clientmodel.cpp | 6 +++--- src/qt/clientmodel.h | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp index f0940824002..75b83026576 100644 --- a/src/qt/bitcoingui.cpp +++ b/src/qt/bitcoingui.cpp @@ -479,8 +479,8 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel) connect(_clientModel, SIGNAL(networkActiveChanged(bool)), this, SLOT(setNetworkActive(bool))); modalOverlay->setKnownBestHeight(_clientModel->getHeaderTipHeight(), QDateTime::fromTime_t(_clientModel->getHeaderTipTime())); - modalOverlay->setPauseResumeState(!clientModel->isAutorequestBlocks()); - connect(modalOverlay, SIGNAL(requestVerificationPauseOrResume()), _clientModel, SLOT(toggleAutorequestBlocks())); + modalOverlay->setPauseResumeState(!_clientModel->isAutoRequestingBlocks()); + connect(modalOverlay, SIGNAL(requestVerificationPauseOrResume()), _clientModel, SLOT(toggleAutoRequestBlocks())); connect(_clientModel, SIGNAL(verificationProgressPauseStateHasChanged(bool)), modalOverlay, SLOT(setPauseResumeState(bool))); setNumBlocks(_clientModel->getNumBlocks(), _clientModel->getLastBlockDate(), _clientModel->getVerificationProgress(NULL), false); diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index 892b396db36..69d727fbc96 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -246,18 +246,18 @@ QString ClientModel::dataDir() const return GUIUtil::boostPathToQString(GetDataDir()); } -bool ClientModel::isAutorequestBlocks() const +bool ClientModel::isAutoRequestingBlocks() const { return fAutoRequestBlocks; } -void ClientModel::setAutorequestBlocks(bool state) +void ClientModel::setAutoRequestBlocks(bool state) { fAutoRequestBlocks = state; Q_EMIT verificationProgressPauseStateHasChanged(!fAutoRequestBlocks); } -void ClientModel::toggleAutorequestBlocks() +void ClientModel::toggleAutoRequestBlocks() { setAutorequestBlocks(!fAutoRequestBlocks); } diff --git a/src/qt/clientmodel.h b/src/qt/clientmodel.h index 1f002b4795f..b4ae7fcf753 100644 --- a/src/qt/clientmodel.h +++ b/src/qt/clientmodel.h @@ -85,8 +85,8 @@ class ClientModel : public QObject mutable std::atomic cachedBestHeaderTime; // get/set state about autorequesting-blocks during IBD - bool isAutorequestBlocks() const; - void setAutorequestBlocks(bool state); + bool isAutoRequestingBlocks() const; + void setAutoRequestBlocks(bool state); private: OptionsModel *optionsModel; @@ -120,7 +120,7 @@ public Q_SLOTS: void updateNetworkActive(bool networkActive); void updateAlert(); void updateBanlist(); - void toggleAutorequestBlocks(); + void toggleAutoRequestBlocks(); }; #endif // BITCOIN_QT_CLIENTMODEL_H From f7e8ef4f652b5f0f65536a4874aea4fb6cb6b4b7 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Wed, 19 Apr 2017 16:37:35 +0200 Subject: [PATCH 5/8] Add setter/getter for fAutoRequestBlocks --- src/net_processing.cpp | 10 +++++++++- src/net_processing.h | 4 +++- src/qt/clientmodel.cpp | 8 ++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 5d3c5d21132..32d895d8988 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -60,7 +60,7 @@ static std::vector> vExtraTxnForCompact GUAR static const uint64_t RANDOMIZER_ID_ADDRESS_RELAY = 0x3cac0035b5866b90ULL; // SHA256("main address relay")[0:8] -std::atomic fAutoRequestBlocks(DEFAULT_AUTOMATIC_BLOCK_REQUESTS); +static std::atomic fAutoRequestBlocks(DEFAULT_AUTOMATIC_BLOCK_REQUESTS); // Internal stuff namespace { @@ -3307,6 +3307,14 @@ bool SendMessages(CNode* pto, CConnman& connman, const std::atomic& interr return true; } +void SetAutoRequestBlocks(bool state) { + fAutoRequestBlocks = state; +} + +bool isAutoRequestingBlocks() { + return fAutoRequestBlocks; +} + class CNetProcessingCleanup { public: diff --git a/src/net_processing.h b/src/net_processing.h index 1f5874dde37..87037d36617 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -29,7 +29,6 @@ void UnregisterNodeSignals(CNodeSignals& nodeSignals); /** if disabled, blocks will not be requested automatically, useful for low-resources-available mode */ static const bool DEFAULT_AUTOMATIC_BLOCK_REQUESTS = true; -extern std::atomic fAutoRequestBlocks; class PeerLogicValidation : public CValidationInterface { private: @@ -68,4 +67,7 @@ bool ProcessMessages(CNode* pfrom, CConnman& connman, const std::atomic& i */ bool SendMessages(CNode* pto, CConnman& connman, const std::atomic& interrupt); +void SetAutoRequestBlocks(bool); +bool isAutoRequestingBlocks(); + #endif // BITCOIN_NET_PROCESSING_H diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index 69d727fbc96..b7e93e4202c 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -248,18 +248,18 @@ QString ClientModel::dataDir() const bool ClientModel::isAutoRequestingBlocks() const { - return fAutoRequestBlocks; + return ::isAutoRequestingBlocks(); } void ClientModel::setAutoRequestBlocks(bool state) { - fAutoRequestBlocks = state; - Q_EMIT verificationProgressPauseStateHasChanged(!fAutoRequestBlocks); + ::SetAutoRequestBlocks(state); + Q_EMIT verificationProgressPauseStateHasChanged(!::isAutoRequestingBlocks()); } void ClientModel::toggleAutoRequestBlocks() { - setAutorequestBlocks(!fAutoRequestBlocks); + setAutoRequestBlocks(!::isAutoRequestingBlocks()); } void ClientModel::updateBanlist() From b07263694ddf82775ce0090d21d9288f0f00760f Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Wed, 19 Apr 2017 17:59:18 +0200 Subject: [PATCH 6/8] Show block in flight --- src/net_processing.cpp | 8 ++++++++ src/net_processing.h | 3 +++ src/qt/forms/modaloverlay.ui | 34 +++++++++++++++++++++++++++------- src/qt/modaloverlay.cpp | 4 ++++ 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 32d895d8988..3344a77f156 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -107,6 +107,7 @@ namespace { std::unique_ptr partialBlock; //!< Optional, used for CMPCTBLOCK downloads }; std::map::iterator> > mapBlocksInFlight; + std::atomic nBlocksInFlight; //!< lock free counter on how many block are in flight /** Stack of nodes which we have set to announce using compact blocks */ std::list lNodesAnnouncingHeaderAndIDs; @@ -293,6 +294,7 @@ void FinalizeNode(NodeId nodeid, bool& fUpdateConnectionTime) { for (const QueuedBlock& entry : state->vBlocksInFlight) { mapBlocksInFlight.erase(entry.hash); } + nBlocksInFlight = mapBlocksInFlight.size(); EraseOrphansFor(nodeid); nPreferredDownload -= state->fPreferredDownload; nPeersWithValidatedDownloads -= (state->nBlocksInFlightValidHeaders != 0); @@ -329,6 +331,7 @@ bool MarkBlockAsReceived(const uint256& hash) { state->nBlocksInFlight--; state->nStallingSince = 0; mapBlocksInFlight.erase(itInFlight); + nBlocksInFlight = mapBlocksInFlight.size(); return true; } return false; @@ -365,6 +368,7 @@ bool MarkBlockAsInFlight(NodeId nodeid, const uint256& hash, const CBlockIndex* nPeersWithValidatedDownloads++; } itInFlight = mapBlocksInFlight.insert(std::make_pair(hash, std::make_pair(nodeid, it))).first; + nBlocksInFlight = mapBlocksInFlight.size(); if (pit) *pit = &itInFlight->second.second; return true; @@ -3315,6 +3319,10 @@ bool isAutoRequestingBlocks() { return fAutoRequestBlocks; } +unsigned int getAmountOfBlocksInFlight() { + return nBlocksInFlight; +} + class CNetProcessingCleanup { public: diff --git a/src/net_processing.h b/src/net_processing.h index 87037d36617..c55c2c74934 100644 --- a/src/net_processing.h +++ b/src/net_processing.h @@ -70,4 +70,7 @@ bool SendMessages(CNode* pto, CConnman& connman, const std::atomic& interr void SetAutoRequestBlocks(bool); bool isAutoRequestingBlocks(); +/** retruns the amount of blocks in flight (in total) */ +unsigned int getAmountOfBlocksInFlight(); + #endif // BITCOIN_NET_PROCESSING_H diff --git a/src/qt/forms/modaloverlay.ui b/src/qt/forms/modaloverlay.ui index fce0db128a6..aab1868df3e 100644 --- a/src/qt/forms/modaloverlay.ui +++ b/src/qt/forms/modaloverlay.ui @@ -224,6 +224,26 @@ QLabel { color: rgb(40,40,40); } + + + + 75 + true + + + + Blocks requested from peers + + + + + + + Unknown... + + + + @@ -236,7 +256,7 @@ QLabel { color: rgb(40,40,40); } - + @@ -249,7 +269,7 @@ QLabel { color: rgb(40,40,40); } - + @@ -262,7 +282,7 @@ QLabel { color: rgb(40,40,40); } - + @@ -283,7 +303,7 @@ QLabel { color: rgb(40,40,40); } - + @@ -296,14 +316,14 @@ QLabel { color: rgb(40,40,40); } - + calculating... - + @@ -316,7 +336,7 @@ QLabel { color: rgb(40,40,40); } - + calculating... diff --git a/src/qt/modaloverlay.cpp b/src/qt/modaloverlay.cpp index e0b9931fe9c..1c9fb3065b6 100644 --- a/src/qt/modaloverlay.cpp +++ b/src/qt/modaloverlay.cpp @@ -8,6 +8,7 @@ #include "guiutil.h" #include "chainparams.h" +#include "net_processing.h" #include #include @@ -129,6 +130,9 @@ void ModalOverlay::tipUpdate(int count, const QDateTime& blockDate, double nVeri // show remaining number of blocks ui->numberOfBlocksLeft->setText(QString::number(bestHeaderHeight - count)); + + // show already requested blocks (in total) + ui->numberBlocksRequested->setText(QString::number(getAmountOfBlocksInFlight())); eventuallyShowHeaderSyncing(count); } From 17e1dab4b0ab8b68356fa510a3aff82c03432a7c Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Thu, 20 Apr 2017 10:28:55 +0200 Subject: [PATCH 7/8] Show special info when autodownload is disabled but blocks are in flight --- src/qt/forms/modaloverlay.ui | 20 ++++++++++++++++++++ src/qt/modaloverlay.cpp | 14 ++++++++++++-- src/qt/modaloverlay.h | 1 + 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/qt/forms/modaloverlay.ui b/src/qt/forms/modaloverlay.ui index aab1868df3e..21665a7b943 100644 --- a/src/qt/forms/modaloverlay.ui +++ b/src/qt/forms/modaloverlay.ui @@ -361,6 +361,26 @@ QLabel { color: rgb(40,40,40); } + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Qt::Horizontal diff --git a/src/qt/modaloverlay.cpp b/src/qt/modaloverlay.cpp index 1c9fb3065b6..85a336eb159 100644 --- a/src/qt/modaloverlay.cpp +++ b/src/qt/modaloverlay.cpp @@ -19,7 +19,8 @@ ui(new Ui::ModalOverlay), bestHeaderHeight(0), bestHeaderDate(QDateTime()), layerIsVisible(false), -userClosed(false) +userClosed(false), +verificationPauseActive(false) { ui->setupUi(this); connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(closeClicked())); @@ -134,6 +135,7 @@ void ModalOverlay::tipUpdate(int count, const QDateTime& blockDate, double nVeri // show already requested blocks (in total) ui->numberBlocksRequested->setText(QString::number(getAmountOfBlocksInFlight())); eventuallyShowHeaderSyncing(count); + updatePauseState(verificationPauseActive); } void ModalOverlay::eventuallyShowHeaderSyncing(int count) @@ -189,5 +191,13 @@ void ModalOverlay::pauseClicked() void ModalOverlay::setPauseResumeState(bool pauseActive) { - ui->pauseResumeVerification->setText((pauseActive ? "Resume downloading blocks": "Pause downloading blocks")); + verificationPauseActive = pauseActive; + updatePauseState(pauseActive); +} + +void ModalOverlay::updatePauseState(bool pauseActive) +{ + ui->labelNumberBlocksRequested->setText((pauseActive ? "Finish downloading blocks": "Blocks requested from peers")); + ui->pauseResumeVerification->setText((pauseActive ? "Resume downloading blocks ": "Pause downloading blocks")); + ui->infoLabel->setText((pauseActive && getAmountOfBlocksInFlight() > 0 ? "Wait to finish current downloads...": "")); } diff --git a/src/qt/modaloverlay.h b/src/qt/modaloverlay.h index cad59dbd5af..1b773ebbbea 100644 --- a/src/qt/modaloverlay.h +++ b/src/qt/modaloverlay.h @@ -53,6 +53,7 @@ public Q_SLOTS: bool userClosed; bool verificationPauseActive; void eventuallyShowHeaderSyncing(int count); + void updatePauseState(bool pauseActive); }; #endif // BITCOIN_QT_MODALOVERLAY_H From f1b057f69e4414a1e2a2c524a3378b7f094e5b79 Mon Sep 17 00:00:00 2001 From: Jonas Schnelli Date: Thu, 29 Jun 2017 17:14:42 +0200 Subject: [PATCH 8/8] Disable "pause downloading blocks" when we can fetch blocks directly --- src/qt/modaloverlay.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/qt/modaloverlay.cpp b/src/qt/modaloverlay.cpp index 85a336eb159..d767681d0d5 100644 --- a/src/qt/modaloverlay.cpp +++ b/src/qt/modaloverlay.cpp @@ -136,6 +136,12 @@ void ModalOverlay::tipUpdate(int count, const QDateTime& blockDate, double nVeri ui->numberBlocksRequested->setText(QString::number(getAmountOfBlocksInFlight())); eventuallyShowHeaderSyncing(count); updatePauseState(verificationPauseActive); + + // disable pause button when we we can fetch directly + // avoid using the core-layer's existing CanFetchDirectly() + bool canFetchDirecly = (blockDate.toTime_t() > GetAdjustedTime() - Params().GetConsensus().nPowTargetSpacing * 20); + ui->pauseResumeVerification->setEnabled(!canFetchDirecly); + ui->infoLabel->setVisible(!canFetchDirecly); } void ModalOverlay::eventuallyShowHeaderSyncing(int count)