Skip to content

Commit

Permalink
wait forwards: add in_htlc_id
Browse files Browse the repository at this point in the history
Without this, we have no unique identifier for which forward happened.

Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
rustyrussell committed Oct 27, 2023
1 parent b88ef0d commit 99eb867
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
14 changes: 11 additions & 3 deletions lightningd/forwards.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@
static u64 forward_index_inc(struct lightningd *ld,
enum forward_status status,
struct short_channel_id in_channel,
u64 in_htlc_id,
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_htlc_id", tal_fmt(tmpctx, "%"PRIu64, in_htlc_id),
"=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);
Expand All @@ -29,31 +31,37 @@ 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,
u64 in_htlc_id,
const struct amount_msat *in_amount,
const struct short_channel_id *out_channel)
{
forward_index_inc(ld, status, in_channel, in_amount, out_channel,
forward_index_inc(ld, status, in_channel, in_htlc_id,
in_amount, out_channel,
WAIT_INDEX_DELETED);
}

/* Fortuntely, dbids start at 1, not 0! */
u64 forward_index_created(struct lightningd *ld,
enum forward_status status,
struct short_channel_id in_channel,
u64 in_htlc_id,
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_htlc_id,
&in_amount, out_channel,
WAIT_INDEX_CREATED);
}

u64 forward_index_update_status(struct lightningd *ld,
enum forward_status status,
struct short_channel_id in_channel,
u64 in_htlc_id,
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_htlc_id,
&in_amount, out_channel,
WAIT_INDEX_UPDATED);
}

Expand Down
3 changes: 3 additions & 0 deletions lightningd/forwards.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,19 @@ 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,
u64 in_htlc_id,
const struct amount_msat *in_amount,
const struct short_channel_id *out_channel);
u64 forward_index_created(struct lightningd *ld,
enum forward_status status,
struct short_channel_id in_channel,
u64 in_htlc_id,
struct amount_msat in_amount,
const struct short_channel_id *out_channel);
u64 forward_index_update_status(struct lightningd *ld,
enum forward_status status,
struct short_channel_id in_channel,
u64 in_htlc_id,
struct amount_msat in_amount,
const struct short_channel_id *out_channel);
#endif /* LIGHTNING_LIGHTNINGD_FORWARDS_H */
5 changes: 5 additions & 0 deletions tests/test_misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2997,13 +2997,15 @@ def test_listforwards_wait(node_factory, executor):
assert waitres == {'subsystem': 'forwards',
'created': 1,
'details': {'in_channel': scid12,
'in_htlc_id': 0,
'in_msat': Millisatoshi(amt1 + 1),
'out_channel': scid23,
'status': 'offered'}}
waitres = waitupdate.result(TIMEOUT)
assert waitres == {'subsystem': 'forwards',
'updated': 1,
'details': {'in_channel': scid12,
'in_htlc_id': 0,
'in_msat': Millisatoshi(amt1 + 1),
'out_channel': scid23,
'status': 'settled'}}
Expand All @@ -3024,13 +3026,15 @@ def test_listforwards_wait(node_factory, executor):
assert waitres == {'subsystem': 'forwards',
'created': 2,
'details': {'in_channel': scid12,
'in_htlc_id': 1,
'in_msat': Millisatoshi(amt2 + 1),
'out_channel': scid23,
'status': 'offered'}}
waitres = waitupdate.result(TIMEOUT)
assert waitres == {'subsystem': 'forwards',
'updated': 2,
'details': {'in_channel': scid12,
'in_htlc_id': 1,
'in_msat': Millisatoshi(amt2 + 1),
'out_channel': scid23,
'status': 'failed'}}
Expand All @@ -3055,6 +3059,7 @@ def test_listforwards_wait(node_factory, executor):
assert waitres == {'subsystem': 'forwards',
'deleted': 1,
'details': {'in_channel': scid12,
'in_htlc_id': 1,
'status': 'failed'}}


Expand Down
3 changes: 3 additions & 0 deletions wallet/test/run-db.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,23 @@ struct peer *find_peer_by_dbid(struct lightningd *ld UNNEEDED, u64 dbid UNNEEDED
u64 forward_index_created(struct lightningd *ld UNNEEDED,
enum forward_status status UNNEEDED,
struct short_channel_id in_channel UNNEEDED,
u64 in_htlc_id 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,
u64 in_htlc_id 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,
u64 in_htlc_id UNNEEDED,
struct amount_msat in_amount UNNEEDED,
const struct short_channel_id *out_channel UNNEEDED)
{ fprintf(stderr, "forward_index_update_status called!\n"); abort(); }
Expand Down
3 changes: 3 additions & 0 deletions wallet/test/run-wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,20 +182,23 @@ void force_peer_disconnect(struct lightningd *ld UNNEEDED,
u64 forward_index_created(struct lightningd *ld UNNEEDED,
enum forward_status status UNNEEDED,
struct short_channel_id in_channel UNNEEDED,
u64 in_htlc_id 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,
u64 in_htlc_id 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,
u64 in_htlc_id UNNEEDED,
struct amount_msat in_amount UNNEEDED,
const struct short_channel_id *out_channel UNNEEDED)
{ fprintf(stderr, "forward_index_update_status called!\n"); abort(); }
Expand Down
3 changes: 3 additions & 0 deletions wallet/wallet.c
Original file line number Diff line number Diff line change
Expand Up @@ -4713,6 +4713,7 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in,
forward_index_update_status(w->ld,
state,
*channel_scid_or_local_alias(in->key.channel),
in->key.id,
in->msat,
out ? channel_scid_or_local_alias(out->key.channel) : NULL);
id = 0;
Expand All @@ -4738,6 +4739,7 @@ void wallet_forwarded_payment_add(struct wallet *w, const struct htlc_in *in,
id = forward_index_created(w->ld,
state,
*channel_scid_or_local_alias(in->key.channel),
in->key.id,
in->msat,
out ? channel_scid_or_local_alias(out->key.channel) : NULL);

Expand Down Expand Up @@ -5127,6 +5129,7 @@ bool wallet_forward_delete(struct wallet *w,
forward_index_deleted(w->ld,
state,
*chan_in,
htlc_id ? *htlc_id : HTLC_INVALID_ID,
NULL, NULL);
}

Expand Down

0 comments on commit 99eb867

Please sign in to comment.