59
59
60
60
#define VALID_STFU_MESSAGE (msg ) \
61
61
((msg) == WIRE_SPLICE || \
62
- (msg) == WIRE_SPLICE_ACK)
62
+ (msg) == WIRE_SPLICE_ACK || \
63
+ (msg) == WIRE_TX_ABORT)
63
64
64
65
#define SAT_MIN (a , b ) (amount_sat_less((a), (b)) ? (a) : (b))
65
66
@@ -4419,6 +4420,7 @@ static void handle_splice_stfu_success(struct peer *peer)
4419
4420
static void handle_splice_init (struct peer * peer , const u8 * inmsg )
4420
4421
{
4421
4422
u8 * msg ;
4423
+ bool skip_stfu ;
4422
4424
4423
4425
/* Can't start a splice with another splice still active */
4424
4426
if (peer -> splicing ) {
@@ -4435,23 +4437,32 @@ static void handle_splice_init(struct peer *peer, const u8 *inmsg)
4435
4437
& peer -> splicing -> current_psbt ,
4436
4438
& peer -> splicing -> opener_relative ,
4437
4439
& peer -> splicing -> feerate_per_kw ,
4438
- & peer -> splicing -> force_feerate ))
4440
+ & peer -> splicing -> force_feerate ,
4441
+ & skip_stfu ))
4439
4442
master_badmsg (WIRE_CHANNELD_SPLICE_INIT , inmsg );
4440
4443
4441
- if (peer -> want_stfu ) {
4444
+ if (! skip_stfu && peer -> want_stfu ) {
4442
4445
msg = towire_channeld_splice_state_error (NULL , "Can't begin a"
4443
4446
" splice while waiting"
4444
4447
" for STFU." );
4445
4448
wire_sync_write (MASTER_FD , take (msg ));
4446
4449
return ;
4447
4450
}
4448
- if (is_stfu_active (peer )) {
4451
+ if (! skip_stfu && is_stfu_active (peer )) {
4449
4452
msg = towire_channeld_splice_state_error (NULL , "Can't begin a"
4450
4453
" splice while"
4451
4454
" currently in STFU" );
4452
4455
wire_sync_write (MASTER_FD , take (msg ));
4453
4456
return ;
4454
4457
}
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
+ }
4455
4466
if (peer -> splicing -> mode ) {
4456
4467
msg = towire_channeld_splice_state_error (NULL , "Can't begin a"
4457
4468
" splice while already"
@@ -4471,16 +4482,77 @@ static void handle_splice_init(struct peer *peer, const u8 *inmsg)
4471
4482
return ;
4472
4483
}
4473
4484
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 ;
4475
4512
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 ;
4477
4539
4478
- /* First things first we must STFU the channel */
4479
4540
peer -> stfu_initiator = LOCAL ;
4480
4541
peer -> want_stfu = true;
4481
4542
maybe_send_stfu (peer );
4482
4543
}
4483
4544
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
+
4484
4556
static void peer_in (struct peer * peer , const u8 * msg )
4485
4557
{
4486
4558
enum peer_wire type = fromwire_peektype (msg );
@@ -4561,6 +4633,9 @@ static void peer_in(struct peer *peer, const u8 *msg)
4561
4633
case WIRE_SPLICE_LOCKED :
4562
4634
handle_peer_splice_locked (peer , msg );
4563
4635
return ;
4636
+ case WIRE_TX_ABORT :
4637
+ check_tx_abort (peer , msg );
4638
+ return ;
4564
4639
case WIRE_INIT :
4565
4640
case WIRE_OPEN_CHANNEL :
4566
4641
case WIRE_ACCEPT_CHANNEL :
@@ -4572,7 +4647,6 @@ static void peer_in(struct peer *peer, const u8 *msg)
4572
4647
case WIRE_TX_ADD_OUTPUT :
4573
4648
case WIRE_TX_REMOVE_OUTPUT :
4574
4649
case WIRE_TX_COMPLETE :
4575
- case WIRE_TX_ABORT :
4576
4650
case WIRE_OPEN_CHANNEL2 :
4577
4651
case WIRE_ACCEPT_CHANNEL2 :
4578
4652
case WIRE_TX_SIGNATURES :
@@ -6048,6 +6122,12 @@ static void req_in(struct peer *peer, const u8 *msg)
6048
6122
case WIRE_CHANNELD_SPLICE_SIGNED :
6049
6123
splice_initiator_user_signed (peer , msg );
6050
6124
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 ;
6051
6131
case WIRE_CHANNELD_SPLICE_CONFIRMED_INIT :
6052
6132
case WIRE_CHANNELD_SPLICE_CONFIRMED_SIGNED :
6053
6133
case WIRE_CHANNELD_SPLICE_SENDING_SIGS :
@@ -6056,6 +6136,7 @@ static void req_in(struct peer *peer, const u8 *msg)
6056
6136
case WIRE_CHANNELD_SPLICE_LOOKUP_TX_RESULT :
6057
6137
case WIRE_CHANNELD_SPLICE_FEERATE_ERROR :
6058
6138
case WIRE_CHANNELD_SPLICE_FUNDING_ERROR :
6139
+ case WIRE_CHANNELD_CONFIRMED_STFU :
6059
6140
break ;
6060
6141
case WIRE_CHANNELD_DEV_REENABLE_COMMIT :
6061
6142
if (peer -> developer ) {
0 commit comments