mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-26 15:36:19 +01:00
move-only: move warnings from common to node
Since rpc/util.cpp is in common, also move GetNodeWarnings() to node::GetWarningsForRPC()
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
82
src/node/warnings.cpp
Normal file
82
src/node/warnings.cpp
Normal file
@@ -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
|
||||
31
src/node/warnings.h
Normal file
31
src/node/warnings.h
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user