@@ -76,13 +76,16 @@ struct peer {
7676 /* What (additional) messages the HSM accepts */
7777 u32 * hsm_capabilities ;
7878
79+ /* The feerate to initiate a splice */
80+ u32 feerate_splice ;
81+
7982 /* Tolerable amounts for feerate (only relevant for fundee). */
8083 u32 feerate_min , feerate_max ;
8184
8285 /* Feerate to be used when creating penalty transactions. */
8386 u32 feerate_penalty ;
8487
85- /* Feerate to be used when opening (or splicing) a channel. */
88+ /* Feerate to be used when opening a channel. */
8689 u32 feerate_opening ;
8790
8891 /* Local next per-commit point. */
@@ -967,6 +970,10 @@ static struct bitcoin_signature *calc_commitsigs(const tal_t *ctx,
967970 const u8 * msg ;
968971 struct bitcoin_signature * htlc_sigs ;
969972
973+ status_debug ("calc_commitsigs(%p, %p, %p, %p, %p, %d, %p, %p)" ,
974+ ctx , peer , txs , funding_wscript , htlc_map ,
975+ (int )commit_index , remote_per_commit , commit_sig );
976+
970977 htlcs = collect_htlcs (tmpctx , htlc_map );
971978 msg = towire_hsmd_sign_remote_commitment_tx (NULL , txs [0 ],
972979 & remote_funding_pubkey ,
@@ -1890,9 +1897,9 @@ static void check_tx_abort(struct peer *peer, const u8 *msg, struct bitcoin_txid
18901897 exit (0 );
18911898}
18921899
1893- static void splice_abort (struct peer * peer , const char * fmt , ...)
1900+ static void splice_abort (struct peer * peer , struct inflight * inflight ,
1901+ const char * fmt , ...)
18941902{
1895- struct inflight * inflight = last_inflight (peer );
18961903 struct bitcoin_outpoint * outpoint ;
18971904 u8 * msg ;
18981905 char * reason ;
@@ -3333,7 +3340,8 @@ static struct amount_sat calc_balance(struct peer *peer)
33333340}
33343341
33353342/* Returns the total channel funding output amount if all checks pass.
3336- * Otherwise, exits via peer_failed_warn. DTODO: Change to `tx_abort`. */
3343+ * Otherwise, exits via peer_failed_warn.
3344+ * Note: Should only be called before adding splice to inflights. */
33373345static struct amount_sat check_balances (struct peer * peer ,
33383346 enum tx_role our_role ,
33393347 const struct wally_psbt * psbt ,
@@ -3374,6 +3382,32 @@ static struct amount_sat check_balances(struct peer *peer,
33743382 "Unable to add HTLC balance" );
33753383 }
33763384
3385+ status_debug ("in[TX_INITIATOR] %s; in[TX_ACCEPTER] %s" ,
3386+ fmt_amount_m_as_sat (tmpctx , in [TX_INITIATOR ]),
3387+ fmt_amount_m_as_sat (tmpctx , in [TX_ACCEPTER ]));
3388+
3389+ /* Here in[*] only contains the amounts from this channel.
3390+ * This is a great opportunity to check their splice out amount does
3391+ * not exceed their channel funds as this is never allowed even if
3392+ * additional funds are otherwise contributed. */
3393+ if (!amount_msat_can_add_sat_s64 (in [TX_INITIATOR ],
3394+ peer -> splicing -> opener_relative )) {
3395+ splice_abort (peer , NULL , "Intiator is attempting to splice out"
3396+ " %" PRId64 "sat funds out of channel while only "
3397+ "having %s funds attributable to them." ,
3398+ peer -> splicing -> opener_relative ,
3399+ fmt_amount_m_as_sat (tmpctx , in [TX_INITIATOR ]));
3400+ }
3401+ if (!amount_msat_can_add_sat_s64 (in [TX_ACCEPTER ],
3402+ peer -> splicing -> accepter_relative )) {
3403+ splice_abort (peer , NULL , "Accepter is attempting to splice out"
3404+ " %" PRId64 "sat funds out of channel while only "
3405+ "having %s funds attributable to them." ,
3406+ peer -> splicing -> accepter_relative ,
3407+ fmt_amount_m_as_sat (tmpctx , in [TX_ACCEPTER ]));
3408+ }
3409+
3410+ /* Now add values from the other outputs */
33773411 for (size_t i = 0 ; i < psbt -> num_inputs ; i ++ )
33783412 if (i != chan_input_index )
33793413 add_amount_to_side (peer , in ,
@@ -3422,32 +3456,41 @@ static struct amount_sat check_balances(struct peer *peer,
34223456 */
34233457 if (!amount_msat_add_sat_s64 (& funding_amount , funding_amount ,
34243458 peer -> splicing -> opener_relative ))
3425- splice_abort (peer , "Splice initiator did not provide enough"
3459+ splice_abort (peer , NULL , "Splice initiator did not provide enough"
34263460 " funding, funding_amount: %s, opener_relative:"
34273461 " %" PRIu64 ,
34283462 fmt_amount_msat (tmpctx , funding_amount ),
34293463 peer -> splicing -> opener_relative );
3464+
3465+ status_debug ("out[TX_INITIATOR] %s + %" PRId64 ,
3466+ fmt_amount_m_as_sat (tmpctx , out [TX_INITIATOR ]),
3467+ peer -> splicing -> opener_relative );
3468+
34303469 if (!amount_msat_add_sat_s64 (& out [TX_INITIATOR ], out [TX_INITIATOR ],
34313470 peer -> splicing -> opener_relative ))
34323471 peer_failed_warn (peer -> pps , & peer -> channel_id ,
34333472 "Unable to add opener funding to out amnt." );
34343473
34353474 if (!amount_msat_add_sat_s64 (& funding_amount , funding_amount ,
34363475 peer -> splicing -> accepter_relative ))
3437- splice_abort (peer , "Splice accepter did not provide enough"
3476+ splice_abort (peer , NULL , "Splice accepter did not provide enough"
34383477 " funding" );
34393478 if (!amount_msat_add_sat_s64 (& out [TX_ACCEPTER ], out [TX_ACCEPTER ],
34403479 peer -> splicing -> accepter_relative ))
34413480 peer_failed_warn (peer -> pps , & peer -> channel_id ,
34423481 "Unable to add accepter funding to out amnt." );
34433482
3483+ status_debug ("is in[TX_INITIATOR] %s less than out[TX_INITIATOR] %s?" ,
3484+ fmt_amount_m_as_sat (tmpctx , in [TX_INITIATOR ]),
3485+ fmt_amount_m_as_sat (tmpctx , out [TX_INITIATOR ]));
3486+
34443487 if (amount_msat_less (in [TX_INITIATOR ], out [TX_INITIATOR ])) {
34453488 msg = towire_channeld_splice_funding_error (NULL ,
34463489 in [TX_INITIATOR ],
34473490 out [TX_INITIATOR ],
34483491 true);
34493492 wire_sync_write (MASTER_FD , take (msg ));
3450- splice_abort (peer ,
3493+ splice_abort (peer , NULL ,
34513494 "Initiator funding is less than commited"
34523495 " amount. Initiator contributing %s but they"
34533496 " committed to %s. Pending offered HTLC"
@@ -3474,7 +3517,7 @@ static struct amount_sat check_balances(struct peer *peer,
34743517 out [TX_INITIATOR ],
34753518 true);
34763519 wire_sync_write (MASTER_FD , take (msg ));
3477- splice_abort (peer ,
3520+ splice_abort (peer , NULL ,
34783521 "Accepter funding is less than commited"
34793522 " amount. Accepter contributing %s but they"
34803523 " committed to %s. Pending offered HTLC"
@@ -3504,10 +3547,10 @@ static struct amount_sat check_balances(struct peer *peer,
35043547 calc_weight (TX_INITIATOR , psbt , opener ));
35053548
35063549 if (opener ) {
3507- status_debug ("User specified fee of %s. Opening feerate %" PRIu32
3550+ status_debug ("User specified fee of %s. Splice feerate %" PRIu32
35083551 " * weight %lu / 1000 = %s" ,
35093552 fmt_amount_m_as_sat (tmpctx , initiator_fee ),
3510- peer -> feerate_opening ,
3553+ peer -> feerate_splice ,
35113554 calc_weight (TX_INITIATOR , psbt , false),
35123555 fmt_amount_sat (tmpctx , max_initiator_fee ));
35133556 }
@@ -3517,7 +3560,7 @@ static struct amount_sat check_balances(struct peer *peer,
35173560 msg = towire_channeld_splice_feerate_error (NULL , initiator_fee ,
35183561 false);
35193562 wire_sync_write (MASTER_FD , take (msg ));
3520- splice_abort (peer ,
3563+ splice_abort (peer , NULL ,
35213564 "%s fee (%s) was too low, must be at least %s" ,
35223565 opener ? "Our" : "Your" ,
35233566 fmt_amount_msat (tmpctx , initiator_fee ),
@@ -3537,7 +3580,7 @@ static struct amount_sat check_balances(struct peer *peer,
35373580
35383581 wire_sync_write (MASTER_FD , take (msg ));
35393582
3540- splice_abort (peer ,
3583+ splice_abort (peer , NULL ,
35413584 "Our own fee (%s) is too high to use without"
35423585 " forcing. Opening feerate %" PRIu32
35433586 " x weight %lu / 1000 = %s (max)" ,
@@ -3551,7 +3594,7 @@ static struct amount_sat check_balances(struct peer *peer,
35513594 msg = towire_channeld_splice_feerate_error (NULL , accepter_fee ,
35523595 false);
35533596 wire_sync_write (MASTER_FD , take (msg ));
3554- splice_abort (peer ,
3597+ splice_abort (peer , NULL ,
35553598 "%s fee (%s) was too low, must be at least %s"
35563599 " weight: %" PRIu64 ", feerate_max: %" PRIu32 ,
35573600 opener ? "Your" : "Our" ,
@@ -3565,7 +3608,7 @@ static struct amount_sat check_balances(struct peer *peer,
35653608 msg = towire_channeld_splice_feerate_error (NULL , accepter_fee ,
35663609 true);
35673610 wire_sync_write (MASTER_FD , take (msg ));
3568- splice_abort (peer ,
3611+ splice_abort (peer , NULL ,
35693612 "Our own fee (%s) was too high, max without"
35703613 " forcing is %s." ,
35713614 fmt_amount_msat (tmpctx , accepter_fee ),
@@ -4988,7 +5031,7 @@ static void handle_abort_req(struct peer *peer, const u8 *inmsg)
49885031 if (!fromwire_channeld_abort (inmsg ))
49895032 master_badmsg (WIRE_CHANNELD_ABORT , inmsg );
49905033
4991- splice_abort (peer , "requested by user" );
5034+ splice_abort (peer , last_inflight ( peer ), "requested by user" );
49925035}
49935036
49945037static void peer_in (struct peer * peer , const u8 * msg )
@@ -5844,7 +5887,8 @@ static void peer_reconnect(struct peer *peer,
58445887 " channel, ignoring it: %s" ,
58455888 fmt_bitcoin_outpoint (tmpctx , & peer -> channel -> funding ));
58465889 else
5847- splice_abort (peer , "next_funding_txid not recognized." );
5890+ splice_abort (peer , NULL ,
5891+ "next_funding_txid not recognized." );
58485892 }
58495893
58505894 /* BOLT #2:
@@ -6338,11 +6382,13 @@ static void handle_feerates(struct peer *peer, const u8 *inmsg)
63386382{
63396383 u32 feerate ;
63406384
6341- if (!fromwire_channeld_feerates (inmsg , & feerate ,
6342- & peer -> feerate_min ,
6343- & peer -> feerate_max ,
6344- & peer -> feerate_penalty ,
6345- & peer -> feerate_opening ))
6385+ if (!fromwire_channeld_feerates (inmsg ,
6386+ & feerate ,
6387+ & peer -> feerate_min ,
6388+ & peer -> feerate_max ,
6389+ & peer -> feerate_penalty ,
6390+ & peer -> feerate_opening ,
6391+ & peer -> feerate_splice ))
63466392 master_badmsg (WIRE_CHANNELD_FEERATES , inmsg );
63476393
63486394 /* BOLT #2:
@@ -6710,6 +6756,7 @@ static void init_channel(struct peer *peer)
67106756 & lease_expiry ,
67116757 & conf [LOCAL ], & conf [REMOTE ],
67126758 & fee_states ,
6759+ & peer -> feerate_splice ,
67136760 & peer -> feerate_min ,
67146761 & peer -> feerate_max ,
67156762 & peer -> feerate_penalty ,
0 commit comments