Skip to content

Commit a657244

Browse files
committed
Add note and test regarding ChannelState's implicit ordering
1 parent db81c65 commit a657244

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.
@@ -8374,6 +8376,18 @@ mod tests {
83748376
use bitcoin::address::{WitnessProgram, WitnessVersion};
83758377
use crate::prelude::*;
83768378

8379+
#[test]
8380+
fn test_channel_state_order() {
8381+
use crate::ln::channel::NegotiatingFundingFlags;
8382+
use crate::ln::channel::AwaitingChannelReadyFlags;
8383+
use crate::ln::channel::ChannelReadyFlags;
8384+
8385+
assert!(ChannelState::NegotiatingFunding(NegotiatingFundingFlags::new()) < ChannelState::FundingNegotiated);
8386+
assert!(ChannelState::FundingNegotiated < ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new()));
8387+
assert!(ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new()) < ChannelState::ChannelReady(ChannelReadyFlags::new()));
8388+
assert!(ChannelState::ChannelReady(ChannelReadyFlags::new()) < ChannelState::ShutdownComplete);
8389+
}
8390+
83778391
struct TestFeeEstimator {
83788392
fee_est: u32
83798393
}

0 commit comments

Comments
 (0)