aboutsummaryrefslogtreecommitdiff
path: root/src/node
diff options
context:
space:
mode:
authorstickies-v <stickies-v@protonmail.com>2024-04-18 14:05:12 +0100
committerstickies-v <stickies-v@protonmail.com>2024-06-13 11:20:47 +0100
commit20e616f86444d00712ac7eb840666e2b0378af4a (patch)
treeccebef6abe4453b165cc406b6b2af526b9ad4f1e /src/node
parentbed29c481aebeb2b0160450c63c03cc68fb89bc6 (diff)
downloadbitcoin-20e616f86444d00712ac7eb840666e2b0378af4a.tar.xz
move-only: move warnings from common to node
Since rpc/util.cpp is in common, also move GetNodeWarnings() to node::GetWarningsForRPC()
Diffstat (limited to 'src/node')
-rw-r--r--src/node/abort.cpp2
-rw-r--r--src/node/interfaces.cpp2
-rw-r--r--src/node/kernel_notifications.cpp4
-rw-r--r--src/node/timeoffsets.cpp6
-rw-r--r--src/node/warnings.cpp82
-rw-r--r--src/node/warnings.h31
6 files changed, 120 insertions, 7 deletions
diff --git a/src/node/abort.cpp b/src/node/abort.cpp
index b727608384..6f836824b2 100644
--- a/src/node/abort.cpp
+++ b/src/node/abort.cpp
@@ -6,9 +6,9 @@
#include <logging.h>
#include <node/interface_ui.h>
+#include <node/warnings.h>
#include <util/signalinterrupt.h>
#include <util/translation.h>
-#include <warnings.h>
#include <atomic>
#include <cstdlib>
diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp
index 19f4aaf9c4..88af9dadbc 100644
--- a/src/node/interfaces.cpp
+++ b/src/node/interfaces.cpp
@@ -32,6 +32,7 @@
#include <node/mini_miner.h>
#include <node/transaction.h>
#include <node/types.h>
+#include <node/warnings.h>
#include <policy/feerate.h>
#include <policy/fees.h>
#include <policy/policy.h>
@@ -53,7 +54,6 @@
#include <util/translation.h>
#include <validation.h>
#include <validationinterface.h>
-#include <warnings.h>
#include <config/bitcoin-config.h> // IWYU pragma: keep
diff --git a/src/node/kernel_notifications.cpp b/src/node/kernel_notifications.cpp
index 1f07014ee2..1900ac3117 100644
--- a/src/node/kernel_notifications.cpp
+++ b/src/node/kernel_notifications.cpp
@@ -13,12 +13,12 @@
#include <logging.h>
#include <node/abort.h>
#include <node/interface_ui.h>
+#include <node/warnings.h>
#include <util/check.h>
#include <util/signalinterrupt.h>
#include <util/strencodings.h>
#include <util/string.h>
#include <util/translation.h>
-#include <warnings.h>
#include <cstdint>
#include <string>
@@ -49,7 +49,7 @@ static void AlertNotify(const std::string& strMessage)
static void DoWarning(const bilingual_str& warning)
{
static bool fWarned = false;
- SetMiscWarning(warning);
+ node::SetMiscWarning(warning);
if (!fWarned) {
AlertNotify(warning.original);
fWarned = true;
diff --git a/src/node/timeoffsets.cpp b/src/node/timeoffsets.cpp
index 62f527be8a..17ee44a92c 100644
--- a/src/node/timeoffsets.cpp
+++ b/src/node/timeoffsets.cpp
@@ -5,11 +5,11 @@
#include <logging.h>
#include <node/interface_ui.h>
#include <node/timeoffsets.h>
+#include <node/warnings.h>
#include <sync.h>
#include <tinyformat.h>
#include <util/time.h>
#include <util/translation.h>
-#include <warnings.h>
#include <algorithm>
#include <chrono>
@@ -49,7 +49,7 @@ bool TimeOffsets::WarnIfOutOfSync() const
// when median == std::numeric_limits<int64_t>::min(), calling std::chrono::abs is UB
auto median{std::max(Median(), std::chrono::seconds(std::numeric_limits<int64_t>::min() + 1))};
if (std::chrono::abs(median) <= WARN_THRESHOLD) {
- SetMedianTimeOffsetWarning(std::nullopt);
+ node::SetMedianTimeOffsetWarning(std::nullopt);
uiInterface.NotifyAlertChanged();
return false;
}
@@ -63,7 +63,7 @@ bool TimeOffsets::WarnIfOutOfSync() const
"RPC methods to get more info."
), Ticks<std::chrono::minutes>(WARN_THRESHOLD))};
LogWarning("%s\n", msg.original);
- SetMedianTimeOffsetWarning(msg);
+ node::SetMedianTimeOffsetWarning(msg);
uiInterface.NotifyAlertChanged();
return true;
}
diff --git a/src/node/warnings.cpp b/src/node/warnings.cpp
new file mode 100644
index 0000000000..9d2239e64a
--- /dev/null
+++ b/src/node/warnings.cpp
@@ -0,0 +1,82 @@
+// Copyright (c) 2009-2010 Satoshi Nakamoto
+// Copyright (c) 2009-2022 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 <config/bitcoin-config.h> // IWYU pragma: keep
+
+#include <node/warnings.h>
+
+#include <common/system.h>
+#include <sync.h>
+#include <univalue.h>
+#include <util/translation.h>
+
+#include <optional>
+#include <vector>
+
+static GlobalMutex g_warnings_mutex;
+static bilingual_str g_misc_warnings GUARDED_BY(g_warnings_mutex);
+static bool fLargeWorkInvalidChainFound GUARDED_BY(g_warnings_mutex) = false;
+static std::optional<bilingual_str> g_timeoffset_warning GUARDED_BY(g_warnings_mutex){};
+
+namespace node {
+void SetMiscWarning(const bilingual_str& warning)
+{
+ LOCK(g_warnings_mutex);
+ g_misc_warnings = warning;
+}
+
+void SetfLargeWorkInvalidChainFound(bool flag)
+{
+ LOCK(g_warnings_mutex);
+ fLargeWorkInvalidChainFound = flag;
+}
+
+void SetMedianTimeOffsetWarning(std::optional<bilingual_str> warning)
+{
+ LOCK(g_warnings_mutex);
+ g_timeoffset_warning = warning;
+}
+
+std::vector<bilingual_str> GetWarnings()
+{
+ std::vector<bilingual_str> warnings;
+
+ LOCK(g_warnings_mutex);
+
+ // Pre-release build warning
+ if (!CLIENT_VERSION_IS_RELEASE) {
+ warnings.emplace_back(_("This is a pre-release test build - use at your own risk - do not use for mining or merchant applications"));
+ }
+
+ // Misc warnings like out of disk space and clock is wrong
+ if (!g_misc_warnings.empty()) {
+ warnings.emplace_back(g_misc_warnings);
+ }
+
+ if (fLargeWorkInvalidChainFound) {
+ warnings.emplace_back(_("Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade."));
+ }
+
+ if (g_timeoffset_warning) {
+ warnings.emplace_back(g_timeoffset_warning.value());
+ }
+
+ return warnings;
+}
+
+UniValue GetWarningsForRpc(bool use_deprecated)
+{
+ if (use_deprecated) {
+ const auto all_warnings{GetWarnings()};
+ return all_warnings.empty() ? "" : all_warnings.back().original;
+ }
+
+ UniValue warnings{UniValue::VARR};
+ for (auto&& warning : GetWarnings()) {
+ warnings.push_back(std::move(warning.original));
+ }
+ return warnings;
+}
+} // namespace node
diff --git a/src/node/warnings.h b/src/node/warnings.h
new file mode 100644
index 0000000000..7766f1dbc9
--- /dev/null
+++ b/src/node/warnings.h
@@ -0,0 +1,31 @@
+// Copyright (c) 2009-2010 Satoshi Nakamoto
+// Copyright (c) 2009-2021 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_WARNINGS_H
+#define BITCOIN_NODE_WARNINGS_H
+
+#include <optional>
+#include <string>
+#include <vector>
+
+class UniValue;
+struct bilingual_str;
+
+namespace node {
+void SetMiscWarning(const bilingual_str& warning);
+void SetfLargeWorkInvalidChainFound(bool flag);
+/** Pass std::nullopt to disable the warning */
+void SetMedianTimeOffsetWarning(std::optional<bilingual_str> warning);
+/** Return potential problems detected by the node. */
+std::vector<bilingual_str> GetWarnings();
+/**
+ * RPC helper function that wraps GetWarnings. Returns a UniValue::VSTR
+ * with the latest warning if use_deprecated is set to true, or a
+ * UniValue::VARR with all warnings otherwise.
+ */
+UniValue GetWarningsForRpc(bool use_deprecated);
+} // namespace node
+
+#endif // BITCOIN_NODE_WARNINGS_H