File tree Expand file tree Collapse file tree 3 files changed +19
-5
lines changed Expand file tree Collapse file tree 3 files changed +19
-5
lines changed Original file line number Diff line number Diff line change @@ -352,6 +352,12 @@ where
352352 } ;
353353 self . with_peer_state ( * counterparty_node_id, handle_response) ;
354354
355+ self . check_and_remove_empty_peer_state ( counterparty_node_id) ;
356+
357+ result
358+ }
359+
360+ fn check_and_remove_empty_peer_state ( & self , counterparty_node_id : & PublicKey ) {
355361 let mut outer_state_lock = self . per_peer_state . write ( ) . unwrap ( ) ;
356362 let should_remove =
357363 if let Some ( peer_state_mutex) = outer_state_lock. get ( counterparty_node_id) {
@@ -364,7 +370,6 @@ where
364370 if should_remove {
365371 outer_state_lock. remove ( counterparty_node_id) ;
366372 }
367- result
368373 }
369374}
370375
Original file line number Diff line number Diff line change @@ -31,13 +31,14 @@ where
3131 }
3232
3333 self . map . insert ( key. clone ( ) , value) ;
34- self . order . push_back ( key. clone ( ) ) ;
34+ self . order . push_back ( key) ;
3535
3636 if self . order . len ( ) > self . cap {
3737 if let Some ( oldest) = self . order . pop_front ( ) {
3838 self . map . remove ( & oldest) ;
3939 }
4040 }
41+ self . check_invariants ( ) ;
4142 }
4243
4344 /// Remove a key (if present) and return its value.
4647 if val. is_some ( ) {
4748 self . order . retain ( |k| k != key) ;
4849 }
50+ self . check_invariants ( ) ;
4951 val
5052 }
5153
54+ fn check_invariants ( & self ) {
55+ debug_assert ! ( self . map. len( ) <= self . cap) ;
56+ debug_assert ! ( self . order. len( ) <= self . cap) ;
57+ debug_assert ! ( self . map. len( ) == self . order. len( ) ) ;
58+ }
59+
5260 /// Get a reference to the value associated with `key`.
5361 #[ cfg( test) ]
5462 pub ( crate ) fn get ( & self , key : & K ) -> Option < & V > {
Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ use lightning::sign::EntropySource;
77
88use crate :: lsps0:: ser:: LSPSRequestId ;
99
10+ pub ( crate ) mod bounded_map;
11+
12+ pub mod time;
13+
1014/// Converts a human-readable string representation of a short channel ID (SCID)
1115pub fn scid_from_human_readable_string ( human_readable_scid : & str ) -> Result < u64 , ( ) > {
1216 let mut parts = human_readable_scid. split ( 'x' ) ;
@@ -56,6 +60,3 @@ mod tests {
5660 assert_eq ! ( vout_from_scid( scid) , vout) ;
5761 }
5862}
59-
60- pub ( crate ) mod bounded_map;
61- pub mod time;
You can’t perform that action at this time.
0 commit comments