diff --git a/src/interfaces/node.h b/src/interfaces/node.h --- a/src/interfaces/node.h +++ b/src/interfaces/node.h @@ -40,6 +40,7 @@ namespace interfaces { class Handler; class Wallet; +struct BlockTip; //! Top-level interface for a bitcoin node (bitcoind process). class Node { @@ -239,16 +240,16 @@ handleBannedListChanged(BannedListChangedFn fn) = 0; //! Register handler for block tip messages. - using NotifyBlockTipFn = std::function; + using NotifyBlockTipFn = + std::function; virtual std::unique_ptr handleNotifyBlockTip(NotifyBlockTipFn fn) = 0; //! Register handler for header tip messages. - using NotifyHeaderTipFn = std::function; + using NotifyHeaderTipFn = + std::function; virtual std::unique_ptr handleNotifyHeaderTip(NotifyHeaderTipFn fn) = 0; @@ -261,6 +262,13 @@ //! Return implementation of Node interface. std::unique_ptr MakeNode(NodeContext *context = nullptr); +//! Block tip (could be a header or not, depends on the subscribed signal). +struct BlockTip { + int block_height; + int64_t block_time; + BlockHash block_hash; +}; + } // namespace interfaces #endif // BITCOIN_INTERFACES_NODE_H diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp --- a/src/interfaces/node.cpp +++ b/src/interfaces/node.cpp @@ -329,8 +329,9 @@ return MakeHandler(::uiInterface.NotifyBlockTip_connect( [fn](SynchronizationState sync_state, const CBlockIndex *block) { - fn(sync_state, block->GetBlockHash(), block->nHeight, - block->GetBlockTime(), + fn(sync_state, + BlockTip{block->nHeight, block->GetBlockTime(), + block->GetBlockHash()}, GuessVerificationProgress(Params().TxData(), block)); })); } @@ -340,8 +341,10 @@ return MakeHandler(::uiInterface.NotifyHeaderTip_connect( [fn](SynchronizationState sync_state, const CBlockIndex *block) { - fn(sync_state, block->GetBlockHash(), block->nHeight, - block->GetBlockTime(), 0); + fn(sync_state, + BlockTip{block->nHeight, block->GetBlockTime(), + block->GetBlockHash()}, + 0); })); } NodeContext *context() override { return m_context; } diff --git a/src/qt/clientmodel.h b/src/qt/clientmodel.h --- a/src/qt/clientmodel.h +++ b/src/qt/clientmodel.h @@ -74,7 +74,7 @@ bool getProxyInfo(std::string &ip_port) const; - // caches for the best header, number of blocks + // caches for the best header: hash, number of blocks and block time mutable std::atomic cachedBestHeaderHeight; mutable std::atomic cachedBestHeaderTime; mutable std::atomic m_cached_num_blocks{-1}; diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -244,17 +244,16 @@ static void BlockTipChanged(ClientModel *clientmodel, SynchronizationState sync_state, - const BlockHash block_hash, int height, - int64_t blockTime, double verificationProgress, - bool fHeader) { + interfaces::BlockTip tip, + double verificationProgress, bool fHeader) { if (fHeader) { // cache best headers time and height to reduce future cs_main locks - clientmodel->cachedBestHeaderHeight = height; - clientmodel->cachedBestHeaderTime = blockTime; + clientmodel->cachedBestHeaderHeight = tip.block_height; + clientmodel->cachedBestHeaderTime = tip.block_time; } else { - clientmodel->m_cached_num_blocks = height; + clientmodel->m_cached_num_blocks = tip.block_height; WITH_LOCK(clientmodel->m_cached_tip_mutex, - clientmodel->m_cached_tip_blocks = block_hash;); + clientmodel->m_cached_tip_blocks = tip.block_hash;); } // Throttle GUI notifications about (a) blocks during initial sync, and (b) @@ -272,7 +271,8 @@ bool invoked = QMetaObject::invokeMethod( clientmodel, "numBlocksChanged", Qt::QueuedConnection, - Q_ARG(int, height), Q_ARG(QDateTime, QDateTime::fromTime_t(blockTime)), + Q_ARG(int, tip.block_height), + Q_ARG(QDateTime, QDateTime::fromTime_t(tip.block_time)), Q_ARG(double, verificationProgress), Q_ARG(bool, fHeader), Q_ARG(SynchronizationState, sync_state)); assert(invoked); @@ -295,12 +295,10 @@ m_node.handleBannedListChanged(std::bind(BannedListChanged, this)); m_handler_notify_block_tip = m_node.handleNotifyBlockTip( std::bind(BlockTipChanged, this, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3, - std::placeholders::_4, std::placeholders::_5, false)); + std::placeholders::_2, std::placeholders::_3, false)); m_handler_notify_header_tip = m_node.handleNotifyHeaderTip( std::bind(BlockTipChanged, this, std::placeholders::_1, - std::placeholders::_2, std::placeholders::_3, - std::placeholders::_4, std::placeholders::_5, true)); + std::placeholders::_2, std::placeholders::_3, true)); } void ClientModel::unsubscribeFromCoreSignals() {