Skip to content

Commit b127784

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 a49e5fb commit b127784

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))
@@ -4095,14 +4096,41 @@ static void splice_initiator(struct peer *peer, const u8 *inmsg)
40954096
struct wally_psbt *psbt = peer->splicing->current_psbt;
40964097
u32 sequence = 0;
40974098
u8 *scriptPubkey;
4099+
enum peer_wire type;
4100+
struct tlv_tx_ack_rbf_tlvs *ack_rbf_tlvs;
40984101

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

41074135
if (!channel_id_eq(&channel_id, &peer->channel_id))
41084136
peer_failed_warn(peer->pps, &peer->channel_id,
@@ -4536,12 +4564,29 @@ static void splice_initiator_user_signed(struct peer *peer, const u8 *inmsg)
45364564
/* This occurs once our 'stfu' transition was successful. */
45374565
static void handle_splice_stfu_success(struct peer *peer)
45384566
{
4539-
u8 *msg = towire_splice(tmpctx,
4540-
&peer->channel_id,
4541-
peer->splicing->opener_relative,
4542-
peer->splicing->feerate_per_kw,
4543-
peer->splicing->current_psbt->fallback_locktime,
4544-
&peer->channel->funding_pubkey[LOCAL]);
4567+
u8 *msg;
4568+
struct tlv_tx_init_rbf_tlvs *init_rbf_tlvs;
4569+
if (!last_inflight(peer)) {
4570+
msg = towire_splice(tmpctx,
4571+
&peer->channel_id,
4572+
peer->splicing->opener_relative,
4573+
peer->splicing->feerate_per_kw,
4574+
peer->splicing->current_psbt->fallback_locktime,
4575+
&peer->channel->funding_pubkey[LOCAL]);
4576+
}
4577+
else { /* RBF attempt */
4578+
init_rbf_tlvs = tlv_tx_init_rbf_tlvs_new(tmpctx);
4579+
init_rbf_tlvs->funding_output_contribution = tal(init_rbf_tlvs, s64);
4580+
*init_rbf_tlvs->funding_output_contribution = peer->splicing->opener_relative;
4581+
init_rbf_tlvs->require_confirmed_inputs = NULL;
4582+
4583+
msg = towire_tx_init_rbf(tmpctx,
4584+
&peer->channel_id,
4585+
peer->splicing->current_psbt->fallback_locktime,
4586+
peer->splicing->feerate_per_kw,
4587+
init_rbf_tlvs);
4588+
}
4589+
45454590
peer->splice_state->await_commitment_succcess = false;
45464591
peer_write(peer->pps, take(msg));
45474592
}
@@ -4615,8 +4660,9 @@ static void handle_splice_init(struct peer *peer, const u8 *inmsg)
46154660
return;
46164661
}
46174662

4618-
status_debug("Getting handle_splice_init psbt version %d",
4619-
peer->splicing->current_psbt->version);
4663+
status_debug("Getting handle_splice_init psbt version %d (RBF?: %s)",
4664+
peer->splicing->current_psbt->version,
4665+
last_inflight(peer) ? "y" : "n");
46204666

46214667
if (skip_stfu) {
46224668
handle_splice_stfu_success(peer);
@@ -4791,6 +4837,7 @@ static void peer_in(struct peer *peer, const u8 *msg)
47914837
splice_accepter(peer, msg);
47924838
return;
47934839
case WIRE_SPLICE_ACK:
4840+
case WIRE_TX_ACK_RBF:
47944841
splice_initiator(peer, msg);
47954842
return;
47964843
case WIRE_SPLICE_LOCKED:
@@ -4817,8 +4864,6 @@ static void peer_in(struct peer *peer, const u8 *msg)
48174864
case WIRE_TX_SIGNATURES:
48184865
handle_unexpected_tx_sigs(peer, msg);
48194866
return;
4820-
case WIRE_TX_ACK_RBF:
4821-
break;
48224867

48234868
case WIRE_CHANNEL_REESTABLISH:
48244869
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)