bkpr-zeroconf: Zeroconfs will emit 'channel_proposed' event

Keep the accounts as an 'append only' log, instead we move the marker
for the 'channel_open' forward when a 'channel_open' comes out.

We also neatly hide the 'channel_proposed' events in 'inspect' if
there's a 'channel_open' for that same event.

If you call inspect before the 'channel_open' is confirmed, you'll see
the tag as 'channel_proposed', afterwards it shows up as
'channel_open'. However the event log rolls forward -- listaccountevents
will show the correct history of the proposal then open confirming (plus
any routing that happened before the channel confirmed).
This commit is contained in:
niftynei
2022-07-27 16:18:05 -05:00
committed by Rusty Russell
parent 30aa1d79fb
commit e048292fdf
5 changed files with 71 additions and 16 deletions

View File

@@ -225,7 +225,8 @@ static struct chain_event **find_txos_for_tx(const tal_t *ctx,
" ORDER BY "
" e.utxo_txid"
", e.outnum"
", e.spending_txid NULLS FIRST"));
", e.spending_txid NULLS FIRST"
", e.blockheight"));
db_bind_txid(stmt, 0, txid);
return find_chain_events(ctx, take(stmt));
@@ -403,8 +404,14 @@ static struct txo_set *find_txo_set(const tal_t *ctx,
} else {
/* We might not have a spend event
* for everything */
if (pr)
tal_arr_expand(&txos->pairs, pr);
if (pr) {
/* Disappear "channel_proposed" events */
if (streq(pr->txo->tag,
mvt_tag_str(CHANNEL_PROPOSED)))
pr = tal_free(pr);
else
tal_arr_expand(&txos->pairs, pr);
}
pr = new_txo_pair(txos->pairs);
pr->txo = tal_steal(pr, ev);
}
@@ -671,7 +678,8 @@ static struct chain_event *find_chain_event(const tal_t *ctx,
struct db *db,
const struct account *acct,
const struct bitcoin_outpoint *outpoint,
const struct bitcoin_txid *spending_txid)
const struct bitcoin_txid *spending_txid,
const char *tag)
{
struct db_stmt *stmt;
@@ -733,7 +741,10 @@ static struct chain_event *find_chain_event(const tal_t *ctx,
" e.account_id = ?"
" AND e.utxo_txid = ?"
" AND e.outnum = ?"
" AND e.spending_txid IS NULL"));
" AND e.spending_txid IS NULL"
" AND e.tag = ?"));
db_bind_text(stmt, 3, tag);
}
db_bind_u64(stmt, 0, acct->db_id);
@@ -1850,7 +1861,8 @@ bool log_chain_event(struct db *db,
/* We're responsible for de-duping chain events! */
if (find_chain_event(e, db, acct,
&e->outpoint, e->spending_txid))
&e->outpoint, e->spending_txid,
e->tag))
return false;
stmt = db_prepare_v2(db, SQL("INSERT INTO chain_events"

View File

@@ -11,6 +11,7 @@ BOOKKEEPER_TEST_COMMON_OBJS := \
common/base32.o \
common/blockheight_states.o \
common/channel_type.o \
common/coin_mvt.o \
common/features.o \
common/json_stream.o \
common/key_derive.o \

View File

@@ -88,6 +88,9 @@ u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
/* Generated stub for fromwire_u8_array */
void fromwire_u8_array(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, u8 *arr UNNEEDED, size_t num UNNEEDED)
{ fprintf(stderr, "fromwire_u8_array called!\n"); abort(); }
/* Generated stub for fromwire_wirestring */
char *fromwire_wirestring(const tal_t *ctx UNNEEDED, const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_wirestring called!\n"); abort(); }
/* Generated stub for htlc_state_flags */
int htlc_state_flags(enum htlc_state state UNNEEDED)
{ fprintf(stderr, "htlc_state_flags called!\n"); abort(); }
@@ -177,9 +180,6 @@ enum htlc_state last_fee_state(enum side opener UNNEEDED)
/* Generated stub for log_level_name */
const char *log_level_name(enum log_level level UNNEEDED)
{ fprintf(stderr, "log_level_name called!\n"); abort(); }
/* Generated stub for mvt_tag_str */
const char *mvt_tag_str(enum mvt_tag tag UNNEEDED)
{ fprintf(stderr, "mvt_tag_str called!\n"); abort(); }
/* Generated stub for new_channel_event */
struct channel_event *new_channel_event(const tal_t *ctx UNNEEDED,
const char *tag UNNEEDED,
@@ -225,6 +225,9 @@ void towire_u8(u8 **pptr UNNEEDED, u8 v UNNEEDED)
/* Generated stub for towire_u8_array */
void towire_u8_array(u8 **pptr UNNEEDED, const u8 *arr UNNEEDED, size_t num UNNEEDED)
{ fprintf(stderr, "towire_u8_array called!\n"); abort(); }
/* Generated stub for towire_wirestring */
void towire_wirestring(u8 **pptr UNNEEDED, const char *str UNNEEDED)
{ fprintf(stderr, "towire_wirestring called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */
static char *tmp_dsn(const tal_t *ctx)

View File

@@ -94,6 +94,9 @@ u8 fromwire_u8(const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
/* Generated stub for fromwire_u8_array */
void fromwire_u8_array(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, u8 *arr UNNEEDED, size_t num UNNEEDED)
{ fprintf(stderr, "fromwire_u8_array called!\n"); abort(); }
/* Generated stub for fromwire_wirestring */
char *fromwire_wirestring(const tal_t *ctx UNNEEDED, const u8 **cursor UNNEEDED, size_t *max UNNEEDED)
{ fprintf(stderr, "fromwire_wirestring called!\n"); abort(); }
/* Generated stub for htlc_state_flags */
int htlc_state_flags(enum htlc_state state UNNEEDED)
{ fprintf(stderr, "htlc_state_flags called!\n"); abort(); }
@@ -183,9 +186,6 @@ enum htlc_state last_fee_state(enum side opener UNNEEDED)
/* Generated stub for log_level_name */
const char *log_level_name(enum log_level level UNNEEDED)
{ fprintf(stderr, "log_level_name called!\n"); abort(); }
/* Generated stub for mvt_tag_str */
const char *mvt_tag_str(enum mvt_tag tag UNNEEDED)
{ fprintf(stderr, "mvt_tag_str called!\n"); abort(); }
/* Generated stub for new_channel_event */
struct channel_event *new_channel_event(const tal_t *ctx UNNEEDED,
const char *tag UNNEEDED,
@@ -231,6 +231,9 @@ void towire_u8(u8 **pptr UNNEEDED, u8 v UNNEEDED)
/* Generated stub for towire_u8_array */
void towire_u8_array(u8 **pptr UNNEEDED, const u8 *arr UNNEEDED, size_t num UNNEEDED)
{ fprintf(stderr, "towire_u8_array called!\n"); abort(); }
/* Generated stub for towire_wirestring */
void towire_wirestring(u8 **pptr UNNEEDED, const char *str UNNEEDED)
{ fprintf(stderr, "towire_wirestring called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */
static char *tmp_dsn(const tal_t *ctx)