Skip to content

Commit e6bc69b

Browse files
committed
Add is_channel_shutting_down to ChannelDetails
1 parent 486c16a commit e6bc69b

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

lightning/src/ln/channel.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5049,6 +5049,13 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
50495049
(self.channel_state & mask) == (ChannelState::ChannelReady as u32) && !self.monitor_pending_channel_ready
50505050
}
50515051

5052+
/// Returns true if this channel is shutting down either triggered remotely or locally
5053+
/// Also returns true if shutdown is completed
5054+
pub fn is_shutting_down(&self) -> bool {
5055+
let mask = ChannelState::ShutdownComplete as u32 | BOTH_SIDES_SHUTDOWN_MASK;
5056+
self.channel_state & mask != 0
5057+
}
5058+
50525059
/// Returns true if this channel is currently available for use. This is a superset of
50535060
/// is_usable() and considers things like the channel being temporarily disabled.
50545061
/// Allowed in any state (including after shutdown)

lightning/src/ln/channelmanager.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,7 @@ pub struct ChannelDetails {
14191419
///
14201420
/// [`confirmations_required`]: ChannelDetails::confirmations_required
14211421
pub is_channel_ready: bool,
1422+
14221423
/// True if the channel is (a) confirmed and channel_ready messages have been exchanged, (b)
14231424
/// the peer is connected, and (c) the channel is not currently negotiating a shutdown.
14241425
///
@@ -1435,6 +1436,10 @@ pub struct ChannelDetails {
14351436
///
14361437
/// This field is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.109.
14371438
pub config: Option<ChannelConfig>,
1439+
1440+
/// True if the channel is shutdown or in the process of shutting down.
1441+
/// ie. either local cooperative/ local forced / remote coorperative / remote forced.
1442+
pub is_channel_shutting_down: bool,
14381443
}
14391444

14401445
impl ChannelDetails {
@@ -1505,6 +1510,7 @@ impl ChannelDetails {
15051510
inbound_htlc_minimum_msat: Some(channel.get_holder_htlc_minimum_msat()),
15061511
inbound_htlc_maximum_msat: channel.get_holder_htlc_maximum_msat(),
15071512
config: Some(channel.config()),
1513+
is_channel_shutting_down: channel.is_shutting_down(),
15081514
}
15091515
}
15101516
}
@@ -7154,6 +7160,7 @@ impl Writeable for ChannelDetails {
71547160
(35, self.inbound_htlc_maximum_msat, option),
71557161
(37, user_channel_id_high_opt, option),
71567162
(39, self.feerate_sat_per_1000_weight, option),
7163+
(41, self.is_channel_shutting_down, required),
71577164
});
71587165
Ok(())
71597166
}
@@ -7190,6 +7197,7 @@ impl Readable for ChannelDetails {
71907197
(35, inbound_htlc_maximum_msat, option),
71917198
(37, user_channel_id_high_opt, option),
71927199
(39, feerate_sat_per_1000_weight, option),
7200+
(41, is_channel_shutting_down, required),
71937201
});
71947202

71957203
// `user_channel_id` used to be a single u64 value. In order to remain backwards compatible with
@@ -7224,6 +7232,7 @@ impl Readable for ChannelDetails {
72247232
inbound_htlc_minimum_msat,
72257233
inbound_htlc_maximum_msat,
72267234
feerate_sat_per_1000_weight,
7235+
is_channel_shutting_down: is_channel_shutting_down.0.unwrap(),
72277236
})
72287237
}
72297238
}

lightning/src/routing/router.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2470,7 +2470,8 @@ mod tests {
24702470
inbound_htlc_minimum_msat: None,
24712471
inbound_htlc_maximum_msat: None,
24722472
config: None,
2473-
feerate_sat_per_1000_weight: None
2473+
feerate_sat_per_1000_weight: None,
2474+
is_channel_shutting_down: false
24742475
}
24752476
}
24762477

@@ -6135,6 +6136,7 @@ pub(crate) mod bench_utils {
61356136
inbound_htlc_maximum_msat: None,
61366137
config: None,
61376138
feerate_sat_per_1000_weight: None,
6139+
is_channel_shutting_down: false,
61386140
}
61396141
}
61406142

0 commit comments

Comments
 (0)