diff --git a/contrib/init/bitcoind.conf b/contrib/init/bitcoind.conf --- a/contrib/init/bitcoind.conf +++ b/contrib/init/bitcoind.conf @@ -35,12 +35,6 @@ echo echo "bash -c 'tr -dc a-zA-Z0-9 < /dev/urandom | head -c32 && echo'" echo - echo "It is also recommended that you also set alertnotify so you are " - echo "notified of problems:" - echo - echo "ie: alertnotify=echo %%s | mail -s \"Bitcoin Alert\"" \ - "admin@foo.com" - echo exit 1 fi diff --git a/contrib/init/bitcoind.openrc b/contrib/init/bitcoind.openrc --- a/contrib/init/bitcoind.openrc +++ b/contrib/init/bitcoind.openrc @@ -81,12 +81,6 @@ eerror "" eerror "bash -c 'tr -dc a-zA-Z0-9 < /dev/urandom | head -c32 && echo'" eerror "" - eerror "It is also recommended that you also set alertnotify so you are " - eerror "notified of problems:" - eerror "" - eerror "ie: alertnotify=echo %%s | mail -s \"Bitcoin Alert\"" \ - "admin@foo.com" - eerror "" return 1 fi } diff --git a/doc/man/bitcoin-qt.1 b/doc/man/bitcoin-qt.1 --- a/doc/man/bitcoin-qt.1 +++ b/doc/man/bitcoin-qt.1 @@ -17,11 +17,6 @@ .IP Print version and exit .HP -\fB\-alertnotify=\fR -.IP -Execute command when a relevant alert is received or we see a really -long fork (%s in cmd is replaced by message) -.HP \fB\-blocknotify=\fR .IP Execute command when the best block changes (%s in cmd is replaced by diff --git a/doc/man/bitcoind.1 b/doc/man/bitcoind.1 --- a/doc/man/bitcoind.1 +++ b/doc/man/bitcoind.1 @@ -18,11 +18,6 @@ .IP Print version and exit .HP -\fB\-alertnotify=\fR -.IP -Execute command when a relevant alert is received or we see a really -long fork (%s in cmd is replaced by message) -.HP \fB\-blocknotify=\fR .IP Execute command when the best block changes (%s in cmd is replaced by diff --git a/doc/release-notes.md b/doc/release-notes.md --- a/doc/release-notes.md +++ b/doc/release-notes.md @@ -8,4 +8,4 @@ - The help message also reflects this. - Code standard updated to c++14. - Remove `depends` from transaction objects provided by `getblocktemplate`. - \ No newline at end of file + - Remove `-alertnotify` functionality. Use log tailing daemon (such as mtail) to alert as a replacement. diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -324,10 +324,6 @@ std::string strUsage = HelpMessageGroup(_("Options:")); strUsage += HelpMessageOpt("-?", _("Print this help message and exit")); strUsage += HelpMessageOpt("-version", _("Print version and exit")); - 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("-blocknotify=", _("Execute command when the best block changes " "(%s in cmd is replaced by block hash)")); diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -935,26 +935,6 @@ CBlockIndex const *pindexBestForkTip = nullptr; CBlockIndex const *pindexBestForkBase = nullptr; -static void AlertNotify(const std::string &strMessage) { - uiInterface.NotifyAlertChanged(); - std::string strCmd = gArgs.GetArg("-alertnotify", ""); - if (strCmd.empty()) { - return; - } - - // Alert text should be plain ascii coming from a trusted source, but to be - // safe we first strip anything not in safeChars, then add single quotes - // around the whole string before passing it to the shell: - std::string singleQuote("'"); - std::string safeStatus = SanitizeString(strMessage); - safeStatus = singleQuote + safeStatus + singleQuote; - boost::replace_all(strCmd, "%s", safeStatus); - - std::thread t(runCommand, strCmd); - // thread runs free - t.detach(); -} - static void CheckForkWarningConditions() { AssertLockHeld(cs_main); // Before we get past initial download, we cannot reliably alert about forks @@ -976,14 +956,6 @@ pindexBestInvalid->nChainWork > chainActive.Tip()->nChainWork + (GetBlockProof(*chainActive.Tip()) * 6))) { - if (!GetfLargeWorkForkFound() && pindexBestForkBase) { - std::string warning = - std::string("'Warning: Large-work fork detected, forking after " - "block ") + - pindexBestForkBase->phashBlock->ToString() + std::string("'"); - AlertNotify(warning); - } - if (pindexBestForkTip && pindexBestForkBase) { LogPrintf("%s: Warning: Large fork found\n forking the " "chain at height %d (%s)\n lasting to height %d " @@ -2120,7 +2092,6 @@ g_best_block_cv.notify_all(); } - static bool fWarned = false; std::vector warningMessages; if (!IsInitialBlockDownload()) { int nUpgraded = 0; @@ -2148,10 +2119,6 @@ // notify GetWarnings(), called by Qt and the JSON-RPC code to warn // the user: SetMiscWarning(strWarning); - if (!fWarned) { - AlertNotify(strWarning); - fWarned = true; - } } } LogPrintf("%s: new best=%s height=%d version=0x%08x log2_work=%.8g tx=%lu " diff --git a/test/functional/feature_notifications.py b/test/functional/feature_notifications.py --- a/test/functional/feature_notifications.py +++ b/test/functional/feature_notifications.py @@ -3,14 +3,13 @@ # Copyright (c) 2018 The Bitcoin developers # Distributed under the MIT software license, see the accompanying # file COPYING or http://www.opensource.org/licenses/mit-license.php. -"""Test the -alertnotify, -blocknotify and -walletnotify options.""" +"""Test the -blocknotify and -walletnotify options.""" import os +import mmap from test_framework.test_framework import BitcoinTestFramework from test_framework.util import assert_equal, connect_nodes_bi, wait_until -FORK_WARNING_MESSAGE = "Warning: Large-work fork detected, forking after block {}\n" - class NotificationsTest(BitcoinTestFramework): def set_test_params(self): @@ -18,15 +17,12 @@ self.setup_clean_chain = True def setup_network(self): - self.alert_filename = os.path.join(self.options.tmpdir, "alert.txt") self.block_filename = os.path.join(self.options.tmpdir, "blocks.txt") self.tx_filename = os.path.join( self.options.tmpdir, "transactions.txt") - # -alertnotify and -blocknotify on node0, walletnotify on node1 + # -blocknotify on node0, walletnotify on node1 self.extra_args = [["-blockversion=2", - "-alertnotify=echo %s >> {}".format( - self.alert_filename), "-blocknotify=echo %s >> {}".format(self.block_filename)], ["-blockversion=211", "-rescan", @@ -72,32 +68,20 @@ with open(self.tx_filename, 'r') as f: assert_equal(sorted(txids_rpc), sorted(f.read().splitlines())) - # Mine another 41 up-version blocks. -alertnotify should trigger on the 51st. - self.log.info("test -alertnotify for bip9") + # Mine another 41 up-version blocks. Warning should appear on the 51st in the logs + self.log.info( + "test that previously defined alertnotify conditions are present in debug.log") self.nodes[1].generate(41) self.sync_all() - # Give bitcoind 10 seconds to write the alert notification - wait_until(lambda: os.path.isfile(self.alert_filename) - and os.path.getsize(self.alert_filename), timeout=10) - - with open(self.alert_filename, 'r', encoding='utf8') as f: - alert_text = f.read() - - # Mine more up-version blocks, should not get more alerts: - self.nodes[1].generate(2) - self.sync_all() - - with open(self.alert_filename, 'r', encoding='utf8') as f: - alert_text2 = f.read() - os.remove(self.alert_filename) - - self.log.info( - "-alertnotify should not continue notifying for more unknown version blocks") - assert_equal(alert_text, alert_text2) + log_file = os.path.join(self.nodes[0].datadir, "regtest", "debug.log") + with open(log_file, 'rb', 0) as file, \ + mmap.mmap(file.fileno(), 0, access=mmap.ACCESS_READ) as s: + assert s.find(b'of last 100 blocks have unexpected version') != - \ + 1, "Unknown version message warning not found in log file." # Create an invalid chain and ensure the node warns. - self.log.info("test -alertnotify for forked chain") + self.log.info("test log for forked chain") fork_block = self.nodes[0].getbestblockhash() self.nodes[0].generate(1) invalid_block = self.nodes[0].getbestblockhash() @@ -106,13 +90,10 @@ # Invalidate a large branch, which should trigger an alert. self.nodes[0].invalidateblock(invalid_block) - # Give bitcoind 10 seconds to write the alert notification - wait_until(lambda: os.path.isfile(self.alert_filename) - and os.path.getsize(self.alert_filename), timeout=10) - - self.log.info(self.alert_filename) - with open(self.alert_filename, 'r', encoding='utf8') as f: - assert_equal(f.read(), (FORK_WARNING_MESSAGE.format(fork_block))) + with open(log_file, 'rb', 0) as file, \ + mmap.mmap(file.fileno(), 0, access=mmap.ACCESS_READ) as s: + assert s.find(b'Warning: Large fork found') != -1 and s.find(fork_block.encode('utf-8')), \ + "Large fork warning not found in log file." if __name__ == '__main__':