From 8c06d0d410c84394a084e2d3561b6119b364f1fb Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 6 Nov 2024 13:54:38 +1030 Subject: [PATCH] channeld_fakenet: remove HTLCs after completion. I started getting "WIRE_TEMPORARY_CHANNEL_FAILURE: Too many HTLCs" after two hundred xpay attempts. This was nice (it found some bugs in injectpaymentonion's handling of local errors, and in xpay's reporting), but shouldn't happen. Signed-off-by: Rusty Russell --- tests/plugins/channeld_fakenet.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/plugins/channeld_fakenet.c b/tests/plugins/channeld_fakenet.c index a73179dc4b87..c9e4f52ecab4 100644 --- a/tests/plugins/channeld_fakenet.c +++ b/tests/plugins/channeld_fakenet.c @@ -189,6 +189,7 @@ static void update_commitment_tx_added(struct info *info, u64 htlc_id) { struct changed_htlc *changed; u8 *msg; + const struct htlc **htlcs = tal_arr(tmpctx, const struct htlc *, 0); changed = tal_arr(tmpctx, struct changed_htlc, 1); changed->id = htlc_id; @@ -202,6 +203,8 @@ static void update_commitment_tx_added(struct info *info, u64 htlc_id) changed); daemon_conn_send(info->dc, take(msg)); + channel_sending_commit(info->channel, &htlcs); + /* Tell it we got revoke & ack from them. */ pretend_got_revoke(info, htlc_id, RCVD_ADD_REVOCATION); @@ -220,6 +223,11 @@ static void update_commitment_tx_added(struct info *info, u64 htlc_id) NULL); daemon_conn_send(info->dc, take(msg)); + /* Tell full_channel.c the htlc is totally committed. */ + channel_rcvd_revoke_and_ack(info->channel, &htlcs); + channel_rcvd_commit(info->channel, &htlcs); + channel_sending_revoke_and_ack(info->channel); + /* Final change to SENT_ADD_ACK_REVOCATION is implied */ info->commit_num++; } @@ -367,6 +375,7 @@ static void fail(struct info *info, const struct failed_htlc **failed_arr; u8 *msg; struct changed_htlc *changed; + enum channel_remove_err err; msg = tal_arr(tmpctx, u8, 0); towire_u16(&msg, failcode); @@ -375,6 +384,12 @@ static void fail(struct info *info, fmt_nodeidx(tmpctx, current_nodeidx), onion_wire_name(failcode)); + err = channel_fail_htlc(info->channel, + LOCAL, + htlc->htlc_id, + NULL); + assert(err == CHANNEL_ERR_REMOVE_OK); + failed_arr = tal_arr(tmpctx, const struct failed_htlc *, 1); failed_arr[0] = failed = tal(failed_arr, struct failed_htlc); failed->id = htlc->htlc_id; @@ -502,6 +517,15 @@ static void succeed(struct info *info, struct changed_htlc *changed; struct fulfilled_htlc *fulfilled; u8 *msg; + enum channel_remove_err err; + + err = channel_fulfill_htlc(info->channel, + LOCAL, + htlc->htlc_id, + preimage, + NULL); + status_debug("channel_fulfill_htlc = %i", err); + assert(err == CHANNEL_ERR_REMOVE_OK); fulfilled = tal_arr(tmpctx, struct fulfilled_htlc, 1); fulfilled->id = htlc->htlc_id; @@ -836,7 +860,6 @@ static void handle_offer_htlc(struct info *info, const u8 *inmsg) u8 *msg; u32 cltv_expiry; struct amount_msat amount; - struct sha256 payment_hash; u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)]; enum channel_add_err e; const u8 *failwiremsg; @@ -854,7 +877,7 @@ static void handle_offer_htlc(struct info *info, const u8 *inmsg) master_badmsg(WIRE_CHANNELD_OFFER_HTLC, inmsg); e = channel_add_htlc(info->channel, LOCAL, htlc->htlc_id, - amount, cltv_expiry, &payment_hash, + amount, cltv_expiry, &htlc->payment_hash, onion_routing_packet, take(blinding), NULL, &htlc_fee, true); status_debug("Adding HTLC %"PRIu64" amount=%s cltv=%u gave %s",