From 7db6aaa523e4eefe2ed0ef87e1d20f9686c52f23 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Mon, 21 Aug 2023 15:08:07 +0930 Subject: [PATCH] renepay: clarify chan_extra_can_send. I am doing to add more more debugging, but sent here is 0. Document that clearly, and put a real value in sent. Also: since we already sub 1 msat from x, amount_msat_less_eq should be amount_msat_less (it may be equal to our min, in theory). Signed-off-by: Rusty Russell --- plugins/renepay/flow.c | 25 +++++++++---------------- plugins/renepay/pay.c | 6 +----- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/plugins/renepay/flow.c b/plugins/renepay/flow.c index a9c0fa480..90708844a 100644 --- a/plugins/renepay/flow.c +++ b/plugins/renepay/flow.c @@ -143,13 +143,14 @@ void chan_extra_can_send( chan_extra_can_send_(ce,scidd->dir,x); } -/* Update the knowledge that this (channel,direction) cannot send x msat.*/ +/* Update the knowledge that this (channel,direction) cannot send.*/ void chan_extra_cannot_send( struct payment *p, struct chan_extra_map *chan_extra_map, const struct short_channel_id_dir *scidd, - struct amount_msat x) + struct amount_msat sent) { + struct amount_msat x; struct chan_extra *ce = chan_extra_map_get(chan_extra_map, scidd->scid); if(!ce) @@ -158,27 +159,19 @@ void chan_extra_cannot_send( __PRETTY_FUNCTION__,__LINE__); } - /* If a channel cannot send x it means that the upper bound for the - * liquidity is MAX_L < x + htlc_total */ - if(!amount_msat_add(&x,x,ce->half[scidd->dir].htlc_total)) + /* Note: sent is already included in htlc_total! */ + if(!amount_msat_sub(&x,ce->half[scidd->dir].htlc_total,AMOUNT_MSAT(1))) { - debug_err("%s (line %d) cannot add x=%s and htlc_total=%s", + debug_err("%s (line %d) unexpected htlc_total=%s is less than 0msat", __PRETTY_FUNCTION__,__LINE__, - type_to_string(tmpctx,struct amount_msat,&x), - type_to_string(tmpctx,struct amount_msat,&ce->half[scidd->dir].htlc_total)); - } - - if(!amount_msat_sub(&x,x,AMOUNT_MSAT(1))) - { - debug_err("%s (line %d) unexpected x=%s is less than 0msat", - __PRETTY_FUNCTION__,__LINE__, - type_to_string(tmpctx,struct amount_msat,&x) + type_to_string(tmpctx,struct amount_msat, + &ce->half[scidd->dir].htlc_total) ); x = AMOUNT_MSAT(0); } /* If we "knew" the capacity was at least this, we just showed we're wrong! */ - if (amount_msat_less_eq(x, ce->half[scidd->dir].known_min)) { + if (amount_msat_less(x, ce->half[scidd->dir].known_min)) { debug_paynote(p, "Expected scid=%s min %s, but %s failed! Setting min to 0", type_to_string(tmpctx,struct short_channel_id_dir,scidd), type_to_string(tmpctx,struct amount_msat,&ce->half[scidd->dir].known_min), diff --git a/plugins/renepay/pay.c b/plugins/renepay/pay.c index 53c384374..300644e51 100644 --- a/plugins/renepay/pay.c +++ b/plugins/renepay/pay.c @@ -1190,11 +1190,7 @@ static void handle_sendpay_failure_flow(struct pay_flow *pf, chan_extra_cannot_send(p,pay_plugin->chan_extra_map, &pf->path_scidds[erridx], - /* This channel can't send all that was - * commited in HTLCs. - * Had we removed the commited amount then - * we would have to put here pf->amounts[erridx]. */ - AMOUNT_MSAT(0)); + pf->amounts[erridx]); } }