Skip to content

Commit a46cea5

Browse files
committed
Add a QuiescentAction to track why we're going quiescent
When we initiate quiescence, it should always be because we're trying to accomplish something (in the short term only splicing). In order to actually do that thing, we need to store the instructions for that thing somewhere the splicing logic knows to look at once we reach quiescence. Here we add a simple enum which will eventually store such actions.
1 parent 5a5d061 commit a46cea5

File tree

2 files changed

+43
-7
lines changed

2 files changed

+43
-7
lines changed

lightning/src/ln/channel.rs

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1877,6 +1877,7 @@ where
18771877
holder_commitment_point,
18781878
#[cfg(splicing)]
18791879
pending_splice: None,
1880+
quiescent_action: None,
18801881
};
18811882
let res = funded_channel.initial_commitment_signed_v2(msg, best_block, signer_provider, logger)
18821883
.map(|monitor| (Some(monitor), None))
@@ -2443,6 +2444,15 @@ impl PendingSplice {
24432444
}
24442445
}
24452446

2447+
pub(crate) enum QuiescentAction {
2448+
// TODO: Make this test-only once we have another variant (as some code requires *a* variant).
2449+
DoNothing,
2450+
}
2451+
2452+
impl_writeable_tlv_based_enum_upgradable!(QuiescentAction,
2453+
(99, DoNothing) => {},
2454+
);
2455+
24462456
/// Wrapper around a [`Transaction`] useful for caching the result of [`Transaction::compute_txid`].
24472457
struct ConfirmedTransaction<'a> {
24482458
tx: &'a Transaction,
@@ -6084,6 +6094,12 @@ where
60846094
/// Info about an in-progress, pending splice (if any), on the pre-splice channel
60856095
#[cfg(splicing)]
60866096
pending_splice: Option<PendingSplice>,
6097+
6098+
/// Once we become quiescent, if we're the initiator, there's some action we'll want to take.
6099+
/// This keeps track of that action. Note that if we become quiescent and we're not the
6100+
/// initiator we may be able to merge this action into what the counterparty wanted to do (e.g.
6101+
/// in the case of splicing).
6102+
quiescent_action: Option<QuiescentAction>,
60876103
}
60886104

60896105
#[cfg(splicing)]
@@ -11548,7 +11564,7 @@ where
1154811564
#[cfg(any(test, fuzzing))]
1154911565
#[rustfmt::skip]
1155011566
pub fn propose_quiescence<L: Deref>(
11551-
&mut self, logger: &L,
11567+
&mut self, logger: &L, action: QuiescentAction,
1155211568
) -> Result<Option<msgs::Stfu>, ChannelError>
1155311569
where
1155411570
L::Target: Logger,
@@ -11560,11 +11576,13 @@ where
1156011576
"Channel is not in a live state to propose quiescence".to_owned()
1156111577
));
1156211578
}
11563-
if self.context.channel_state.is_quiescent() {
11564-
return Err(ChannelError::Ignore("Channel is already quiescent".to_owned()));
11579+
if self.quiescent_action.is_some() {
11580+
return Err(ChannelError::Ignore("Channel is already quiescing".to_owned()));
1156511581
}
1156611582

11567-
if self.context.channel_state.is_awaiting_quiescence()
11583+
self.quiescent_action = Some(action);
11584+
if self.context.channel_state.is_quiescent()
11585+
|| self.context.channel_state.is_awaiting_quiescence()
1156811586
|| self.context.channel_state.is_local_stfu_sent()
1156911587
{
1157011588
return Ok(None);
@@ -11683,6 +11701,21 @@ where
1168311701
if !is_holder_quiescence_initiator { " not" } else { "" }
1168411702
);
1168511703

11704+
if is_holder_quiescence_initiator {
11705+
match self.quiescent_action.take() {
11706+
None => {
11707+
debug_assert!(false);
11708+
return Err(ChannelError::WarnAndDisconnect(
11709+
"Internal Error: Didn't have anything to do after reaching quiescence".to_owned()
11710+
));
11711+
},
11712+
Some(QuiescentAction::DoNothing) => {
11713+
// In quiescence test we want to just hang out here, letting the test manually
11714+
// leave quiescence.
11715+
},
11716+
}
11717+
}
11718+
1168611719
Ok(None)
1168711720
}
1168811721

@@ -12048,6 +12081,7 @@ where
1204812081
holder_commitment_point,
1204912082
#[cfg(splicing)]
1205012083
pending_splice: None,
12084+
quiescent_action: None,
1205112085
};
1205212086

1205312087
let need_channel_ready = channel.check_get_channel_ready(0, logger).is_some()
@@ -12334,6 +12368,7 @@ where
1233412368
holder_commitment_point,
1233512369
#[cfg(splicing)]
1233612370
pending_splice: None,
12371+
quiescent_action: None,
1233712372
};
1233812373
let need_channel_ready = channel.check_get_channel_ready(0, logger).is_some()
1233912374
|| channel.context.signer_pending_channel_ready;
@@ -13991,6 +14026,7 @@ where
1399114026
holder_commitment_point,
1399214027
#[cfg(splicing)]
1399314028
pending_splice: None,
14029+
quiescent_action: None,
1399414030
})
1399514031
}
1399614032
}

lightning/src/ln/channelmanager.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ use crate::events::{
5757
};
5858
use crate::events::{FundingInfo, PaidBolt12Invoice};
5959
use crate::ln::chan_utils::selected_commitment_sat_per_1000_weight;
60-
// Since this struct is returned in `list_channels` methods, expose it here in case users want to
61-
// construct one themselves.
60+
#[cfg(any(test, fuzzing))]
61+
use crate::ln::channel::QuiescentAction;
6262
use crate::ln::channel::{
6363
self, hold_time_since, Channel, ChannelError, ChannelUpdateStatus, FundedChannel,
6464
InboundV1Channel, OutboundV1Channel, PendingV2Channel, ReconnectionMsg, ShutdownResult,
@@ -11660,7 +11660,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1166011660
&self.logger, Some(*counterparty_node_id), Some(*channel_id), None
1166111661
);
1166211662

11663-
match chan.propose_quiescence(&&logger) {
11663+
match chan.propose_quiescence(&&logger, QuiescentAction::DoNothing) {
1166411664
Ok(None) => {},
1166511665
Ok(Some(stfu)) => {
1166611666
peer_state.pending_msg_events.push(MessageSendEvent::SendStfu {

0 commit comments

Comments
 (0)