From f89faa258404d2e6fd4300990275cd2439e51255 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Tue, 7 May 2013 18:37:37 +0200 Subject: [PATCH] Call the -alertnotify script when we see a long or invalid fork. --- src/init.cpp | 2 +- src/main.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/init.cpp b/src/init.cpp index f6b2c91b4..14617809e 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -225,7 +225,7 @@ std::string HelpMessage() strUsage += " -rpcthreads= " + _("Set the number of threads to service RPC calls (default: 4)") + "\n"; strUsage += " -blocknotify= " + _("Execute command when the best block changes (%s in cmd is replaced by block hash)") + "\n"; strUsage += " -walletnotify= " + _("Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)") + "\n"; - strUsage += " -alertnotify= " + _("Execute command when a relevant alert is received (%s in cmd is replaced by message)") + "\n"; + strUsage += " -alertnotify= " + _("Execute command when a relevant alert is received or we see a really long fork (%s in cmd is replaced by message)") + "\n"; strUsage += " -upgradewallet " + _("Upgrade wallet to latest format") + "\n"; strUsage += " -keypool= " + _("Set key pool size to (default: 100)") + "\n"; strUsage += " -rescan " + _("Rescan the block chain for missing wallet transactions") + "\n"; diff --git a/src/main.cpp b/src/main.cpp index 2e79c874d..b206b6803 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1395,6 +1395,16 @@ void CheckForkWarningConditions() if (pindexBestForkTip || nBestInvalidWork > nBestChainWork + (pindexBest->GetBlockWork() * 6).getuint256()) { + if (!fLargeWorkForkFound) + { + std::string strCmd = GetArg("-alertnotify", ""); + if (!strCmd.empty()) + { + std::string warning("'Warning: Large-work fork detected. You may need to upgrade, or other nodes may need to upgrade.'"); + boost::replace_all(strCmd, "%s", warning); + boost::thread t(runCommand, strCmd); // thread runs free + } + } fLargeWorkForkFound = true; printf("CheckForkWarningConditions: Warning: Displayed transactions may not be correct! You may need to upgrade, or other nodes may need to upgrade.\n"); } else