Skip to content

Commit 9324c3b

Browse files
committed
splice: Enable user splice RBF
Allow user’s to RBF existing splices. For now this is done by simple executing an additional splice command, in the future this will can also be done with dedicated RPCs. Changelog-Added: Enabled the ability to RBF splices
1 parent eb7c9df commit 9324c3b

File tree

2 files changed

+66
-20
lines changed

2 files changed

+66
-20
lines changed

channeld/channeld.c

Lines changed: 62 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
((msg) == WIRE_SPLICE || \
6060
(msg) == WIRE_SPLICE_ACK || \
6161
(msg) == WIRE_TX_INIT_RBF || \
62+
(msg) == WIRE_TX_ACK_RBF || \
6263
(msg) == WIRE_TX_ABORT)
6364

6465
#define SAT_MIN(a, b) (amount_sat_less((a), (b)) ? (a) : (b))
@@ -4087,14 +4088,41 @@ static void splice_initiator(struct peer *peer, const u8 *inmsg)
40874088
struct wally_psbt *psbt = peer->splicing->current_psbt;
40884089
u32 sequence = 0;
40894090
u8 *scriptPubkey;
4091+
enum peer_wire type;
4092+
struct tlv_tx_ack_rbf_tlvs *ack_rbf_tlvs;
40904093

4091-
if (!fromwire_splice_ack(inmsg,
4092-
&channel_id,
4093-
&peer->splicing->accepter_relative,
4094-
&peer->splicing->remote_funding_pubkey))
4095-
peer_failed_warn(peer->pps, &peer->channel_id,
4096-
"Bad wire_splice_ack %s",
4097-
tal_hex(tmpctx, inmsg));
4094+
type = fromwire_peektype(inmsg);
4095+
4096+
if (type == WIRE_SPLICE_ACK) {
4097+
if (!fromwire_splice_ack(inmsg,
4098+
&channel_id,
4099+
&peer->splicing->accepter_relative,
4100+
&peer->splicing->remote_funding_pubkey))
4101+
peer_failed_warn(peer->pps, &peer->channel_id,
4102+
"Bad wire_splice_ack %s",
4103+
tal_hex(tmpctx, inmsg));
4104+
} else if (type == WIRE_TX_ACK_RBF) {
4105+
if (!fromwire_tx_ack_rbf(tmpctx,
4106+
inmsg,
4107+
&channel_id,
4108+
&ack_rbf_tlvs))
4109+
peer_failed_warn(peer->pps, &peer->channel_id,
4110+
"Bad tx_ack_rbf %s",
4111+
tal_hex(tmpctx, inmsg));
4112+
4113+
if (!ack_rbf_tlvs
4114+
|| !ack_rbf_tlvs->funding_output_contribution)
4115+
peer_failed_warn(peer->pps, &peer->channel_id,
4116+
"tx_ack_rbf must contain tlv with a"
4117+
" funding_output_contribution value");
4118+
peer->splicing->accepter_relative = *ack_rbf_tlvs->funding_output_contribution;
4119+
4120+
if (!last_inflight(peer))
4121+
peer_failed_err(peer->pps, &peer->channel_id,
4122+
"Can't handle tx_ack_rbf because we"
4123+
" have no pending splice");
4124+
peer->splicing->remote_funding_pubkey = last_inflight(peer)->remote_funding;
4125+
}
40984126

40994127
if (!channel_id_eq(&channel_id, &peer->channel_id))
41004128
peer_failed_warn(peer->pps, &peer->channel_id,
@@ -4528,12 +4556,29 @@ static void splice_initiator_user_signed(struct peer *peer, const u8 *inmsg)
45284556
/* This occurs once our 'stfu' transition was successful. */
45294557
static void handle_splice_stfu_success(struct peer *peer)
45304558
{
4531-
u8 *msg = towire_splice(tmpctx,
4532-
&peer->channel_id,
4533-
peer->splicing->opener_relative,
4534-
peer->splicing->feerate_per_kw,
4535-
peer->splicing->current_psbt->fallback_locktime,
4536-
&peer->channel->funding_pubkey[LOCAL]);
4559+
u8 *msg;
4560+
struct tlv_tx_init_rbf_tlvs *init_rbf_tlvs;
4561+
if (!last_inflight(peer)) {
4562+
msg = towire_splice(tmpctx,
4563+
&peer->channel_id,
4564+
peer->splicing->opener_relative,
4565+
peer->splicing->feerate_per_kw,
4566+
peer->splicing->current_psbt->fallback_locktime,
4567+
&peer->channel->funding_pubkey[LOCAL]);
4568+
}
4569+
else { /* RBF attempt */
4570+
init_rbf_tlvs = tlv_tx_init_rbf_tlvs_new(tmpctx);
4571+
init_rbf_tlvs->funding_output_contribution = tal(init_rbf_tlvs, s64);
4572+
*init_rbf_tlvs->funding_output_contribution = peer->splicing->opener_relative;
4573+
init_rbf_tlvs->require_confirmed_inputs = NULL;
4574+
4575+
msg = towire_tx_init_rbf(tmpctx,
4576+
&peer->channel_id,
4577+
peer->splicing->current_psbt->fallback_locktime,
4578+
peer->splicing->feerate_per_kw,
4579+
init_rbf_tlvs);
4580+
}
4581+
45374582
peer->splice_state->await_commitment_succcess = false;
45384583
peer_write(peer->pps, take(msg));
45394584
}
@@ -4607,8 +4652,9 @@ static void handle_splice_init(struct peer *peer, const u8 *inmsg)
46074652
return;
46084653
}
46094654

4610-
status_debug("Getting handle_splice_init psbt version %d",
4611-
peer->splicing->current_psbt->version);
4655+
status_debug("Getting handle_splice_init psbt version %d (RBF?: %s)",
4656+
peer->splicing->current_psbt->version,
4657+
last_inflight(peer) ? "y" : "n");
46124658

46134659
if (skip_stfu) {
46144660
handle_splice_stfu_success(peer);
@@ -4783,6 +4829,7 @@ static void peer_in(struct peer *peer, const u8 *msg)
47834829
splice_accepter(peer, msg);
47844830
return;
47854831
case WIRE_SPLICE_ACK:
4832+
case WIRE_TX_ACK_RBF:
47864833
splice_initiator(peer, msg);
47874834
return;
47884835
case WIRE_SPLICE_LOCKED:
@@ -4809,8 +4856,6 @@ static void peer_in(struct peer *peer, const u8 *msg)
48094856
case WIRE_TX_SIGNATURES:
48104857
handle_unexpected_tx_sigs(peer, msg);
48114858
return;
4812-
case WIRE_TX_ACK_RBF:
4813-
break;
48144859

48154860
case WIRE_CHANNEL_REESTABLISH:
48164861
handle_unexpected_reestablish(peer, msg);

lightningd/channel_control.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,11 +2204,12 @@ static struct command_result *channel_for_splice(struct command *cmd,
22042204
"abnormal owner state %s",
22052205
(*channel)->owner->name);
22062206

2207-
if ((*channel)->state != CHANNELD_NORMAL)
2207+
if ((*channel)->state != CHANNELD_NORMAL
2208+
&& (*channel)->state != CHANNELD_AWAITING_SPLICE)
22082209
return command_fail(cmd,
22092210
SPLICE_INVALID_CHANNEL_STATE,
2210-
"Channel needs to be in normal state but "
2211-
"is in state %s",
2211+
"Channel needs to be in normal or awaiting"
2212+
" splice state but is in state %s",
22122213
channel_state_name(*channel));
22132214

22142215
return NULL;

0 commit comments

Comments
 (0)