Skip to content

Commit 3b5ec3b

Browse files
committed
Add is_channel_shutting_down to ChannelDetails
1 parent b6787a4 commit 3b5ec3b

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

fuzz/src/router.rs

+1
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
270270
inbound_htlc_maximum_msat: None,
271271
config: None,
272272
feerate_sat_per_1000_weight: None,
273+
is_channel_shutting_down: false,
273274
});
274275
}
275276
Some(&first_hops_vec[..])

lightning/src/ln/channel.rs

+7
Original file line numberDiff line numberDiff line change
@@ -5164,6 +5164,13 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
51645164
(self.channel_state & mask) == (ChannelState::ChannelReady as u32) && !self.monitor_pending_channel_ready
51655165
}
51665166

5167+
/// Returns true if this channel is shutting down either triggered remotely or locally
5168+
/// Also returns true if shutdown is completed
5169+
pub fn is_shutting_down(&self) -> bool {
5170+
let mask = ChannelState::ShutdownComplete as u32 | BOTH_SIDES_SHUTDOWN_MASK;
5171+
self.channel_state & mask != 0
5172+
}
5173+
51675174
/// Returns true if this channel is currently available for use. This is a superset of
51685175
/// is_usable() and considers things like the channel being temporarily disabled.
51695176
/// Allowed in any state (including after shutdown)

lightning/src/ln/channelmanager.rs

+9
Original file line numberDiff line numberDiff line change
@@ -1425,6 +1425,7 @@ pub struct ChannelDetails {
14251425
///
14261426
/// [`confirmations_required`]: ChannelDetails::confirmations_required
14271427
pub is_channel_ready: bool,
1428+
14281429
/// True if the channel is (a) confirmed and channel_ready messages have been exchanged, (b)
14291430
/// the peer is connected, and (c) the channel is not currently negotiating a shutdown.
14301431
///
@@ -1441,6 +1442,10 @@ pub struct ChannelDetails {
14411442
///
14421443
/// This field is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.109.
14431444
pub config: Option<ChannelConfig>,
1445+
1446+
/// True if the channel is shutdown or in the process of shutting down.
1447+
/// ie. either local cooperative/ local forced / remote coorperative / remote forced.
1448+
pub is_channel_shutting_down: bool,
14441449
}
14451450

14461451
impl ChannelDetails {
@@ -1512,6 +1517,7 @@ impl ChannelDetails {
15121517
inbound_htlc_minimum_msat: Some(channel.get_holder_htlc_minimum_msat()),
15131518
inbound_htlc_maximum_msat: channel.get_holder_htlc_maximum_msat(),
15141519
config: Some(channel.config()),
1520+
is_channel_shutting_down: channel.is_shutting_down(),
15151521
}
15161522
}
15171523
}
@@ -7190,6 +7196,7 @@ impl Writeable for ChannelDetails {
71907196
(35, self.inbound_htlc_maximum_msat, option),
71917197
(37, user_channel_id_high_opt, option),
71927198
(39, self.feerate_sat_per_1000_weight, option),
7199+
(41, self.is_channel_shutting_down, required),
71937200
});
71947201
Ok(())
71957202
}
@@ -7227,6 +7234,7 @@ impl Readable for ChannelDetails {
72277234
(35, inbound_htlc_maximum_msat, option),
72287235
(37, user_channel_id_high_opt, option),
72297236
(39, feerate_sat_per_1000_weight, option),
7237+
(41, is_channel_shutting_down, required),
72307238
});
72317239

72327240
// `user_channel_id` used to be a single u64 value. In order to remain backwards compatible with
@@ -7262,6 +7270,7 @@ impl Readable for ChannelDetails {
72627270
inbound_htlc_minimum_msat,
72637271
inbound_htlc_maximum_msat,
72647272
feerate_sat_per_1000_weight,
7273+
is_channel_shutting_down: is_channel_shutting_down.0.unwrap(),
72657274
})
72667275
}
72677276
}

lightning/src/routing/router.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2503,7 +2503,8 @@ mod tests {
25032503
inbound_htlc_minimum_msat: None,
25042504
inbound_htlc_maximum_msat: None,
25052505
config: None,
2506-
feerate_sat_per_1000_weight: None
2506+
feerate_sat_per_1000_weight: None,
2507+
is_channel_shutting_down: false
25072508
}
25082509
}
25092510

@@ -6290,6 +6291,7 @@ pub(crate) mod bench_utils {
62906291
inbound_htlc_maximum_msat: None,
62916292
config: None,
62926293
feerate_sat_per_1000_weight: None,
6294+
is_channel_shutting_down: false,
62936295
}
62946296
}
62956297

0 commit comments

Comments
 (0)