Skip to content

Commit c892953

Browse files
committed
f add test
1 parent e5dd416 commit c892953

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

lightning/src/ln/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl HTLCCandidate {
288288
}
289289

290290
/// Information needed for constructing an invoice route hint for this channel.
291-
#[derive(Clone)]
291+
#[derive(Clone, Debug, PartialEq)]
292292
pub struct CounterpartyForwardingInfo {
293293
/// Base routing fee in millisatoshis.
294294
pub fee_base_msat: u32,

lightning/src/ln/channelmanager.rs

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ const CHECK_CLTV_EXPIRY_SANITY: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRA
632632
const CHECK_CLTV_EXPIRY_SANITY_2: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRACE_PERIOD_BLOCKS - 2*CLTV_CLAIM_BUFFER;
633633

634634
/// Details of a channel, as returned by ChannelManager::list_channels and ChannelManager::list_usable_channels
635-
#[derive(Clone)]
635+
#[derive(Clone, Debug, PartialEq)]
636636
pub struct ChannelDetails {
637637
/// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
638638
/// thereafter this is the txid of the funding transaction xor the funding transaction output).
@@ -4829,6 +4829,9 @@ mod tests {
48294829
use core::sync::atomic::{AtomicBool, Ordering};
48304830
use std::thread;
48314831
use core::time::Duration;
4832+
use ln::functional_test_utils::*;
4833+
use ln::features::InitFeatures;
4834+
use ln::msgs::ChannelMessageHandler;
48324835

48334836
#[test]
48344837
fn test_wait_timeout() {
@@ -4871,6 +4874,53 @@ mod tests {
48714874
}
48724875
}
48734876
}
4877+
4878+
#[test]
4879+
fn test_notify_limits() {
4880+
// Check that a few cases which don't require the persistence of a new ChannelManager,
4881+
// indeed, do not cause the persistence of a new ChannelManager.
4882+
let chanmon_cfgs = create_chanmon_cfgs(3);
4883+
let node_cfgs = create_node_cfgs(3, &chanmon_cfgs);
4884+
let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]);
4885+
let nodes = create_network(3, &node_cfgs, &node_chanmgrs);
4886+
4887+
let mut chan = create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
4888+
4889+
// We check that the channel info nodes have doesn't change too early, even though we try
4890+
// to connect messages with new values
4891+
chan.0.contents.fee_base_msat *= 2;
4892+
chan.1.contents.fee_base_msat *= 2;
4893+
let node_a_chan_info = nodes[0].node.list_channels()[0].clone();
4894+
let node_b_chan_info = nodes[1].node.list_channels()[0].clone();
4895+
4896+
// The first two nodes (which opened a channel) should now require fresh persistence
4897+
assert!(nodes[0].node.await_persistable_update_timeout(Duration::from_millis(1)));
4898+
assert!(nodes[1].node.await_persistable_update_timeout(Duration::from_millis(1)));
4899+
// ... but the last node should not.
4900+
assert!(!nodes[2].node.await_persistable_update_timeout(Duration::from_millis(1)));
4901+
// After persisting the first two nodes they should no longer need fresh persistence.
4902+
assert!(!nodes[0].node.await_persistable_update_timeout(Duration::from_millis(1)));
4903+
assert!(!nodes[1].node.await_persistable_update_timeout(Duration::from_millis(1)));
4904+
4905+
// Node 3, unrelated to the only channel, shouldn't care if it receives a channel_update
4906+
// about the channel.
4907+
nodes[2].node.handle_channel_update(&nodes[1].node.get_our_node_id(), &chan.0);
4908+
nodes[2].node.handle_channel_update(&nodes[1].node.get_our_node_id(), &chan.1);
4909+
assert!(!nodes[2].node.await_persistable_update_timeout(Duration::from_millis(1)));
4910+
4911+
// The nodes which are a party to the channel should also ignore messages from unrelated
4912+
// parties.
4913+
nodes[0].node.handle_channel_update(&nodes[2].node.get_our_node_id(), &chan.0);
4914+
nodes[0].node.handle_channel_update(&nodes[2].node.get_our_node_id(), &chan.1);
4915+
nodes[1].node.handle_channel_update(&nodes[2].node.get_our_node_id(), &chan.0);
4916+
nodes[1].node.handle_channel_update(&nodes[2].node.get_our_node_id(), &chan.1);
4917+
assert!(!nodes[0].node.await_persistable_update_timeout(Duration::from_millis(1)));
4918+
assert!(!nodes[1].node.await_persistable_update_timeout(Duration::from_millis(1)));
4919+
4920+
// At this point the channel info given by peers should still be the same.
4921+
assert_eq!(nodes[0].node.list_channels()[0], node_a_chan_info);
4922+
assert_eq!(nodes[1].node.list_channels()[0], node_b_chan_info);
4923+
}
48744924
}
48754925

48764926
#[cfg(all(any(test, feature = "_test_utils"), feature = "unstable"))]

0 commit comments

Comments
 (0)