Skip to content

Commit 4f8ab7b

Browse files
authored
Merge pull request #4426 from wpaulino/no-stfu-send-while-pending-splice
Avoid sending stfu for quiescent splice action while pending splice
2 parents 94b1c72 + 15b04b5 commit 4f8ab7b

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

lightning/src/ln/channel.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13619,6 +13619,17 @@ where
1361913619
return Ok(None);
1362013620
}
1362113621

13622+
if let Some(action) = self.quiescent_action.as_ref() {
13623+
// We can't initiate another splice while ours is pending, so don't bother becoming
13624+
// quiescent yet.
13625+
// TODO(splicing): Allow the splice as an RBF once supported.
13626+
let has_splice_action = matches!(action, QuiescentAction::Splice { .. })
13627+
|| matches!(action, QuiescentAction::LegacySplice(_));
13628+
if has_splice_action && self.pending_splice.is_some() {
13629+
return Ok(None);
13630+
}
13631+
}
13632+
1362213633
// We need to send our `stfu`, either because we're trying to initiate quiescence, or the
1362313634
// counterparty is and we've yet to send ours.
1362413635
if self.context.channel_state.is_awaiting_quiescence()

lightning/src/ln/splicing_tests.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,6 +1031,12 @@ fn test_splice_in_and_out() {
10311031

10321032
#[test]
10331033
fn test_fails_initiating_concurrent_splices() {
1034+
fails_initiating_concurrent_splices(true);
1035+
fails_initiating_concurrent_splices(false);
1036+
}
1037+
1038+
#[cfg(test)]
1039+
fn fails_initiating_concurrent_splices(reconnect: bool) {
10341040
let chanmon_cfgs = create_chanmon_cfgs(2);
10351041
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
10361042
let config = test_default_channel_config();
@@ -1043,6 +1049,7 @@ fn test_fails_initiating_concurrent_splices() {
10431049
let node_0_id = nodes[0].node.get_our_node_id();
10441050
let node_1_id = nodes[1].node.get_our_node_id();
10451051

1052+
send_payment(&nodes[0], &[&nodes[1]], 1_000);
10461053
provide_utxo_reserves(&nodes, 2, Amount::ONE_BTC);
10471054

10481055
let outputs = vec![TxOut {
@@ -1116,15 +1123,23 @@ fn test_fails_initiating_concurrent_splices() {
11161123
expect_splice_pending_event(&nodes[0], &node_1_id);
11171124
expect_splice_pending_event(&nodes[1], &node_0_id);
11181125

1119-
// Now that the splice is pending, another splice may be initiated.
1126+
// Now that the splice is pending, another splice may be initiated, but we must wait until
1127+
// the `splice_locked` exchange to send the initiator `stfu`.
11201128
assert!(nodes[0].node.splice_channel(&channel_id, &node_1_id, feerate).is_ok());
11211129

1130+
if reconnect {
1131+
nodes[0].node.peer_disconnected(node_1_id);
1132+
nodes[1].node.peer_disconnected(node_0_id);
1133+
reconnect_nodes(ReconnectArgs::new(&nodes[0], &nodes[1]));
1134+
}
1135+
1136+
assert!(nodes[0].node.get_and_clear_pending_msg_events().is_empty());
1137+
assert!(nodes[1].node.get_and_clear_pending_msg_events().is_empty());
1138+
11221139
mine_transaction(&nodes[0], &splice_tx);
11231140
mine_transaction(&nodes[1], &splice_tx);
11241141
let stfu = lock_splice_after_blocks(&nodes[0], &nodes[1], ANTI_REORG_DELAY - 1);
11251142

1126-
// However, the acceptor had enqueued a quiescent action while the splice was pending, so it
1127-
// will now attempt to initiate quiescence.
11281143
assert!(
11291144
matches!(stfu, Some(MessageSendEvent::SendStfu { node_id, .. }) if node_id == node_0_id)
11301145
);

0 commit comments

Comments
 (0)