Skip to content

Commit ff89bd8

Browse files
committed
splice: Enable the receiving of splice RBF
Turn on the receiving of splice RBF attempts.
1 parent 9584400 commit ff89bd8

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
@@ -58,6 +58,7 @@
5858
#define VALID_STFU_MESSAGE(msg) \
5959
((msg) == WIRE_SPLICE || \
6060
(msg) == WIRE_SPLICE_ACK || \
61+
(msg) == WIRE_TX_INIT_RBF || \
6162
(msg) == WIRE_TX_ABORT)
6263

6364
#define SAT_MIN(a, b) (amount_sat_less((a), (b)) ? (a) : (b))
@@ -3888,6 +3889,9 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg)
38883889
struct amount_msat current_push_val;
38893890
const enum tx_role our_role = TX_ACCEPTER;
38903891
u8 *abort_msg;
3892+
enum peer_wire type;
3893+
struct tlv_tx_init_rbf_tlvs *init_rbf_tlvs;
3894+
struct tlv_tx_ack_rbf_tlvs *ack_rbf_tlvs;
38913895

38923896
/* Can't start a splice with another splice still active */
38933897
assert(!peer->splicing);
@@ -3896,14 +3900,46 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg)
38963900
ictx = new_interactivetx_context(tmpctx, our_role,
38973901
peer->pps, peer->channel_id);
38983902

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

39083944
peer->splice_state->await_commitment_succcess = false;
39093945

@@ -3926,10 +3962,24 @@ static void splice_accepter(struct peer *peer, const u8 *inmsg)
39263962
/* TODO: Add plugin hook for user to adjust accepter amount */
39273963
peer->splicing->accepter_relative = 0;
39283964

3929-
msg = towire_splice_ack(NULL,
3930-
&peer->channel_id,
3931-
peer->splicing->accepter_relative,
3932-
&peer->channel->funding_pubkey[LOCAL]);
3965+
if (type == WIRE_SPLICE) {
3966+
msg = towire_splice_ack(NULL,
3967+
&peer->channel_id,
3968+
peer->splicing->accepter_relative,
3969+
&peer->channel->funding_pubkey[LOCAL]);
3970+
} else if (type == WIRE_TX_INIT_RBF) {
3971+
ack_rbf_tlvs = tlv_tx_ack_rbf_tlvs_new(tmpctx);
3972+
ack_rbf_tlvs->funding_output_contribution = tal(ack_rbf_tlvs, s64);
3973+
*ack_rbf_tlvs->funding_output_contribution = 0;
3974+
ack_rbf_tlvs->require_confirmed_inputs = NULL;
3975+
msg = towire_tx_ack_rbf(NULL,
3976+
&peer->channel_id,
3977+
ack_rbf_tlvs);
3978+
} else {
3979+
status_failed(STATUS_FAIL_INTERNAL_ERROR,
3980+
"message type unsupported");
3981+
msg = NULL; /* Squelch unused warning */
3982+
}
39333983

39343984
peer->splicing->mode = true;
39353985

@@ -4729,6 +4779,7 @@ static void peer_in(struct peer *peer, const u8 *msg)
47294779
handle_stfu(peer, msg);
47304780
return;
47314781
case WIRE_SPLICE:
4782+
case WIRE_TX_INIT_RBF:
47324783
splice_accepter(peer, msg);
47334784
return;
47344785
case WIRE_SPLICE_ACK:
@@ -4758,7 +4809,6 @@ static void peer_in(struct peer *peer, const u8 *msg)
47584809
case WIRE_TX_SIGNATURES:
47594810
handle_unexpected_tx_sigs(peer, msg);
47604811
return;
4761-
case WIRE_TX_INIT_RBF:
47624812
case WIRE_TX_ACK_RBF:
47634813
break;
47644814

0 commit comments

Comments
 (0)