Skip to content

Commit 239c4f8

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 239c4f8

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

lightning/src/ln/channel.rs

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,6 +2443,15 @@ impl PendingSplice {
24432443
}
24442444
}
24452445

2446+
pub(crate) enum QuiescentAction {
2447+
// TODO: Make this test-only once we have another variant (as some code requires *a* variant).
2448+
DoNothing,
2449+
}
2450+
2451+
impl_writeable_tlv_based_enum_upgradable!(QuiescentAction,
2452+
(99, DoNothing) => {},
2453+
);
2454+
24462455
/// Wrapper around a [`Transaction`] useful for caching the result of [`Transaction::compute_txid`].
24472456
struct ConfirmedTransaction<'a> {
24482457
tx: &'a Transaction,
@@ -2742,6 +2751,12 @@ where
27422751
/// If we can't release a [`ChannelMonitorUpdate`] until some external action completes, we
27432752
/// store it here and only release it to the `ChannelManager` once it asks for it.
27442753
blocked_monitor_updates: Vec<PendingChannelMonitorUpdate>,
2754+
2755+
/// Once we become quiescent, if we're the initiator, there's some action we'll want to take.
2756+
/// This keeps track of that action. Note that if we become quiescent and we're not the
2757+
/// initiator we may be able to merge this action into what the counterparty wanted to do (e.g.
2758+
/// in the case of splicing).
2759+
post_quiescence_action: Option<QuiescentAction>,
27452760
}
27462761

27472762
/// A channel struct implementing this trait can receive an initial counterparty commitment
@@ -3316,6 +3331,8 @@ where
33163331
blocked_monitor_updates: Vec::new(),
33173332

33183333
is_manual_broadcast: false,
3334+
3335+
post_quiescence_action: None,
33193336
};
33203337

33213338
Ok((funding, channel_context))
@@ -3552,6 +3569,8 @@ where
35523569
blocked_monitor_updates: Vec::new(),
35533570
local_initiated_shutdown: None,
35543571
is_manual_broadcast: false,
3572+
3573+
post_quiescence_action: None,
35553574
};
35563575

35573576
Ok((funding, channel_context))
@@ -11548,7 +11567,7 @@ where
1154811567
#[cfg(any(test, fuzzing))]
1154911568
#[rustfmt::skip]
1155011569
pub fn propose_quiescence<L: Deref>(
11551-
&mut self, logger: &L,
11570+
&mut self, logger: &L, action: QuiescentAction,
1155211571
) -> Result<Option<msgs::Stfu>, ChannelError>
1155311572
where
1155411573
L::Target: Logger,
@@ -11560,11 +11579,13 @@ where
1156011579
"Channel is not in a live state to propose quiescence".to_owned()
1156111580
));
1156211581
}
11563-
if self.context.channel_state.is_quiescent() {
11564-
return Err(ChannelError::Ignore("Channel is already quiescent".to_owned()));
11582+
if self.context.post_quiescence_action.is_some() {
11583+
return Err(ChannelError::Ignore("Channel is already quiescing".to_owned()));
1156511584
}
1156611585

11567-
if self.context.channel_state.is_awaiting_quiescence()
11586+
self.context.post_quiescence_action = Some(action);
11587+
if self.context.channel_state.is_quiescent()
11588+
|| self.context.channel_state.is_awaiting_quiescence()
1156811589
|| self.context.channel_state.is_local_stfu_sent()
1156911590
{
1157011591
return Ok(None);
@@ -11683,6 +11704,21 @@ where
1168311704
if !is_holder_quiescence_initiator { " not" } else { "" }
1168411705
);
1168511706

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

@@ -13986,6 +14022,8 @@ where
1398614022

1398714023
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
1398814024
is_manual_broadcast: is_manual_broadcast.unwrap_or(false),
14025+
14026+
post_quiescence_action: None,
1398914027
},
1399014028
interactive_tx_signing_session,
1399114029
holder_commitment_point,

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)