From af971fd02521dc98dfe6c2fcb42089da8de479d7 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sat, 28 Oct 2023 13:42:18 +1030 Subject: [PATCH] wait forwards: add in_htlc_id Without this, we have no unique identifier for which forward happened. Signed-off-by: Rusty Russell --- lightningd/forwards.c | 14 +++++++++++--- lightningd/forwards.h | 3 +++ tests/test_misc.py | 5 +++++ wallet/test/run-db.c | 3 +++ wallet/test/run-wallet.c | 3 +++ wallet/wallet.c | 3 +++ 6 files changed, 28 insertions(+), 3 deletions(-) diff --git a/lightningd/forwards.c b/lightningd/forwards.c index c62e8aa7d..690651c32 100644 --- a/lightningd/forwards.c +++ b/lightningd/forwards.c @@ -14,6 +14,7 @@ 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) @@ -21,6 +22,7 @@ static u64 forward_index_inc(struct lightningd *ld, 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); @@ -29,10 +31,12 @@ 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); } @@ -40,20 +44,24 @@ void forward_index_deleted(struct lightningd *ld, 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); } diff --git a/lightningd/forwards.h b/lightningd/forwards.h index 1f478c001..e1cb04786 100644 --- a/lightningd/forwards.h +++ b/lightningd/forwards.h @@ -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 */ diff --git a/tests/test_misc.py b/tests/test_misc.py index bf8f5620a..6ebe157c6 100644 --- a/tests/test_misc.py +++ b/tests/test_misc.py @@ -3013,6 +3013,7 @@ 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'}} @@ -3020,6 +3021,7 @@ def test_listforwards_wait(node_factory, executor): assert waitres == {'subsystem': 'forwards', 'updated': 1, 'details': {'in_channel': scid12, + 'in_htlc_id': 0, 'in_msat': Millisatoshi(amt1 + 1), 'out_channel': scid23, 'status': 'settled'}} @@ -3040,6 +3042,7 @@ 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'}} @@ -3047,6 +3050,7 @@ def test_listforwards_wait(node_factory, executor): assert waitres == {'subsystem': 'forwards', 'updated': 2, 'details': {'in_channel': scid12, + 'in_htlc_id': 1, 'in_msat': Millisatoshi(amt2 + 1), 'out_channel': scid23, 'status': 'failed'}} @@ -3071,6 +3075,7 @@ def test_listforwards_wait(node_factory, executor): assert waitres == {'subsystem': 'forwards', 'deleted': 1, 'details': {'in_channel': scid12, + 'in_htlc_id': 1, 'status': 'failed'}} diff --git a/wallet/test/run-db.c b/wallet/test/run-db.c index ce0a223f1..34aea12d8 100644 --- a/wallet/test/run-db.c +++ b/wallet/test/run-db.c @@ -56,6 +56,7 @@ 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(); } @@ -63,6 +64,7 @@ u64 forward_index_created(struct lightningd *ld UNNEEDED, 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(); } @@ -70,6 +72,7 @@ void forward_index_deleted(struct lightningd *ld UNNEEDED, 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(); } diff --git a/wallet/test/run-wallet.c b/wallet/test/run-wallet.c index 875900bbb..6024dfba9 100644 --- a/wallet/test/run-wallet.c +++ b/wallet/test/run-wallet.c @@ -204,6 +204,7 @@ 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(); } @@ -211,6 +212,7 @@ u64 forward_index_created(struct lightningd *ld UNNEEDED, 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(); } @@ -218,6 +220,7 @@ void forward_index_deleted(struct lightningd *ld UNNEEDED, 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(); } diff --git a/wallet/wallet.c b/wallet/wallet.c index f129f52d7..11ba3f2e1 100644 --- a/wallet/wallet.c +++ b/wallet/wallet.c @@ -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; @@ -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); @@ -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); }