mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-12 11:19:08 -05:00
refactor: remove warnings globals
This commit is contained in:
parent
9c4b0b7ce4
commit
260f8da71a
27 changed files with 87 additions and 51 deletions
|
@ -17,6 +17,7 @@
|
||||||
#include <kernel/context.h>
|
#include <kernel/context.h>
|
||||||
#include <node/context.h>
|
#include <node/context.h>
|
||||||
#include <node/interface_ui.h>
|
#include <node/interface_ui.h>
|
||||||
|
#include <node/warnings.h>
|
||||||
#include <noui.h>
|
#include <noui.h>
|
||||||
#include <util/check.h>
|
#include <util/check.h>
|
||||||
#include <util/exception.h>
|
#include <util/exception.h>
|
||||||
|
@ -181,6 +182,8 @@ static bool AppInit(NodeContext& node)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
node.warnings = std::make_unique<node::Warnings>();
|
||||||
|
|
||||||
node.kernel = std::make_unique<kernel::Context>();
|
node.kernel = std::make_unique<kernel::Context>();
|
||||||
node.ecc_context = std::make_unique<ECC_Context>();
|
node.ecc_context = std::make_unique<ECC_Context>();
|
||||||
if (!AppInitSanityChecks(*node.kernel))
|
if (!AppInitSanityChecks(*node.kernel))
|
||||||
|
|
|
@ -30,7 +30,7 @@ template <typename... Args>
|
||||||
void BaseIndex::FatalErrorf(const char* fmt, const Args&... args)
|
void BaseIndex::FatalErrorf(const char* fmt, const Args&... args)
|
||||||
{
|
{
|
||||||
auto message = tfm::format(fmt, args...);
|
auto message = tfm::format(fmt, args...);
|
||||||
node::AbortNode(m_chain->context()->shutdown, m_chain->context()->exit_status, Untranslated(message));
|
node::AbortNode(m_chain->context()->shutdown, m_chain->context()->exit_status, Untranslated(message), m_chain->context()->warnings.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
CBlockLocator GetLocator(interfaces::Chain& chain, const uint256& block_hash)
|
CBlockLocator GetLocator(interfaces::Chain& chain, const uint256& block_hash)
|
||||||
|
|
|
@ -1486,7 +1486,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||||
|
|
||||||
// ********************************************************* Step 7: load block chain
|
// ********************************************************* Step 7: load block chain
|
||||||
|
|
||||||
node.notifications = std::make_unique<KernelNotifications>(*Assert(node.shutdown), node.exit_status);
|
node.notifications = std::make_unique<KernelNotifications>(*Assert(node.shutdown), node.exit_status, *Assert(node.warnings));
|
||||||
ReadNotificationArgs(args, *node.notifications);
|
ReadNotificationArgs(args, *node.notifications);
|
||||||
ChainstateManager::Options chainman_opts{
|
ChainstateManager::Options chainman_opts{
|
||||||
.chainparams = chainparams,
|
.chainparams = chainparams,
|
||||||
|
@ -1639,7 +1639,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||||
assert(!node.peerman);
|
assert(!node.peerman);
|
||||||
node.peerman = PeerManager::make(*node.connman, *node.addrman,
|
node.peerman = PeerManager::make(*node.connman, *node.addrman,
|
||||||
node.banman.get(), chainman,
|
node.banman.get(), chainman,
|
||||||
*node.mempool, peerman_opts);
|
*node.mempool, *node.warnings,
|
||||||
|
peerman_opts);
|
||||||
validation_signals.RegisterValidationInterface(node.peerman.get());
|
validation_signals.RegisterValidationInterface(node.peerman.get());
|
||||||
|
|
||||||
// ********************************************************* Step 8: start indexers
|
// ********************************************************* Step 8: start indexers
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include <node/blockstorage.h>
|
#include <node/blockstorage.h>
|
||||||
#include <node/timeoffsets.h>
|
#include <node/timeoffsets.h>
|
||||||
#include <node/txreconciliation.h>
|
#include <node/txreconciliation.h>
|
||||||
|
#include <node/warnings.h>
|
||||||
#include <policy/fees.h>
|
#include <policy/fees.h>
|
||||||
#include <policy/policy.h>
|
#include <policy/policy.h>
|
||||||
#include <policy/settings.h>
|
#include <policy/settings.h>
|
||||||
|
@ -489,7 +490,7 @@ class PeerManagerImpl final : public PeerManager
|
||||||
public:
|
public:
|
||||||
PeerManagerImpl(CConnman& connman, AddrMan& addrman,
|
PeerManagerImpl(CConnman& connman, AddrMan& addrman,
|
||||||
BanMan* banman, ChainstateManager& chainman,
|
BanMan* banman, ChainstateManager& chainman,
|
||||||
CTxMemPool& pool, Options opts);
|
CTxMemPool& pool, node::Warnings& warnings, Options opts);
|
||||||
|
|
||||||
/** Overridden from CValidationInterface. */
|
/** Overridden from CValidationInterface. */
|
||||||
void BlockConnected(ChainstateRole role, const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected) override
|
void BlockConnected(ChainstateRole role, const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindexConnected) override
|
||||||
|
@ -790,7 +791,8 @@ private:
|
||||||
/** Next time to check for stale tip */
|
/** Next time to check for stale tip */
|
||||||
std::chrono::seconds m_stale_tip_check_time GUARDED_BY(cs_main){0s};
|
std::chrono::seconds m_stale_tip_check_time GUARDED_BY(cs_main){0s};
|
||||||
|
|
||||||
TimeOffsets m_outbound_time_offsets;
|
node::Warnings& m_warnings;
|
||||||
|
TimeOffsets m_outbound_time_offsets{m_warnings};
|
||||||
|
|
||||||
const Options m_opts;
|
const Options m_opts;
|
||||||
|
|
||||||
|
@ -2042,14 +2044,14 @@ std::optional<std::string> PeerManagerImpl::FetchBlock(NodeId peer_id, const CBl
|
||||||
|
|
||||||
std::unique_ptr<PeerManager> PeerManager::make(CConnman& connman, AddrMan& addrman,
|
std::unique_ptr<PeerManager> PeerManager::make(CConnman& connman, AddrMan& addrman,
|
||||||
BanMan* banman, ChainstateManager& chainman,
|
BanMan* banman, ChainstateManager& chainman,
|
||||||
CTxMemPool& pool, Options opts)
|
CTxMemPool& pool, node::Warnings& warnings, Options opts)
|
||||||
{
|
{
|
||||||
return std::make_unique<PeerManagerImpl>(connman, addrman, banman, chainman, pool, opts);
|
return std::make_unique<PeerManagerImpl>(connman, addrman, banman, chainman, pool, warnings, opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
PeerManagerImpl::PeerManagerImpl(CConnman& connman, AddrMan& addrman,
|
PeerManagerImpl::PeerManagerImpl(CConnman& connman, AddrMan& addrman,
|
||||||
BanMan* banman, ChainstateManager& chainman,
|
BanMan* banman, ChainstateManager& chainman,
|
||||||
CTxMemPool& pool, Options opts)
|
CTxMemPool& pool, node::Warnings& warnings, Options opts)
|
||||||
: m_rng{opts.deterministic_rng},
|
: m_rng{opts.deterministic_rng},
|
||||||
m_fee_filter_rounder{CFeeRate{DEFAULT_MIN_RELAY_TX_FEE}, m_rng},
|
m_fee_filter_rounder{CFeeRate{DEFAULT_MIN_RELAY_TX_FEE}, m_rng},
|
||||||
m_chainparams(chainman.GetParams()),
|
m_chainparams(chainman.GetParams()),
|
||||||
|
@ -2058,6 +2060,7 @@ PeerManagerImpl::PeerManagerImpl(CConnman& connman, AddrMan& addrman,
|
||||||
m_banman(banman),
|
m_banman(banman),
|
||||||
m_chainman(chainman),
|
m_chainman(chainman),
|
||||||
m_mempool(pool),
|
m_mempool(pool),
|
||||||
|
m_warnings{warnings},
|
||||||
m_opts{opts}
|
m_opts{opts}
|
||||||
{
|
{
|
||||||
// While Erlay support is incomplete, it must be enabled explicitly via -txreconciliation.
|
// While Erlay support is incomplete, it must be enabled explicitly via -txreconciliation.
|
||||||
|
|
|
@ -16,6 +16,10 @@ class CChainParams;
|
||||||
class CTxMemPool;
|
class CTxMemPool;
|
||||||
class ChainstateManager;
|
class ChainstateManager;
|
||||||
|
|
||||||
|
namespace node {
|
||||||
|
class Warnings;
|
||||||
|
} // namespace node
|
||||||
|
|
||||||
/** Whether transaction reconciliation protocol should be enabled by default. */
|
/** Whether transaction reconciliation protocol should be enabled by default. */
|
||||||
static constexpr bool DEFAULT_TXRECONCILIATION_ENABLE{false};
|
static constexpr bool DEFAULT_TXRECONCILIATION_ENABLE{false};
|
||||||
/** Default for -maxorphantx, maximum number of orphan transactions kept in memory */
|
/** Default for -maxorphantx, maximum number of orphan transactions kept in memory */
|
||||||
|
@ -73,7 +77,7 @@ public:
|
||||||
|
|
||||||
static std::unique_ptr<PeerManager> make(CConnman& connman, AddrMan& addrman,
|
static std::unique_ptr<PeerManager> make(CConnman& connman, AddrMan& addrman,
|
||||||
BanMan* banman, ChainstateManager& chainman,
|
BanMan* banman, ChainstateManager& chainman,
|
||||||
CTxMemPool& pool, Options opts);
|
CTxMemPool& pool, node::Warnings& warnings, Options opts);
|
||||||
virtual ~PeerManager() { }
|
virtual ~PeerManager() { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -15,9 +15,9 @@
|
||||||
|
|
||||||
namespace node {
|
namespace node {
|
||||||
|
|
||||||
void AbortNode(util::SignalInterrupt* shutdown, std::atomic<int>& exit_status, const bilingual_str& message)
|
void AbortNode(util::SignalInterrupt* shutdown, std::atomic<int>& exit_status, const bilingual_str& message, node::Warnings* warnings)
|
||||||
{
|
{
|
||||||
g_warnings.Set(Warning::FATAL_INTERNAL_ERROR, message);
|
if (warnings) warnings->Set(Warning::FATAL_INTERNAL_ERROR, message);
|
||||||
InitError(_("A fatal internal error occurred, see debug.log for details: ") + message);
|
InitError(_("A fatal internal error occurred, see debug.log for details: ") + message);
|
||||||
exit_status.store(EXIT_FAILURE);
|
exit_status.store(EXIT_FAILURE);
|
||||||
if (shutdown && !(*shutdown)()) {
|
if (shutdown && !(*shutdown)()) {
|
||||||
|
|
|
@ -14,7 +14,8 @@ class SignalInterrupt;
|
||||||
} // namespace util
|
} // namespace util
|
||||||
|
|
||||||
namespace node {
|
namespace node {
|
||||||
void AbortNode(util::SignalInterrupt* shutdown, std::atomic<int>& exit_status, const bilingual_str& message);
|
class Warnings;
|
||||||
|
void AbortNode(util::SignalInterrupt* shutdown, std::atomic<int>& exit_status, const bilingual_str& message, node::Warnings* warnings);
|
||||||
} // namespace node
|
} // namespace node
|
||||||
|
|
||||||
#endif // BITCOIN_NODE_ABORT_H
|
#endif // BITCOIN_NODE_ABORT_H
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <net_processing.h>
|
#include <net_processing.h>
|
||||||
#include <netgroup.h>
|
#include <netgroup.h>
|
||||||
#include <node/kernel_notifications.h>
|
#include <node/kernel_notifications.h>
|
||||||
|
#include <node/warnings.h>
|
||||||
#include <policy/fees.h>
|
#include <policy/fees.h>
|
||||||
#include <scheduler.h>
|
#include <scheduler.h>
|
||||||
#include <txmempool.h>
|
#include <txmempool.h>
|
||||||
|
|
|
@ -39,6 +39,7 @@ class SignalInterrupt;
|
||||||
|
|
||||||
namespace node {
|
namespace node {
|
||||||
class KernelNotifications;
|
class KernelNotifications;
|
||||||
|
class Warnings;
|
||||||
|
|
||||||
//! NodeContext struct containing references to chain state and connection
|
//! NodeContext struct containing references to chain state and connection
|
||||||
//! state.
|
//! state.
|
||||||
|
@ -81,6 +82,8 @@ struct NodeContext {
|
||||||
//! Issues calls about blocks and transactions
|
//! Issues calls about blocks and transactions
|
||||||
std::unique_ptr<ValidationSignals> validation_signals;
|
std::unique_ptr<ValidationSignals> validation_signals;
|
||||||
std::atomic<int> exit_status{EXIT_SUCCESS};
|
std::atomic<int> exit_status{EXIT_SUCCESS};
|
||||||
|
//! Manages all the node warnings
|
||||||
|
std::unique_ptr<node::Warnings> warnings;
|
||||||
|
|
||||||
//! Declare default constructor and destructor that are not inline, so code
|
//! Declare default constructor and destructor that are not inline, so code
|
||||||
//! instantiating the NodeContext struct doesn't need to #include class
|
//! instantiating the NodeContext struct doesn't need to #include class
|
||||||
|
|
|
@ -93,7 +93,7 @@ public:
|
||||||
explicit NodeImpl(NodeContext& context) { setContext(&context); }
|
explicit NodeImpl(NodeContext& context) { setContext(&context); }
|
||||||
void initLogging() override { InitLogging(args()); }
|
void initLogging() override { InitLogging(args()); }
|
||||||
void initParameterInteraction() override { InitParameterInteraction(args()); }
|
void initParameterInteraction() override { InitParameterInteraction(args()); }
|
||||||
bilingual_str getWarnings() override { return Join(node::g_warnings.GetMessages(), Untranslated("<hr />")); }
|
bilingual_str getWarnings() override { return Join(Assert(m_context->warnings)->GetMessages(), Untranslated("<hr />")); }
|
||||||
int getExitStatus() override { return Assert(m_context)->exit_status.load(); }
|
int getExitStatus() override { return Assert(m_context)->exit_status.load(); }
|
||||||
uint32_t getLogCategories() override { return LogInstance().GetCategoryMask(); }
|
uint32_t getLogCategories() override { return LogInstance().GetCategoryMask(); }
|
||||||
bool baseInitialize() override
|
bool baseInitialize() override
|
||||||
|
@ -101,6 +101,7 @@ public:
|
||||||
if (!AppInitBasicSetup(args(), Assert(context())->exit_status)) return false;
|
if (!AppInitBasicSetup(args(), Assert(context())->exit_status)) return false;
|
||||||
if (!AppInitParameterInteraction(args())) return false;
|
if (!AppInitParameterInteraction(args())) return false;
|
||||||
|
|
||||||
|
m_context->warnings = std::make_unique<node::Warnings>();
|
||||||
m_context->kernel = std::make_unique<kernel::Context>();
|
m_context->kernel = std::make_unique<kernel::Context>();
|
||||||
m_context->ecc_context = std::make_unique<ECC_Context>();
|
m_context->ecc_context = std::make_unique<ECC_Context>();
|
||||||
if (!AppInitSanityChecks(*m_context->kernel)) return false;
|
if (!AppInitSanityChecks(*m_context->kernel)) return false;
|
||||||
|
|
|
@ -72,25 +72,25 @@ void KernelNotifications::progress(const bilingual_str& title, int progress_perc
|
||||||
|
|
||||||
void KernelNotifications::warningSet(kernel::Warning id, const bilingual_str& message)
|
void KernelNotifications::warningSet(kernel::Warning id, const bilingual_str& message)
|
||||||
{
|
{
|
||||||
if (node::g_warnings.Set(id, message)) {
|
if (m_warnings.Set(id, message)) {
|
||||||
AlertNotify(message.original);
|
AlertNotify(message.original);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void KernelNotifications::warningUnset(kernel::Warning id)
|
void KernelNotifications::warningUnset(kernel::Warning id)
|
||||||
{
|
{
|
||||||
g_warnings.Unset(id);
|
m_warnings.Unset(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KernelNotifications::flushError(const bilingual_str& message)
|
void KernelNotifications::flushError(const bilingual_str& message)
|
||||||
{
|
{
|
||||||
AbortNode(&m_shutdown, m_exit_status, message);
|
AbortNode(&m_shutdown, m_exit_status, message, &m_warnings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KernelNotifications::fatalError(const bilingual_str& message)
|
void KernelNotifications::fatalError(const bilingual_str& message)
|
||||||
{
|
{
|
||||||
node::AbortNode(m_shutdown_on_fatal_error ? &m_shutdown : nullptr,
|
node::AbortNode(m_shutdown_on_fatal_error ? &m_shutdown : nullptr,
|
||||||
m_exit_status, message);
|
m_exit_status, message, &m_warnings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ReadNotificationArgs(const ArgsManager& args, KernelNotifications& notifications)
|
void ReadNotificationArgs(const ArgsManager& args, KernelNotifications& notifications)
|
||||||
|
|
|
@ -25,12 +25,14 @@ class SignalInterrupt;
|
||||||
|
|
||||||
namespace node {
|
namespace node {
|
||||||
|
|
||||||
|
class Warnings;
|
||||||
static constexpr int DEFAULT_STOPATHEIGHT{0};
|
static constexpr int DEFAULT_STOPATHEIGHT{0};
|
||||||
|
|
||||||
class KernelNotifications : public kernel::Notifications
|
class KernelNotifications : public kernel::Notifications
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
KernelNotifications(util::SignalInterrupt& shutdown, std::atomic<int>& exit_status) : m_shutdown(shutdown), m_exit_status{exit_status} {}
|
KernelNotifications(util::SignalInterrupt& shutdown, std::atomic<int>& exit_status, node::Warnings& warnings)
|
||||||
|
: m_shutdown(shutdown), m_exit_status{exit_status}, m_warnings{warnings} {}
|
||||||
|
|
||||||
[[nodiscard]] kernel::InterruptResult blockTip(SynchronizationState state, CBlockIndex& index) override;
|
[[nodiscard]] kernel::InterruptResult blockTip(SynchronizationState state, CBlockIndex& index) override;
|
||||||
|
|
||||||
|
@ -53,6 +55,7 @@ public:
|
||||||
private:
|
private:
|
||||||
util::SignalInterrupt& m_shutdown;
|
util::SignalInterrupt& m_shutdown;
|
||||||
std::atomic<int>& m_exit_status;
|
std::atomic<int>& m_exit_status;
|
||||||
|
node::Warnings& m_warnings;
|
||||||
};
|
};
|
||||||
|
|
||||||
void ReadNotificationArgs(const ArgsManager& args, KernelNotifications& notifications);
|
void ReadNotificationArgs(const ArgsManager& args, KernelNotifications& notifications);
|
||||||
|
|
|
@ -48,7 +48,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) {
|
||||||
node::g_warnings.Unset(node::Warning::CLOCK_OUT_OF_SYNC);
|
m_warnings.Unset(node::Warning::CLOCK_OUT_OF_SYNC);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,6 +61,6 @@ 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);
|
||||||
node::g_warnings.Set(node::Warning::CLOCK_OUT_OF_SYNC, msg);
|
m_warnings.Set(node::Warning::CLOCK_OUT_OF_SYNC, msg);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,16 @@
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
|
||||||
|
namespace node {
|
||||||
|
class Warnings;
|
||||||
|
} // namespace node
|
||||||
|
|
||||||
class TimeOffsets
|
class TimeOffsets
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
TimeOffsets(node::Warnings& warnings) : m_warnings{warnings} {}
|
||||||
|
|
||||||
|
private:
|
||||||
//! Maximum number of timeoffsets stored.
|
//! Maximum number of timeoffsets stored.
|
||||||
static constexpr size_t MAX_SIZE{50};
|
static constexpr size_t MAX_SIZE{50};
|
||||||
//! Minimum difference between system and network time for a warning to be raised.
|
//! Minimum difference between system and network time for a warning to be raised.
|
||||||
|
@ -23,6 +31,8 @@ class TimeOffsets
|
||||||
* positive offset means our peer's clock is ahead of our local clock. */
|
* positive offset means our peer's clock is ahead of our local clock. */
|
||||||
std::deque<std::chrono::seconds> m_offsets GUARDED_BY(m_mutex){};
|
std::deque<std::chrono::seconds> m_offsets GUARDED_BY(m_mutex){};
|
||||||
|
|
||||||
|
node::Warnings& m_warnings;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/** Add a new time offset sample. */
|
/** Add a new time offset sample. */
|
||||||
void Add(std::chrono::seconds offset) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
|
void Add(std::chrono::seconds offset) EXCLUSIVE_LOCKS_REQUIRED(!m_mutex);
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace node {
|
namespace node {
|
||||||
Warnings g_warnings;
|
|
||||||
|
|
||||||
Warnings::Warnings()
|
Warnings::Warnings()
|
||||||
{
|
{
|
||||||
// Pre-release build warning
|
// Pre-release build warning
|
||||||
|
@ -54,17 +52,17 @@ std::vector<bilingual_str> Warnings::GetMessages() const
|
||||||
return messages;
|
return messages;
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue GetWarningsForRpc(bool use_deprecated)
|
UniValue GetWarningsForRpc(const Warnings& warnings, bool use_deprecated)
|
||||||
{
|
{
|
||||||
if (use_deprecated) {
|
if (use_deprecated) {
|
||||||
const auto all_warnings{g_warnings.GetMessages()};
|
const auto all_messages{warnings.GetMessages()};
|
||||||
return all_warnings.empty() ? "" : all_warnings.back().original;
|
return all_messages.empty() ? "" : all_messages.back().original;
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue warnings{UniValue::VARR};
|
UniValue messages{UniValue::VARR};
|
||||||
for (auto&& warning : g_warnings.GetMessages()) {
|
for (auto&& message : warnings.GetMessages()) {
|
||||||
warnings.push_back(std::move(warning.original));
|
messages.push_back(std::move(message.original));
|
||||||
}
|
}
|
||||||
return warnings;
|
return messages;
|
||||||
}
|
}
|
||||||
} // namespace node
|
} // namespace node
|
||||||
|
|
|
@ -7,13 +7,13 @@
|
||||||
#define BITCOIN_NODE_WARNINGS_H
|
#define BITCOIN_NODE_WARNINGS_H
|
||||||
|
|
||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
|
#include <util/translation.h>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <variant>
|
#include <variant>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class UniValue;
|
class UniValue;
|
||||||
struct bilingual_str;
|
|
||||||
|
|
||||||
namespace kernel {
|
namespace kernel {
|
||||||
enum class Warning;
|
enum class Warning;
|
||||||
|
@ -79,14 +79,12 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RPC helper function that wraps g_warnings.GetMessages().
|
* RPC helper function that wraps warnings.GetMessages().
|
||||||
*
|
*
|
||||||
* Returns a UniValue::VSTR with the latest warning if use_deprecated is
|
* Returns a UniValue::VSTR with the latest warning if use_deprecated is
|
||||||
* set to true, or a UniValue::VARR with all warnings otherwise.
|
* set to true, or a UniValue::VARR with all warnings otherwise.
|
||||||
*/
|
*/
|
||||||
UniValue GetWarningsForRpc(bool use_deprecated);
|
UniValue GetWarningsForRpc(const Warnings& warnings, bool use_deprecated);
|
||||||
|
|
||||||
extern Warnings g_warnings;
|
|
||||||
} // namespace node
|
} // namespace node
|
||||||
|
|
||||||
#endif // BITCOIN_NODE_WARNINGS_H
|
#endif // BITCOIN_NODE_WARNINGS_H
|
||||||
|
|
|
@ -1309,7 +1309,8 @@ RPCHelpMan getblockchaininfo()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
obj.pushKV("warnings", node::GetWarningsForRpc(IsDeprecatedRPCEnabled("warnings")));
|
NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||||
|
obj.pushKV("warnings", node::GetWarningsForRpc(*CHECK_NONFATAL(node.warnings), IsDeprecatedRPCEnabled("warnings")));
|
||||||
return obj;
|
return obj;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -455,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", node::GetWarningsForRpc(IsDeprecatedRPCEnabled("warnings")));
|
obj.pushKV("warnings", node::GetWarningsForRpc(*CHECK_NONFATAL(node.warnings), IsDeprecatedRPCEnabled("warnings")));
|
||||||
return obj;
|
return obj;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -716,7 +716,7 @@ static RPCHelpMan getnetworkinfo()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
obj.pushKV("localaddresses", std::move(localAddresses));
|
obj.pushKV("localaddresses", std::move(localAddresses));
|
||||||
obj.pushKV("warnings", node::GetWarningsForRpc(IsDeprecatedRPCEnabled("warnings")));
|
obj.pushKV("warnings", node::GetWarningsForRpc(*CHECK_NONFATAL(node.warnings), IsDeprecatedRPCEnabled("warnings")));
|
||||||
return obj;
|
return obj;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -27,7 +27,7 @@ BOOST_FIXTURE_TEST_SUITE(blockmanager_tests, BasicTestingSetup)
|
||||||
BOOST_AUTO_TEST_CASE(blockmanager_find_block_pos)
|
BOOST_AUTO_TEST_CASE(blockmanager_find_block_pos)
|
||||||
{
|
{
|
||||||
const auto params {CreateChainParams(ArgsManager{}, ChainType::MAIN)};
|
const auto params {CreateChainParams(ArgsManager{}, ChainType::MAIN)};
|
||||||
KernelNotifications notifications{*Assert(m_node.shutdown), m_node.exit_status};
|
KernelNotifications notifications{*Assert(m_node.shutdown), m_node.exit_status, *Assert(m_node.warnings)};
|
||||||
const BlockManager::Options blockman_opts{
|
const BlockManager::Options blockman_opts{
|
||||||
.chainparams = *params,
|
.chainparams = *params,
|
||||||
.blocks_dir = m_args.GetBlocksDirPath(),
|
.blocks_dir = m_args.GetBlocksDirPath(),
|
||||||
|
@ -134,7 +134,7 @@ BOOST_FIXTURE_TEST_CASE(blockmanager_block_data_availability, TestChain100Setup)
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(blockmanager_flush_block_file)
|
BOOST_AUTO_TEST_CASE(blockmanager_flush_block_file)
|
||||||
{
|
{
|
||||||
KernelNotifications notifications{*Assert(m_node.shutdown), m_node.exit_status};
|
KernelNotifications notifications{*Assert(m_node.shutdown), m_node.exit_status, *Assert(m_node.warnings)};
|
||||||
node::BlockManager::Options blockman_opts{
|
node::BlockManager::Options blockman_opts{
|
||||||
.chainparams = Params(),
|
.chainparams = Params(),
|
||||||
.blocks_dir = m_args.GetBlocksDirPath(),
|
.blocks_dir = m_args.GetBlocksDirPath(),
|
||||||
|
|
|
@ -141,7 +141,7 @@ BOOST_AUTO_TEST_CASE(stale_tip_peer_management)
|
||||||
{
|
{
|
||||||
NodeId id{0};
|
NodeId id{0};
|
||||||
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params());
|
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params());
|
||||||
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr, *m_node.chainman, *m_node.mempool, {});
|
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr, *m_node.chainman, *m_node.mempool, *m_node.warnings, {});
|
||||||
|
|
||||||
constexpr int max_outbound_full_relay = MAX_OUTBOUND_FULL_RELAY_CONNECTIONS;
|
constexpr int max_outbound_full_relay = MAX_OUTBOUND_FULL_RELAY_CONNECTIONS;
|
||||||
CConnman::Options options;
|
CConnman::Options options;
|
||||||
|
@ -239,7 +239,7 @@ BOOST_AUTO_TEST_CASE(block_relay_only_eviction)
|
||||||
{
|
{
|
||||||
NodeId id{0};
|
NodeId id{0};
|
||||||
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params());
|
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params());
|
||||||
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr, *m_node.chainman, *m_node.mempool, {});
|
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, nullptr, *m_node.chainman, *m_node.mempool, *m_node.warnings, {});
|
||||||
|
|
||||||
constexpr int max_outbound_block_relay{MAX_BLOCK_RELAY_ONLY_CONNECTIONS};
|
constexpr int max_outbound_block_relay{MAX_BLOCK_RELAY_ONLY_CONNECTIONS};
|
||||||
constexpr int64_t MINIMUM_CONNECT_TIME{30};
|
constexpr int64_t MINIMUM_CONNECT_TIME{30};
|
||||||
|
@ -300,7 +300,7 @@ BOOST_AUTO_TEST_CASE(peer_discouragement)
|
||||||
|
|
||||||
auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
||||||
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params());
|
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params());
|
||||||
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(), *m_node.chainman, *m_node.mempool, {});
|
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(), *m_node.chainman, *m_node.mempool, *m_node.warnings, {});
|
||||||
|
|
||||||
CNetAddr tor_netaddr;
|
CNetAddr tor_netaddr;
|
||||||
BOOST_REQUIRE(
|
BOOST_REQUIRE(
|
||||||
|
@ -402,7 +402,7 @@ BOOST_AUTO_TEST_CASE(DoS_bantime)
|
||||||
|
|
||||||
auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
auto banman = std::make_unique<BanMan>(m_args.GetDataDirBase() / "banlist", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
||||||
auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params());
|
auto connman = std::make_unique<CConnman>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params());
|
||||||
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(), *m_node.chainman, *m_node.mempool, {});
|
auto peerLogic = PeerManager::make(*connman, *m_node.addrman, banman.get(), *m_node.chainman, *m_node.mempool, *m_node.warnings, {});
|
||||||
|
|
||||||
banman->ClearBanned();
|
banman->ClearBanned();
|
||||||
int64_t nStartTime = GetTime();
|
int64_t nStartTime = GetTime();
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
#include <node/timeoffsets.h>
|
#include <node/timeoffsets.h>
|
||||||
|
#include <node/warnings.h>
|
||||||
#include <test/fuzz/FuzzedDataProvider.h>
|
#include <test/fuzz/FuzzedDataProvider.h>
|
||||||
#include <test/fuzz/fuzz.h>
|
#include <test/fuzz/fuzz.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
|
@ -19,7 +20,8 @@ void initialize_timeoffsets()
|
||||||
FUZZ_TARGET(timeoffsets, .init = initialize_timeoffsets)
|
FUZZ_TARGET(timeoffsets, .init = initialize_timeoffsets)
|
||||||
{
|
{
|
||||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||||
TimeOffsets offsets{};
|
node::Warnings warnings{};
|
||||||
|
TimeOffsets offsets{warnings};
|
||||||
LIMITED_WHILE(fuzzed_data_provider.remaining_bytes() > 0, 4'000) {
|
LIMITED_WHILE(fuzzed_data_provider.remaining_bytes() > 0, 4'000) {
|
||||||
(void)offsets.Median();
|
(void)offsets.Median();
|
||||||
offsets.Add(std::chrono::seconds{fuzzed_data_provider.ConsumeIntegral<std::chrono::seconds::rep>()});
|
offsets.Add(std::chrono::seconds{fuzzed_data_provider.ConsumeIntegral<std::chrono::seconds::rep>()});
|
||||||
|
|
|
@ -84,7 +84,7 @@ static void AddPeer(NodeId& id, std::vector<CNode*>& nodes, PeerManager& peerman
|
||||||
BOOST_AUTO_TEST_CASE(test_addnode_getaddednodeinfo_and_connection_detection)
|
BOOST_AUTO_TEST_CASE(test_addnode_getaddednodeinfo_and_connection_detection)
|
||||||
{
|
{
|
||||||
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params());
|
auto connman = std::make_unique<ConnmanTestMsg>(0x1337, 0x1337, *m_node.addrman, *m_node.netgroupman, Params());
|
||||||
auto peerman = PeerManager::make(*connman, *m_node.addrman, nullptr, *m_node.chainman, *m_node.mempool, {});
|
auto peerman = PeerManager::make(*connman, *m_node.addrman, nullptr, *m_node.chainman, *m_node.mempool, *m_node.warnings, {});
|
||||||
NodeId id{0};
|
NodeId id{0};
|
||||||
std::vector<CNode*> nodes;
|
std::vector<CNode*> nodes;
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ static void mineBlock(const node::NodeContext& node, std::chrono::seconds block_
|
||||||
// Verifying when network-limited peer connections are desirable based on the node's proximity to the tip
|
// Verifying when network-limited peer connections are desirable based on the node's proximity to the tip
|
||||||
BOOST_AUTO_TEST_CASE(connections_desirable_service_flags)
|
BOOST_AUTO_TEST_CASE(connections_desirable_service_flags)
|
||||||
{
|
{
|
||||||
std::unique_ptr<PeerManager> peerman = PeerManager::make(*m_node.connman, *m_node.addrman, nullptr, *m_node.chainman, *m_node.mempool, {});
|
std::unique_ptr<PeerManager> peerman = PeerManager::make(*m_node.connman, *m_node.addrman, nullptr, *m_node.chainman, *m_node.mempool, *m_node.warnings, {});
|
||||||
auto consensus = m_node.chainman->GetParams().GetConsensus();
|
auto consensus = m_node.chainman->GetParams().GetConsensus();
|
||||||
|
|
||||||
// Check we start connecting to full nodes
|
// Check we start connecting to full nodes
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include <node/timeoffsets.h>
|
#include <node/timeoffsets.h>
|
||||||
|
#include <node/warnings.h>
|
||||||
#include <test/util/setup_common.h>
|
#include <test/util/setup_common.h>
|
||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
@ -24,7 +25,8 @@ BOOST_FIXTURE_TEST_SUITE(timeoffsets_tests, BasicTestingSetup)
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(timeoffsets)
|
BOOST_AUTO_TEST_CASE(timeoffsets)
|
||||||
{
|
{
|
||||||
TimeOffsets offsets{};
|
node::Warnings warnings{};
|
||||||
|
TimeOffsets offsets{warnings};
|
||||||
BOOST_CHECK(offsets.Median() == 0s);
|
BOOST_CHECK(offsets.Median() == 0s);
|
||||||
|
|
||||||
AddMulti(offsets, {{0s, -1s, -2s, -3s}});
|
AddMulti(offsets, {{0s, -1s, -2s, -3s}});
|
||||||
|
@ -50,7 +52,8 @@ BOOST_AUTO_TEST_CASE(timeoffsets)
|
||||||
|
|
||||||
static bool IsWarningRaised(const std::vector<std::chrono::seconds>& check_offsets)
|
static bool IsWarningRaised(const std::vector<std::chrono::seconds>& check_offsets)
|
||||||
{
|
{
|
||||||
TimeOffsets offsets{};
|
node::Warnings warnings{};
|
||||||
|
TimeOffsets offsets{warnings};
|
||||||
AddMulti(offsets, check_offsets);
|
AddMulti(offsets, check_offsets);
|
||||||
return offsets.WarnIfOutOfSync();
|
return offsets.WarnIfOutOfSync();
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
#include <node/miner.h>
|
#include <node/miner.h>
|
||||||
#include <node/peerman_args.h>
|
#include <node/peerman_args.h>
|
||||||
#include <node/validation_cache_args.h>
|
#include <node/validation_cache_args.h>
|
||||||
|
#include <node/warnings.h>
|
||||||
#include <noui.h>
|
#include <noui.h>
|
||||||
#include <policy/fees.h>
|
#include <policy/fees.h>
|
||||||
#include <policy/fees_args.h>
|
#include <policy/fees_args.h>
|
||||||
|
@ -182,6 +183,7 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, const std::vecto
|
||||||
InitLogging(*m_node.args);
|
InitLogging(*m_node.args);
|
||||||
AppInitParameterInteraction(*m_node.args);
|
AppInitParameterInteraction(*m_node.args);
|
||||||
LogInstance().StartLogging();
|
LogInstance().StartLogging();
|
||||||
|
m_node.warnings = std::make_unique<node::Warnings>();
|
||||||
m_node.kernel = std::make_unique<kernel::Context>();
|
m_node.kernel = std::make_unique<kernel::Context>();
|
||||||
m_node.ecc_context = std::make_unique<ECC_Context>();
|
m_node.ecc_context = std::make_unique<ECC_Context>();
|
||||||
SetupEnvironment();
|
SetupEnvironment();
|
||||||
|
@ -230,10 +232,11 @@ ChainTestingSetup::ChainTestingSetup(const ChainType chainType, const std::vecto
|
||||||
bilingual_str error{};
|
bilingual_str error{};
|
||||||
m_node.mempool = std::make_unique<CTxMemPool>(MemPoolOptionsForTest(m_node), error);
|
m_node.mempool = std::make_unique<CTxMemPool>(MemPoolOptionsForTest(m_node), error);
|
||||||
Assert(error.empty());
|
Assert(error.empty());
|
||||||
|
m_node.warnings = std::make_unique<node::Warnings>();
|
||||||
|
|
||||||
m_cache_sizes = CalculateCacheSizes(m_args);
|
m_cache_sizes = CalculateCacheSizes(m_args);
|
||||||
|
|
||||||
m_node.notifications = std::make_unique<KernelNotifications>(*Assert(m_node.shutdown), m_node.exit_status);
|
m_node.notifications = std::make_unique<KernelNotifications>(*Assert(m_node.shutdown), m_node.exit_status, *Assert(m_node.warnings));
|
||||||
|
|
||||||
const ChainstateManager::Options chainman_opts{
|
const ChainstateManager::Options chainman_opts{
|
||||||
.chainparams = chainparams,
|
.chainparams = chainparams,
|
||||||
|
@ -322,7 +325,8 @@ TestingSetup::TestingSetup(
|
||||||
peerman_opts.deterministic_rng = true;
|
peerman_opts.deterministic_rng = true;
|
||||||
m_node.peerman = PeerManager::make(*m_node.connman, *m_node.addrman,
|
m_node.peerman = PeerManager::make(*m_node.connman, *m_node.addrman,
|
||||||
m_node.banman.get(), *m_node.chainman,
|
m_node.banman.get(), *m_node.chainman,
|
||||||
*m_node.mempool, peerman_opts);
|
*m_node.mempool, *m_node.warnings,
|
||||||
|
peerman_opts);
|
||||||
|
|
||||||
{
|
{
|
||||||
CConnman::Options options;
|
CConnman::Options options;
|
||||||
|
|
|
@ -378,7 +378,7 @@ struct SnapshotTestSetup : TestChain100Setup {
|
||||||
LOCK(::cs_main);
|
LOCK(::cs_main);
|
||||||
chainman.ResetChainstates();
|
chainman.ResetChainstates();
|
||||||
BOOST_CHECK_EQUAL(chainman.GetAll().size(), 0);
|
BOOST_CHECK_EQUAL(chainman.GetAll().size(), 0);
|
||||||
m_node.notifications = std::make_unique<KernelNotifications>(*Assert(m_node.shutdown), m_node.exit_status);
|
m_node.notifications = std::make_unique<KernelNotifications>(*Assert(m_node.shutdown), m_node.exit_status, *Assert(m_node.warnings));
|
||||||
const ChainstateManager::Options chainman_opts{
|
const ChainstateManager::Options chainman_opts{
|
||||||
.chainparams = ::Params(),
|
.chainparams = ::Params(),
|
||||||
.datadir = chainman.m_options.datadir,
|
.datadir = chainman.m_options.datadir,
|
||||||
|
|
Loading…
Add table
Reference in a new issue