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:
14 files changed
+50
-39
No files matched your search
+2
-2
@@ -239,6 +239,7 @@ BITCOIN_CORE_H = \
|
|||||||
node/types.h \
|
node/types.h \
|
||||||
node/utxo_snapshot.h \
|
node/utxo_snapshot.h \
|
||||||
node/validation_cache_args.h \
|
node/validation_cache_args.h \
|
||||||
|
node/warnings.h \
|
||||||
noui.h \
|
noui.h \
|
||||||
outputtype.h \
|
outputtype.h \
|
||||||
policy/v3_policy.h \
|
policy/v3_policy.h \
|
||||||
@@ -367,7 +368,6 @@ BITCOIN_CORE_H = \
|
|||||||
wallet/wallettool.h \
|
wallet/wallettool.h \
|
||||||
wallet/walletutil.h \
|
wallet/walletutil.h \
|
||||||
walletinitinterface.h \
|
walletinitinterface.h \
|
||||||
warnings.h \
|
|
||||||
zmq/zmqabstractnotifier.h \
|
zmq/zmqabstractnotifier.h \
|
||||||
zmq/zmqnotificationinterface.h \
|
zmq/zmqnotificationinterface.h \
|
||||||
zmq/zmqpublishnotifier.h \
|
zmq/zmqpublishnotifier.h \
|
||||||
@@ -444,6 +444,7 @@ libbitcoin_node_a_SOURCES = \
|
|||||||
node/txreconciliation.cpp \
|
node/txreconciliation.cpp \
|
||||||
node/utxo_snapshot.cpp \
|
node/utxo_snapshot.cpp \
|
||||||
node/validation_cache_args.cpp \
|
node/validation_cache_args.cpp \
|
||||||
|
node/warnings.cpp \
|
||||||
noui.cpp \
|
noui.cpp \
|
||||||
policy/v3_policy.cpp \
|
policy/v3_policy.cpp \
|
||||||
policy/fees.cpp \
|
policy/fees.cpp \
|
||||||
@@ -721,7 +722,6 @@ libbitcoin_common_a_SOURCES = \
|
|||||||
script/sign.cpp \
|
script/sign.cpp \
|
||||||
script/signingprovider.cpp \
|
script/signingprovider.cpp \
|
||||||
script/solver.cpp \
|
script/solver.cpp \
|
||||||
warnings.cpp \
|
|
||||||
$(BITCOIN_CORE_H)
|
$(BITCOIN_CORE_H)
|
||||||
#
|
#
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
#include <util/thread.h>
|
#include <util/thread.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <validation.h> // For g_chainman
|
#include <validation.h> // For g_chainman
|
||||||
#include <warnings.h>
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|||||||
+1
-1
@@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
#include <node/interface_ui.h>
|
#include <node/interface_ui.h>
|
||||||
|
#include <node/warnings.h>
|
||||||
#include <util/signalinterrupt.h>
|
#include <util/signalinterrupt.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <warnings.h>
|
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|||||||
@@ -32,6 +32,7 @@
|
|||||||
#include <node/mini_miner.h>
|
#include <node/mini_miner.h>
|
||||||
#include <node/transaction.h>
|
#include <node/transaction.h>
|
||||||
#include <node/types.h>
|
#include <node/types.h>
|
||||||
|
#include <node/warnings.h>
|
||||||
#include <policy/feerate.h>
|
#include <policy/feerate.h>
|
||||||
#include <policy/fees.h>
|
#include <policy/fees.h>
|
||||||
#include <policy/policy.h>
|
#include <policy/policy.h>
|
||||||
@@ -53,7 +54,6 @@
|
|||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <validation.h>
|
#include <validation.h>
|
||||||
#include <validationinterface.h>
|
#include <validationinterface.h>
|
||||||
#include <warnings.h>
|
|
||||||
|
|
||||||
#include <config/bitcoin-config.h> // IWYU pragma: keep
|
#include <config/bitcoin-config.h> // IWYU pragma: keep
|
||||||
|
|
||||||
|
|||||||
@@ -13,12 +13,12 @@
|
|||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
#include <node/abort.h>
|
#include <node/abort.h>
|
||||||
#include <node/interface_ui.h>
|
#include <node/interface_ui.h>
|
||||||
|
#include <node/warnings.h>
|
||||||
#include <util/check.h>
|
#include <util/check.h>
|
||||||
#include <util/signalinterrupt.h>
|
#include <util/signalinterrupt.h>
|
||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
#include <util/string.h>
|
#include <util/string.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <warnings.h>
|
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -49,7 +49,7 @@ static void AlertNotify(const std::string& strMessage)
|
|||||||
static void DoWarning(const bilingual_str& warning)
|
static void DoWarning(const bilingual_str& warning)
|
||||||
{
|
{
|
||||||
static bool fWarned = false;
|
static bool fWarned = false;
|
||||||
SetMiscWarning(warning);
|
node::SetMiscWarning(warning);
|
||||||
if (!fWarned) {
|
if (!fWarned) {
|
||||||
AlertNotify(warning.original);
|
AlertNotify(warning.original);
|
||||||
fWarned = true;
|
fWarned = true;
|
||||||
|
|||||||
@@ -5,11 +5,11 @@
|
|||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
#include <node/interface_ui.h>
|
#include <node/interface_ui.h>
|
||||||
#include <node/timeoffsets.h>
|
#include <node/timeoffsets.h>
|
||||||
|
#include <node/warnings.h>
|
||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
#include <tinyformat.h>
|
#include <tinyformat.h>
|
||||||
#include <util/time.h>
|
#include <util/time.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <warnings.h>
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
@@ -49,7 +49,7 @@ bool TimeOffsets::WarnIfOutOfSync() const
|
|||||||
// when median == std::numeric_limits<int64_t>::min(), calling std::chrono::abs is UB
|
// 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))};
|
auto median{std::max(Median(), std::chrono::seconds(std::numeric_limits<int64_t>::min() + 1))};
|
||||||
if (std::chrono::abs(median) <= WARN_THRESHOLD) {
|
if (std::chrono::abs(median) <= WARN_THRESHOLD) {
|
||||||
SetMedianTimeOffsetWarning(std::nullopt);
|
node::SetMedianTimeOffsetWarning(std::nullopt);
|
||||||
uiInterface.NotifyAlertChanged();
|
uiInterface.NotifyAlertChanged();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ bool TimeOffsets::WarnIfOutOfSync() const
|
|||||||
"RPC methods to get more info."
|
"RPC methods to get more info."
|
||||||
), Ticks<std::chrono::minutes>(WARN_THRESHOLD))};
|
), Ticks<std::chrono::minutes>(WARN_THRESHOLD))};
|
||||||
LogWarning("%s\n", msg.original);
|
LogWarning("%s\n", msg.original);
|
||||||
SetMedianTimeOffsetWarning(msg);
|
node::SetMedianTimeOffsetWarning(msg);
|
||||||
uiInterface.NotifyAlertChanged();
|
uiInterface.NotifyAlertChanged();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -5,10 +5,11 @@
|
|||||||
|
|
||||||
#include <config/bitcoin-config.h> // IWYU pragma: keep
|
#include <config/bitcoin-config.h> // IWYU pragma: keep
|
||||||
|
|
||||||
#include <warnings.h>
|
#include <node/warnings.h>
|
||||||
|
|
||||||
#include <common/system.h>
|
#include <common/system.h>
|
||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
|
#include <univalue.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
@@ -19,6 +20,7 @@ static bilingual_str g_misc_warnings GUARDED_BY(g_warnings_mutex);
|
|||||||
static bool fLargeWorkInvalidChainFound GUARDED_BY(g_warnings_mutex) = false;
|
static bool fLargeWorkInvalidChainFound GUARDED_BY(g_warnings_mutex) = false;
|
||||||
static std::optional<bilingual_str> g_timeoffset_warning GUARDED_BY(g_warnings_mutex){};
|
static std::optional<bilingual_str> g_timeoffset_warning GUARDED_BY(g_warnings_mutex){};
|
||||||
|
|
||||||
|
namespace node {
|
||||||
void SetMiscWarning(const bilingual_str& warning)
|
void SetMiscWarning(const bilingual_str& warning)
|
||||||
{
|
{
|
||||||
LOCK(g_warnings_mutex);
|
LOCK(g_warnings_mutex);
|
||||||
@@ -63,3 +65,18 @@ std::vector<bilingual_str> GetWarnings()
|
|||||||
|
|
||||||
return warnings;
|
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
|
||||||
@@ -3,20 +3,29 @@
|
|||||||
// Distributed under the MIT software license, see the accompanying
|
// Distributed under the MIT software license, see the accompanying
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
#ifndef BITCOIN_WARNINGS_H
|
#ifndef BITCOIN_NODE_WARNINGS_H
|
||||||
#define BITCOIN_WARNINGS_H
|
#define BITCOIN_NODE_WARNINGS_H
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
class UniValue;
|
||||||
struct bilingual_str;
|
struct bilingual_str;
|
||||||
|
|
||||||
|
namespace node {
|
||||||
void SetMiscWarning(const bilingual_str& warning);
|
void SetMiscWarning(const bilingual_str& warning);
|
||||||
void SetfLargeWorkInvalidChainFound(bool flag);
|
void SetfLargeWorkInvalidChainFound(bool flag);
|
||||||
/** Pass std::nullopt to disable the warning */
|
/** Pass std::nullopt to disable the warning */
|
||||||
void SetMedianTimeOffsetWarning(std::optional<bilingual_str> warning);
|
void SetMedianTimeOffsetWarning(std::optional<bilingual_str> warning);
|
||||||
/** Return potential problems detected by the node. */
|
/** Return potential problems detected by the node. */
|
||||||
std::vector<bilingual_str> GetWarnings();
|
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_WARNINGS_H
|
#endif // BITCOIN_NODE_WARNINGS_H
|
||||||
@@ -29,6 +29,7 @@
|
|||||||
#include <node/context.h>
|
#include <node/context.h>
|
||||||
#include <node/transaction.h>
|
#include <node/transaction.h>
|
||||||
#include <node/utxo_snapshot.h>
|
#include <node/utxo_snapshot.h>
|
||||||
|
#include <node/warnings.h>
|
||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
#include <rpc/server.h>
|
#include <rpc/server.h>
|
||||||
#include <rpc/server_util.h>
|
#include <rpc/server_util.h>
|
||||||
@@ -1308,7 +1309,7 @@ RPCHelpMan getblockchaininfo()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.pushKV("warnings", GetNodeWarnings(IsDeprecatedRPCEnabled("warnings")));
|
obj.pushKV("warnings", node::GetWarningsForRpc(IsDeprecatedRPCEnabled("warnings")));
|
||||||
return obj;
|
return obj;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
+2
-1
@@ -20,6 +20,7 @@
|
|||||||
#include <net.h>
|
#include <net.h>
|
||||||
#include <node/context.h>
|
#include <node/context.h>
|
||||||
#include <node/miner.h>
|
#include <node/miner.h>
|
||||||
|
#include <node/warnings.h>
|
||||||
#include <pow.h>
|
#include <pow.h>
|
||||||
#include <rpc/blockchain.h>
|
#include <rpc/blockchain.h>
|
||||||
#include <rpc/mining.h>
|
#include <rpc/mining.h>
|
||||||
@@ -454,7 +455,7 @@ static RPCHelpMan getmininginfo()
|
|||||||
obj.pushKV("networkhashps", getnetworkhashps().HandleRequest(request));
|
obj.pushKV("networkhashps", getnetworkhashps().HandleRequest(request));
|
||||||
obj.pushKV("pooledtx", (uint64_t)mempool.size());
|
obj.pushKV("pooledtx", (uint64_t)mempool.size());
|
||||||
obj.pushKV("chain", chainman.GetParams().GetChainTypeString());
|
obj.pushKV("chain", chainman.GetParams().GetChainTypeString());
|
||||||
obj.pushKV("warnings", GetNodeWarnings(IsDeprecatedRPCEnabled("warnings")));
|
obj.pushKV("warnings", node::GetWarningsForRpc(IsDeprecatedRPCEnabled("warnings")));
|
||||||
return obj;
|
return obj;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
+2
-1
@@ -16,6 +16,7 @@
|
|||||||
#include <netbase.h>
|
#include <netbase.h>
|
||||||
#include <node/context.h>
|
#include <node/context.h>
|
||||||
#include <node/protocol_version.h>
|
#include <node/protocol_version.h>
|
||||||
|
#include <node/warnings.h>
|
||||||
#include <policy/settings.h>
|
#include <policy/settings.h>
|
||||||
#include <protocol.h>
|
#include <protocol.h>
|
||||||
#include <rpc/blockchain.h>
|
#include <rpc/blockchain.h>
|
||||||
@@ -715,7 +716,7 @@ static RPCHelpMan getnetworkinfo()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
obj.pushKV("localaddresses", std::move(localAddresses));
|
obj.pushKV("localaddresses", std::move(localAddresses));
|
||||||
obj.pushKV("warnings", GetNodeWarnings(IsDeprecatedRPCEnabled("warnings")));
|
obj.pushKV("warnings", node::GetWarningsForRpc(IsDeprecatedRPCEnabled("warnings")));
|
||||||
return obj;
|
return obj;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
+2
-17
@@ -5,17 +5,17 @@
|
|||||||
#include <config/bitcoin-config.h> // IWYU pragma: keep
|
#include <config/bitcoin-config.h> // IWYU pragma: keep
|
||||||
|
|
||||||
#include <clientversion.h>
|
#include <clientversion.h>
|
||||||
#include <core_io.h>
|
|
||||||
#include <common/args.h>
|
#include <common/args.h>
|
||||||
#include <common/messages.h>
|
#include <common/messages.h>
|
||||||
#include <common/types.h>
|
#include <common/types.h>
|
||||||
#include <consensus/amount.h>
|
#include <consensus/amount.h>
|
||||||
#include <script/interpreter.h>
|
#include <core_io.h>
|
||||||
#include <key_io.h>
|
#include <key_io.h>
|
||||||
#include <node/types.h>
|
#include <node/types.h>
|
||||||
#include <outputtype.h>
|
#include <outputtype.h>
|
||||||
#include <rpc/util.h>
|
#include <rpc/util.h>
|
||||||
#include <script/descriptor.h>
|
#include <script/descriptor.h>
|
||||||
|
#include <script/interpreter.h>
|
||||||
#include <script/signingprovider.h>
|
#include <script/signingprovider.h>
|
||||||
#include <script/solver.h>
|
#include <script/solver.h>
|
||||||
#include <tinyformat.h>
|
#include <tinyformat.h>
|
||||||
@@ -25,7 +25,6 @@
|
|||||||
#include <util/strencodings.h>
|
#include <util/strencodings.h>
|
||||||
#include <util/string.h>
|
#include <util/string.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <warnings.h>
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
@@ -1382,17 +1381,3 @@ void PushWarnings(const std::vector<bilingual_str>& warnings, UniValue& obj)
|
|||||||
if (warnings.empty()) return;
|
if (warnings.empty()) return;
|
||||||
obj.pushKV("warnings", BilingualStringsToUniValue(warnings));
|
obj.pushKV("warnings", BilingualStringsToUniValue(warnings));
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue GetNodeWarnings(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;
|
|
||||||
}
|
|
||||||
@@ -503,6 +503,4 @@ private:
|
|||||||
void PushWarnings(const UniValue& warnings, UniValue& obj);
|
void PushWarnings(const UniValue& warnings, UniValue& obj);
|
||||||
void PushWarnings(const std::vector<bilingual_str>& warnings, UniValue& obj);
|
void PushWarnings(const std::vector<bilingual_str>& warnings, UniValue& obj);
|
||||||
|
|
||||||
UniValue GetNodeWarnings(bool use_deprecated);
|
|
||||||
|
|
||||||
#endif // BITCOIN_RPC_UTIL_H
|
#endif // BITCOIN_RPC_UTIL_H
|
||||||
+3
-3
@@ -31,6 +31,7 @@
|
|||||||
#include <logging/timer.h>
|
#include <logging/timer.h>
|
||||||
#include <node/blockstorage.h>
|
#include <node/blockstorage.h>
|
||||||
#include <node/utxo_snapshot.h>
|
#include <node/utxo_snapshot.h>
|
||||||
|
#include <node/warnings.h>
|
||||||
#include <policy/policy.h>
|
#include <policy/policy.h>
|
||||||
#include <policy/rbf.h>
|
#include <policy/rbf.h>
|
||||||
#include <policy/settings.h>
|
#include <policy/settings.h>
|
||||||
@@ -62,7 +63,6 @@
|
|||||||
#include <util/trace.h>
|
#include <util/trace.h>
|
||||||
#include <util/translation.h>
|
#include <util/translation.h>
|
||||||
#include <validationinterface.h>
|
#include <validationinterface.h>
|
||||||
#include <warnings.h>
|
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
@@ -1922,9 +1922,9 @@ void Chainstate::CheckForkWarningConditions()
|
|||||||
|
|
||||||
if (m_chainman.m_best_invalid && m_chainman.m_best_invalid->nChainWork > m_chain.Tip()->nChainWork + (GetBlockProof(*m_chain.Tip()) * 6)) {
|
if (m_chainman.m_best_invalid && m_chainman.m_best_invalid->nChainWork > m_chain.Tip()->nChainWork + (GetBlockProof(*m_chain.Tip()) * 6)) {
|
||||||
LogPrintf("%s: Warning: Found invalid chain at least ~6 blocks longer than our best chain.\nChain state database corruption likely.\n", __func__);
|
LogPrintf("%s: Warning: Found invalid chain at least ~6 blocks longer than our best chain.\nChain state database corruption likely.\n", __func__);
|
||||||
SetfLargeWorkInvalidChainFound(true);
|
node::SetfLargeWorkInvalidChainFound(true);
|
||||||
} else {
|
} else {
|
||||||
SetfLargeWorkInvalidChainFound(false);
|
node::SetfLargeWorkInvalidChainFound(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user