mirror of
https://github.com/aljazceru/lightning.git
synced 2025-12-20 15:44:21 +01:00
db: decouple fatal reliance, have as impl defined function
`fatal` is defined in lightningd and has logfile dependencies etc. Make it more generic by allowing declaration in the use file (wallet.c)
This commit is contained in:
@@ -809,22 +809,25 @@ void log_backtrace_exit(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void fatal_vfmt(const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
vfprintf(stderr, fmt, ap);
|
||||||
|
fprintf(stderr, "\n");
|
||||||
|
|
||||||
|
if (!crashlog)
|
||||||
|
exit(1);
|
||||||
|
|
||||||
|
logv(crashlog, LOG_BROKEN, NULL, true, fmt, ap);
|
||||||
|
abort();
|
||||||
|
}
|
||||||
|
|
||||||
void fatal(const char *fmt, ...)
|
void fatal(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
vfprintf(stderr, fmt, ap);
|
fatal_vfmt(fmt, ap);
|
||||||
fprintf(stderr, "\n");
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
if (!crashlog)
|
|
||||||
exit(1);
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
logv(crashlog, LOG_BROKEN, NULL, true, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
abort();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct log_info {
|
struct log_info {
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ char *arg_log_to_file(const char *arg, struct lightningd *ld);
|
|||||||
/* Once this is set, we dump fatal with a backtrace to this log */
|
/* Once this is set, we dump fatal with a backtrace to this log */
|
||||||
extern struct log *crashlog;
|
extern struct log *crashlog;
|
||||||
void NORETURN PRINTF_FMT(1,2) fatal(const char *fmt, ...);
|
void NORETURN PRINTF_FMT(1,2) fatal(const char *fmt, ...);
|
||||||
|
void NORETURN fatal_vfmt(const char *fmt, va_list ap);
|
||||||
|
|
||||||
void log_backtrace_print(const char *fmt, ...);
|
void log_backtrace_print(const char *fmt, ...);
|
||||||
void log_backtrace_exit(void);
|
void log_backtrace_exit(void);
|
||||||
|
|||||||
@@ -6,11 +6,6 @@
|
|||||||
#include <ccan/strset/strset.h>
|
#include <ccan/strset/strset.h>
|
||||||
#include <common/autodata.h>
|
#include <common/autodata.h>
|
||||||
|
|
||||||
/* For testing, we want to catch fatal messages. */
|
|
||||||
#ifndef db_fatal
|
|
||||||
#define db_fatal fatal
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct db {
|
struct db {
|
||||||
char *filename;
|
char *filename;
|
||||||
const char *in_transaction;
|
const char *in_transaction;
|
||||||
@@ -163,6 +158,9 @@ struct db_config {
|
|||||||
/* Provide a way for DB backends to register themselves */
|
/* Provide a way for DB backends to register themselves */
|
||||||
AUTODATA_TYPE(db_backends, struct db_config);
|
AUTODATA_TYPE(db_backends, struct db_config);
|
||||||
|
|
||||||
|
void db_fatal(const char *fmt, ...)
|
||||||
|
PRINTF_FMT(1, 2);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Report a statement that changes the wallet
|
* Report a statement that changes the wallet
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <lightningd/log.h>
|
#include <lightningd/log.h>
|
||||||
|
|
||||||
static void db_test_fatal(const char *fmt, ...);
|
|
||||||
#define db_fatal db_test_fatal
|
|
||||||
|
|
||||||
static void db_log_(struct log *log UNUSED, enum log_level level UNUSED, const struct node_id *node_id UNUSED, bool call_notifier UNUSED, const char *fmt UNUSED, ...)
|
static void db_log_(struct log *log UNUSED, enum log_level level UNUSED, const struct node_id *node_id UNUSED, bool call_notifier UNUSED, const char *fmt UNUSED, ...)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -59,7 +56,7 @@ bool wire_sync_write(int fd UNNEEDED, const void *msg TAKES UNNEEDED)
|
|||||||
/* AUTOGENERATED MOCKS END */
|
/* AUTOGENERATED MOCKS END */
|
||||||
|
|
||||||
static char *db_err;
|
static char *db_err;
|
||||||
static void db_test_fatal(const char *fmt, ...)
|
void db_fatal(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,34 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <lightningd/log.h>
|
#include <lightningd/log.h>
|
||||||
|
|
||||||
static void wallet_test_fatal(const char *fmt, ...);
|
|
||||||
#define db_fatal wallet_test_fatal
|
|
||||||
#include "test_utils.h"
|
#include "test_utils.h"
|
||||||
|
#include <ccan/tal/str/str.h>
|
||||||
|
#include <wallet/db_common.h>
|
||||||
|
|
||||||
static void db_log_(struct log *log UNUSED, enum log_level level UNUSED, const struct node_id *node_id UNUSED, bool call_notifier UNUSED, const char *fmt UNUSED, ...)
|
static void db_log_(struct log *log UNUSED, enum log_level level UNUSED, const struct node_id *node_id UNUSED, bool call_notifier UNUSED, const char *fmt UNUSED, ...)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
#define log_ db_log_
|
#define log_ db_log_
|
||||||
|
|
||||||
|
#ifndef DB_FATAL
|
||||||
|
#define DB_FATAL
|
||||||
|
static char *wallet_err;
|
||||||
|
void db_fatal(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
/* Fail hard if we're complaining about not being in transaction */
|
||||||
|
assert(!strstarts(fmt, "No longer in transaction"));
|
||||||
|
|
||||||
|
/* Fail hard if we're complaining about not being in transaction */
|
||||||
|
assert(!strstarts(fmt, "No longer in transaction"));
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
wallet_err = tal_vfmt(NULL, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
#endif /* DB_FATAL */
|
||||||
|
|
||||||
#include "wallet/wallet.c"
|
#include "wallet/wallet.c"
|
||||||
#include "lightningd/htlc_end.c"
|
#include "lightningd/htlc_end.c"
|
||||||
#include "lightningd/peer_control.c"
|
#include "lightningd/peer_control.c"
|
||||||
@@ -837,22 +856,6 @@ bool fromwire_hsmd_get_channel_basepoints_reply(const void *p UNNEEDED,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *wallet_err;
|
|
||||||
static void wallet_test_fatal(const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
/* Fail hard if we're complaining about not being in transaction */
|
|
||||||
assert(!strstarts(fmt, "No longer in transaction"));
|
|
||||||
|
|
||||||
/* Fail hard if we're complaining about not being in transaction */
|
|
||||||
assert(!strstarts(fmt, "No longer in transaction"));
|
|
||||||
|
|
||||||
va_start(ap, fmt);
|
|
||||||
wallet_err = tal_vfmt(NULL, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define transaction_wrap(db, ...) \
|
#define transaction_wrap(db, ...) \
|
||||||
(db_begin_transaction(db), __VA_ARGS__, db_commit_transaction(db), wallet_err == NULL)
|
(db_begin_transaction(db), __VA_ARGS__, db_commit_transaction(db), wallet_err == NULL)
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,21 @@ struct channel_state_param {
|
|||||||
const enum channel_state_bucket state;
|
const enum channel_state_bucket state;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Implement db_fatal, as a wrapper around fatal.
|
||||||
|
* We use a ifndef block so that it can get be
|
||||||
|
* implemented in a test file first, if necessary */
|
||||||
|
#ifndef DB_FATAL
|
||||||
|
#define DB_FATAL
|
||||||
|
void db_fatal(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
|
||||||
|
va_start(ap, fmt);
|
||||||
|
fatal_vfmt(fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
#endif /* DB_FATAL */
|
||||||
|
|
||||||
static void outpointfilters_init(struct wallet *w)
|
static void outpointfilters_init(struct wallet *w)
|
||||||
{
|
{
|
||||||
struct db_stmt *stmt;
|
struct db_stmt *stmt;
|
||||||
|
|||||||
Reference in New Issue
Block a user