From: Arik Sosman Date: Mon, 20 May 2024 06:02:39 +0000 (-0700) Subject: Version-aware serialization of node features and addresses in delta. X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=dcec6006e8662271ff237781525848c209103037;p=rapid-gossip-sync-server Version-aware serialization of node features and addresses in delta. --- diff --git a/src/config.rs b/src/config.rs index f9f4c0f..4950ec0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -22,6 +22,10 @@ pub(crate) const MAX_SNAPSHOT_SCOPE: u32 = 3600 * 24 * 21; // three weeks /// That reminder may be either in the form of a channel announcement, or in the form of empty /// updates in both directions. pub(crate) const CHANNEL_REMINDER_AGE: Duration = Duration::from_secs(6 * 24 * 60 * 60); + +/// Maximum number of default features to calculate for node announcements +pub(crate) const NODE_DEFAULT_FEATURE_COUNT: u8 = 6; + /// The number of successful peer connections to await prior to continuing to gossip storage. /// The application will still work if the number of specified peers is lower, as long as there is /// at least one successful peer connection, but it may result in long startup times. diff --git a/src/lib.rs b/src/lib.rs index 64f0ff2..58fcc76 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,7 +26,7 @@ use crate::config::SYMLINK_GRANULARITY_INTERVAL; use crate::lookup::DeltaSet; use crate::persistence::GossipPersister; -use crate::serialization::UpdateSerialization; +use crate::serialization::{SerializationSet, UpdateSerialization}; use crate::snapshot::Snapshotter; use crate::types::RGSSLogger; @@ -49,7 +49,7 @@ mod tests; /// sync formats arise in the future. /// /// The fourth byte is the protocol version in case our format gets updated. -const GOSSIP_PREFIX: [u8; 4] = [76, 68, 75, 1]; +const GOSSIP_PREFIX: [u8; 3] = [76, 68, 75]; pub struct RapidSyncProcessor where L::Target: Logger { network_graph: Arc>, @@ -59,7 +59,13 @@ pub struct RapidSyncProcessor where L::Target: Logger { pub struct SerializedResponse { pub data: Vec, pub message_count: u32, - pub announcement_count: u32, + pub node_announcement_count: u32, + /// Despite the name, the count of node announcements that have associated updates, be those + /// features, addresses, or both + pub node_update_count: u32, + pub node_feature_update_count: u32, + pub node_address_update_count: u32, + pub channel_announcement_count: u32, pub update_count: u32, pub update_count_full: u32, pub update_count_incremental: u32, @@ -171,18 +177,31 @@ fn serialize_empty_blob(current_timestamp: u64) -> Vec { blob } -async fn serialize_delta(network_graph: Arc>, last_sync_timestamp: u32, snapshot_reference_timestamp: Option, logger: L) -> SerializedResponse where L::Target: Logger { +async fn calculate_delta(network_graph: Arc>, last_sync_timestamp: u32, snapshot_reference_timestamp: Option, logger: L) -> SerializationSet where L::Target: Logger { let client = connect_to_db().await; network_graph.remove_stale_channels_and_tracking(); - let mut output: Vec = vec![]; - let snapshot_interval = config::snapshot_generation_interval(); - // set a flag if the chain hash is prepended // chain hash only necessary if either channel announcements or non-incremental updates are present // for announcement-free incremental-only updates, chain hash can be skipped + let mut delta_set = DeltaSet::new(); + lookup::fetch_channel_announcements(&mut delta_set, network_graph, &client, last_sync_timestamp, snapshot_reference_timestamp, logger.clone()).await; + log_info!(logger, "announcement channel count: {}", delta_set.len()); + lookup::fetch_channel_updates(&mut delta_set, &client, last_sync_timestamp, logger.clone()).await; + log_info!(logger, "update-fetched channel count: {}", delta_set.len()); + let node_delta_set = lookup::fetch_node_updates(&client, last_sync_timestamp, logger.clone()).await; + log_info!(logger, "update-fetched node count: {}", node_delta_set.len()); + lookup::filter_delta_set(&mut delta_set, logger.clone()); + log_info!(logger, "update-filtered channel count: {}", delta_set.len()); + serialization::serialize_delta_set(delta_set, node_delta_set, last_sync_timestamp) +} + +fn serialize_delta(serialization_details: &SerializationSet, serialization_version: u8, logger: L) -> SerializedResponse where L::Target: Logger { + let mut output: Vec = vec![]; + let snapshot_interval = config::snapshot_generation_interval(); + let mut node_id_set: HashSet = HashSet::new(); let mut node_id_indices: HashMap = HashMap::new(); let mut node_ids: Vec = Vec::new(); @@ -199,21 +218,12 @@ async fn serialize_delta(network_graph: Arc>, node_id_indices[&node_id] }; - let mut delta_set = DeltaSet::new(); - lookup::fetch_channel_announcements(&mut delta_set, network_graph, &client, last_sync_timestamp, snapshot_reference_timestamp, logger.clone()).await; - log_info!(logger, "announcement channel count: {}", delta_set.len()); - lookup::fetch_channel_updates(&mut delta_set, &client, last_sync_timestamp, logger.clone()).await; - log_info!(logger, "update-fetched channel count: {}", delta_set.len()); - lookup::filter_delta_set(&mut delta_set, logger.clone()); - log_info!(logger, "update-filtered channel count: {}", delta_set.len()); - let serialization_details = serialization::serialize_delta_set(delta_set, last_sync_timestamp); - // process announcements // write the number of channel announcements to the output let announcement_count = serialization_details.announcements.len() as u32; announcement_count.write(&mut output).unwrap(); let mut previous_announcement_scid = 0; - for current_announcement in serialization_details.announcements { + for current_announcement in &serialization_details.announcements { let id_index_1 = get_node_id_index(current_announcement.node_id_1); let id_index_2 = get_node_id_index(current_announcement.node_id_2); let mut stripped_announcement = serialization::serialize_stripped_channel_announcement(¤t_announcement, id_index_1, id_index_2, previous_announcement_scid); @@ -227,7 +237,7 @@ async fn serialize_delta(network_graph: Arc>, let update_count = serialization_details.updates.len() as u32; update_count.write(&mut output).unwrap(); - let default_update_values = serialization_details.full_update_defaults; + let default_update_values = &serialization_details.full_update_defaults; if update_count > 0 { default_update_values.cltv_expiry_delta.write(&mut output).unwrap(); default_update_values.htlc_minimum_msat.write(&mut output).unwrap(); @@ -238,7 +248,7 @@ async fn serialize_delta(network_graph: Arc>, let mut update_count_full = 0; let mut update_count_incremental = 0; - for current_update in serialization_details.updates { + for current_update in &serialization_details.updates { match ¤t_update { UpdateSerialization::Full(_) => { update_count_full += 1; @@ -258,6 +268,7 @@ async fn serialize_delta(network_graph: Arc>, let message_count = announcement_count + update_count; let mut prefixed_output = GOSSIP_PREFIX.to_vec(); + prefixed_output.push(serialization_version); // always write the chain hash serialization_details.chain_hash.write(&mut prefixed_output).unwrap(); @@ -267,11 +278,97 @@ async fn serialize_delta(network_graph: Arc>, let serialized_seen_timestamp = latest_seen_timestamp.saturating_sub(overflow_seconds); serialized_seen_timestamp.write(&mut prefixed_output).unwrap(); + if serialization_version >= 2 { // serialize the most common node features + for mutated_node_id in serialization_details.node_mutations.keys() { + // consider mutated nodes outside channel announcements + get_node_id_index(mutated_node_id.clone()); + } + + let default_feature_count = serialization_details.node_announcement_feature_defaults.len() as u8; + debug_assert!(default_feature_count <= config::NODE_DEFAULT_FEATURE_COUNT, "Default feature count cannot exceed maximum"); + default_feature_count.write(&mut prefixed_output).unwrap(); + + for current_feature in &serialization_details.node_announcement_feature_defaults { + current_feature.write(&mut prefixed_output).unwrap(); + } + } + let node_id_count = node_ids.len() as u32; node_id_count.write(&mut prefixed_output).unwrap(); + let mut node_update_count = 0u32; + let mut node_feature_update_count = 0u32; + let mut node_address_update_count = 0u32; + for current_node_id in node_ids { - current_node_id.write(&mut prefixed_output).unwrap(); + let mut current_node_delta_serialization: Vec = Vec::new(); + current_node_id.write(&mut current_node_delta_serialization).unwrap(); + + if serialization_version >= 2 { + if let Some(node_delta) = serialization_details.node_mutations.get(¤t_node_id) { + /* + Bitmap: + 7: expect extra data after the pubkey (a u16 for the count, and then that number of bytes) + 5-3: index of new features among default (1-6). If index is 7 (all 3 bits are set, it's + outside the present default range). 0 means no feature changes. + 2: addresses have changed + + 1: used for all keys + 0: used for odd keys + */ + + if node_delta.has_address_set_changed { + node_address_update_count += 1; + + let address_set = &node_delta.latest_details_after_seen.as_ref().unwrap().addresses; + let mut address_serialization = Vec::new(); + + // we don't know a priori how many are <= 255 bytes + let mut total_address_count = 0u8; + + for address in address_set.iter() { + if total_address_count == u8::MAX { + // don't serialize more than 255 addresses + break; + } + if let Ok(serialized_length) = u8::try_from(address.serialized_length()) { + total_address_count += 1; + serialized_length.write(&mut address_serialization).unwrap(); + address.write(&mut address_serialization).unwrap(); + }; + } + + if total_address_count > 0 { + // signal the presence of node addresses + current_node_delta_serialization[0] |= 1 << 2; + // serialize the actual addresses and count + total_address_count.write(&mut current_node_delta_serialization).unwrap(); + current_node_delta_serialization.append(&mut address_serialization); + } + } + + if node_delta.has_feature_set_changed { + node_feature_update_count += 1; + + let latest_features = &node_delta.latest_details_after_seen.as_ref().unwrap().features; + + // are these features among the most common ones? + if let Some(index) = serialization_details.node_announcement_feature_defaults.iter().position(|f| f == latest_features) { + // this feature set is among the 6 defaults + current_node_delta_serialization[0] |= ((index + 1) as u8) << 3; + } else { + current_node_delta_serialization[0] |= 0b_0011_1000; // 7 << 3 + latest_features.write(&mut current_node_delta_serialization).unwrap(); + } + } + + if node_delta.has_address_set_changed || node_delta.has_feature_set_changed { + node_update_count += 1; + } + } + } + + prefixed_output.append(&mut current_node_delta_serialization); } prefixed_output.append(&mut output); @@ -282,7 +379,11 @@ async fn serialize_delta(network_graph: Arc>, SerializedResponse { data: prefixed_output, message_count, - announcement_count, + node_announcement_count: node_id_count, + node_update_count, + node_feature_update_count, + node_address_update_count, + channel_announcement_count: announcement_count, update_count, update_count_full, update_count_incremental, diff --git a/src/serialization.rs b/src/serialization.rs index b9306d8..5f11b27 100644 --- a/src/serialization.rs +++ b/src/serialization.rs @@ -4,16 +4,19 @@ use std::time::{SystemTime, UNIX_EPOCH}; use bitcoin::Network; use bitcoin::blockdata::constants::ChainHash; +use lightning::ln::features::NodeFeatures; use lightning::ln::msgs::{UnsignedChannelAnnouncement, UnsignedChannelUpdate}; use lightning::util::ser::{BigSize, Writeable}; use crate::config; -use crate::lookup::{DeltaSet, DirectedUpdateDelta}; +use crate::lookup::{DeltaSet, DirectedUpdateDelta, NodeDeltaSet}; pub(super) struct SerializationSet { pub(super) announcements: Vec, pub(super) updates: Vec, pub(super) full_update_defaults: DefaultUpdateValues, + pub(super) node_announcement_feature_defaults: Vec, + pub(super) node_mutations: NodeDeltaSet, pub(super) latest_seen: u32, pub(super) chain_hash: ChainHash, } @@ -104,11 +107,13 @@ struct FullUpdateValueHistograms { htlc_maximum_msat: HashMap, } -pub(super) fn serialize_delta_set(delta_set: DeltaSet, last_sync_timestamp: u32) -> SerializationSet { +pub(super) fn serialize_delta_set(channel_delta_set: DeltaSet, node_delta_set: NodeDeltaSet, last_sync_timestamp: u32) -> SerializationSet { let mut serialization_set = SerializationSet { announcements: vec![], updates: vec![], full_update_defaults: Default::default(), + node_announcement_feature_defaults: vec![], + node_mutations: Default::default(), chain_hash: ChainHash::using_genesis_block(Network::Bitcoin), latest_seen: 0, }; @@ -134,7 +139,7 @@ pub(super) fn serialize_delta_set(delta_set: DeltaSet, last_sync_timestamp: u32) // if the previous seen update happened more than 6 days ago, the client may have pruned it, and an incremental update wouldn't work let non_incremental_previous_update_threshold_timestamp = SystemTime::now().checked_sub(config::CHANNEL_REMINDER_AGE).unwrap().duration_since(UNIX_EPOCH).unwrap().as_secs() as u32; - for (scid, channel_delta) in delta_set.into_iter() { + for (scid, channel_delta) in channel_delta_set.into_iter() { // any announcement chain hash is gonna be the same value. Just set it from the first one. let channel_announcement_delta = channel_delta.announcement.as_ref().unwrap(); @@ -214,6 +219,22 @@ pub(super) fn serialize_delta_set(delta_set: DeltaSet, last_sync_timestamp: u32) }; serialization_set.full_update_defaults = default_update_values; + + serialization_set.node_mutations = node_delta_set.into_iter().filter(|(_id, delta)| { + // either something changed, or this node is new + delta.has_feature_set_changed || delta.has_address_set_changed || delta.last_details_before_seen.is_none() + }).collect(); + + let mut node_feature_histogram: HashMap<&NodeFeatures, usize> = Default::default(); + for (_id, delta) in serialization_set.node_mutations.iter() { + if delta.has_feature_set_changed || delta.last_details_before_seen.is_none() { + if let Some(latest_details) = delta.latest_details_after_seen.as_ref() { + *node_feature_histogram.entry(&latest_details.features).or_insert(0) += 1; + }; + } + } + serialization_set.node_announcement_feature_defaults = find_leading_histogram_entries(node_feature_histogram, config::NODE_DEFAULT_FEATURE_COUNT as usize); + serialization_set } @@ -327,3 +348,9 @@ pub(super) fn find_most_common_histogram_entry_with_default(histogram: // though for htlc maximum msat it could be a u64::max default } + +pub(super) fn find_leading_histogram_entries(histogram: HashMap<&NodeFeatures, usize>, count: usize) -> Vec { + let mut entry_counts: Vec<_> = histogram.iter().filter(|&(_, &count)| count > 1).collect(); + entry_counts.sort_by(|a, b| b.1.cmp(&a.1)); + entry_counts.into_iter().take(count).map(|(&features, _count)| features.clone()).collect() +} diff --git a/src/snapshot.rs b/src/snapshot.rs index c5154c7..ee12080 100644 --- a/src/snapshot.rs +++ b/src/snapshot.rs @@ -114,12 +114,13 @@ impl Snapshotter where L::Target: Logger { { log_info!(self.logger, "Calculating {}-second snapshot", current_scope); // calculate the snapshot - let snapshot = super::serialize_delta(network_graph_clone, current_last_sync_timestamp.clone() as u32, Some(reference_timestamp), self.logger.clone()).await; + let delta = super::calculate_delta(network_graph_clone.clone(), current_last_sync_timestamp.clone() as u32, Some(reference_timestamp), self.logger.clone()).await; + let snapshot = super::serialize_delta(&delta, 1, self.logger.clone()); // persist the snapshot and update the symlink let snapshot_filename = format!("snapshot__calculated-at:{}__range:{}-scope__previous-sync:{}.lngossip", reference_timestamp, current_scope, current_last_sync_timestamp); let snapshot_path = format!("{}/{}", pending_snapshot_directory, snapshot_filename); - log_info!(self.logger, "Persisting {}-second snapshot: {} ({} messages, {} announcements, {} updates ({} full, {} incremental))", current_scope, snapshot_filename, snapshot.message_count, snapshot.announcement_count, snapshot.update_count, snapshot.update_count_full, snapshot.update_count_incremental); + log_info!(self.logger, "Persisting {}-second snapshot: {} ({} messages, {} announcements, {} updates ({} full, {} incremental))", current_scope, snapshot_filename, snapshot.message_count, snapshot.channel_announcement_count, snapshot.update_count, snapshot.update_count_full, snapshot.update_count_incremental); fs::write(&snapshot_path, snapshot.data).unwrap(); snapshot_filenames_by_scope.insert(current_scope.clone(), snapshot_filename); } diff --git a/src/tests/mod.rs b/src/tests/mod.rs index b967608..bf5cd4a 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -16,7 +16,7 @@ use lightning::ln::msgs::{ChannelAnnouncement, ChannelUpdate, NodeAnnouncement, use lightning::routing::gossip::{NetworkGraph, NodeAlias, NodeId}; use lightning::util::ser::Writeable; use lightning_rapid_gossip_sync::RapidGossipSync; -use crate::{config, serialize_delta}; +use crate::{calculate_delta, config, serialize_delta}; use crate::persistence::GossipPersister; use crate::snapshot::Snapshotter; use crate::types::{GossipMessage, tests::TestLogger}; @@ -248,7 +248,8 @@ async fn test_trivial_setup() { persister.persist_gossip().await; } - let serialization = serialize_delta(network_graph_arc.clone(), 0, None, logger.clone()).await; + let delta = calculate_delta(network_graph_arc.clone(), 0, None, logger.clone()).await; + let serialization = serialize_delta(&delta, 1, logger.clone()); logger.assert_log_contains("rapid_gossip_sync_server", "announcement channel count: 1", 1); clean_test_db().await; @@ -256,7 +257,7 @@ async fn test_trivial_setup() { assert_eq!(channel_count, 1); assert_eq!(serialization.message_count, 3); - assert_eq!(serialization.announcement_count, 1); + assert_eq!(serialization.channel_announcement_count, 1); assert_eq!(serialization.update_count, 2); let client_graph = NetworkGraph::new(Network::Bitcoin, logger.clone()); @@ -334,6 +335,84 @@ async fn test_node_announcement_persistence() { clean_test_db().await; } +#[tokio::test] +async fn test_node_announcement_delta_detection() { + let _sanitizer = SchemaSanitizer::new(); + let logger = Arc::new(TestLogger::new()); + let network_graph = NetworkGraph::new(Network::Bitcoin, logger.clone()); + let network_graph_arc = Arc::new(network_graph); + let (mut persister, receiver) = GossipPersister::new(network_graph_arc.clone(), logger.clone()); + + let timestamp = current_time() - 10; + + { // seed the db + let mut announcement = generate_node_announcement(None); + receiver.send(GossipMessage::NodeAnnouncement(announcement.clone(), Some(timestamp - 10))).await.unwrap(); + receiver.send(GossipMessage::NodeAnnouncement(announcement.clone(), Some(timestamp - 8))).await.unwrap(); + + { + let mut current_announcement = generate_node_announcement(Some(SecretKey::from_slice(&[2; 32]).unwrap())); + current_announcement.contents.features = NodeFeatures::from_be_bytes(vec![23, 48]); + receiver.send(GossipMessage::NodeAnnouncement(current_announcement, Some(timestamp))).await.unwrap(); + } + + { + let mut current_announcement = generate_node_announcement(Some(SecretKey::from_slice(&[3; 32]).unwrap())); + current_announcement.contents.features = NodeFeatures::from_be_bytes(vec![22, 49]); + receiver.send(GossipMessage::NodeAnnouncement(current_announcement, Some(timestamp))).await.unwrap(); + } + + { + // modify announcement to contain a bunch of addresses + announcement.contents.addresses.push(SocketAddress::Hostname { + hostname: "google.com".to_string().try_into().unwrap(), + port: 443, + }); + announcement.contents.features = NodeFeatures::from_be_bytes(vec![23, 48]); + announcement.contents.addresses.push(SocketAddress::TcpIpV4 { addr: [127, 0, 0, 1], port: 9635 }); + announcement.contents.addresses.push(SocketAddress::TcpIpV6 { addr: [1; 16], port: 1337 }); + announcement.contents.addresses.push(SocketAddress::OnionV2([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12])); + announcement.contents.addresses.push(SocketAddress::OnionV3 { + ed25519_pubkey: [1; 32], + checksum: 2, + version: 3, + port: 4, + }); + } + receiver.send(GossipMessage::NodeAnnouncement(announcement, Some(timestamp))).await.unwrap(); + + { // necessary for the node announcements to be considered relevant + let announcement = generate_channel_announcement(1); + let update_1 = generate_update(1, false, timestamp, 0, 0, 0, 6, 0); + let update_2 = generate_update(1, true, timestamp, 0, 0, 0, 6, 0); + + network_graph_arc.update_channel_from_announcement_no_lookup(&announcement).unwrap(); + network_graph_arc.update_channel_unsigned(&update_1.contents).unwrap(); + network_graph_arc.update_channel_unsigned(&update_2.contents).unwrap(); + + receiver.send(GossipMessage::ChannelAnnouncement(announcement, Some(timestamp))).await.unwrap(); + receiver.send(GossipMessage::ChannelUpdate(update_1, Some(timestamp))).await.unwrap(); + receiver.send(GossipMessage::ChannelUpdate(update_2, Some(timestamp))).await.unwrap(); + } + + drop(receiver); + persister.persist_gossip().await; + + tokio::task::spawn_blocking(move || { + drop(persister); + }).await.unwrap(); + } + + let delta = calculate_delta(network_graph_arc.clone(), timestamp - 5, None, logger.clone()).await; + let serialization = serialize_delta(&delta, 2, logger.clone()); + clean_test_db().await; + + assert_eq!(serialization.message_count, 3); + assert_eq!(serialization.node_announcement_count, 3); + assert_eq!(serialization.node_update_count, 1); + assert_eq!(serialization.node_feature_update_count, 1); + assert_eq!(serialization.node_address_update_count, 1); +} /// If a channel has only seen updates in one direction, it should not be announced #[tokio::test] @@ -375,14 +454,15 @@ async fn test_unidirectional_intermediate_update_consideration() { let client_graph_arc = Arc::new(client_graph); let rgs = RapidGossipSync::new(client_graph_arc.clone(), logger.clone()); - let serialization = serialize_delta(network_graph_arc.clone(), timestamp + 1, None, logger.clone()).await; + let delta = calculate_delta(network_graph_arc.clone(), timestamp + 1, None, logger.clone()).await; + let serialization = serialize_delta(&delta, 1, logger.clone()); logger.assert_log_contains("rapid_gossip_sync_server::lookup", "Fetched 1 update rows of the first update in a new direction", 1); logger.assert_log_contains("rapid_gossip_sync_server::lookup", "Processed 1 reference rows", 1); logger.assert_log_contains("rapid_gossip_sync_server::lookup", "Processed intermediate rows (2)", 1); assert_eq!(serialization.message_count, 3); - assert_eq!(serialization.announcement_count, 1); + assert_eq!(serialization.channel_announcement_count, 1); assert_eq!(serialization.update_count, 2); assert_eq!(serialization.update_count_full, 2); assert_eq!(serialization.update_count_incremental, 0); @@ -442,14 +522,15 @@ async fn test_bidirectional_intermediate_update_consideration() { let channel_count = network_graph_arc.read_only().channels().len(); assert_eq!(channel_count, 1); - let serialization = serialize_delta(network_graph_arc.clone(), timestamp + 1, None, logger.clone()).await; + let delta = calculate_delta(network_graph_arc.clone(), timestamp + 1, None, logger.clone()).await; + let serialization = serialize_delta(&delta, 1, logger.clone()); logger.assert_log_contains("rapid_gossip_sync_server::lookup", "Fetched 0 update rows of the first update in a new direction", 1); logger.assert_log_contains("rapid_gossip_sync_server::lookup", "Processed 2 reference rows", 1); logger.assert_log_contains("rapid_gossip_sync_server::lookup", "Processed intermediate rows (2)", 1); assert_eq!(serialization.message_count, 1); - assert_eq!(serialization.announcement_count, 0); + assert_eq!(serialization.channel_announcement_count, 0); assert_eq!(serialization.update_count, 1); assert_eq!(serialization.update_count_full, 0); assert_eq!(serialization.update_count_incremental, 1); @@ -525,7 +606,8 @@ async fn test_channel_reminders() { let channel_count = network_graph_arc.read_only().channels().len(); assert_eq!(channel_count, 2); - let serialization = serialize_delta(network_graph_arc.clone(), timestamp - channel_reminder_delta + 15, None, logger.clone()).await; + let delta = calculate_delta(network_graph_arc.clone(), timestamp - channel_reminder_delta + 15, None, logger.clone()).await; + let serialization = serialize_delta(&delta, 1, logger.clone()); logger.assert_log_contains("rapid_gossip_sync_server::lookup", "Fetched 0 update rows of the first update in a new direction", 1); logger.assert_log_contains("rapid_gossip_sync_server::lookup", "Fetched 4 update rows of the latest update in the less recently updated direction", 1); @@ -533,7 +615,7 @@ async fn test_channel_reminders() { logger.assert_log_contains("rapid_gossip_sync_server::lookup", "Processed intermediate rows (2)", 1); assert_eq!(serialization.message_count, 4); - assert_eq!(serialization.announcement_count, 0); + assert_eq!(serialization.channel_announcement_count, 0); assert_eq!(serialization.update_count, 4); assert_eq!(serialization.update_count_full, 0); assert_eq!(serialization.update_count_incremental, 4); @@ -594,14 +676,15 @@ async fn test_full_snapshot_recency() { let client_graph_arc = Arc::new(client_graph); { // sync after initial seed - let serialization = serialize_delta(network_graph_arc.clone(), 0, None, logger.clone()).await; + let delta = calculate_delta(network_graph_arc.clone(), 0, None, logger.clone()).await; + let serialization = serialize_delta(&delta, 1, logger.clone()); logger.assert_log_contains("rapid_gossip_sync_server", "announcement channel count: 1", 1); let channel_count = network_graph_arc.read_only().channels().len(); assert_eq!(channel_count, 1); assert_eq!(serialization.message_count, 3); - assert_eq!(serialization.announcement_count, 1); + assert_eq!(serialization.channel_announcement_count, 1); assert_eq!(serialization.update_count, 2); let rgs = RapidGossipSync::new(client_graph_arc.clone(), logger.clone()); @@ -674,14 +757,15 @@ async fn test_full_snapshot_recency_with_wrong_seen_order() { let client_graph_arc = Arc::new(client_graph); { // sync after initial seed - let serialization = serialize_delta(network_graph_arc.clone(), 0, None, logger.clone()).await; + let delta = calculate_delta(network_graph_arc.clone(), 0, None, logger.clone()).await; + let serialization = serialize_delta(&delta, 1, logger.clone()); logger.assert_log_contains("rapid_gossip_sync_server", "announcement channel count: 1", 1); let channel_count = network_graph_arc.read_only().channels().len(); assert_eq!(channel_count, 1); assert_eq!(serialization.message_count, 3); - assert_eq!(serialization.announcement_count, 1); + assert_eq!(serialization.channel_announcement_count, 1); assert_eq!(serialization.update_count, 2); let rgs = RapidGossipSync::new(client_graph_arc.clone(), logger.clone()); @@ -753,14 +837,15 @@ async fn test_full_snapshot_recency_with_wrong_propagation_order() { let client_graph_arc = Arc::new(client_graph); { // sync after initial seed - let serialization = serialize_delta(network_graph_arc.clone(), 0, None, logger.clone()).await; + let delta = calculate_delta(network_graph_arc.clone(), 0, None, logger.clone()).await; + let serialization = serialize_delta(&delta, 1, logger.clone()); logger.assert_log_contains("rapid_gossip_sync_server", "announcement channel count: 1", 1); let channel_count = network_graph_arc.read_only().channels().len(); assert_eq!(channel_count, 1); assert_eq!(serialization.message_count, 3); - assert_eq!(serialization.announcement_count, 1); + assert_eq!(serialization.channel_announcement_count, 1); assert_eq!(serialization.update_count, 2); let rgs = RapidGossipSync::new(client_graph_arc.clone(), logger.clone()); @@ -886,14 +971,15 @@ async fn test_full_snapshot_mutiny_scenario() { let client_graph_arc = Arc::new(client_graph); { // sync after initial seed - let serialization = serialize_delta(network_graph_arc.clone(), 0, None, logger.clone()).await; + let delta = calculate_delta(network_graph_arc.clone(), 0, None, logger.clone()).await; + let serialization = serialize_delta(&delta, 1, logger.clone()); logger.assert_log_contains("rapid_gossip_sync_server", "announcement channel count: 1", 1); let channel_count = network_graph_arc.read_only().channels().len(); assert_eq!(channel_count, 1); assert_eq!(serialization.message_count, 3); - assert_eq!(serialization.announcement_count, 1); + assert_eq!(serialization.channel_announcement_count, 1); assert_eq!(serialization.update_count, 2); let rgs = RapidGossipSync::new(client_graph_arc.clone(), logger.clone()); @@ -999,14 +1085,15 @@ async fn test_full_snapshot_interlaced_channel_timestamps() { let client_graph_arc = Arc::new(client_graph); { // sync after initial seed - let serialization = serialize_delta(network_graph_arc.clone(), 0, None, logger.clone()).await; + let delta = calculate_delta(network_graph_arc.clone(), 0, None, logger.clone()).await; + let serialization = serialize_delta(&delta, 1, logger.clone()); logger.assert_log_contains("rapid_gossip_sync_server", "announcement channel count: 2", 1); let channel_count = network_graph_arc.read_only().channels().len(); assert_eq!(channel_count, 2); assert_eq!(serialization.message_count, 6); - assert_eq!(serialization.announcement_count, 2); + assert_eq!(serialization.channel_announcement_count, 2); assert_eq!(serialization.update_count, 4); let rgs = RapidGossipSync::new(client_graph_arc.clone(), logger.clone());