Skip to content

Commit

Permalink
Add is_channel_shutting_down to ChannelDetails
Browse files Browse the repository at this point in the history
  • Loading branch information
henghonglee committed Jun 9, 2023
1 parent b6787a4 commit 3b5ec3b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions fuzz/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
inbound_htlc_maximum_msat: None,
config: None,
feerate_sat_per_1000_weight: None,
is_channel_shutting_down: false,
});
}
Some(&first_hops_vec[..])
Expand Down
7 changes: 7 additions & 0 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5164,6 +5164,13 @@ impl<Signer: WriteableEcdsaChannelSigner> Channel<Signer> {
(self.channel_state & mask) == (ChannelState::ChannelReady as u32) && !self.monitor_pending_channel_ready
}

/// Returns true if this channel is shutting down either triggered remotely or locally
/// Also returns true if shutdown is completed
pub fn is_shutting_down(&self) -> bool {
let mask = ChannelState::ShutdownComplete as u32 | BOTH_SIDES_SHUTDOWN_MASK;
self.channel_state & mask != 0
}

/// Returns true if this channel is currently available for use. This is a superset of
/// is_usable() and considers things like the channel being temporarily disabled.
/// Allowed in any state (including after shutdown)
Expand Down
9 changes: 9 additions & 0 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,7 @@ pub struct ChannelDetails {
///
/// [`confirmations_required`]: ChannelDetails::confirmations_required
pub is_channel_ready: bool,

/// True if the channel is (a) confirmed and channel_ready messages have been exchanged, (b)
/// the peer is connected, and (c) the channel is not currently negotiating a shutdown.
///
Expand All @@ -1441,6 +1442,10 @@ pub struct ChannelDetails {
///
/// This field is only `None` for `ChannelDetails` objects serialized prior to LDK 0.0.109.
pub config: Option<ChannelConfig>,

/// True if the channel is shutdown or in the process of shutting down.
/// ie. either local cooperative/ local forced / remote coorperative / remote forced.
pub is_channel_shutting_down: bool,
}

impl ChannelDetails {
Expand Down Expand Up @@ -1512,6 +1517,7 @@ impl ChannelDetails {
inbound_htlc_minimum_msat: Some(channel.get_holder_htlc_minimum_msat()),
inbound_htlc_maximum_msat: channel.get_holder_htlc_maximum_msat(),
config: Some(channel.config()),
is_channel_shutting_down: channel.is_shutting_down(),
}
}
}
Expand Down Expand Up @@ -7190,6 +7196,7 @@ impl Writeable for ChannelDetails {
(35, self.inbound_htlc_maximum_msat, option),
(37, user_channel_id_high_opt, option),
(39, self.feerate_sat_per_1000_weight, option),
(41, self.is_channel_shutting_down, required),
});
Ok(())
}
Expand Down Expand Up @@ -7227,6 +7234,7 @@ impl Readable for ChannelDetails {
(35, inbound_htlc_maximum_msat, option),
(37, user_channel_id_high_opt, option),
(39, feerate_sat_per_1000_weight, option),
(41, is_channel_shutting_down, required),
});

// `user_channel_id` used to be a single u64 value. In order to remain backwards compatible with
Expand Down Expand Up @@ -7262,6 +7270,7 @@ impl Readable for ChannelDetails {
inbound_htlc_minimum_msat,
inbound_htlc_maximum_msat,
feerate_sat_per_1000_weight,
is_channel_shutting_down: is_channel_shutting_down.0.unwrap(),
})
}
}
Expand Down
4 changes: 3 additions & 1 deletion lightning/src/routing/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2503,7 +2503,8 @@ mod tests {
inbound_htlc_minimum_msat: None,
inbound_htlc_maximum_msat: None,
config: None,
feerate_sat_per_1000_weight: None
feerate_sat_per_1000_weight: None,
is_channel_shutting_down: false
}
}

Expand Down Expand Up @@ -6290,6 +6291,7 @@ pub(crate) mod bench_utils {
inbound_htlc_maximum_msat: None,
config: None,
feerate_sat_per_1000_weight: None,
is_channel_shutting_down: false,
}
}

Expand Down

0 comments on commit 3b5ec3b

Please sign in to comment.