diff --git a/src/init.cpp b/src/init.cpp index 149338eb7081b..3a84442c70031 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -316,6 +316,7 @@ std::string HelpMessage(HelpMessageMode mode) strUsage += HelpMessageOpt("-alertnotify=", _("Execute command when a relevant alert is received or we see a really long fork (%s in cmd is replaced by message)")); strUsage += HelpMessageOpt("-alerts", strprintf(_("Receive and display P2P network alerts (default: %u)"), DEFAULT_ALERTS)); strUsage += HelpMessageOpt("-blocknotify=", _("Execute command when the best block changes (%s in cmd is replaced by block hash)")); + strUsage += HelpMessageOpt("-blocksizenotify=", _("Execute command when the best block changes and its size is over (%s in cmd is replaced by block hash, %d with the block size)")); strUsage += HelpMessageOpt("-checkblocks=", strprintf(_("How many blocks to check at startup (default: %u, 0 = all)"), 500)); strUsage += HelpMessageOpt("-conf=", strprintf(_("Specify configuration file (default: %s)"), "pivx.conf")); if (mode == HMM_BITCOIND) { @@ -552,6 +553,15 @@ static void BlockNotifyCallback(const uint256& hashNewTip) boost::thread t(runCommand, strCmd); // thread runs free } +static void BlockSizeNotifyCallback(int size, const uint256& hashNewTip) +{ + std::string strCmd = GetArg("-blocksizenotify", ""); + + boost::replace_all(strCmd, "%s", hashNewTip.GetHex()); + boost::replace_all(strCmd, "%d", std::to_string(size)); + boost::thread t(runCommand, strCmd); // thread runs free +} + struct CImportingNow { CImportingNow() { @@ -1580,6 +1590,9 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) if (mapArgs.count("-blocknotify")) uiInterface.NotifyBlockTip.connect(BlockNotifyCallback); + if (mapArgs.count("-blocksizenotify")) + uiInterface.NotifyBlockSize.connect(BlockSizeNotifyCallback); + // 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 2ab24d04c10f5..1bfc7b99efb45 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4114,6 +4114,12 @@ bool ActivateBestChain(CValidationState& state, CBlock* pblock, bool fAlreadyChe } // Notify external listeners about the new tip. uiInterface.NotifyBlockTip(hashNewTip); + + unsigned size = GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION); + // If the size is over 1 MB notify external listeners, and it is within the last 5 minutes + if (size > MAX_BLOCK_SIZE_LEGACY && pblock->GetBlockTime() > GetAdjustedTime() - 300) { + uiInterface.NotifyBlockSize(static_cast(size), hashNewTip); + } } } while (pindexMostWork != chainActive.Tip()); CheckBlockIndex(); diff --git a/src/ui_interface.h b/src/ui_interface.h index 744b32e7dbf3d..bee72b2342eb3 100644 --- a/src/ui_interface.h +++ b/src/ui_interface.h @@ -102,6 +102,9 @@ class CClientUIInterface /** New block has been accepted */ boost::signals2::signal NotifyBlockTip; + /** New block has been accepted and is over a certain size */ + boost::signals2::signal NotifyBlockSize; + /** Banlist did change. */ boost::signals2::signal BannedListChanged; };