Page MenuHomePhabricator

D8335.diff
No OneTemporary

D8335.diff

diff --git a/src/init.cpp b/src/init.cpp
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -81,6 +81,7 @@
#endif
#include <cstdint>
#include <cstdio>
+#include <functional>
#include <set>
static const bool DEFAULT_PROXYRANDOMIZE = true;
@@ -340,13 +341,13 @@
static boost::signals2::connection rpc_notify_block_change_connection;
static void OnRPCStarted() {
- rpc_notify_block_change_connection =
- uiInterface.NotifyBlockTip_connect(&RPCNotifyBlockChange);
+ rpc_notify_block_change_connection = uiInterface.NotifyBlockTip_connect(
+ std::bind(RPCNotifyBlockChange, std::placeholders::_2));
}
static void OnRPCStopped() {
rpc_notify_block_change_connection.disconnect();
- RPCNotifyBlockChange(false, nullptr);
+ RPCNotifyBlockChange(nullptr);
g_best_block_cv.notify_all();
LogPrint(BCLog::RPC, "RPC stopped.\n");
}
@@ -1211,9 +1212,9 @@
}
#if defined(HAVE_SYSTEM)
-static void BlockNotifyCallback(bool initialSync,
+static void BlockNotifyCallback(SynchronizationState sync_state,
const CBlockIndex *pBlockIndex) {
- if (initialSync || !pBlockIndex) {
+ if (sync_state != SynchronizationState::POST_INIT || !pBlockIndex) {
return;
}
@@ -1231,7 +1232,7 @@
static Mutex g_genesis_wait_mutex;
static std::condition_variable g_genesis_wait_cv;
-static void BlockNotifyGenesisWait(bool, const CBlockIndex *pBlockIndex) {
+static void BlockNotifyGenesisWait(const CBlockIndex *pBlockIndex) {
if (pBlockIndex != nullptr) {
{
LOCK(g_genesis_wait_mutex);
@@ -2537,7 +2538,7 @@
}
CBlockIndex *tip = ::ChainActive().Tip();
- RPCNotifyBlockChange(true, tip);
+ RPCNotifyBlockChange(tip);
if (tip && tip->nTime >
GetAdjustedTime() + MAX_FUTURE_BLOCK_TIME) {
strLoadError =
@@ -2664,7 +2665,8 @@
boost::signals2::connection block_notify_genesis_wait_connection;
if (::ChainActive().Tip() == nullptr) {
block_notify_genesis_wait_connection =
- uiInterface.NotifyBlockTip_connect(BlockNotifyGenesisWait);
+ uiInterface.NotifyBlockTip_connect(
+ std::bind(BlockNotifyGenesisWait, std::placeholders::_2));
} else {
fHaveGenesis = true;
}
diff --git a/src/interfaces/node.h b/src/interfaces/node.h
--- a/src/interfaces/node.h
+++ b/src/interfaces/node.h
@@ -32,6 +32,7 @@
class proxyType;
class RPCServer;
class RPCTimerInterface;
+enum class SynchronizationState;
class UniValue;
enum class WalletCreationStatus;
struct bilingual_str;
@@ -277,15 +278,15 @@
//! Register handler for block tip messages.
using NotifyBlockTipFn =
- std::function<void(bool initial_download, int height,
- int64_t block_time, double verification_progress)>;
+ std::function<void(SynchronizationState, int height, int64_t block_time,
+ double verification_progress)>;
virtual std::unique_ptr<Handler>
handleNotifyBlockTip(NotifyBlockTipFn fn) = 0;
//! Register handler for header tip messages.
using NotifyHeaderTipFn =
- std::function<void(bool initial_download, int height,
- int64_t block_time, double verification_progress)>;
+ std::function<void(SynchronizationState, int height, int64_t block_time,
+ double verification_progress)>;
virtual std::unique_ptr<Handler>
handleNotifyHeaderTip(NotifyHeaderTipFn fn) = 0;
diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp
--- a/src/interfaces/node.cpp
+++ b/src/interfaces/node.cpp
@@ -353,8 +353,9 @@
std::unique_ptr<Handler>
handleNotifyBlockTip(NotifyBlockTipFn fn) override {
return MakeHandler(::uiInterface.NotifyBlockTip_connect(
- [fn](bool initial_download, const CBlockIndex *block) {
- fn(initial_download, block->nHeight, block->GetBlockTime(),
+ [fn](SynchronizationState sync_state,
+ const CBlockIndex *block) {
+ fn(sync_state, block->nHeight, block->GetBlockTime(),
GuessVerificationProgress(Params().TxData(), block));
}));
}
@@ -362,9 +363,9 @@
handleNotifyHeaderTip(NotifyHeaderTipFn fn) override {
/* verification progress is unused when a header was received */
return MakeHandler(::uiInterface.NotifyHeaderTip_connect(
- [fn](bool initial_download, const CBlockIndex *block) {
- fn(initial_download, block->nHeight, block->GetBlockTime(),
- 0);
+ [fn](SynchronizationState sync_state,
+ const CBlockIndex *block) {
+ fn(sync_state, block->nHeight, block->GetBlockTime(), 0);
}));
}
NodeContext *context() override { return m_context; }
diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp
--- a/src/qt/bitcoin.cpp
+++ b/src/qt/bitcoin.cpp
@@ -28,6 +28,7 @@
#include <util/system.h>
#include <util/threadnames.h>
#include <util/translation.h>
+#include <validation.h>
#ifdef ENABLE_WALLET
#include <qt/paymentserver.h>
@@ -59,6 +60,7 @@
// Declare meta types used for QMetaObject::invokeMethod
Q_DECLARE_METATYPE(bool *)
Q_DECLARE_METATYPE(Amount)
+Q_DECLARE_METATYPE(SynchronizationState)
Q_DECLARE_METATYPE(uint256)
// Config is non-copyable so we can only register pointers to it
@@ -544,6 +546,7 @@
// Register meta types used for QMetaObject::invokeMethod and
// Qt::QueuedConnection
qRegisterMetaType<bool *>();
+ qRegisterMetaType<SynchronizationState>();
#ifdef ENABLE_WALLET
qRegisterMetaType<WalletModel *>();
#endif
diff --git a/src/qt/bitcoingui.h b/src/qt/bitcoingui.h
--- a/src/qt/bitcoingui.h
+++ b/src/qt/bitcoingui.h
@@ -27,20 +27,20 @@
#include <memory>
class ClientModel;
+class Config;
+class HelpMessageDialog;
+class ModalOverlay;
class NetworkStyle;
class Notificator;
class OptionsModel;
class PlatformStyle;
class RPCConsole;
class SendCoinsRecipient;
+enum class SynchronizationState;
class UnitDisplayStatusBarControl;
class WalletController;
class WalletFrame;
class WalletModel;
-class HelpMessageDialog;
-class ModalOverlay;
-
-class Config;
namespace interfaces {
class Handler;
@@ -224,7 +224,8 @@
void setNetworkActive(bool networkActive);
/** Set number of blocks and last block date shown in the UI */
void setNumBlocks(int count, const QDateTime &blockDate,
- double nVerificationProgress, bool headers);
+ double nVerificationProgress, bool headers,
+ SynchronizationState sync_state);
/**
* Notify the user of an event from the core network or transaction
diff --git a/src/qt/bitcoingui.cpp b/src/qt/bitcoingui.cpp
--- a/src/qt/bitcoingui.cpp
+++ b/src/qt/bitcoingui.cpp
@@ -34,6 +34,7 @@
#include <ui_interface.h>
#include <util/system.h>
#include <util/translation.h>
+#include <validation.h>
#include <QAction>
#include <QApplication>
@@ -672,7 +673,8 @@
QDateTime::fromTime_t(_clientModel->getHeaderTipTime()));
setNumBlocks(m_node.getNumBlocks(),
QDateTime::fromTime_t(m_node.getLastBlockTime()),
- m_node.getVerificationProgress(), false);
+ m_node.getVerificationProgress(), false,
+ SynchronizationState::INIT_DOWNLOAD);
connect(_clientModel, &ClientModel::numBlocksChanged, this,
&BitcoinGUI::setNumBlocks);
@@ -1072,13 +1074,15 @@
}
void BitcoinGUI::setNumBlocks(int count, const QDateTime &blockDate,
- double nVerificationProgress, bool header) {
+ double nVerificationProgress, bool header,
+ SynchronizationState sync_state) {
// Disabling macOS App Nap on initial sync, disk and reindex operations.
#ifdef Q_OS_MAC
- (m_node.isInitialBlockDownload() || m_node.getReindex() ||
- m_node.getImporting())
- ? m_app_nap_inhibitor->disableAppNap()
- : m_app_nap_inhibitor->enableAppNap();
+ if (sync_state == SynchronizationState::POST_INIT) {
+ m_app_nap_inhibitor->enableAppNap();
+ } else {
+ m_app_nap_inhibitor->disableAppNap();
+ }
#endif
if (modalOverlay) {
diff --git a/src/qt/clientmodel.h b/src/qt/clientmodel.h
--- a/src/qt/clientmodel.h
+++ b/src/qt/clientmodel.h
@@ -12,10 +12,12 @@
#include <memory>
class BanTableModel;
+class CBlockIndex;
class OptionsModel;
class PeerTableModel;
class CBlockIndex;
+enum class SynchronizationState;
namespace interfaces {
class Handler;
@@ -96,7 +98,8 @@
Q_SIGNALS:
void numConnectionsChanged(int count);
void numBlocksChanged(int count, const QDateTime &blockDate,
- double nVerificationProgress, bool header);
+ double nVerificationProgress, bool header,
+ SynchronizationState sync_state);
void mempoolSizeChanged(long count, size_t mempoolSizeInBytes);
void networkActiveChanged(bool networkActive);
void alertsChanged(const QString &warnings);
diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp
--- a/src/qt/clientmodel.cpp
+++ b/src/qt/clientmodel.cpp
@@ -16,6 +16,7 @@
#include <qt/guiutil.h>
#include <qt/peertablemodel.h>
#include <util/system.h>
+#include <validation.h>
#include <QDebug>
#include <QThread>
@@ -212,39 +213,36 @@
assert(invoked);
}
-static void BlockTipChanged(ClientModel *clientmodel, bool initialSync,
- int height, int64_t blockTime,
- double verificationProgress, bool fHeader) {
- // lock free async UI updates in case we have a new block tip
- // during initial sync, only update the UI if the last update
- // was > 250ms (MODEL_UPDATE_DELAY) ago
- int64_t now = 0;
- if (initialSync) {
- now = GetTimeMillis();
- }
-
- int64_t &nLastUpdateNotification = fHeader
- ? nLastHeaderTipUpdateNotification
- : nLastBlockTipUpdateNotification;
-
+static void BlockTipChanged(ClientModel *clientmodel,
+ SynchronizationState sync_state, int height,
+ int64_t blockTime, double verificationProgress,
+ bool fHeader) {
if (fHeader) {
// cache best headers time and height to reduce future cs_main locks
clientmodel->cachedBestHeaderHeight = height;
clientmodel->cachedBestHeaderTime = blockTime;
}
- // During initial sync, block notifications, and header notifications from
- // reindexing are both throttled.
- if (!initialSync || (fHeader && !clientmodel->node().getReindex()) ||
- now - nLastUpdateNotification > MODEL_UPDATE_DELAY) {
- // pass an async signal to the UI thread
- bool invoked = QMetaObject::invokeMethod(
- clientmodel, "numBlocksChanged", Qt::QueuedConnection,
- Q_ARG(int, height),
- Q_ARG(QDateTime, QDateTime::fromTime_t(blockTime)),
- Q_ARG(double, verificationProgress), Q_ARG(bool, fHeader));
- assert(invoked);
- nLastUpdateNotification = now;
+
+ // Throttle GUI notifications about (a) blocks during initial sync, and (b)
+ // both blocks and headers during reindex.
+ const bool throttle =
+ (sync_state != SynchronizationState::POST_INIT && !fHeader) ||
+ sync_state == SynchronizationState::INIT_REINDEX;
+ const int64_t now = throttle ? GetTimeMillis() : 0;
+ int64_t &nLastUpdateNotification = fHeader
+ ? nLastHeaderTipUpdateNotification
+ : nLastBlockTipUpdateNotification;
+ if (throttle && now < nLastUpdateNotification + MODEL_UPDATE_DELAY) {
+ return;
}
+
+ bool invoked = QMetaObject::invokeMethod(
+ clientmodel, "numBlocksChanged", Qt::QueuedConnection,
+ Q_ARG(int, height), Q_ARG(QDateTime, QDateTime::fromTime_t(blockTime)),
+ Q_ARG(double, verificationProgress), Q_ARG(bool, fHeader),
+ Q_ARG(SynchronizationState, sync_state));
+ assert(invoked);
+ nLastUpdateNotification = now;
}
void ClientModel::subscribeToCoreSignals() {
diff --git a/src/rpc/blockchain.h b/src/rpc/blockchain.h
--- a/src/rpc/blockchain.h
+++ b/src/rpc/blockchain.h
@@ -32,7 +32,7 @@
double GetDifficulty(const CBlockIndex *blockindex);
/** Callback for when block tip changed. */
-void RPCNotifyBlockChange(bool ibd, const CBlockIndex *pindex);
+void RPCNotifyBlockChange(const CBlockIndex *pindex);
/** Block description to JSON */
UniValue blockToJSON(const CBlock &block, const CBlockIndex *tip,
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -235,7 +235,7 @@
return UniValue(UniValue::VSTR);
}
-void RPCNotifyBlockChange(bool ibd, const CBlockIndex *pindex) {
+void RPCNotifyBlockChange(const CBlockIndex *pindex) {
if (pindex) {
LOCK(cs_blockchange);
latestblock.hash = pindex->GetBlockHash();
diff --git a/src/ui_interface.h b/src/ui_interface.h
--- a/src/ui_interface.h
+++ b/src/ui_interface.h
@@ -11,6 +11,7 @@
#include <string>
class CBlockIndex;
+enum class SynchronizationState;
struct bilingual_str;
namespace boost {
@@ -127,10 +128,12 @@
int nProgress, bool resume_possible);
/** New block has been accepted */
- ADD_SIGNALS_DECL_WRAPPER(NotifyBlockTip, void, bool, const CBlockIndex *);
+ ADD_SIGNALS_DECL_WRAPPER(NotifyBlockTip, void, SynchronizationState,
+ const CBlockIndex *);
/** Best header has changed */
- ADD_SIGNALS_DECL_WRAPPER(NotifyHeaderTip, void, bool, const CBlockIndex *);
+ ADD_SIGNALS_DECL_WRAPPER(NotifyHeaderTip, void, SynchronizationState,
+ const CBlockIndex *);
/** Banlist did change. */
ADD_SIGNALS_DECL_WRAPPER(BannedListChanged, void, void);
diff --git a/src/ui_interface.cpp b/src/ui_interface.cpp
--- a/src/ui_interface.cpp
+++ b/src/ui_interface.cpp
@@ -79,11 +79,13 @@
bool resume_possible) {
return g_ui_signals.ShowProgress(title, nProgress, resume_possible);
}
-void CClientUIInterface::NotifyBlockTip(bool b, const CBlockIndex *i) {
- return g_ui_signals.NotifyBlockTip(b, i);
+void CClientUIInterface::NotifyBlockTip(SynchronizationState s,
+ const CBlockIndex *i) {
+ return g_ui_signals.NotifyBlockTip(s, i);
}
-void CClientUIInterface::NotifyHeaderTip(bool b, const CBlockIndex *i) {
- return g_ui_signals.NotifyHeaderTip(b, i);
+void CClientUIInterface::NotifyHeaderTip(SynchronizationState s,
+ const CBlockIndex *i) {
+ return g_ui_signals.NotifyHeaderTip(s, i);
}
void CClientUIInterface::BannedListChanged() {
return g_ui_signals.BannedListChanged();
diff --git a/src/validation.h b/src/validation.h
--- a/src/validation.h
+++ b/src/validation.h
@@ -162,6 +162,9 @@
*/
static const int64_t DEFAULT_MIN_FINALIZATION_DELAY = 2 * 60 * 60;
+/** Current sync state passed to tip changed callbacks. */
+enum class SynchronizationState { INIT_REINDEX, INIT_DOWNLOAD, POST_INIT };
+
extern RecursiveMutex cs_main;
extern CTxMemPool g_mempool;
typedef std::unordered_map<BlockHash, CBlockIndex *, BlockHasher> BlockMap;
diff --git a/src/validation.cpp b/src/validation.cpp
--- a/src/validation.cpp
+++ b/src/validation.cpp
@@ -2768,6 +2768,16 @@
return true;
}
+static SynchronizationState GetSynchronizationState(bool init) {
+ if (!init) {
+ return SynchronizationState::POST_INIT;
+ }
+ if (::fReindex) {
+ return SynchronizationState::INIT_REINDEX;
+ }
+ return SynchronizationState::INIT_DOWNLOAD;
+}
+
static bool NotifyHeaderTip() LOCKS_EXCLUDED(cs_main) {
bool fNotify = false;
bool fInitialBlockDownload = false;
@@ -2787,7 +2797,8 @@
// Send block tip changed notifications without cs_main
if (fNotify) {
- uiInterface.NotifyHeaderTip(fInitialBlockDownload, pindexHeader);
+ uiInterface.NotifyHeaderTip(
+ GetSynchronizationState(fInitialBlockDownload), pindexHeader);
}
return fNotify;
}
@@ -2909,7 +2920,8 @@
fInitialDownload);
// Always notify the UI if a new block tip was connected
- uiInterface.NotifyBlockTip(fInitialDownload, pindexNewTip);
+ uiInterface.NotifyBlockTip(
+ GetSynchronizationState(fInitialDownload), pindexNewTip);
}
}
// When we reach this point, we switched to a new tip (stored in
@@ -3166,8 +3178,9 @@
// Only notify about a new block tip if the active chain was modified.
if (pindex_was_in_chain) {
- uiInterface.NotifyBlockTip(IsInitialBlockDownload(),
- to_mark_failed_or_parked->pprev);
+ uiInterface.NotifyBlockTip(
+ GetSynchronizationState(IsInitialBlockDownload()),
+ to_mark_failed_or_parked->pprev);
}
return true;
}

File Metadata

Mime Type
text/plain
Expires
Sat, Mar 1, 11:56 (24 m, 13 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5187740
Default Alt Text
D8335.diff (17 KB)

Event Timeline