Skip to content

Commit 9d9d6bc

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 ae7aeec commit 9d9d6bc

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
@@ -61,6 +61,7 @@
6161
((msg) == WIRE_SPLICE || \
6262
(msg) == WIRE_SPLICE_ACK || \
6363
(msg) == WIRE_TX_INIT_RBF || \
64+
(msg) == WIRE_TX_ACK_RBF || \
6465
(msg) == WIRE_TX_ABORT)
6566

6667
#define SAT_MIN(a, b) (amount_sat_less((a), (b)) ? (a) : (b))
@@ -4097,14 +4098,41 @@ static void splice_initiator(struct peer *peer, const u8 *inmsg)
40974098
struct wally_psbt *psbt = peer->splicing->current_psbt;
40984099
u32 sequence = 0;
40994100
u8 *scriptPubkey;
4101+
enum peer_wire type;
4102+
struct tlv_tx_ack_rbf_tlvs *ack_rbf_tlvs;
41004103

4101-
if (!fromwire_splice_ack(inmsg,
4102-
&channel_id,
4103-
&peer->splicing->accepter_relative,
4104-
&peer->splicing->remote_funding_pubkey))
4105-
peer_failed_warn(peer->pps, &peer->channel_id,
4106-
"Bad wire_splice_ack %s",
4107-
tal_hex(tmpctx, inmsg));
4104+
type = fromwire_peektype(inmsg);
4105+
4106+
if (type == WIRE_SPLICE_ACK) {
4107+
if (!fromwire_splice_ack(inmsg,
4108+
&channel_id,
4109+
&peer->splicing->accepter_relative,
4110+
&peer->splicing->remote_funding_pubkey))
4111+
peer_failed_warn(peer->pps, &peer->channel_id,
4112+
"Bad wire_splice_ack %s",
4113+
tal_hex(tmpctx, inmsg));
4114+
} else if (type == WIRE_TX_ACK_RBF) {
4115+
if (!fromwire_tx_ack_rbf(tmpctx,
4116+
inmsg,
4117+
&channel_id,
4118+
&ack_rbf_tlvs))
4119+
peer_failed_warn(peer->pps, &peer->channel_id,
4120+
"Bad tx_ack_rbf %s",
4121+
tal_hex(tmpctx, inmsg));
4122+
4123+
if (!ack_rbf_tlvs
4124+
|| !ack_rbf_tlvs->funding_output_contribution)
4125+
peer_failed_warn(peer->pps, &peer->channel_id,
4126+
"tx_ack_rbf must contain tlv with a"
4127+
" funding_output_contribution value");
4128+
peer->splicing->accepter_relative = *ack_rbf_tlvs->funding_output_contribution;
4129+
4130+
if (!last_inflight(peer))
4131+
peer_failed_err(peer->pps, &peer->channel_id,
4132+
"Can't handle tx_ack_rbf because we"
4133+
" have no pending splice");
4134+
peer->splicing->remote_funding_pubkey = last_inflight(peer)->remote_funding;
4135+
}
41084136

41094137
if (!channel_id_eq(&channel_id, &peer->channel_id))
41104138
peer_failed_warn(peer->pps, &peer->channel_id,
@@ -4538,12 +4566,29 @@ static void splice_initiator_user_signed(struct peer *peer, const u8 *inmsg)
45384566
/* This occurs once our 'stfu' transition was successful. */
45394567
static void handle_splice_stfu_success(struct peer *peer)
45404568
{
4541-
u8 *msg = towire_splice(tmpctx,
4542-
&peer->channel_id,
4543-
peer->splicing->opener_relative,
4544-
peer->splicing->feerate_per_kw,
4545-
peer->splicing->current_psbt->fallback_locktime,
4546-
&peer->channel->funding_pubkey[LOCAL]);
4569+
u8 *msg;
4570+
struct tlv_tx_init_rbf_tlvs *init_rbf_tlvs;
4571+
if (!last_inflight(peer)) {
4572+
msg = towire_splice(tmpctx,
4573+
&peer->channel_id,
4574+
peer->splicing->opener_relative,
4575+
peer->splicing->feerate_per_kw,
4576+
peer->splicing->current_psbt->fallback_locktime,
4577+
&peer->channel->funding_pubkey[LOCAL]);
4578+
}
4579+
else { /* RBF attempt */
4580+
init_rbf_tlvs = tlv_tx_init_rbf_tlvs_new(tmpctx);
4581+
init_rbf_tlvs->funding_output_contribution = tal(init_rbf_tlvs, s64);
4582+
*init_rbf_tlvs->funding_output_contribution = peer->splicing->opener_relative;
4583+
init_rbf_tlvs->require_confirmed_inputs = NULL;
4584+
4585+
msg = towire_tx_init_rbf(tmpctx,
4586+
&peer->channel_id,
4587+
peer->splicing->current_psbt->fallback_locktime,
4588+
peer->splicing->feerate_per_kw,
4589+
init_rbf_tlvs);
4590+
}
4591+
45474592
peer->splice_state->await_commitment_succcess = false;
45484593
peer_write(peer->pps, take(msg));
45494594
}
@@ -4617,8 +4662,9 @@ static void handle_splice_init(struct peer *peer, const u8 *inmsg)
46174662
return;
46184663
}
46194664

4620-
status_debug("Getting handle_splice_init psbt version %d",
4621-
peer->splicing->current_psbt->version);
4665+
status_debug("Getting handle_splice_init psbt version %d (RBF?: %s)",
4666+
peer->splicing->current_psbt->version,
4667+
last_inflight(peer) ? "y" : "n");
46224668

46234669
if (skip_stfu) {
46244670
handle_splice_stfu_success(peer);
@@ -4793,6 +4839,7 @@ static void peer_in(struct peer *peer, const u8 *msg)
47934839
splice_accepter(peer, msg);
47944840
return;
47954841
case WIRE_SPLICE_ACK:
4842+
case WIRE_TX_ACK_RBF:
47964843
splice_initiator(peer, msg);
47974844
return;
47984845
case WIRE_SPLICE_LOCKED:
@@ -4819,8 +4866,6 @@ static void peer_in(struct peer *peer, const u8 *msg)
48194866
case WIRE_TX_SIGNATURES:
48204867
handle_unexpected_tx_sigs(peer, msg);
48214868
return;
4822-
case WIRE_TX_ACK_RBF:
4823-
break;
48244869

48254870
case WIRE_CHANNEL_REESTABLISH:
48264871
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)