@@ -334,10 +334,19 @@ static void fail_out_htlc(struct htlc_out *hout,
334
334
static bool check_fwd_amount (struct htlc_in * hin ,
335
335
struct amount_msat amt_to_forward ,
336
336
struct amount_msat amt_in_htlc ,
337
- struct amount_msat fee )
337
+ u32 feerate_base , u32 feerate_ppm )
338
338
{
339
+ struct amount_msat fee ;
339
340
struct amount_msat fwd ;
340
341
342
+ if (!amount_msat_fee (& fee , amt_to_forward ,
343
+ feerate_base , feerate_ppm )) {
344
+ log_broken (hin -> key .channel -> log , "Fee overflow forwarding %s!" ,
345
+ type_to_string (tmpctx , struct amount_msat ,
346
+ & amt_to_forward ));
347
+ return false;
348
+ }
349
+
341
350
if (amount_msat_sub (& fwd , amt_in_htlc , fee )
342
351
&& amount_msat_greater_eq (fwd , amt_to_forward ))
343
352
return true;
@@ -673,7 +682,6 @@ static void forward_htlc(struct htlc_in *hin,
673
682
const struct pubkey * next_blinding )
674
683
{
675
684
const u8 * failmsg ;
676
- struct amount_msat fee ;
677
685
struct lightningd * ld = hin -> key .channel -> peer -> ld ;
678
686
struct channel * next = active_channel_by_scid (ld , scid );
679
687
struct htlc_out * hout = NULL ;
@@ -695,17 +703,9 @@ static void forward_htlc(struct htlc_in *hin,
695
703
* - SHOULD accept HTLCs that pay a fee equal to or greater than:
696
704
* - fee_base_msat + ( amount_to_forward * fee_proportional_millionths / 1000000 )
697
705
*/
698
- if (!amount_msat_fee (& fee , amt_to_forward ,
699
- next -> feerate_base ,
700
- next -> feerate_ppm )) {
701
- log_broken (ld -> log , "Fee overflow forwarding %s!" ,
702
- type_to_string (tmpctx , struct amount_msat ,
703
- & amt_to_forward ));
704
- needs_update_appended = true;
705
- failmsg = towire_fee_insufficient (tmpctx , hin -> msat , NULL );
706
- goto fail ;
707
- }
708
- if (!check_fwd_amount (hin , amt_to_forward , hin -> msat , fee )) {
706
+ if (!check_fwd_amount (hin , amt_to_forward , hin -> msat ,
707
+ next -> feerate_base ,
708
+ next -> feerate_ppm )) {
709
709
needs_update_appended = true;
710
710
failmsg = towire_fee_insufficient (tmpctx , hin -> msat , NULL );
711
711
goto fail ;
0 commit comments