forwards: hook into the wait subsystem.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Added: JSON-RPC: `wait` now works for `forwards` infrastructure.
This commit is contained in:
Rusty Russell 2023-10-28 13:41:11 +10:30
parent e58ae31947
commit de1e459196
5 changed files with 76 additions and 13 deletions

View File

@ -14,14 +14,14 @@
static u64 forward_index_inc(struct lightningd *ld,
enum forward_status status,
struct short_channel_id in_channel,
struct amount_msat in_amount,
const struct amount_msat *in_amount,
const struct short_channel_id *out_channel,
enum wait_index idx)
{
return wait_index_increment(ld, WAIT_SUBSYSTEM_FORWARD, idx,
"status", forward_status_name(status),
"in_channel", short_channel_id_to_str(tmpctx, &in_channel),
"=in_msat", tal_fmt(tmpctx, "%"PRIu64, in_amount.millisatoshis), /* Raw: JSON output */
"=in_msat", in_amount ? tal_fmt(tmpctx, "%"PRIu64, in_amount->millisatoshis) : NULL, /* Raw: JSON output */
"out_channel", out_channel ? short_channel_id_to_str(tmpctx, out_channel): NULL,
NULL);
}
@ -29,7 +29,7 @@ static u64 forward_index_inc(struct lightningd *ld,
void forward_index_deleted(struct lightningd *ld,
enum forward_status status,
struct short_channel_id in_channel,
struct amount_msat in_amount,
const struct amount_msat *in_amount,
const struct short_channel_id *out_channel)
{
forward_index_inc(ld, status, in_channel, in_amount, out_channel,
@ -43,7 +43,7 @@ u64 forward_index_created(struct lightningd *ld,
struct amount_msat in_amount,
const struct short_channel_id *out_channel)
{
return forward_index_inc(ld, status, in_channel, in_amount, out_channel,
return forward_index_inc(ld, status, in_channel, &in_amount, out_channel,
WAIT_INDEX_CREATED);
}
@ -53,7 +53,7 @@ u64 forward_index_update_status(struct lightningd *ld,
struct amount_msat in_amount,
const struct short_channel_id *out_channel)
{
return forward_index_inc(ld, status, in_channel, in_amount, out_channel,
return forward_index_inc(ld, status, in_channel, &in_amount, out_channel,
WAIT_INDEX_UPDATED);
}

View File

@ -92,7 +92,7 @@ static inline const char *forward_style_name(enum forward_style style)
void forward_index_deleted(struct lightningd *ld,
enum forward_status status,
struct short_channel_id in_channel,
struct amount_msat in_amount,
const struct amount_msat *in_amount,
const struct short_channel_id *out_channel);
u64 forward_index_created(struct lightningd *ld,
enum forward_status status,

View File

@ -52,6 +52,27 @@ void fatal_vfmt(const char *fmt UNNEEDED, va_list ap UNNEEDED)
/* Generated stub for find_peer_by_dbid */
struct peer *find_peer_by_dbid(struct lightningd *ld UNNEEDED, u64 dbid UNNEEDED)
{ fprintf(stderr, "find_peer_by_dbid called!\n"); abort(); }
/* Generated stub for forward_index_created */
u64 forward_index_created(struct lightningd *ld UNNEEDED,
enum forward_status status UNNEEDED,
struct short_channel_id in_channel UNNEEDED,
struct amount_msat in_amount UNNEEDED,
const struct short_channel_id *out_channel UNNEEDED)
{ fprintf(stderr, "forward_index_created called!\n"); abort(); }
/* Generated stub for forward_index_deleted */
void forward_index_deleted(struct lightningd *ld UNNEEDED,
enum forward_status status UNNEEDED,
struct short_channel_id in_channel UNNEEDED,
const struct amount_msat *in_amount UNNEEDED,
const struct short_channel_id *out_channel UNNEEDED)
{ fprintf(stderr, "forward_index_deleted called!\n"); abort(); }
/* Generated stub for forward_index_update_status */
u64 forward_index_update_status(struct lightningd *ld UNNEEDED,
enum forward_status status UNNEEDED,
struct short_channel_id in_channel UNNEEDED,
struct amount_msat in_amount UNNEEDED,
const struct short_channel_id *out_channel UNNEEDED)
{ fprintf(stderr, "forward_index_update_status called!\n"); abort(); }
/* Generated stub for fromwire_hsmd_get_channel_basepoints_reply */
bool fromwire_hsmd_get_channel_basepoints_reply(const void *p UNNEEDED, struct basepoints *basepoints UNNEEDED, struct pubkey *funding_pubkey UNNEEDED)
{ fprintf(stderr, "fromwire_hsmd_get_channel_basepoints_reply called!\n"); abort(); }

View File

@ -200,6 +200,27 @@ void force_peer_disconnect(struct lightningd *ld UNNEEDED,
const struct peer *peer UNNEEDED,
const char *why UNNEEDED)
{ fprintf(stderr, "force_peer_disconnect called!\n"); abort(); }
/* Generated stub for forward_index_created */
u64 forward_index_created(struct lightningd *ld UNNEEDED,
enum forward_status status UNNEEDED,
struct short_channel_id in_channel UNNEEDED,
struct amount_msat in_amount UNNEEDED,
const struct short_channel_id *out_channel UNNEEDED)
{ fprintf(stderr, "forward_index_created called!\n"); abort(); }
/* Generated stub for forward_index_deleted */
void forward_index_deleted(struct lightningd *ld UNNEEDED,
enum forward_status status UNNEEDED,
struct short_channel_id in_channel UNNEEDED,
const struct amount_msat *in_amount UNNEEDED,
const struct short_channel_id *out_channel UNNEEDED)
{ fprintf(stderr, "forward_index_deleted called!\n"); abort(); }
/* Generated stub for forward_index_update_status */
u64 forward_index_update_status(struct lightningd *ld UNNEEDED,
enum forward_status status UNNEEDED,
struct short_channel_id in_channel UNNEEDED,
struct amount_msat in_amount UNNEEDED,
const struct short_channel_id *out_channel UNNEEDED)
{ fprintf(stderr, "forward_index_update_status called!\n"); abort(); }
/* Generated stub for fromwire_channeld_dev_memleak_reply */
bool fromwire_channeld_dev_memleak_reply(const void *p UNNEEDED, bool *leak UNNEEDED)
{ fprintf(stderr, "fromwire_channeld_dev_memleak_reply called!\n"); abort(); }
@ -415,10 +436,6 @@ void json_add_string(struct json_stream *js UNNEEDED,
const char *fieldname UNNEEDED,
const char *str TAKES UNNEEDED)
{ fprintf(stderr, "json_add_string called!\n"); abort(); }
/* Generated stub for json_add_timeabs */
void json_add_timeabs(struct json_stream *result UNNEEDED, const char *fieldname UNNEEDED,
struct timeabs t UNNEEDED)
{ fprintf(stderr, "json_add_timeabs called!\n"); abort(); }
/* Generated stub for json_add_timeiso */
void json_add_timeiso(struct json_stream *result UNNEEDED,
const char *fieldname UNNEEDED,

View File

@ -4643,13 +4643,20 @@ static bool wallet_forwarded_payment_update(struct wallet *w,
* one without the htlc_out restriction).*/
stmt = db_prepare_v2(w->db,
SQL("UPDATE forwards SET"
" in_msatoshi=?"
" updated_index=?"
", in_msatoshi=?"
", out_msatoshi=?"
", state=?"
", resolved_time=?"
", failcode=?"
", forward_style=?"
" WHERE in_htlc_id=? AND in_channel_scid=?"));
db_bind_u64(stmt,
forward_index_update_status(w->ld,
state,
*channel_scid_or_local_alias(in->key.channel),
in->msat,
out ? channel_scid_or_local_alias(out->key.channel) : NULL));
db_bind_amount_msat(stmt, &in->msat);
if (out) {
@ -4696,6 +4703,7 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in,
{
struct db_stmt *stmt;
struct timeabs *resolved_time;
u64 id;
if (state == FORWARD_SETTLED || state == FORWARD_FAILED) {
resolved_time = tal(tmpctx, struct timeabs);
@ -4709,7 +4717,8 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in,
stmt = db_prepare_v2(w->db,
SQL("INSERT INTO forwards ("
" in_htlc_id"
" rowid"
", in_htlc_id"
", out_htlc_id"
", in_channel_scid"
", out_channel_scid"
@ -4720,7 +4729,14 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in,
", resolved_time"
", failcode"
", forward_style"
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"));
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"));
id = forward_index_created(w->ld,
state,
*channel_scid_or_local_alias(in->key.channel),
in->msat,
out ? channel_scid_or_local_alias(out->key.channel) : NULL);
db_bind_u64(stmt, id);
db_bind_u64(stmt, in->key.id);
/* FORWARD_LOCAL_FAILED may occur before we get htlc_out */
@ -5014,6 +5030,15 @@ bool wallet_forward_delete(struct wallet *w,
changed = db_count_changes(stmt) != 0;
tal_free(stmt);
if (changed) {
/* FIXME: We don't set in->msat or out here, since that would
* need an extra lookup */
forward_index_deleted(w->ld,
state,
*chan_in,
NULL, NULL);
}
return changed;
}