Skip to content

Commit

Permalink
Add blocksizenotify command
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremy authored and blondfrogs committed Feb 2, 2018
1 parent 4c01ba6 commit 44e4d2e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ std::string HelpMessage(HelpMessageMode mode)
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)"));
strUsage += HelpMessageOpt("-alerts", strprintf(_("Receive and display P2P network alerts (default: %u)"), DEFAULT_ALERTS));
strUsage += HelpMessageOpt("-blocknotify=<cmd>", _("Execute command when the best block changes (%s in cmd is replaced by block hash)"));
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)"));
strUsage += HelpMessageOpt("-checkblocks=<n>", strprintf(_("How many blocks to check at startup (default: %u, 0 = all)"), 500));
strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file (default: %s)"), "pivx.conf"));
if (mode == HMM_BITCOIND) {
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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))
Expand Down
6 changes: 6 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(size), hashNewTip);
}
}
} while (pindexMostWork != chainActive.Tip());
CheckBlockIndex();
Expand Down
3 changes: 3 additions & 0 deletions src/ui_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ class CClientUIInterface
/** New block has been accepted */
boost::signals2::signal<void(const uint256& hash)> NotifyBlockTip;

/** New block has been accepted and is over a certain size */
boost::signals2::signal<void(int size, const uint256& hash)> NotifyBlockSize;

/** Banlist did change. */
boost::signals2::signal<void (void)> BannedListChanged;
};
Expand Down

0 comments on commit 44e4d2e

Please sign in to comment.