6060#define VALID_STFU_MESSAGE (msg ) \
6161 ((msg) == WIRE_SPLICE || \
6262 (msg) == WIRE_SPLICE_ACK || \
63+ (msg) == WIRE_TX_INIT_RBF || \
6364 (msg) == WIRE_TX_ABORT)
6465
6566#define SAT_MIN (a , b ) (amount_sat_less((a), (b)) ? (a) : (b))
@@ -3896,6 +3897,9 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg)
38963897 struct amount_msat current_push_val ;
38973898 const enum tx_role our_role = TX_ACCEPTER ;
38983899 u8 * abort_msg ;
3900+ enum peer_wire type ;
3901+ struct tlv_tx_init_rbf_tlvs * init_rbf_tlvs ;
3902+ struct tlv_tx_ack_rbf_tlvs * ack_rbf_tlvs ;
38993903
39003904 /* Can't start a splice with another splice still active */
39013905 assert (!peer -> splicing );
@@ -3904,14 +3908,46 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg)
39043908 ictx = new_interactivetx_context (tmpctx , our_role ,
39053909 peer -> pps , peer -> channel_id );
39063910
3907- if (!fromwire_splice (inmsg ,
3908- & channel_id ,
3909- & peer -> splicing -> opener_relative ,
3910- & funding_feerate_perkw ,
3911- & locktime ,
3912- & peer -> splicing -> remote_funding_pubkey ))
3913- peer_failed_warn (peer -> pps , & peer -> channel_id ,
3914- "Bad wire_splice %s" , tal_hex (tmpctx , inmsg ));
3911+ type = fromwire_peektype (inmsg );
3912+
3913+ if (type == WIRE_SPLICE ) {
3914+ if (!fromwire_splice (inmsg ,
3915+ & channel_id ,
3916+ & peer -> splicing -> opener_relative ,
3917+ & funding_feerate_perkw ,
3918+ & locktime ,
3919+ & peer -> splicing -> remote_funding_pubkey ))
3920+ peer_failed_warn (peer -> pps , & peer -> channel_id ,
3921+ "Bad wire_splice %s" ,
3922+ tal_hex (tmpctx , inmsg ));
3923+ if (last_inflight (peer )) {
3924+ peer_failed_warn (peer -> pps , & peer -> channel_id ,
3925+ "Can't splice_init because we already"
3926+ " have a pending splice (did you mean"
3927+ " to splice RBF?)" );
3928+ }
3929+ }
3930+ else if (type == WIRE_TX_INIT_RBF ) {
3931+ if (!fromwire_tx_init_rbf (tmpctx , inmsg ,
3932+ & channel_id ,
3933+ & locktime ,
3934+ & funding_feerate_perkw ,
3935+ & init_rbf_tlvs ))
3936+ peer_failed_warn (peer -> pps , & peer -> channel_id ,
3937+ "Bad tx_init_rbf %s" ,
3938+ tal_hex (tmpctx , inmsg ));
3939+ if (!init_rbf_tlvs
3940+ || !init_rbf_tlvs -> funding_output_contribution )
3941+ peer_failed_warn (peer -> pps , & peer -> channel_id ,
3942+ "tx_init_rbf must contain tlv with a"
3943+ " funding_output_contribution value" );
3944+ peer -> splicing -> opener_relative = * init_rbf_tlvs -> funding_output_contribution ;
3945+ if (!last_inflight (peer ))
3946+ peer_failed_warn (peer -> pps , & peer -> channel_id ,
3947+ "Can't tx_init_rbf because we have no"
3948+ " pending splice" );
3949+ peer -> splicing -> remote_funding_pubkey = last_inflight (peer )-> remote_funding ;
3950+ }
39153951
39163952 peer -> splice_state -> await_commitment_succcess = false;
39173953
@@ -3934,10 +3970,24 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg)
39343970 /* TODO: Add plugin hook for user to adjust accepter amount */
39353971 peer -> splicing -> accepter_relative = 0 ;
39363972
3937- msg = towire_splice_ack (NULL ,
3938- & peer -> channel_id ,
3939- peer -> splicing -> accepter_relative ,
3940- & peer -> channel -> funding_pubkey [LOCAL ]);
3973+ if (type == WIRE_SPLICE ) {
3974+ msg = towire_splice_ack (NULL ,
3975+ & peer -> channel_id ,
3976+ peer -> splicing -> accepter_relative ,
3977+ & peer -> channel -> funding_pubkey [LOCAL ]);
3978+ } else if (type == WIRE_TX_INIT_RBF ) {
3979+ ack_rbf_tlvs = tlv_tx_ack_rbf_tlvs_new (tmpctx );
3980+ ack_rbf_tlvs -> funding_output_contribution = tal (ack_rbf_tlvs , s64 );
3981+ * ack_rbf_tlvs -> funding_output_contribution = 0 ;
3982+ ack_rbf_tlvs -> require_confirmed_inputs = NULL ;
3983+ msg = towire_tx_ack_rbf (NULL ,
3984+ & peer -> channel_id ,
3985+ ack_rbf_tlvs );
3986+ } else {
3987+ status_failed (STATUS_FAIL_INTERNAL_ERROR ,
3988+ "message type unsupported" );
3989+ msg = NULL ; /* Squelch unused warning */
3990+ }
39413991
39423992 peer -> splicing -> mode = true;
39433993
@@ -4737,6 +4787,7 @@ static void peer_in(struct peer *peer, const u8 *msg)
47374787 handle_stfu (peer , msg );
47384788 return ;
47394789 case WIRE_SPLICE :
4790+ case WIRE_TX_INIT_RBF :
47404791 splice_accepter (peer , msg );
47414792 return ;
47424793 case WIRE_SPLICE_ACK :
@@ -4766,7 +4817,6 @@ static void peer_in(struct peer *peer, const u8 *msg)
47664817 case WIRE_TX_SIGNATURES :
47674818 handle_unexpected_tx_sigs (peer , msg );
47684819 return ;
4769- case WIRE_TX_INIT_RBF :
47704820 case WIRE_TX_ACK_RBF :
47714821 break ;
47724822
0 commit comments