Skip to content

Commit bc5d606

Browse files
committed
splice: Bulk channel stfu and abort RPC
The ability to stfu channels in bulk is required to do complex multi channel operations. When stfu’ing in this manner, the available funds at the moment of stfu is returned to the user. In order to cancel the stfu we also add a bulk tx_abort command. Changelog-Added: `stfu_channels` and `abort_channels` are added for bulk multi-channel splice commands. These allow the user to pause (and resume) multiple channels in place.
1 parent cc08860 commit bc5d606

File tree

3 files changed

+312
-12
lines changed

3 files changed

+312
-12
lines changed

channeld/channeld.c

Lines changed: 89 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959

6060
#define VALID_STFU_MESSAGE(msg) \
6161
((msg) == WIRE_SPLICE || \
62-
(msg) == WIRE_SPLICE_ACK)
62+
(msg) == WIRE_SPLICE_ACK || \
63+
(msg) == WIRE_TX_ABORT)
6364

6465
#define SAT_MIN(a, b) (amount_sat_less((a), (b)) ? (a) : (b))
6566

@@ -4419,6 +4420,7 @@ static void handle_splice_stfu_success(struct peer *peer)
44194420
static void handle_splice_init(struct peer *peer, const u8 *inmsg)
44204421
{
44214422
u8 *msg;
4423+
bool skip_stfu;
44224424

44234425
/* Can't start a splice with another splice still active */
44244426
if (peer->splicing) {
@@ -4435,23 +4437,32 @@ static void handle_splice_init(struct peer *peer, const u8 *inmsg)
44354437
&peer->splicing->current_psbt,
44364438
&peer->splicing->opener_relative,
44374439
&peer->splicing->feerate_per_kw,
4438-
&peer->splicing->force_feerate))
4440+
&peer->splicing->force_feerate,
4441+
&skip_stfu))
44394442
master_badmsg(WIRE_CHANNELD_SPLICE_INIT, inmsg);
44404443

4441-
if (peer->want_stfu) {
4444+
if (!skip_stfu && peer->want_stfu) {
44424445
msg = towire_channeld_splice_state_error(NULL, "Can't begin a"
44434446
" splice while waiting"
44444447
" for STFU.");
44454448
wire_sync_write(MASTER_FD, take(msg));
44464449
return;
44474450
}
4448-
if (is_stfu_active(peer)) {
4451+
if (!skip_stfu && is_stfu_active(peer)) {
44494452
msg = towire_channeld_splice_state_error(NULL, "Can't begin a"
44504453
" splice while"
44514454
" currently in STFU");
44524455
wire_sync_write(MASTER_FD, take(msg));
44534456
return;
44544457
}
4458+
if (skip_stfu && !is_stfu_active(peer)) {
4459+
msg = towire_channeld_splice_state_error(NULL, "Can't begin a"
4460+
" splice with"
4461+
" skip_stfu if not"
4462+
" already in STFU");
4463+
wire_sync_write(MASTER_FD, take(msg));
4464+
return;
4465+
}
44554466
if (peer->splicing->mode) {
44564467
msg = towire_channeld_splice_state_error(NULL, "Can't begin a"
44574468
" splice while already"
@@ -4471,16 +4482,77 @@ static void handle_splice_init(struct peer *peer, const u8 *inmsg)
44714482
return;
44724483
}
44734484

4474-
status_debug("Getting handle_splice_init psbt version %d", peer->splicing->current_psbt->version);
4485+
status_debug("Getting handle_splice_init psbt version %d",
4486+
peer->splicing->current_psbt->version);
4487+
4488+
if (skip_stfu) {
4489+
handle_splice_stfu_success(peer);
4490+
} else {
4491+
peer->on_stfu_success = handle_splice_stfu_success;
4492+
4493+
/* First things first we must STFU the channel */
4494+
peer->stfu_initiator = LOCAL;
4495+
peer->want_stfu = true;
4496+
maybe_send_stfu(peer);
4497+
}
4498+
}
4499+
4500+
static void handle_stfu_req_success(struct peer *peer)
4501+
{
4502+
struct amount_msat available_funds = peer->channel->view->owed[LOCAL];
4503+
/* DTODO: Subtract reserve requirment from available_funds? */
4504+
wire_sync_write(MASTER_FD,
4505+
take(towire_channeld_confirmed_stfu(NULL,
4506+
available_funds)));
4507+
}
4508+
4509+
static void handle_stfu_req(struct peer *peer, const u8 *inmsg)
4510+
{
4511+
u8 *msg;
44754512

4476-
peer->on_stfu_success = handle_splice_stfu_success;
4513+
if (!fromwire_channeld_stfu(inmsg))
4514+
master_badmsg(WIRE_CHANNELD_STFU, inmsg);
4515+
4516+
if (peer->splicing) {
4517+
msg = towire_channeld_splice_state_error(NULL, "Can't start"
4518+
" stfu when a splice"
4519+
" is active");
4520+
wire_sync_write(MASTER_FD, take(msg));
4521+
return;
4522+
}
4523+
if (peer->want_stfu) {
4524+
msg = towire_channeld_splice_state_error(NULL, "Can't stfu"
4525+
" splice while waiting"
4526+
" for STFU.");
4527+
wire_sync_write(MASTER_FD, take(msg));
4528+
return;
4529+
}
4530+
if (is_stfu_active(peer)) {
4531+
msg = towire_channeld_splice_state_error(NULL, "Can't stfu"
4532+
" splice while"
4533+
" currently in STFU");
4534+
wire_sync_write(MASTER_FD, take(msg));
4535+
return;
4536+
}
4537+
4538+
peer->on_stfu_success = handle_stfu_req_success;
44774539

4478-
/* First things first we must STFU the channel */
44794540
peer->stfu_initiator = LOCAL;
44804541
peer->want_stfu = true;
44814542
maybe_send_stfu(peer);
44824543
}
44834544

4545+
static void handle_abort_req(struct peer *peer, const u8 *inmsg)
4546+
{
4547+
if (!fromwire_channeld_abort(inmsg))
4548+
master_badmsg(WIRE_CHANNELD_ABORT, inmsg);
4549+
4550+
peer_write(peer->pps,
4551+
take(towire_tx_abort(NULL,
4552+
&peer->channel_id,
4553+
NULL)));
4554+
}
4555+
44844556
static void peer_in(struct peer *peer, const u8 *msg)
44854557
{
44864558
enum peer_wire type = fromwire_peektype(msg);
@@ -4561,6 +4633,9 @@ static void peer_in(struct peer *peer, const u8 *msg)
45614633
case WIRE_SPLICE_LOCKED:
45624634
handle_peer_splice_locked(peer, msg);
45634635
return;
4636+
case WIRE_TX_ABORT:
4637+
check_tx_abort(peer, msg);
4638+
return;
45644639
case WIRE_INIT:
45654640
case WIRE_OPEN_CHANNEL:
45664641
case WIRE_ACCEPT_CHANNEL:
@@ -4572,7 +4647,6 @@ static void peer_in(struct peer *peer, const u8 *msg)
45724647
case WIRE_TX_ADD_OUTPUT:
45734648
case WIRE_TX_REMOVE_OUTPUT:
45744649
case WIRE_TX_COMPLETE:
4575-
case WIRE_TX_ABORT:
45764650
case WIRE_OPEN_CHANNEL2:
45774651
case WIRE_ACCEPT_CHANNEL2:
45784652
case WIRE_TX_SIGNATURES:
@@ -6048,6 +6122,12 @@ static void req_in(struct peer *peer, const u8 *msg)
60486122
case WIRE_CHANNELD_SPLICE_SIGNED:
60496123
splice_initiator_user_signed(peer, msg);
60506124
return;
6125+
case WIRE_CHANNELD_STFU:
6126+
handle_stfu_req(peer, msg);
6127+
return;
6128+
case WIRE_CHANNELD_ABORT:
6129+
handle_abort_req(peer, msg);
6130+
return;
60516131
case WIRE_CHANNELD_SPLICE_CONFIRMED_INIT:
60526132
case WIRE_CHANNELD_SPLICE_CONFIRMED_SIGNED:
60536133
case WIRE_CHANNELD_SPLICE_SENDING_SIGS:
@@ -6056,6 +6136,7 @@ static void req_in(struct peer *peer, const u8 *msg)
60566136
case WIRE_CHANNELD_SPLICE_LOOKUP_TX_RESULT:
60576137
case WIRE_CHANNELD_SPLICE_FEERATE_ERROR:
60586138
case WIRE_CHANNELD_SPLICE_FUNDING_ERROR:
6139+
case WIRE_CHANNELD_CONFIRMED_STFU:
60596140
break;
60606141
case WIRE_CHANNELD_DEV_REENABLE_COMMIT:
60616142
if (peer->developer) {

channeld/channeld_wire.csv

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ msgdata,channeld_splice_init,psbt,wally_psbt,
211211
msgdata,channeld_splice_init,relative_amount,s64,
212212
msgdata,channeld_splice_init,feerate_per_kw,u32,
213213
msgdata,channeld_splice_init,force_feerate,bool,
214+
msgdata,channeld_splice_init,skip_stfu,bool,
214215

215216
# channeld->master: hello, I started a channel splice open
216217
msgtype,channeld_splice_confirmed_init,7205
@@ -224,6 +225,7 @@ msgdata,channeld_splice_update,psbt,wally_psbt,
224225
msgtype,channeld_splice_confirmed_update,7207
225226
msgdata,channeld_splice_confirmed_update,psbt,wally_psbt,
226227
msgdata,channeld_splice_confirmed_update,commitments_secured,bool,
228+
msgdata,channeld_splice_confirmed_update,signatures_secured,bool,
227229

228230
# channeld->master: Lookup a transaction
229231
msgtype,channeld_splice_lookup_tx,7208
@@ -282,6 +284,16 @@ msgdata,channeld_splice_funding_error,opener_error,bool,
282284
msgtype,channeld_splice_state_error,7221
283285
msgdata,channeld_splice_state_error,state_error,wirestring,
284286

287+
# master->channeld: Please enter stfu mode
288+
msgtype,channeld_stfu,7222
289+
290+
# channeld->master: Entered stfu result
291+
msgtype,channeld_confirmed_stfu,7223
292+
msgdata,channeld_confirmed_stfu,available_funds,amount_msat,
293+
294+
# master->channeld: Please enter perform tx_abort
295+
msgtype,channeld_abort,7224
296+
285297
# Tell peer to shut down channel.
286298
msgtype,channeld_send_shutdown,1023
287299
msgdata,channeld_send_shutdown,final_index,?u32,

0 commit comments

Comments
 (0)