61
61
((msg) == WIRE_SPLICE || \
62
62
(msg) == WIRE_SPLICE_ACK)
63
63
64
+ #define SAT_MIN (a , b ) (amount_sat_less((a), (b)) ? (a) : (b))
65
+
64
66
struct peer {
65
67
struct per_peer_state * pps ;
66
68
bool channel_ready [NUM_SIDES ];
@@ -2907,7 +2909,7 @@ static size_t calc_weight(enum tx_role role, const struct wally_psbt *psbt)
2907
2909
weight += psbt_input_get_weight (psbt , i );
2908
2910
2909
2911
for (size_t i = 0 ; i < psbt -> num_outputs ; i ++ )
2910
- if (is_initiators_serial (& psbt -> inputs [i ].unknowns )) {
2912
+ if (is_initiators_serial (& psbt -> outputs [i ].unknowns )) {
2911
2913
if (role == TX_INITIATOR )
2912
2914
weight += psbt_output_get_weight (psbt , i );
2913
2915
}
@@ -2928,7 +2930,7 @@ static struct amount_sat check_balances(struct peer *peer,
2928
2930
{
2929
2931
struct amount_sat min_initiator_fee , min_accepter_fee ,
2930
2932
max_initiator_fee , max_accepter_fee ,
2931
- funding_amount_res ;
2933
+ funding_amount_res , min_multiplied ;
2932
2934
struct amount_msat funding_amount ,
2933
2935
initiator_fee , accepter_fee ;
2934
2936
struct amount_msat in [NUM_TX_ROLES ], out [NUM_TX_ROLES ];
@@ -2977,45 +2979,23 @@ static struct amount_sat check_balances(struct peer *peer,
2977
2979
* While we're, here, adjust the output counts by splice amount.
2978
2980
*/
2979
2981
2980
- if (peer -> splicing -> opener_relative > 0 ) {
2981
- if (!amount_msat_add_sat (& funding_amount , funding_amount ,
2982
- amount_sat ((u64 )peer -> splicing -> opener_relative )))
2983
- peer_failed_warn (peer -> pps , & peer -> channel_id ,
2984
- "Unable to add opener funding" );
2985
- if (!amount_msat_add_sat (& out [TX_INITIATOR ], out [TX_INITIATOR ],
2986
- amount_sat ((u64 )peer -> splicing -> opener_relative )))
2987
- peer_failed_warn (peer -> pps , & peer -> channel_id ,
2988
- "Unable to add opener funding to out amnt." );
2989
- } else {
2990
- if (!amount_msat_sub_sat (& funding_amount , funding_amount ,
2991
- amount_sat ((u64 )- peer -> splicing -> opener_relative )))
2992
- peer_failed_warn (peer -> pps , & peer -> channel_id ,
2993
- "Unable to sub opener funding" );
2994
- if (!amount_msat_sub_sat (& out [TX_INITIATOR ], out [TX_INITIATOR ],
2995
- amount_sat ((u64 )peer -> splicing -> opener_relative )))
2996
- peer_failed_warn (peer -> pps , & peer -> channel_id ,
2997
- "Unable to sub opener funding from out amnt." );
2998
- }
2982
+ if (!amount_msat_add_sat_s64 (& funding_amount , funding_amount ,
2983
+ peer -> splicing -> opener_relative ))
2984
+ peer_failed_warn (peer -> pps , & peer -> channel_id ,
2985
+ "Unable to add opener funding" );
2986
+ if (!amount_msat_add_sat_s64 (& out [TX_INITIATOR ], out [TX_INITIATOR ],
2987
+ peer -> splicing -> opener_relative ))
2988
+ peer_failed_warn (peer -> pps , & peer -> channel_id ,
2989
+ "Unable to add opener funding to out amnt." );
2999
2990
3000
- if (peer -> splicing -> accepter_relative > 0 ) {
3001
- if (!amount_msat_add_sat (& funding_amount , funding_amount ,
3002
- amount_sat ((u64 )peer -> splicing -> accepter_relative )))
3003
- peer_failed_warn (peer -> pps , & peer -> channel_id ,
3004
- "Unable to add accepter funding" );
3005
- if (!amount_msat_add_sat (& out [TX_ACCEPTER ], out [TX_ACCEPTER ],
3006
- amount_sat ((u64 )peer -> splicing -> accepter_relative )))
3007
- peer_failed_warn (peer -> pps , & peer -> channel_id ,
3008
- "Unable to add accepter funding to out amnt." );
3009
- } else {
3010
- if (!amount_msat_sub_sat (& funding_amount , funding_amount ,
3011
- amount_sat ((u64 )- peer -> splicing -> accepter_relative )))
3012
- peer_failed_warn (peer -> pps , & peer -> channel_id ,
3013
- "Unable to subtract accepter funding" );
3014
- if (!amount_msat_sub_sat (& out [TX_ACCEPTER ], out [TX_ACCEPTER ],
3015
- amount_sat ((u64 )- peer -> splicing -> accepter_relative )))
3016
- peer_failed_warn (peer -> pps , & peer -> channel_id ,
3017
- "Unable to sub accepter funding from out amnt." );
3018
- }
2991
+ if (!amount_msat_add_sat_s64 (& funding_amount , funding_amount ,
2992
+ peer -> splicing -> accepter_relative ))
2993
+ peer_failed_warn (peer -> pps , & peer -> channel_id ,
2994
+ "Unable to add accepter funding" );
2995
+ if (!amount_msat_add_sat_s64 (& out [TX_ACCEPTER ], out [TX_ACCEPTER ],
2996
+ peer -> splicing -> accepter_relative ))
2997
+ peer_failed_warn (peer -> pps , & peer -> channel_id ,
2998
+ "Unable to add accepter funding to out amnt." );
3019
2999
3020
3000
if (amount_msat_less (in [TX_INITIATOR ], out [TX_INITIATOR ])) {
3021
3001
msg = towire_channeld_splice_funding_error (NULL , in [TX_INITIATOR ],
@@ -3064,6 +3044,14 @@ static struct amount_sat check_balances(struct peer *peer,
3064
3044
max_initiator_fee = amount_tx_fee (peer -> feerate_max ,
3065
3045
calc_weight (TX_INITIATOR , psbt ));
3066
3046
3047
+ /* Sometimes feerate_max is some absurdly high value, in that case we
3048
+ * give a fee warning based of a multiple of the min value. */
3049
+ amount_sat_mul (& min_multiplied , min_accepter_fee , 5 );
3050
+ max_accepter_fee = SAT_MIN (min_multiplied , max_accepter_fee );
3051
+
3052
+ amount_sat_mul (& min_multiplied , min_initiator_fee , 5 );
3053
+ max_initiator_fee = SAT_MIN (min_multiplied , max_initiator_fee );
3054
+
3067
3055
/* Check initiator fee */
3068
3056
if (amount_msat_less_sat (initiator_fee , min_initiator_fee )) {
3069
3057
msg = towire_channeld_splice_feerate_error (NULL , initiator_fee ,
0 commit comments