From beb36e800c393da3c5857a8f1e5959748ac0f96b Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Tue, 29 Jul 2014 10:53:38 -0400 Subject: [PATCH 1/2] ui_interface: remove unused NotifyBlocksChanged signal --- src/main.cpp | 5 +---- src/qt/clientmodel.cpp | 8 -------- src/ui_interface.h | 3 --- 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index e135e93a..e73942d7 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1386,10 +1386,8 @@ void Misbehaving(NodeId pnode, int howmuch) void static InvalidChainFound(CBlockIndex* pindexNew) { if (!pindexBestInvalid || pindexNew->nChainWork > pindexBestInvalid->nChainWork) - { pindexBestInvalid = pindexNew; - uiInterface.NotifyBlocksChanged(); - } + LogPrintf("InvalidChainFound: invalid block=%s height=%d log2_work=%.8g date=%s\n", pindexNew->GetBlockHash().ToString(), pindexNew->nHeight, log(pindexNew->nChainWork.getdouble())/log(2.0), DateTimeStrFormat("%Y-%m-%d %H:%M:%S", @@ -2175,7 +2173,6 @@ bool ActivateBestChain(CValidationState &state) { boost::thread t(runCommand, strCmd); // thread runs free } } - uiInterface.NotifyBlocksChanged(); } while(pindexMostWork != chainActive.Tip()); return true; diff --git a/src/qt/clientmodel.cpp b/src/qt/clientmodel.cpp index 4c21eb55..fea99bfd 100644 --- a/src/qt/clientmodel.cpp +++ b/src/qt/clientmodel.cpp @@ -208,12 +208,6 @@ static void ShowProgress(ClientModel *clientmodel, const std::string &title, int Q_ARG(int, nProgress)); } -static void NotifyBlocksChanged(ClientModel *clientmodel) -{ - // This notification is too frequent. Don't trigger a signal. - // Don't remove it, though, as it might be useful later. -} - static void NotifyNumConnectionsChanged(ClientModel *clientmodel, int newNumConnections) { // Too noisy: qDebug() << "NotifyNumConnectionsChanged : " + QString::number(newNumConnections); @@ -233,7 +227,6 @@ void ClientModel::subscribeToCoreSignals() { // Connect signals to client uiInterface.ShowProgress.connect(boost::bind(ShowProgress, this, _1, _2)); - uiInterface.NotifyBlocksChanged.connect(boost::bind(NotifyBlocksChanged, this)); uiInterface.NotifyNumConnectionsChanged.connect(boost::bind(NotifyNumConnectionsChanged, this, _1)); uiInterface.NotifyAlertChanged.connect(boost::bind(NotifyAlertChanged, this, _1, _2)); } @@ -242,7 +235,6 @@ void ClientModel::unsubscribeFromCoreSignals() { // Disconnect signals from client uiInterface.ShowProgress.disconnect(boost::bind(ShowProgress, this, _1, _2)); - uiInterface.NotifyBlocksChanged.disconnect(boost::bind(NotifyBlocksChanged, this)); uiInterface.NotifyNumConnectionsChanged.disconnect(boost::bind(NotifyNumConnectionsChanged, this, _1)); uiInterface.NotifyAlertChanged.disconnect(boost::bind(NotifyAlertChanged, this, _1, _2)); } diff --git a/src/ui_interface.h b/src/ui_interface.h index b3df2b5a..a073a328 100644 --- a/src/ui_interface.h +++ b/src/ui_interface.h @@ -78,9 +78,6 @@ public: /** Translate a message to the native language of the user. */ boost::signals2::signal Translate; - /** Block chain changed. */ - boost::signals2::signal NotifyBlocksChanged; - /** Number of network connections changed. */ boost::signals2::signal NotifyNumConnectionsChanged; From c7b6117debf4ebabc464a55b840bdd7bdeb94fa3 Mon Sep 17 00:00:00 2001 From: Jeff Garzik Date: Thu, 14 Aug 2014 12:32:34 -0400 Subject: [PATCH 2/2] Create new signal for notification of new blocks. Use w/ -blocknotify --- src/init.cpp | 11 +++++++++++ src/main.cpp | 8 +++----- src/ui_interface.h | 3 +++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 8ae228bb..494342c6 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -367,6 +367,14 @@ std::string LicenseInfo() "\n"; } +static void BlockNotifyCallback(const uint256& hashNewTip) +{ + std::string strCmd = GetArg("-blocknotify", ""); + + boost::replace_all(strCmd, "%s", hashNewTip.GetHex()); + boost::thread t(runCommand, strCmd); // thread runs free +} + struct CImportingNow { CImportingNow() { @@ -1184,6 +1192,9 @@ bool AppInit2(boost::thread_group& threadGroup) #endif // !ENABLE_WALLET // ********************************************************* Step 9: import blocks + if (mapArgs.count("-blocknotify")) + uiInterface.NotifyBlockTip.connect(BlockNotifyCallback); + // scan for better chains in the block chain database, that are not yet connected in the active best chain CValidationState state; if (!ActivateBestChain(state)) diff --git a/src/main.cpp b/src/main.cpp index e73942d7..841cc195 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2162,16 +2162,14 @@ bool ActivateBestChain(CValidationState &state) { uint256 hashNewTip = pindexNewTip->GetBlockHash(); // Relay inventory, but don't relay old inventory during initial block download. int nBlockEstimate = Checkpoints::GetTotalBlocksEstimate(); + { LOCK(cs_vNodes); BOOST_FOREACH(CNode* pnode, vNodes) if (chainActive.Height() > (pnode->nStartingHeight != -1 ? pnode->nStartingHeight - 2000 : nBlockEstimate)) pnode->PushInventory(CInv(MSG_BLOCK, hashNewTip)); - - std::string strCmd = GetArg("-blocknotify", ""); - if (!strCmd.empty()) { - boost::replace_all(strCmd, "%s", hashNewTip.GetHex()); - boost::thread t(runCommand, strCmd); // thread runs free } + + uiInterface.NotifyBlockTip(hashNewTip); } } while(pindexMostWork != chainActive.Tip()); diff --git a/src/ui_interface.h b/src/ui_interface.h index a073a328..bbc8a203 100644 --- a/src/ui_interface.h +++ b/src/ui_interface.h @@ -92,6 +92,9 @@ public: /** Show progress e.g. for verifychain */ boost::signals2::signal ShowProgress; + + /** New block has been accepted */ + boost::signals2::signal NotifyBlockTip; }; extern CClientUIInterface uiInterface;