introduce and use the generalized node::Warnings interface

Instead of having separate warning functions (and globals) for each
different warning that can be raised, encapsulate this logic into
a single class and allow to (un)set any number of warnings.

Introduces behaviour change:
- the `-alertnotify` command is executed for all
  `KernelNotifications::warningSet` calls, which now also covers the
  `LARGE_WORK_INVALID_CHAIN` warning.
- previously, warnings were returned based on a predetermined order,
  e.g. with the "pre-release test build" warning always first. This
  is no longer the case, and Warnings::GetMessages() will return
  messages sorted by the id of the warning.

Removes warnings.cpp from kernel.
This commit is contained in:
stickies-v
2024-05-07 17:05:40 +01:00
parent 20e616f864
commit b071ad9770
15 changed files with 215 additions and 83 deletions

View File

@@ -10,6 +10,7 @@
#include <common/args.h>
#include <common/system.h>
#include <kernel/context.h>
#include <kernel/warning.h>
#include <logging.h>
#include <node/abort.h>
#include <node/interface_ui.h>
@@ -46,16 +47,6 @@ static void AlertNotify(const std::string& strMessage)
#endif
}
static void DoWarning(const bilingual_str& warning)
{
static bool fWarned = false;
node::SetMiscWarning(warning);
if (!fWarned) {
AlertNotify(warning.original);
fWarned = true;
}
}
namespace node {
kernel::InterruptResult KernelNotifications::blockTip(SynchronizationState state, CBlockIndex& index)
@@ -80,9 +71,16 @@ void KernelNotifications::progress(const bilingual_str& title, int progress_perc
uiInterface.ShowProgress(title.translated, progress_percent, resume_possible);
}
void KernelNotifications::warning(const bilingual_str& warning)
void KernelNotifications::warningSet(kernel::Warning id, const bilingual_str& message)
{
DoWarning(warning);
if (node::g_warnings.Set(id, message)) {
AlertNotify(message.original);
}
}
void KernelNotifications::warningUnset(kernel::Warning id)
{
g_warnings.Unset(id);
}
void KernelNotifications::flushError(const bilingual_str& message)