@@ -2960,6 +2960,26 @@ static size_t calc_weight(enum tx_role role, const struct wally_psbt *psbt)
29602960 return weight ;
29612961}
29622962
2963+ /* Get the non-initiator (acceptor) amount after the splice */
2964+ static struct amount_msat splice_acceptor_balance (struct peer * peer ,
2965+ enum tx_role our_role )
2966+ {
2967+ struct amount_msat acceptor_value ;
2968+
2969+ /* Start with the acceptor's balance before the splice */
2970+ acceptor_value =
2971+ peer -> channel -> view -> owed [our_role == TX_INITIATOR ? REMOTE : LOCAL ];
2972+
2973+ /* Adjust by the acceptor's relative splice amount (signed) */
2974+ if (!amount_msat_add_sat_s64 (& acceptor_value , acceptor_value ,
2975+ peer -> splicing -> accepter_relative ))
2976+ peer_failed_warn (
2977+ peer -> pps , & peer -> channel_id ,
2978+ "Unable to add accepter's relative splice to prior balance." );
2979+
2980+ return acceptor_value ;
2981+ }
2982+
29632983/* Returns the total channel funding output amount if all checks pass.
29642984 * Otherwise, exits via peer_failed_warn. DTODO: Change to `tx_abort`. */
29652985static struct amount_sat check_balances (struct peer * peer ,
@@ -3492,6 +3512,39 @@ static struct inflight *inflights_new(struct peer *peer)
34923512 return inf ;
34933513}
34943514
3515+ static void update_hsmd_with_splice (struct peer * peer ,
3516+ struct inflight * inflight ,
3517+ const struct amount_msat push_val )
3518+ {
3519+ u8 * msg ;
3520+
3521+ /* local_upfront_shutdown_script, local_upfront_shutdown_wallet_index,
3522+ * remote_upfront_shutdown_script aren't allowed to change, so we
3523+ * don't need to gather them */
3524+ msg = towire_hsmd_ready_channel (
3525+ NULL ,
3526+ peer -> channel -> opener == LOCAL ,
3527+ inflight -> amnt ,
3528+ push_val ,
3529+ & inflight -> outpoint .txid ,
3530+ inflight -> outpoint .n ,
3531+ peer -> channel -> config [LOCAL ].to_self_delay ,
3532+ /*local_upfront_shutdown_script*/ NULL ,
3533+ /*local_upfront_shutdown_wallet_index*/ NULL ,
3534+ & peer -> channel -> basepoints [REMOTE ],
3535+ & peer -> channel -> funding_pubkey [REMOTE ],
3536+ peer -> channel -> config [REMOTE ].to_self_delay ,
3537+ /*remote_upfront_shutdown_script*/ NULL ,
3538+ peer -> channel -> type );
3539+
3540+ wire_sync_write (HSM_FD , take (msg ));
3541+ msg = wire_sync_read (tmpctx , HSM_FD );
3542+ if (!fromwire_hsmd_ready_channel_reply (msg ))
3543+ status_failed (STATUS_FAIL_HSM_IO , "Bad ready_channel_reply %s" ,
3544+ tal_hex (tmpctx , msg ));
3545+ }
3546+
3547+
34953548/* ACCEPTER side of the splice. Here we handle all the accepter's steps for the
34963549 * splice. Since the channel must be in STFU mode we block the daemon here until
34973550 * the splice is finished or aborted. */
@@ -3628,6 +3681,10 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg)
36283681 new_inflight -> last_tx = NULL ;
36293682 new_inflight -> i_am_initiator = false;
36303683
3684+ update_hsmd_with_splice (peer ,
3685+ new_inflight ,
3686+ splice_acceptor_balance (peer , TX_ACCEPTER ));
3687+
36313688 update_view_from_inflights (peer );
36323689
36333690 peer -> splice_state -> count ++ ;
@@ -3862,6 +3919,10 @@ static void splice_initiator_user_finalized(struct peer *peer)
38623919 new_inflight -> last_tx = NULL ;
38633920 new_inflight -> i_am_initiator = true;
38643921
3922+ update_hsmd_with_splice (peer ,
3923+ new_inflight ,
3924+ splice_acceptor_balance (peer , TX_INITIATOR ));
3925+
38653926 update_view_from_inflights (peer );
38663927
38673928 peer -> splice_state -> count ++ ;
0 commit comments