Skip to content

Commit a2478f7

Browse files
committed
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 <[email protected]>
1 parent a9a3978 commit a2478f7

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

tests/plugins/channeld_fakenet.c

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ static void update_commitment_tx_added(struct info *info, u64 htlc_id)
189189
{
190190
struct changed_htlc *changed;
191191
u8 *msg;
192+
const struct htlc **htlcs = tal_arr(tmpctx, const struct htlc *, 0);
192193

193194
changed = tal_arr(tmpctx, struct changed_htlc, 1);
194195
changed->id = htlc_id;
@@ -202,6 +203,8 @@ static void update_commitment_tx_added(struct info *info, u64 htlc_id)
202203
changed);
203204
daemon_conn_send(info->dc, take(msg));
204205

206+
channel_sending_commit(info->channel, &htlcs);
207+
205208
/* Tell it we got revoke & ack from them. */
206209
pretend_got_revoke(info, htlc_id, RCVD_ADD_REVOCATION);
207210

@@ -220,6 +223,11 @@ static void update_commitment_tx_added(struct info *info, u64 htlc_id)
220223
NULL);
221224
daemon_conn_send(info->dc, take(msg));
222225

226+
/* Tell full_channel.c the htlc is totally committed. */
227+
channel_rcvd_revoke_and_ack(info->channel, &htlcs);
228+
channel_rcvd_commit(info->channel, &htlcs);
229+
channel_sending_revoke_and_ack(info->channel);
230+
223231
/* Final change to SENT_ADD_ACK_REVOCATION is implied */
224232
info->commit_num++;
225233
}
@@ -367,6 +375,7 @@ static void fail(struct info *info,
367375
const struct failed_htlc **failed_arr;
368376
u8 *msg;
369377
struct changed_htlc *changed;
378+
enum channel_remove_err err;
370379

371380
msg = tal_arr(tmpctx, u8, 0);
372381
towire_u16(&msg, failcode);
@@ -375,6 +384,12 @@ static void fail(struct info *info,
375384
fmt_nodeidx(tmpctx, current_nodeidx),
376385
onion_wire_name(failcode));
377386

387+
err = channel_fail_htlc(info->channel,
388+
LOCAL,
389+
htlc->htlc_id,
390+
NULL);
391+
assert(err == CHANNEL_ERR_REMOVE_OK);
392+
378393
failed_arr = tal_arr(tmpctx, const struct failed_htlc *, 1);
379394
failed_arr[0] = failed = tal(failed_arr, struct failed_htlc);
380395
failed->id = htlc->htlc_id;
@@ -502,6 +517,15 @@ static void succeed(struct info *info,
502517
struct changed_htlc *changed;
503518
struct fulfilled_htlc *fulfilled;
504519
u8 *msg;
520+
enum channel_remove_err err;
521+
522+
err = channel_fulfill_htlc(info->channel,
523+
LOCAL,
524+
htlc->htlc_id,
525+
preimage,
526+
NULL);
527+
status_debug("channel_fulfill_htlc = %i", err);
528+
assert(err == CHANNEL_ERR_REMOVE_OK);
505529

506530
fulfilled = tal_arr(tmpctx, struct fulfilled_htlc, 1);
507531
fulfilled->id = htlc->htlc_id;
@@ -836,7 +860,6 @@ static void handle_offer_htlc(struct info *info, const u8 *inmsg)
836860
u8 *msg;
837861
u32 cltv_expiry;
838862
struct amount_msat amount;
839-
struct sha256 payment_hash;
840863
u8 onion_routing_packet[TOTAL_PACKET_SIZE(ROUTING_INFO_SIZE)];
841864
enum channel_add_err e;
842865
const u8 *failwiremsg;
@@ -854,7 +877,7 @@ static void handle_offer_htlc(struct info *info, const u8 *inmsg)
854877
master_badmsg(WIRE_CHANNELD_OFFER_HTLC, inmsg);
855878

856879
e = channel_add_htlc(info->channel, LOCAL, htlc->htlc_id,
857-
amount, cltv_expiry, &payment_hash,
880+
amount, cltv_expiry, &htlc->payment_hash,
858881
onion_routing_packet, take(blinding), NULL,
859882
&htlc_fee, true);
860883
status_debug("Adding HTLC %"PRIu64" amount=%s cltv=%u gave %s",

0 commit comments

Comments
 (0)