@@ -632,7 +632,7 @@ const CHECK_CLTV_EXPIRY_SANITY: u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRA
632
632
const CHECK_CLTV_EXPIRY_SANITY_2 : u32 = MIN_CLTV_EXPIRY_DELTA as u32 - LATENCY_GRACE_PERIOD_BLOCKS - 2 * CLTV_CLAIM_BUFFER ;
633
633
634
634
/// Details of a channel, as returned by ChannelManager::list_channels and ChannelManager::list_usable_channels
635
- #[ derive( Clone ) ]
635
+ #[ derive( Clone , Debug , PartialEq ) ]
636
636
pub struct ChannelDetails {
637
637
/// The channel's ID (prior to funding transaction generation, this is a random 32 bytes,
638
638
/// thereafter this is the txid of the funding transaction xor the funding transaction output).
@@ -3346,14 +3346,15 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3346
3346
Ok ( ( ) )
3347
3347
}
3348
3348
3349
- fn internal_channel_update ( & self , counterparty_node_id : & PublicKey , msg : & msgs:: ChannelUpdate ) -> Result < ( ) , MsgHandleErrInternal > {
3349
+ /// Returns ShouldPersist if anything changed, otherwise either SkipPersist or an Err.
3350
+ fn internal_channel_update ( & self , counterparty_node_id : & PublicKey , msg : & msgs:: ChannelUpdate ) -> Result < NotifyOption , MsgHandleErrInternal > {
3350
3351
let mut channel_state_lock = self . channel_state . lock ( ) . unwrap ( ) ;
3351
3352
let channel_state = & mut * channel_state_lock;
3352
3353
let chan_id = match channel_state. short_to_id . get ( & msg. contents . short_channel_id ) {
3353
3354
Some ( chan_id) => chan_id. clone ( ) ,
3354
3355
None => {
3355
3356
// It's not a local channel
3356
- return Ok ( ( ) )
3357
+ return Ok ( NotifyOption :: SkipPersist )
3357
3358
}
3358
3359
} ;
3359
3360
match channel_state. by_id . entry ( chan_id) {
@@ -3363,15 +3364,15 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
3363
3364
// If the announcement is about a channel of ours which is public, some
3364
3365
// other peer may simply be forwarding all its gossip to us. Don't provide
3365
3366
// a scary-looking error message and return Ok instead.
3366
- return Ok ( ( ) ) ;
3367
+ return Ok ( NotifyOption :: SkipPersist ) ;
3367
3368
}
3368
3369
return Err ( MsgHandleErrInternal :: send_err_msg_no_close ( "Got a channel_update for a channel from the wrong node - it shouldn't know about our private channels!" . to_owned ( ) , chan_id) ) ;
3369
3370
}
3370
3371
try_chan_entry ! ( self , chan. get_mut( ) . channel_update( & msg) , channel_state, chan) ;
3371
3372
} ,
3372
3373
hash_map:: Entry :: Vacant ( _) => unreachable ! ( )
3373
3374
}
3374
- Ok ( ( ) )
3375
+ Ok ( NotifyOption :: DoPersist )
3375
3376
}
3376
3377
3377
3378
fn internal_channel_reestablish ( & self , counterparty_node_id : & PublicKey , msg : & msgs:: ChannelReestablish ) -> Result < ( ) , MsgHandleErrInternal > {
@@ -4116,8 +4117,13 @@ impl<Signer: Sign, M: Deref , T: Deref , K: Deref , F: Deref , L: Deref >
4116
4117
}
4117
4118
4118
4119
fn handle_channel_update ( & self , counterparty_node_id : & PublicKey , msg : & msgs:: ChannelUpdate ) {
4119
- let _persistence_guard = PersistenceNotifierGuard :: notify_on_drop ( & self . total_consistency_lock , & self . persistence_notifier ) ;
4120
- let _ = handle_error ! ( self , self . internal_channel_update( counterparty_node_id, msg) , * counterparty_node_id) ;
4120
+ PersistenceNotifierGuard :: optionally_notify ( & self . total_consistency_lock , & self . persistence_notifier , || {
4121
+ if let Ok ( persist) = handle_error ! ( self , self . internal_channel_update( counterparty_node_id, msg) , * counterparty_node_id) {
4122
+ persist
4123
+ } else {
4124
+ NotifyOption :: SkipPersist
4125
+ }
4126
+ } ) ;
4121
4127
}
4122
4128
4123
4129
fn handle_channel_reestablish ( & self , counterparty_node_id : & PublicKey , msg : & msgs:: ChannelReestablish ) {
@@ -4823,6 +4829,9 @@ mod tests {
4823
4829
use core:: sync:: atomic:: { AtomicBool , Ordering } ;
4824
4830
use std:: thread;
4825
4831
use core:: time:: Duration ;
4832
+ use ln:: functional_test_utils:: * ;
4833
+ use ln:: features:: InitFeatures ;
4834
+ use ln:: msgs:: ChannelMessageHandler ;
4826
4835
4827
4836
#[ test]
4828
4837
fn test_wait_timeout ( ) {
@@ -4865,6 +4874,53 @@ mod tests {
4865
4874
}
4866
4875
}
4867
4876
}
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
+ }
4868
4924
}
4869
4925
4870
4926
#[ cfg( all( any( test, feature = "_test_utils" ) , feature = "unstable" ) ) ]
0 commit comments