aboutsummaryrefslogtreecommitdiff
path: root/src/node
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2023-05-30 14:43:38 +0100
committerfanquake <fanquake@gmail.com>2023-05-30 14:57:22 +0100
commit9564f98fee9809530e10070ab18738aefe95445e (patch)
treeecf8206327049c7ed0379a72ff0def70b0434639 /src/node
parentf467b28ac35add304442f30c2a05ef5d9df496e2 (diff)
parent7d3b35004b039f2bd606bb46a540de7babdbc41e (diff)
Merge bitcoin/bitcoin#27636: kernel: Remove util/system from kernel library, interface_ui from validation.
7d3b35004b039f2bd606bb46a540de7babdbc41e refactor: Move system from util to common library (TheCharlatan) 7eee356c0a7fefd70c8de21689efa335f52a69ba refactor: Split util::AnyPtr into its own file (TheCharlatan) 44de325d95447498036479c3112ba741caf45bf6 refactor: Split util::insert into its own file (TheCharlatan) 9ec5da36b62276ae22e348f26f88aaf646357d6d refactor: Move ScheduleBatchPriority to its own file (TheCharlatan) f871c69191dfe1331861ebcdbadb6bd47e45c8b1 kernel: Add warning method to notifications (TheCharlatan) 4452707edec91c7d7991f486dd41ef3edb4f7fbf kernel: Add progress method to notifications (TheCharlatan) 84d71457e7250ab25c0a11d1ad1c7657197ffd90 kernel: Add headerTip method to notifications (TheCharlatan) 447761c8228d58f948aae7e73ed079c028cacb97 kernel: Add notification interface (TheCharlatan) Pull request description: This pull request is part of the `libbitcoinkernel` project https://github.com/bitcoin/bitcoin/issues/27587 https://github.com/bitcoin/bitcoin/projects/18 and more specifically its "Step 2: Decouple most non-consensus code from libbitcoinkernel". --- It removes the kernel library's dependency on `util/system` and `interface_ui`. `util/system` contains networking and shell-related code that should not be part of the kernel library. The following pull requests prepared `util/system` for this final step: https://github.com/bitcoin/bitcoin/pull/27419 https://github.com/bitcoin/bitcoin/pull/27254 https://github.com/bitcoin/bitcoin/pull/27238. `interface_ui` defines functions for a more general node interface and has a dependency on `boost/signals2`. After applying the patches from this pull request, the kernel's reliance on boost is down to `boost::multiindex`. The approach implemented here introduces some indirection, which makes the code a bit harder to read. Any suggestions for improving or reworking this pull request to make it more concise, or even reworking it into a more proper interface, are appreciated. ACKs for top commit: MarcoFalke: re-ACK 7d3b35004b039f2bd606bb46a540de7babdbc41e (no change) 🎋 stickies-v: Code Review ACK 7d3b35004b039f2bd606bb46a540de7babdbc41e hebasto: re-ACK 7d3b35004b039f2bd606bb46a540de7babdbc41e, only last two commits dropped since my [recent](https://github.com/bitcoin/bitcoin/pull/27636#pullrequestreview-1435394620) review. Tree-SHA512: c8cfc698dc9d78e20191c444708f2d957501229abe95e5806106d1126fb9c5fbcee686fb55645658c0107ce71f10646f37a2fdf7fde16bbf22cbf1ac885dd08d
Diffstat (limited to 'src/node')
-rw-r--r--src/node/blockstorage.cpp2
-rw-r--r--src/node/chainstate.cpp2
-rw-r--r--src/node/context.cpp1
-rw-r--r--src/node/context.h3
-rw-r--r--src/node/kernel_notifications.cpp75
-rw-r--r--src/node/kernel_notifications.h31
-rw-r--r--src/node/txreconciliation.cpp2
7 files changed, 113 insertions, 3 deletions
diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp
index f8d4e6c1da..b7afa8a7c3 100644
--- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -17,9 +17,9 @@
#include <signet.h>
#include <streams.h>
#include <undo.h>
+#include <util/batchpriority.h>
#include <util/fs.h>
#include <util/syscall_sandbox.h>
-#include <util/system.h>
#include <validation.h>
#include <map>
diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp
index 40b609d069..8f997b0594 100644
--- a/src/node/chainstate.cpp
+++ b/src/node/chainstate.cpp
@@ -253,7 +253,7 @@ ChainstateLoadResult VerifyLoadedChainstate(ChainstateManager& chainman, const C
"Only rebuild the block database if you are sure that your computer's date and time are correct")};
}
- VerifyDBResult result = CVerifyDB().VerifyDB(
+ VerifyDBResult result = CVerifyDB(chainman.GetNotifications()).VerifyDB(
*chainstate, chainman.GetConsensus(), chainstate->CoinsDB(),
options.check_level,
options.check_blocks);
diff --git a/src/node/context.cpp b/src/node/context.cpp
index af59ab932b..ca56fa0b86 100644
--- a/src/node/context.cpp
+++ b/src/node/context.cpp
@@ -11,6 +11,7 @@
#include <net.h>
#include <net_processing.h>
#include <netgroup.h>
+#include <node/kernel_notifications.h>
#include <policy/fees.h>
#include <scheduler.h>
#include <txmempool.h>
diff --git a/src/node/context.h b/src/node/context.h
index 84f4053c84..9532153cdb 100644
--- a/src/node/context.h
+++ b/src/node/context.h
@@ -30,6 +30,8 @@ class WalletLoader;
} // namespace interfaces
namespace node {
+class KernelNotifications;
+
//! NodeContext struct containing references to chain state and connection
//! state.
//!
@@ -62,6 +64,7 @@ struct NodeContext {
interfaces::WalletLoader* wallet_loader{nullptr};
std::unique_ptr<CScheduler> scheduler;
std::function<void()> rpc_interruption_point = [] {};
+ std::unique_ptr<KernelNotifications> notifications;
//! Declare default constructor and destructor that are not inline, so code
//! instantiating the NodeContext struct doesn't need to #include class
diff --git a/src/node/kernel_notifications.cpp b/src/node/kernel_notifications.cpp
new file mode 100644
index 0000000000..926b157f3b
--- /dev/null
+++ b/src/node/kernel_notifications.cpp
@@ -0,0 +1,75 @@
+// Copyright (c) 2023 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include <node/kernel_notifications.h>
+
+#if defined(HAVE_CONFIG_H)
+#include <config/bitcoin-config.h>
+#endif
+
+#include <common/args.h>
+#include <common/system.h>
+#include <node/interface_ui.h>
+#include <util/strencodings.h>
+#include <util/string.h>
+#include <util/translation.h>
+#include <warnings.h>
+
+#include <cstdint>
+#include <string>
+#include <thread>
+
+static void AlertNotify(const std::string& strMessage)
+{
+ uiInterface.NotifyAlertChanged();
+#if HAVE_SYSTEM
+ 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;
+ ReplaceAll(strCmd, "%s", safeStatus);
+
+ std::thread t(runCommand, strCmd);
+ t.detach(); // thread runs free
+#endif
+}
+
+static void DoWarning(const bilingual_str& warning)
+{
+ static bool fWarned = false;
+ SetMiscWarning(warning);
+ if (!fWarned) {
+ AlertNotify(warning.original);
+ fWarned = true;
+ }
+}
+
+namespace node {
+
+void KernelNotifications::blockTip(SynchronizationState state, CBlockIndex& index)
+{
+ uiInterface.NotifyBlockTip(state, &index);
+}
+
+void KernelNotifications::headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync)
+{
+ uiInterface.NotifyHeaderTip(state, height, timestamp, presync);
+}
+
+void KernelNotifications::progress(const bilingual_str& title, int progress_percent, bool resume_possible)
+{
+ uiInterface.ShowProgress(title.translated, progress_percent, resume_possible);
+}
+
+void KernelNotifications::warning(const bilingual_str& warning)
+{
+ DoWarning(warning);
+}
+
+} // namespace node
diff --git a/src/node/kernel_notifications.h b/src/node/kernel_notifications.h
new file mode 100644
index 0000000000..3e665bbf14
--- /dev/null
+++ b/src/node/kernel_notifications.h
@@ -0,0 +1,31 @@
+// Copyright (c) 2023 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#ifndef BITCOIN_NODE_KERNEL_NOTIFICATIONS_H
+#define BITCOIN_NODE_KERNEL_NOTIFICATIONS_H
+
+#include <kernel/notifications_interface.h>
+
+#include <cstdint>
+#include <string>
+
+class CBlockIndex;
+enum class SynchronizationState;
+struct bilingual_str;
+
+namespace node {
+class KernelNotifications : public kernel::Notifications
+{
+public:
+ void blockTip(SynchronizationState state, CBlockIndex& index) override;
+
+ void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) override;
+
+ void progress(const bilingual_str& title, int progress_percent, bool resume_possible) override;
+
+ void warning(const bilingual_str& warning) override;
+};
+} // namespace node
+
+#endif // BITCOIN_NODE_KERNEL_NOTIFICATIONS_H
diff --git a/src/node/txreconciliation.cpp b/src/node/txreconciliation.cpp
index 9938759074..d62046daaa 100644
--- a/src/node/txreconciliation.cpp
+++ b/src/node/txreconciliation.cpp
@@ -4,9 +4,9 @@
#include <node/txreconciliation.h>
+#include <common/system.h>
#include <logging.h>
#include <util/check.h>
-#include <util/system.h>
#include <unordered_map>
#include <variant>