use crate::util::logger::{Logger, Level};
use crate::util::events::{Event, EventHandler, MessageSendEvent, MessageSendEventsProvider};
use crate::util::scid_utils::{block_from_scid, scid_from_parts, MAX_SCID_BLOCK};
+use crate::util::string::PrintableString;
use crate::io;
use crate::io_extras::{copy, sink};
impl fmt::Display for NodeAlias {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
- let control_symbol = core::char::REPLACEMENT_CHARACTER;
let first_null = self.0.iter().position(|b| *b == 0).unwrap_or(self.0.len());
let bytes = self.0.split_at(first_null).0;
match core::str::from_utf8(bytes) {
- Ok(alias) => {
- for c in alias.chars() {
- let mut bytes = [0u8; 4];
- let c = if !c.is_control() { c } else { control_symbol };
- f.write_str(c.encode_utf8(&mut bytes))?;
- }
- },
+ Ok(alias) => PrintableString(alias).fmt(f)?,
Err(_) => {
+ use core::fmt::Write;
for c in bytes.iter().map(|b| *b as char) {
// Display printable ASCII characters
- let mut bytes = [0u8; 4];
+ let control_symbol = core::char::REPLACEMENT_CHARACTER;
let c = if c >= '\x20' && c <= '\x7e' { c } else { control_symbol };
- f.write_str(c.encode_utf8(&mut bytes))?;
+ f.write_char(c)?;
}
},
};
for scid in scids_to_remove {
let info = channels.remove(&scid).expect("We just accessed this scid, it should be present");
Self::remove_channel_in_nodes(&mut nodes, &info, scid);
+ self.removed_channels.lock().unwrap().insert(scid, Some(current_time_unix));
}
}
assert_eq!(network_graph.read_only().nodes().len(), 2);
network_graph.remove_stale_channels_and_tracking_with_time(101 + STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS);
+ #[cfg(not(feature = "std"))] {
+ // Make sure removed channels are tracked.
+ assert_eq!(network_graph.removed_channels.lock().unwrap().len(), 1);
+ }
+ network_graph.remove_stale_channels_and_tracking_with_time(101 + STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS +
+ REMOVED_ENTRIES_TRACKING_AGE_LIMIT_SECS);
+
#[cfg(feature = "std")]
{
// In std mode, a further check is performed before fully removing the channel -
assert!(gossip_sync.handle_channel_update(&valid_channel_update).is_ok());
assert!(network_graph.read_only().channels().get(&short_channel_id).unwrap().one_to_two.is_some());
network_graph.remove_stale_channels_and_tracking_with_time(announcement_time + 1 + STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS);
+ // Make sure removed channels are tracked.
+ assert_eq!(network_graph.removed_channels.lock().unwrap().len(), 1);
+ // Provide a later time so that sufficient time has passed
+ network_graph.remove_stale_channels_and_tracking_with_time(announcement_time + 1 + STALE_CHANNEL_UPDATE_AGE_LIMIT_SECS +
+ REMOVED_ENTRIES_TRACKING_AGE_LIMIT_SECS);
}
assert_eq!(network_graph.read_only().channels().len(), 0);
assert_eq!(network_graph.read_only().nodes().len(), 0);
+ assert!(network_graph.removed_channels.lock().unwrap().is_empty());
#[cfg(feature = "std")]
{