Skip to content

Commit 3e6c57b

Browse files
committed
splice: Enable the receiving of splice RBF
Turn on the receiving of splice RBF attempts.
1 parent 25e6f81 commit 3e6c57b

File tree

1 file changed

+63
-13
lines changed

1 file changed

+63
-13
lines changed

channeld/channeld.c

Lines changed: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
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))
@@ -3898,6 +3899,9 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg)
38983899
struct amount_msat current_push_val;
38993900
const enum tx_role our_role = TX_ACCEPTER;
39003901
u8 *abort_msg;
3902+
enum peer_wire type;
3903+
struct tlv_tx_init_rbf_tlvs *init_rbf_tlvs;
3904+
struct tlv_tx_ack_rbf_tlvs *ack_rbf_tlvs;
39013905

39023906
/* Can't start a splice with another splice still active */
39033907
assert(!peer->splicing);
@@ -3906,14 +3910,46 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg)
39063910
ictx = new_interactivetx_context(tmpctx, our_role,
39073911
peer->pps, peer->channel_id);
39083912

3909-
if (!fromwire_splice(inmsg,
3910-
&channel_id,
3911-
&peer->splicing->opener_relative,
3912-
&funding_feerate_perkw,
3913-
&locktime,
3914-
&peer->splicing->remote_funding_pubkey))
3915-
peer_failed_warn(peer->pps, &peer->channel_id,
3916-
"Bad wire_splice %s", tal_hex(tmpctx, inmsg));
3913+
type = fromwire_peektype(inmsg);
3914+
3915+
if (type == WIRE_SPLICE) {
3916+
if (!fromwire_splice(inmsg,
3917+
&channel_id,
3918+
&peer->splicing->opener_relative,
3919+
&funding_feerate_perkw,
3920+
&locktime,
3921+
&peer->splicing->remote_funding_pubkey))
3922+
peer_failed_warn(peer->pps, &peer->channel_id,
3923+
"Bad wire_splice %s",
3924+
tal_hex(tmpctx, inmsg));
3925+
if (last_inflight(peer)) {
3926+
peer_failed_warn(peer->pps, &peer->channel_id,
3927+
"Can't splice_init because we already"
3928+
" have a pending splice (did you mean"
3929+
" to splice RBF?)");
3930+
}
3931+
}
3932+
else if (type == WIRE_TX_INIT_RBF) {
3933+
if (!fromwire_tx_init_rbf(tmpctx, inmsg,
3934+
&channel_id,
3935+
&locktime,
3936+
&funding_feerate_perkw,
3937+
&init_rbf_tlvs))
3938+
peer_failed_warn(peer->pps, &peer->channel_id,
3939+
"Bad tx_init_rbf %s",
3940+
tal_hex(tmpctx, inmsg));
3941+
if (!init_rbf_tlvs
3942+
|| !init_rbf_tlvs->funding_output_contribution)
3943+
peer_failed_warn(peer->pps, &peer->channel_id,
3944+
"tx_init_rbf must contain tlv with a"
3945+
" funding_output_contribution value");
3946+
peer->splicing->opener_relative = *init_rbf_tlvs->funding_output_contribution;
3947+
if (!last_inflight(peer))
3948+
peer_failed_warn(peer->pps, &peer->channel_id,
3949+
"Can't tx_init_rbf because we have no"
3950+
" pending splice");
3951+
peer->splicing->remote_funding_pubkey = last_inflight(peer)->remote_funding;
3952+
}
39173953

39183954
peer->splice_state->await_commitment_succcess = false;
39193955

@@ -3936,10 +3972,24 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg)
39363972
/* TODO: Add plugin hook for user to adjust accepter amount */
39373973
peer->splicing->accepter_relative = 0;
39383974

3939-
msg = towire_splice_ack(NULL,
3940-
&peer->channel_id,
3941-
peer->splicing->accepter_relative,
3942-
&peer->channel->funding_pubkey[LOCAL]);
3975+
if (type == WIRE_SPLICE) {
3976+
msg = towire_splice_ack(NULL,
3977+
&peer->channel_id,
3978+
peer->splicing->accepter_relative,
3979+
&peer->channel->funding_pubkey[LOCAL]);
3980+
} else if (type == WIRE_TX_INIT_RBF) {
3981+
ack_rbf_tlvs = tlv_tx_ack_rbf_tlvs_new(tmpctx);
3982+
ack_rbf_tlvs->funding_output_contribution = tal(ack_rbf_tlvs, s64);
3983+
*ack_rbf_tlvs->funding_output_contribution = 0;
3984+
ack_rbf_tlvs->require_confirmed_inputs = NULL;
3985+
msg = towire_tx_ack_rbf(NULL,
3986+
&peer->channel_id,
3987+
ack_rbf_tlvs);
3988+
} else {
3989+
status_failed(STATUS_FAIL_INTERNAL_ERROR,
3990+
"message type unsupported");
3991+
msg = NULL; /* Squelch unused warning */
3992+
}
39433993

39443994
peer->splicing->mode = true;
39453995

@@ -4739,6 +4789,7 @@ static void peer_in(struct peer *peer, const u8 *msg)
47394789
handle_stfu(peer, msg);
47404790
return;
47414791
case WIRE_SPLICE:
4792+
case WIRE_TX_INIT_RBF:
47424793
splice_accepter(peer, msg);
47434794
return;
47444795
case WIRE_SPLICE_ACK:
@@ -4768,7 +4819,6 @@ static void peer_in(struct peer *peer, const u8 *msg)
47684819
case WIRE_TX_SIGNATURES:
47694820
handle_unexpected_tx_sigs(peer, msg);
47704821
return;
4771-
case WIRE_TX_INIT_RBF:
47724822
case WIRE_TX_ACK_RBF:
47734823
break;
47744824

0 commit comments

Comments
 (0)