Skip to content

Commit be71d37

Browse files
committed
Add note and test regarding ChannelState's implicit ordering
1 parent 9856fb6 commit be71d37

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lightning/src/ln/channel.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,8 @@ define_state_flags!(
419419
]
420420
);
421421

422+
// Note that the order of this enum is implicitly defined by where each variant is placed. Take this
423+
// into account when introducing new states and update `test_channel_state_order` accordingly.
422424
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Eq)]
423425
enum ChannelState {
424426
/// We are negotiating the parameters required for the channel prior to funding it.
@@ -8321,6 +8323,18 @@ mod tests {
83218323
use bitcoin::address::{WitnessProgram, WitnessVersion};
83228324
use crate::prelude::*;
83238325

8326+
#[test]
8327+
fn test_channel_state_order() {
8328+
use crate::ln::channel::NegotiatingFundingFlags;
8329+
use crate::ln::channel::AwaitingChannelReadyFlags;
8330+
use crate::ln::channel::ChannelReadyFlags;
8331+
8332+
assert!(ChannelState::NegotiatingFunding(NegotiatingFundingFlags::new()) < ChannelState::FundingNegotiated);
8333+
assert!(ChannelState::FundingNegotiated < ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new()));
8334+
assert!(ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new()) < ChannelState::ChannelReady(ChannelReadyFlags::new()));
8335+
assert!(ChannelState::ChannelReady(ChannelReadyFlags::new()) < ChannelState::ShutdownComplete);
8336+
}
8337+
83248338
struct TestFeeEstimator {
83258339
fee_est: u32
83268340
}

0 commit comments

Comments
 (0)