bkpr: pass bkpr struct into all functions in recorder.c.

We want to access it in stmt2chain_event, so plumb it through.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell
2025-08-19 10:30:50 +09:30
parent 0afc4c0346
commit e28443ed40
7 changed files with 124 additions and 121 deletions

View File

@@ -266,7 +266,7 @@ static struct command_result *json_inspect(struct command *cmd,
acct_name);
db_begin_transaction(bkpr->db);
find_txo_chain(cmd, bkpr->db, acct, &txos);
find_txo_chain(cmd, bkpr, acct, &txos);
fee_sums = find_account_onchain_fees(cmd, bkpr, acct);
db_commit_transaction(bkpr->db);
@@ -464,7 +464,7 @@ static struct command_result *json_list_account_events(struct command *cmd,
db_begin_transaction(bkpr->db);
if (acct) {
channel_events = account_get_channel_events(cmd, bkpr->db, acct);
chain_events = account_get_chain_events(cmd, bkpr->db, acct);
chain_events = account_get_chain_events(cmd, bkpr, acct);
onchain_fees = account_get_chain_fees(tmpctx, bkpr, acct->name);
} else if (payment_id != NULL) {
channel_events = get_channel_events_by_id(cmd, bkpr->db, payment_id);
@@ -474,11 +474,11 @@ static struct command_result *json_list_account_events(struct command *cmd,
/* Transaction ids are stored as big-endian in the database */
reverse_bytes(tx_id->shad.sha.u.u8, sizeof(tx_id->shad.sha.u.u8));
chain_events = find_chain_events_bytxid(cmd, bkpr->db, tx_id);
chain_events = find_chain_events_bytxid(cmd, bkpr, tx_id);
onchain_fees = get_chain_fees_by_txid(cmd, bkpr, tx_id);
} else {
channel_events = list_channel_events(cmd, bkpr->db);
chain_events = list_chain_events(cmd, bkpr->db);
chain_events = list_chain_events(cmd, bkpr);
onchain_fees = list_chain_fees(cmd, bkpr);
}
db_commit_transaction(bkpr->db);
@@ -521,7 +521,7 @@ static struct command_result *json_edit_desc_utxo(struct command *cmd,
db_begin_transaction(bkpr->db);
add_utxo_description(cmd, bkpr, outpoint, new_desc);
chain_events = get_chain_events_by_outpoint(cmd, bkpr->db, outpoint, true);
chain_events = get_chain_events_by_outpoint(cmd, bkpr, outpoint, true);
db_commit_transaction(bkpr->db);
res = jsonrpc_stream_success(cmd);
@@ -552,7 +552,7 @@ static struct command_result *json_edit_desc_payment_id(struct command *cmd,
db_begin_transaction(bkpr->db);
add_payment_hash_description(cmd, bkpr, identifier, new_desc);
chain_events = get_chain_events_by_id(cmd, bkpr->db, identifier);
chain_events = get_chain_events_by_id(cmd, bkpr, identifier);
channel_events = get_channel_events_by_id(cmd, bkpr->db, identifier);
db_commit_transaction(bkpr->db);
@@ -652,7 +652,7 @@ static void try_update_open_fees(struct command *cmd,
struct bkpr *bkpr = bkpr_of(cmd->plugin);
assert(acct->closed_event_db_id);
ev = find_chain_event_by_id(cmd, bkpr->db, *acct->closed_event_db_id);
ev = find_chain_event_by_id(cmd, bkpr, *acct->closed_event_db_id);
assert(ev);
err = maybe_update_onchain_fees(cmd, cmd, bkpr, ev->spending_txid);
@@ -804,7 +804,7 @@ static bool new_missed_channel_account(struct command *cmd,
chain_ev->credit = amt;
db_begin_transaction(bkpr->db);
if (!log_chain_event(bkpr->db, acct, chain_ev))
if (!log_chain_event(bkpr, acct, chain_ev))
goto done;
maybe_update_account(cmd, acct, chain_ev,
@@ -1027,7 +1027,7 @@ static char *do_account_close_checks(struct command *cmd,
if (closed_acct && closed_acct->closed_event_db_id) {
u64 closeheight = account_onchain_closeheight(bkpr->db, closed_acct);
u64 closeheight = account_onchain_closeheight(bkpr, closed_acct);
if (closeheight != 0) {
char *err;
account_update_closeheight(cmd, closed_acct, closeheight);
@@ -1546,7 +1546,7 @@ parse_and_log_chain_move(struct command *cmd,
orig_acct = NULL;
if (!log_chain_event(bkpr->db, acct, e)) {
if (!log_chain_event(bkpr, acct, e)) {
db_commit_transaction(bkpr->db);
/* This is not a new event, do nothing */
return notification_handled(cmd);
@@ -1578,7 +1578,7 @@ parse_and_log_chain_move(struct command *cmd,
/* Go see if there's any deposits to an external
* that are now confirmed */
/* FIXME: might need updating when we can splice? */
maybe_closeout_external_deposits(bkpr->db, e->spending_txid,
maybe_closeout_external_deposits(bkpr, e->spending_txid,
e->blockheight);
db_commit_transaction(bkpr->db);
}
@@ -1785,7 +1785,7 @@ static struct command_result *json_utxo_deposit(struct command *cmd, const char
ev->timestamp, ev->blockheight,
fmt_bitcoin_outpoint(tmpctx, &ev->outpoint));
if (!log_chain_event(bkpr->db, acct, ev)) {
if (!log_chain_event(bkpr, acct, ev)) {
db_commit_transaction(bkpr->db);
/* This is not a new event, do nothing */
return notification_handled(cmd);
@@ -1854,7 +1854,7 @@ static struct command_result *json_utxo_spend(struct command *cmd, const char *b
fmt_bitcoin_outpoint(tmpctx, &ev->outpoint),
fmt_bitcoin_txid(tmpctx, ev->spending_txid));
if (!log_chain_event(bkpr->db, acct, ev)) {
if (!log_chain_event(bkpr, acct, ev)) {
db_commit_transaction(bkpr->db);
/* This is not a new event, do nothing */
return notification_handled(cmd);
@@ -1879,7 +1879,7 @@ static struct command_result *json_utxo_spend(struct command *cmd, const char *b
/* Go see if there's any deposits to an external
* that are now confirmed */
/* FIXME: might need updating when we can splice? */
maybe_closeout_external_deposits(bkpr->db, ev->spending_txid,
maybe_closeout_external_deposits(bkpr, ev->spending_txid,
ev->blockheight);
db_commit_transaction(bkpr->db);

View File

@@ -96,7 +96,7 @@ static struct account *search_account(struct account **accts, const char *acctna
return NULL;
}
static void fillin_apy_acct_details(struct db *db,
static void fillin_apy_acct_details(const struct bkpr *bkpr,
const struct account *acct,
u32 current_blockheight,
struct channel_apy *apy)
@@ -107,7 +107,7 @@ static void fillin_apy_acct_details(struct db *db,
apy->acct_name = tal_strdup(apy, acct->name);
assert(acct->open_event_db_id);
ev = find_chain_event_by_id(tmpctx, db, *acct->open_event_db_id);
ev = find_chain_event_by_id(tmpctx, bkpr, *acct->open_event_db_id);
assert(ev);
apy->start_blockheight = ev->blockheight;
@@ -116,7 +116,7 @@ static void fillin_apy_acct_details(struct db *db,
/* if this account is closed, add closing blockheight */
if (acct->closed_event_db_id) {
ev = find_chain_event_by_id(acct, db,
ev = find_chain_event_by_id(acct, bkpr,
*acct->closed_event_db_id);
assert(ev);
apy->end_blockheight = ev->blockheight;
@@ -167,7 +167,7 @@ struct channel_apy **compute_channel_apys(const tal_t *ctx,
if (!acct || !streq(acct->name, ev->acct_name)) {
if (acct && is_channel_account(acct->name)) {
fillin_apy_acct_details(bkpr->db, acct,
fillin_apy_acct_details(bkpr, acct,
current_blockheight,
apy);
/* Save current apy, make new */
@@ -225,7 +225,7 @@ struct channel_apy **compute_channel_apys(const tal_t *ctx,
}
if (acct && is_channel_account(acct->name)) {
fillin_apy_acct_details(bkpr->db, acct,
fillin_apy_acct_details(bkpr, acct,
current_blockheight,
apy);
/* Save current apy, make new */

View File

@@ -313,13 +313,11 @@ struct income_event **list_income_events(const tal_t *ctx,
struct channel_event **channel_events;
struct chain_event **chain_events;
struct onchain_fee **onchain_fees;
struct db *db = bkpr->db;
struct income_event **evs;
channel_events = list_channel_events_timebox(ctx, db,
channel_events = list_channel_events_timebox(ctx, bkpr->db,
start_time, end_time);
chain_events = list_chain_events_timebox(ctx, db, start_time, end_time);
chain_events = list_chain_events_timebox(ctx, bkpr, start_time, end_time);
if (consolidate_fees) {
onchain_fees = find_consolidated_fees(ctx, bkpr,

View File

@@ -397,9 +397,9 @@ char *update_channel_onchain_fees(const tal_t *ctx,
struct amount_msat onchain_amt;
assert(acct->onchain_resolved_block);
close_ev = find_chain_event_by_id(ctx, bkpr->db,
close_ev = find_chain_event_by_id(ctx, bkpr,
*acct->closed_event_db_id);
events = find_chain_events_bytxid(ctx, bkpr->db,
events = find_chain_events_bytxid(ctx, bkpr,
close_ev->spending_txid);
/* Starting balance is close-ev's debit amount */
@@ -475,7 +475,7 @@ static char *is_closed_channel_txid(const tal_t *ctx,
/* is the closed utxo the same as the one
* we're trying to find fees for now */
closed = find_chain_event_by_id(inner_ctx, bkpr->db,
closed = find_chain_event_by_id(inner_ctx, bkpr,
*acct->closed_event_db_id);
if (!closed) {
*is_channel_close_tx = false;
@@ -516,7 +516,7 @@ char *maybe_update_onchain_fees(const tal_t *ctx,
u8 *inner_ctx = tal(NULL, u8);
/* Find all the deposits/withdrawals for this txid */
events = find_chain_events_bytxid(inner_ctx, bkpr->db, txid);
events = find_chain_events_bytxid(inner_ctx, bkpr, txid);
/* If we don't even have two events, skip */
if (tal_count(events) < 2)

View File

@@ -20,7 +20,9 @@
#include <plugins/libplugin.h>
static struct chain_event *stmt2chain_event(const tal_t *ctx, struct db_stmt *stmt)
static struct chain_event *stmt2chain_event(const tal_t *ctx,
const struct bkpr *bkpr,
struct db_stmt *stmt)
{
struct chain_event *e = tal(ctx, struct chain_event);
e->db_id = db_col_u64(stmt, "e.id");
@@ -62,6 +64,7 @@ static struct chain_event *stmt2chain_event(const tal_t *ctx, struct db_stmt *st
}
static struct chain_event **find_chain_events(const tal_t *ctx,
const struct bkpr *bkpr,
struct db_stmt *stmt TAKES)
{
struct chain_event **results;
@@ -71,7 +74,7 @@ static struct chain_event **find_chain_events(const tal_t *ctx,
db_fatal(stmt->db, "find_chain_events err: %s", stmt->error);
results = tal_arr(ctx, struct chain_event *, 0);
while (db_step(stmt)) {
struct chain_event *e = stmt2chain_event(results, stmt);
struct chain_event *e = stmt2chain_event(results, bkpr, stmt);
tal_arr_expand(&results, e);
}
@@ -126,13 +129,13 @@ static struct channel_event **find_channel_events(const tal_t *ctx,
}
struct chain_event **list_chain_events_timebox(const tal_t *ctx,
struct db *db,
const struct bkpr *bkpr,
u64 start_time,
u64 end_time)
{
struct db_stmt *stmt;
stmt = db_prepare_v2(db, SQL("SELECT"
stmt = db_prepare_v2(bkpr->db, SQL("SELECT"
" e.id"
", e.account_name"
", e.origin"
@@ -155,21 +158,21 @@ struct chain_event **list_chain_events_timebox(const tal_t *ctx,
db_bind_u64(stmt, start_time);
db_bind_u64(stmt, end_time);
return find_chain_events(ctx, take(stmt));
return find_chain_events(ctx, bkpr, take(stmt));
}
struct chain_event **list_chain_events(const tal_t *ctx, struct db *db)
struct chain_event **list_chain_events(const tal_t *ctx, const struct bkpr *bkpr)
{
return list_chain_events_timebox(ctx, db, 0, SQLITE_MAX_UINT);
return list_chain_events_timebox(ctx, bkpr, 0, SQLITE_MAX_UINT);
}
struct chain_event **account_get_chain_events(const tal_t *ctx,
struct db *db,
const struct bkpr *bkpr,
struct account *acct)
{
struct db_stmt *stmt;
stmt = db_prepare_v2(db, SQL("SELECT"
stmt = db_prepare_v2(bkpr->db, SQL("SELECT"
" e.id"
", e.account_name"
", e.origin"
@@ -190,16 +193,16 @@ struct chain_event **account_get_chain_events(const tal_t *ctx,
" ORDER BY e.timestamp, e.id"));
db_bind_text(stmt, acct->name);
return find_chain_events(ctx, take(stmt));
return find_chain_events(ctx, bkpr, take(stmt));
}
static struct chain_event **find_txos_for_tx(const tal_t *ctx,
struct db *db,
const struct bkpr *bkpr,
struct bitcoin_txid *txid)
{
struct db_stmt *stmt;
stmt = db_prepare_v2(db, SQL("SELECT"
stmt = db_prepare_v2(bkpr->db, SQL("SELECT"
" e.id"
", e.account_name"
", e.origin"
@@ -224,7 +227,7 @@ static struct chain_event **find_txos_for_tx(const tal_t *ctx,
", e.blockheight"));
db_bind_txid(stmt, txid);
return find_chain_events(ctx, take(stmt));
return find_chain_events(ctx, bkpr, take(stmt));
}
static struct txo_pair *new_txo_pair(const tal_t *ctx)
@@ -236,7 +239,7 @@ static struct txo_pair *new_txo_pair(const tal_t *ctx)
}
static struct txo_set *find_txo_set(const tal_t *ctx,
struct db *db,
const struct bkpr *bkpr,
struct bitcoin_txid *txid,
const char *acct_name,
bool *is_complete)
@@ -248,7 +251,7 @@ static struct txo_set *find_txo_set(const tal_t *ctx,
/* In some special cases (the opening tx), we only
* want the outputs that pertain to a given account,
* most other times we want all utxos, regardless of account */
evs = find_txos_for_tx(ctx, db, txid);
evs = find_txos_for_tx(ctx, bkpr, txid);
txos->pairs = tal_arr(txos, struct txo_pair *, 0);
txos->txid = tal_dup(txos, struct bitcoin_txid, txid);
@@ -315,7 +318,7 @@ static bool txid_in_list(struct bitcoin_txid **list,
}
bool find_txo_chain(const tal_t *ctx,
struct db *db,
const struct bkpr *bkpr,
const struct account *acct,
struct txo_set ***sets)
{
@@ -325,7 +328,7 @@ bool find_txo_chain(const tal_t *ctx,
const char *start_acct_name;
assert(acct->open_event_db_id);
open_ev = find_chain_event_by_id(ctx, db,
open_ev = find_chain_event_by_id(ctx, bkpr,
*acct->open_event_db_id);
if (sets)
@@ -342,7 +345,7 @@ bool find_txo_chain(const tal_t *ctx,
struct txo_set *set;
bool set_complete;
set = find_txo_set(ctx, db, txids[i],
set = find_txo_set(ctx, bkpr, txids[i],
start_acct_name,
&set_complete);
@@ -413,7 +416,7 @@ const char *find_close_account_name(const tal_t *ctx,
return acct_name;
}
u64 account_onchain_closeheight(struct db *db, const struct account *acct)
u64 account_onchain_closeheight(const struct bkpr *bkpr, const struct account *acct)
{
const u8 *ctx = tal(NULL, u8);
struct txo_set **sets;
@@ -423,10 +426,10 @@ u64 account_onchain_closeheight(struct db *db, const struct account *acct)
assert(acct->closed_count > 0);
close_ev = find_chain_event_by_id(ctx, db,
close_ev = find_chain_event_by_id(ctx, bkpr,
*acct->closed_event_db_id);
if (find_txo_chain(ctx, db, acct, &sets)) {
if (find_txo_chain(ctx, bkpr, acct, &sets)) {
/* Ok now we find the max block height of the
* spending chain_events for this channel */
bool ok;
@@ -448,7 +451,7 @@ u64 account_onchain_closeheight(struct db *db, const struct account *acct)
return 0;
}
stmt = db_prepare_v2(db, SQL("SELECT"
stmt = db_prepare_v2(bkpr->db, SQL("SELECT"
" blockheight"
" FROM chain_events"
" WHERE account_name = ?"
@@ -472,13 +475,13 @@ u64 account_onchain_closeheight(struct db *db, const struct account *acct)
}
struct chain_event *find_chain_event_by_id(const tal_t *ctx,
struct db *db,
const struct bkpr *bkpr,
u64 event_db_id)
{
struct db_stmt *stmt;
struct chain_event *e;
stmt = db_prepare_v2(db, SQL("SELECT"
stmt = db_prepare_v2(bkpr->db, SQL("SELECT"
" e.id"
", e.account_name"
", e.origin"
@@ -501,7 +504,7 @@ struct chain_event *find_chain_event_by_id(const tal_t *ctx,
db_bind_u64(stmt, event_db_id);
db_query_prepared(stmt);
if (db_step(stmt))
e = stmt2chain_event(ctx, stmt);
e = stmt2chain_event(ctx, bkpr, stmt);
else
e = NULL;
@@ -510,13 +513,13 @@ struct chain_event *find_chain_event_by_id(const tal_t *ctx,
}
struct chain_event **get_chain_events_by_outpoint(const tal_t *ctx,
struct db *db,
const struct bkpr *bkpr,
const struct bitcoin_outpoint *outpoint,
bool credits_only)
{
struct db_stmt *stmt;
if (credits_only)
stmt = db_prepare_v2(db, SQL("SELECT"
stmt = db_prepare_v2(bkpr->db, SQL("SELECT"
" e.id"
", e.account_name"
", e.origin"
@@ -538,7 +541,7 @@ struct chain_event **get_chain_events_by_outpoint(const tal_t *ctx,
" AND e.outnum = ?"
" AND credit > 0"));
else
stmt = db_prepare_v2(db, SQL("SELECT"
stmt = db_prepare_v2(bkpr->db, SQL("SELECT"
" e.id"
", e.account_name"
", e.origin"
@@ -561,15 +564,15 @@ struct chain_event **get_chain_events_by_outpoint(const tal_t *ctx,
db_bind_txid(stmt, &outpoint->txid);
db_bind_int(stmt, outpoint->n);
return find_chain_events(ctx, take(stmt));
return find_chain_events(ctx, bkpr, take(stmt));
}
struct chain_event **get_chain_events_by_id(const tal_t *ctx,
struct db *db,
const struct bkpr *bkpr,
const struct sha256 *id)
{
struct db_stmt *stmt;
stmt = db_prepare_v2(db, SQL("SELECT"
stmt = db_prepare_v2(bkpr->db, SQL("SELECT"
" e.id"
", e.account_name"
", e.origin"
@@ -590,11 +593,11 @@ struct chain_event **get_chain_events_by_id(const tal_t *ctx,
" e.payment_id = ?"));
db_bind_sha256(stmt, id);
return find_chain_events(ctx, take(stmt));
return find_chain_events(ctx, bkpr, take(stmt));
}
static struct chain_event *find_chain_event(const tal_t *ctx,
struct db *db,
struct bkpr *bkpr,
const struct account *acct,
const struct bitcoin_outpoint *outpoint,
const struct bitcoin_txid *spending_txid,
@@ -605,7 +608,7 @@ static struct chain_event *find_chain_event(const tal_t *ctx,
struct chain_event *e;
if (spending_txid) {
stmt = db_prepare_v2(db, SQL("SELECT"
stmt = db_prepare_v2(bkpr->db, SQL("SELECT"
" e.id"
", e.account_name"
", e.origin"
@@ -629,7 +632,7 @@ static struct chain_event *find_chain_event(const tal_t *ctx,
" AND e.outnum = ?"));
db_bind_txid(stmt, spending_txid);
} else {
stmt = db_prepare_v2(db, SQL("SELECT"
stmt = db_prepare_v2(bkpr->db, SQL("SELECT"
" e.id"
", e.account_name"
", e.origin"
@@ -661,7 +664,7 @@ static struct chain_event *find_chain_event(const tal_t *ctx,
db_query_prepared(stmt);
if (db_step(stmt))
e = stmt2chain_event(ctx, stmt);
e = stmt2chain_event(ctx, bkpr, stmt);
else
e = NULL;
@@ -863,12 +866,13 @@ void log_channel_event(struct db *db,
tal_free(stmt);
}
struct chain_event **find_chain_events_bytxid(const tal_t *ctx, struct db *db,
struct bitcoin_txid *txid)
struct chain_event **find_chain_events_bytxid(const tal_t *ctx,
const struct bkpr *bkpr,
const struct bitcoin_txid *txid)
{
struct db_stmt *stmt;
stmt = db_prepare_v2(db, SQL("SELECT "
stmt = db_prepare_v2(bkpr->db, SQL("SELECT "
" e.id"
", e.account_name"
", e.origin"
@@ -891,7 +895,7 @@ struct chain_event **find_chain_events_bytxid(const tal_t *ctx, struct db *db,
db_bind_txid(stmt, txid);
db_bind_txid(stmt, txid);
return find_chain_events(ctx, take(stmt));
return find_chain_events(ctx, bkpr, take(stmt));
}
void maybe_record_rebalance(struct command *cmd,
@@ -932,14 +936,14 @@ void maybe_record_rebalance(struct command *cmd,
tal_free(stmt);
}
void maybe_closeout_external_deposits(struct db *db,
void maybe_closeout_external_deposits(struct bkpr *bkpr,
const struct bitcoin_txid *txid,
u32 blockheight)
{
struct db_stmt *stmt;
assert(txid);
stmt = db_prepare_v2(db, SQL("SELECT "
stmt = db_prepare_v2(bkpr->db, SQL("SELECT "
" e.id"
" FROM chain_events e"
" WHERE e.blockheight = ?"
@@ -957,7 +961,7 @@ void maybe_closeout_external_deposits(struct db *db,
u64 id;
id = db_col_u64(stmt, "e.id");
update_stmt = db_prepare_v2(db, SQL("UPDATE chain_events SET"
update_stmt = db_prepare_v2(bkpr->db, SQL("UPDATE chain_events SET"
" blockheight = ?"
" WHERE id = ?"));
@@ -969,19 +973,19 @@ void maybe_closeout_external_deposits(struct db *db,
tal_free(stmt);
}
bool log_chain_event(struct db *db,
bool log_chain_event(struct bkpr *bkpr,
const struct account *acct,
struct chain_event *e)
{
struct db_stmt *stmt;
/* We're responsible for de-duping chain events! */
if (find_chain_event(tmpctx, db, acct,
if (find_chain_event(tmpctx, bkpr, acct,
&e->outpoint, e->spending_txid,
e->tag))
return false;
stmt = db_prepare_v2(db, SQL("INSERT INTO chain_events"
stmt = db_prepare_v2(bkpr->db, SQL("INSERT INTO chain_events"
" ("
" account_name"
", origin"

View File

@@ -58,15 +58,16 @@ struct channel_event **list_channel_events_timebox(const tal_t *ctx,
/* Get all chain events for this account */
struct chain_event **account_get_chain_events(const tal_t *ctx,
struct db *db,
const struct bkpr *bkpr,
struct account *acct);
/* Get all chain events for a transaction id, order by timestamp */
struct chain_event **find_chain_events_bytxid(const tal_t *ctx, struct db *db,
struct bitcoin_txid *txid);
struct chain_event **find_chain_events_bytxid(const tal_t *ctx,
const struct bkpr *bkpr,
const struct bitcoin_txid *txid);
/* Get all chain events, order by timestamp. */
struct chain_event **list_chain_events(const tal_t *ctx, struct db *db);
struct chain_event **list_chain_events(const tal_t *ctx, const struct bkpr *bkpr);
/* Get all chain events, order by timestamp.
*
@@ -76,18 +77,18 @@ struct chain_event **list_chain_events(const tal_t *ctx, struct db *db);
* @end_time - UNIX timestamp to query until (inclusive)
*/
struct chain_event **list_chain_events_timebox(const tal_t *ctx,
struct db *db,
const struct bkpr *bkpr,
u64 start_time,
u64 end_time);
/* Get all chain events for a payment hash */
struct chain_event **get_chain_events_by_id(const tal_t *ctx,
struct db *db,
const struct bkpr *bkpr,
const struct sha256 *id);
/* Get all chain events for a utxo */
struct chain_event **get_chain_events_by_outpoint(const tal_t *ctx,
struct db *db,
const struct bkpr *bkpr,
const struct bitcoin_outpoint *outpoint,
bool credits_only);
@@ -102,7 +103,7 @@ bool account_get_credit_debit(struct plugin *plugin,
/* Find a chain event by its database id */
struct chain_event *find_chain_event_by_id(const tal_t *ctx,
struct db *db,
const struct bkpr *bkpr,
u64 event_db_id);
/* Find the utxos for this account.
@@ -111,7 +112,7 @@ struct chain_event *find_chain_event_by_id(const tal_t *ctx,
* (all outputs terminate either to wallet or external)
*/
bool find_txo_chain(const tal_t *ctx,
struct db *db,
const struct bkpr *bkpr,
const struct account *acct,
struct txo_set ***sets);
@@ -126,7 +127,7 @@ const char *find_close_account_name(const tal_t *ctx,
* highest blockheight that has a resolving tx in it.
*
* The point of this is to allow us to prune data, eventually */
u64 account_onchain_closeheight(struct db *db, const struct account *acct);
u64 account_onchain_closeheight(const struct bkpr *bkpr, const struct account *acct);
/* When we make external deposits from the wallet, we don't
* count them until any output that was spent *into* them is
@@ -134,7 +135,7 @@ u64 account_onchain_closeheight(struct db *db, const struct account *acct);
*
* This method updates the blockheight on these events to the
* height an input was spent into */
void maybe_closeout_external_deposits(struct db *db,
void maybe_closeout_external_deposits(struct bkpr *bkpr,
const struct bitcoin_txid *txid,
u32 blockheight);
@@ -151,7 +152,7 @@ void log_channel_event(struct db *db,
/* Log a chain event.
* Returns true if inserted, false if already exists;
* ctx is for allocating objects onto chain_event `e` */
bool log_chain_event(struct db *db,
bool log_chain_event(struct bkpr *bkpr,
const struct account *acct,
struct chain_event *e);

View File

@@ -309,7 +309,7 @@ static bool test_onchain_fee_wallet_spend(const tal_t *ctx)
* deposit 1111 0 700 external
*/
db_begin_transaction(db);
log_chain_event(db, wal_acct,
log_chain_event(bkpr, wal_acct,
make_chain_event(ctx, "withdrawal",
AMOUNT_MSAT(0),
AMOUNT_MSAT(1000),
@@ -318,7 +318,7 @@ static bool test_onchain_fee_wallet_spend(const tal_t *ctx)
'X', 0, '1'));
maybe_update_onchain_fees(ctx, NULL, bkpr, &txid);
log_chain_event(db, wal_acct,
log_chain_event(bkpr, wal_acct,
make_chain_event(ctx, "deposit",
AMOUNT_MSAT(200),
AMOUNT_MSAT(0),
@@ -327,7 +327,7 @@ static bool test_onchain_fee_wallet_spend(const tal_t *ctx)
'1', 1, '*'));
maybe_update_onchain_fees(ctx, NULL, bkpr, &txid);
log_chain_event(db, ext_acct,
log_chain_event(bkpr, ext_acct,
make_chain_event(ctx, "deposit",
AMOUNT_MSAT(700),
AMOUNT_MSAT(0),
@@ -407,7 +407,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
AMOUNT_MSAT(1660),
blockheight,
'X', 0, '*');
log_chain_event(db, acct, ev);
log_chain_event(bkpr, acct, ev);
tags[0] = MVT_CHANNEL_OPEN;
maybe_update_account(NULL, acct, ev, tags, 0, NULL);
@@ -417,13 +417,13 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
AMOUNT_MSAT(1660),
blockheight,
'X', 0, '1');
log_chain_event(db, acct, ev);
log_chain_event(bkpr, acct, ev);
/* Update the account to have the right info! */
tags[0] = MVT_CHANNEL_CLOSE;
maybe_update_account(NULL, acct, ev, tags, close_output_count, NULL);
log_chain_event(db, acct,
log_chain_event(bkpr, acct,
make_chain_event(ctx, "delayed_to_us",
AMOUNT_MSAT(200),
AMOUNT_MSAT(0),
@@ -433,14 +433,14 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
memset(&txid, '1', sizeof(struct bitcoin_txid));
maybe_update_onchain_fees(ctx, NULL, bkpr, &txid);
log_chain_event(db, wal_acct,
log_chain_event(bkpr, wal_acct,
make_chain_event(ctx, "anchor",
AMOUNT_MSAT(30),
AMOUNT_MSAT(0),
AMOUNT_MSAT(30),
blockheight,
'1', 0, '*'));
log_chain_event(db, ext_acct,
log_chain_event(bkpr, ext_acct,
make_chain_event(ctx, "anchor",
AMOUNT_MSAT(30),
AMOUNT_MSAT(0),
@@ -454,7 +454,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
ofs = list_chain_fees(ctx, bkpr);
CHECK(tal_count(ofs) == 0);
log_chain_event(db, acct,
log_chain_event(bkpr, acct,
make_chain_event(ctx, "htlc_timeout",
AMOUNT_MSAT(600),
AMOUNT_MSAT(0),
@@ -462,7 +462,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
blockheight,
'1', 2, '*'));
log_chain_event(db, ext_acct,
log_chain_event(bkpr, ext_acct,
make_chain_event(ctx, "to_them",
AMOUNT_MSAT(300),
AMOUNT_MSAT(0),
@@ -476,7 +476,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
/* txid 2222 */
db_begin_transaction(db);
log_chain_event(db, acct,
log_chain_event(bkpr, acct,
make_chain_event(ctx, "to_wallet",
AMOUNT_MSAT(0),
AMOUNT_MSAT(200),
@@ -484,7 +484,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
blockheight + 1,
'1', 1, '2'));
log_chain_event(db, wal_acct,
log_chain_event(bkpr, wal_acct,
make_chain_event(ctx, "deposit",
AMOUNT_MSAT(150),
AMOUNT_MSAT(0),
@@ -495,7 +495,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
maybe_update_onchain_fees(ctx, NULL, bkpr, &txid);
CHECK(acct->onchain_resolved_block == 0);
assert(account_onchain_closeheight(db, acct) == 0);
assert(account_onchain_closeheight(bkpr, acct) == 0);
CHECK(acct->onchain_resolved_block == 0);
db_commit_transaction(db);
@@ -508,7 +508,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
/* txid 4444 */
db_begin_transaction(db);
log_chain_event(db, wal_acct,
log_chain_event(bkpr, wal_acct,
make_chain_event(ctx, "deposit",
AMOUNT_MSAT(350),
AMOUNT_MSAT(0),
@@ -520,7 +520,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
maybe_update_onchain_fees(ctx, NULL, bkpr, &txid);
/* txid 3333 */
log_chain_event(db, acct,
log_chain_event(bkpr, acct,
make_chain_event(ctx, "htlc_timeout",
AMOUNT_MSAT(0),
AMOUNT_MSAT(600),
@@ -528,10 +528,10 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
blockheight + 2,
'1', 2, '3'));
assert(account_onchain_closeheight(db, acct) == 0);
assert(account_onchain_closeheight(bkpr, acct) == 0);
CHECK(acct->onchain_resolved_block == 0);
log_chain_event(db, acct,
log_chain_event(bkpr, acct,
make_chain_event(ctx, "htlc_tx",
AMOUNT_MSAT(450),
AMOUNT_MSAT(0),
@@ -542,7 +542,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
memset(&txid, '3', sizeof(struct bitcoin_txid));
maybe_update_onchain_fees(ctx, NULL, bkpr, &txid);
log_chain_event(db, acct,
log_chain_event(bkpr, acct,
make_chain_event(ctx, "to_wallet",
AMOUNT_MSAT(0),
AMOUNT_MSAT(450),
@@ -565,7 +565,7 @@ static bool test_onchain_fee_chan_close(const tal_t *ctx)
/* Now we update the channel's onchain fees */
CHECK(acct->onchain_resolved_block == 0);
db_begin_transaction(db);
account_update_closeheight(NULL, acct, account_onchain_closeheight(db, acct));
account_update_closeheight(NULL, acct, account_onchain_closeheight(bkpr, acct));
CHECK(acct->onchain_resolved_block == blockheight + 2);
err = update_channel_onchain_fees(ctx, NULL, bkpr, acct);
CHECK_MSG(!err, err);
@@ -660,14 +660,14 @@ static bool test_onchain_fee_chan_open(const tal_t *ctx)
*/
memset(&txid, 'A', sizeof(struct bitcoin_txid));
db_begin_transaction(db);
log_chain_event(db, wal_acct,
log_chain_event(bkpr, wal_acct,
make_chain_event(ctx, "withdrawal",
AMOUNT_MSAT(0),
AMOUNT_MSAT(1000),
AMOUNT_MSAT(1000),
blockheight,
'X', 0, 'A'));
log_chain_event(db, wal_acct,
log_chain_event(bkpr, wal_acct,
make_chain_event(ctx, "withdrawal",
AMOUNT_MSAT(0),
AMOUNT_MSAT(3001),
@@ -675,7 +675,7 @@ static bool test_onchain_fee_chan_open(const tal_t *ctx)
blockheight,
'Y', 0, 'A'));
log_chain_event(db, acct,
log_chain_event(bkpr, acct,
make_chain_event(ctx, "deposit",
AMOUNT_MSAT(500),
AMOUNT_MSAT(0),
@@ -684,7 +684,7 @@ static bool test_onchain_fee_chan_open(const tal_t *ctx)
'A', 0, '*'));
maybe_update_onchain_fees(ctx, NULL, bkpr, &txid);
log_chain_event(db, acct2,
log_chain_event(bkpr, acct2,
make_chain_event(ctx, "deposit",
AMOUNT_MSAT(1000),
AMOUNT_MSAT(0),
@@ -693,7 +693,7 @@ static bool test_onchain_fee_chan_open(const tal_t *ctx)
'A', 1, '*'));
maybe_update_onchain_fees(ctx, NULL, bkpr, &txid);
log_chain_event(db, wal_acct,
log_chain_event(bkpr, wal_acct,
make_chain_event(ctx, "deposit",
AMOUNT_MSAT(2200),
AMOUNT_MSAT(0),
@@ -946,7 +946,7 @@ static bool test_chain_event_crud(const tal_t *ctx)
ev1->payment_id = NULL;
db_begin_transaction(db);
log_chain_event(db, acct, ev1);
log_chain_event(bkpr, acct, ev1);
db_commit_transaction(db);
ev2->tag = tal_fmt(ctx, "deposit");
@@ -982,20 +982,20 @@ static bool test_chain_event_crud(const tal_t *ctx)
ev3->payment_id = NULL;
db_begin_transaction(db);
log_chain_event(db, acct, ev2);
log_chain_event(bkpr, acct, ev2);
/* log new event to a different account.. */
log_chain_event(db, acct2, ev3);
log_chain_event(bkpr, acct2, ev3);
db_commit_transaction(db);
/* Try to add an already exiting event */
db_begin_transaction(db);
log_chain_event(db, acct, ev2);
log_chain_event(bkpr, acct, ev2);
db_commit_transaction(db);
/* Ok now we ge the list, there should only be two */
db_begin_transaction(db);
chain_evs = account_get_chain_events(ctx, db, acct);
chain_evs = account_get_chain_events(ctx, bkpr, acct);
db_commit_transaction(db);
CHECK(tal_count(chain_evs) == 2);
@@ -1018,9 +1018,9 @@ static bool test_chain_event_crud(const tal_t *ctx)
db_begin_transaction(db);
log_chain_event(db, acct, ev1);
log_chain_event(db, acct, ev2);
chain_evs = account_get_chain_events(ctx, db, acct);
log_chain_event(bkpr, acct, ev1);
log_chain_event(bkpr, acct, ev2);
chain_evs = account_get_chain_events(ctx, bkpr, acct);
db_commit_transaction(db);
/* There should be four now */
@@ -1075,7 +1075,7 @@ static bool test_account_balances(const tal_t *ctx)
account_datastore_set(NULL, acct2, "must-create");
/* +1000btc */
log_chain_event(db, acct,
log_chain_event(bkpr, acct,
make_chain_event(ctx, "one",
AMOUNT_MSAT(1000),
AMOUNT_MSAT(0),
@@ -1088,7 +1088,7 @@ static bool test_account_balances(const tal_t *ctx)
1020, 'A', 2, '*');
/* -999btc */
log_chain_event(db, acct, ev1);
log_chain_event(bkpr, acct, ev1);
/* -440btc */
log_channel_event(db, acct,
@@ -1117,7 +1117,7 @@ static bool test_account_balances(const tal_t *ctx)
AMOUNT_MSAT(0), AMOUNT_MSAT(5001),
AMOUNT_MSAT(5001), 2020,
'A', 4, '*');
log_chain_event(db, acct, ev1);
log_chain_event(bkpr, acct, ev1);
ok = account_get_balance(NULL, db, acct->name, &balance);
CHECK(!ok);
@@ -1183,7 +1183,7 @@ static bool test_account_crud(const tal_t *ctx)
ev1->payment_id = NULL;
db_begin_transaction(db);
log_chain_event(db, acct, ev1);
log_chain_event(bkpr, acct, ev1);
tags = tal_arr(ctx, enum mvt_tag, 2);