Skip to content

Commit 44e4d2e

Browse files
Jeremyblondfrogs
authored andcommitted
Add blocksizenotify command
1 parent 4c01ba6 commit 44e4d2e

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

src/init.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ std::string HelpMessage(HelpMessageMode mode)
316316
strUsage += HelpMessageOpt("-alertnotify=<cmd>", _("Execute command when a relevant alert is received or we see a really long fork (%s in cmd is replaced by message)"));
317317
strUsage += HelpMessageOpt("-alerts", strprintf(_("Receive and display P2P network alerts (default: %u)"), DEFAULT_ALERTS));
318318
strUsage += HelpMessageOpt("-blocknotify=<cmd>", _("Execute command when the best block changes (%s in cmd is replaced by block hash)"));
319+
strUsage += HelpMessageOpt("-blocksizenotify=<cmd>", _("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)"));
319320
strUsage += HelpMessageOpt("-checkblocks=<n>", strprintf(_("How many blocks to check at startup (default: %u, 0 = all)"), 500));
320321
strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file (default: %s)"), "pivx.conf"));
321322
if (mode == HMM_BITCOIND) {
@@ -552,6 +553,15 @@ static void BlockNotifyCallback(const uint256& hashNewTip)
552553
boost::thread t(runCommand, strCmd); // thread runs free
553554
}
554555

556+
static void BlockSizeNotifyCallback(int size, const uint256& hashNewTip)
557+
{
558+
std::string strCmd = GetArg("-blocksizenotify", "");
559+
560+
boost::replace_all(strCmd, "%s", hashNewTip.GetHex());
561+
boost::replace_all(strCmd, "%d", std::to_string(size));
562+
boost::thread t(runCommand, strCmd); // thread runs free
563+
}
564+
555565
struct CImportingNow {
556566
CImportingNow()
557567
{
@@ -1580,6 +1590,9 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
15801590
if (mapArgs.count("-blocknotify"))
15811591
uiInterface.NotifyBlockTip.connect(BlockNotifyCallback);
15821592

1593+
if (mapArgs.count("-blocksizenotify"))
1594+
uiInterface.NotifyBlockSize.connect(BlockSizeNotifyCallback);
1595+
15831596
// scan for better chains in the block chain database, that are not yet connected in the active best chain
15841597
CValidationState state;
15851598
if (!ActivateBestChain(state))

src/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4114,6 +4114,12 @@ bool ActivateBestChain(CValidationState& state, CBlock* pblock, bool fAlreadyChe
41144114
}
41154115
// Notify external listeners about the new tip.
41164116
uiInterface.NotifyBlockTip(hashNewTip);
4117+
4118+
unsigned size = GetSerializeSize(*pblock, SER_NETWORK, PROTOCOL_VERSION);
4119+
// If the size is over 1 MB notify external listeners, and it is within the last 5 minutes
4120+
if (size > MAX_BLOCK_SIZE_LEGACY && pblock->GetBlockTime() > GetAdjustedTime() - 300) {
4121+
uiInterface.NotifyBlockSize(static_cast<int>(size), hashNewTip);
4122+
}
41174123
}
41184124
} while (pindexMostWork != chainActive.Tip());
41194125
CheckBlockIndex();

src/ui_interface.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ class CClientUIInterface
102102
/** New block has been accepted */
103103
boost::signals2::signal<void(const uint256& hash)> NotifyBlockTip;
104104

105+
/** New block has been accepted and is over a certain size */
106+
boost::signals2::signal<void(int size, const uint256& hash)> NotifyBlockSize;
107+
105108
/** Banlist did change. */
106109
boost::signals2::signal<void (void)> BannedListChanged;
107110
};

0 commit comments

Comments
 (0)