diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e3ad979f..725c32e6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,9 +33,11 @@ jobs: - name: Pin dependencies if: ${{ matrix.toolchain == '1.63.0' }} run: | - cargo update -p tokio --precise "1.37.0" --verbose - cargo update -p tokio-macros --precise "2.2.0" --verbose + cargo update -p tokio --precise "1.38.1" --verbose cargo update -p postgres-types --precise "0.2.6" --verbose + cargo update -p parking_lot@0.12.4 --precise "0.12.3" --verbose + cargo update -p parking_lot_core@0.9.11 --precise "0.9.10" --verbose + cargo update -p lock_api --precise "0.4.12" --verbose - name: Build on Rust ${{ matrix.toolchain }} run: | cargo build --verbose --color always diff --git a/src/lib.rs b/src/lib.rs index 1adfdc4d..f794044d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -248,10 +248,10 @@ fn serialize_delta(serialization_details: &SerializationSet, s 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, funding_sats) 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); + let mut stripped_announcement = serialization::serialize_stripped_channel_announcement(¤t_announcement, *funding_sats, id_index_1, id_index_2, previous_announcement_scid, serialization_version); output.append(&mut stripped_announcement); previous_announcement_scid = current_announcement.short_channel_id; diff --git a/src/lookup.rs b/src/lookup.rs index 48e68895..39c17df8 100644 --- a/src/lookup.rs +++ b/src/lookup.rs @@ -27,6 +27,7 @@ pub(super) type NodeDeltaSet = HashMap; pub(super) struct AnnouncementDelta { pub(super) seen: u32, pub(super) announcement: UnsignedChannelAnnouncement, + pub(super) funding_sats: u64, } pub(super) struct UpdateDelta { @@ -148,7 +149,7 @@ pub(super) async fn fetch_channel_announcements(delta_set: &mut DeltaS log_info!(logger, "Obtaining corresponding database entries"); // get all the channel announcements that are currently in the network graph - let announcement_rows = client.query_raw("SELECT announcement_signed, CAST(EXTRACT('epoch' from seen) AS BIGINT) AS seen FROM channel_announcements WHERE short_channel_id = any($1) ORDER BY short_channel_id ASC", [&channel_ids]).await.unwrap(); + let announcement_rows = client.query_raw("SELECT announcement_signed, funding_amount_sats, CAST(EXTRACT('epoch' from seen) AS BIGINT) AS seen FROM channel_announcements WHERE short_channel_id = any($1) ORDER BY short_channel_id ASC", [&channel_ids]).await.unwrap(); let mut pinned_rows = Box::pin(announcement_rows); let mut announcement_count = 0; @@ -159,11 +160,13 @@ pub(super) async fn fetch_channel_announcements(delta_set: &mut DeltaS let unsigned_announcement = ChannelAnnouncement::read(&mut readable).unwrap().contents; let scid = unsigned_announcement.short_channel_id; + let funding_sats = current_announcement_row.get::<_, i64>("funding_amount_sats") as u64; let current_seen_timestamp = current_announcement_row.get::<_, i64>("seen") as u32; let current_channel_delta = delta_set.entry(scid).or_insert(ChannelDelta::default()); (*current_channel_delta).announcement = Some(AnnouncementDelta { announcement: unsigned_announcement, + funding_sats, seen: current_seen_timestamp, }); diff --git a/src/serialization.rs b/src/serialization.rs index ab2ae816..6be4f8d1 100644 --- a/src/serialization.rs +++ b/src/serialization.rs @@ -11,7 +11,7 @@ use crate::config; use crate::lookup::{DeltaSet, DirectedUpdateDelta, NodeDeltaSet}; pub(super) struct SerializationSet { - pub(super) announcements: Vec, + pub(super) announcements: Vec<(UnsignedChannelAnnouncement, u64)>, pub(super) updates: Vec, pub(super) full_update_defaults: DefaultUpdateValues, pub(super) node_announcement_feature_defaults: Vec, @@ -166,7 +166,8 @@ pub(super) fn serialize_delta_set(channel_delta_set: DeltaSet, node_delta_set: N let send_announcement = is_new_announcement || is_newly_included_announcement; if send_announcement { serialization_set.latest_seen = max(serialization_set.latest_seen, current_announcement_seen); - serialization_set.announcements.push(channel_delta.announcement.unwrap().announcement); + let announcement_delta = channel_delta.announcement.unwrap(); + serialization_set.announcements.push((announcement_delta.announcement, announcement_delta.funding_sats)); } let direction_a_updates = channel_delta.updates.0; @@ -266,7 +267,7 @@ pub(super) fn serialize_delta_set(channel_delta_set: DeltaSet, node_delta_set: N serialization_set } -pub fn serialize_stripped_channel_announcement(announcement: &UnsignedChannelAnnouncement, node_id_a_index: usize, node_id_b_index: usize, previous_scid: u64) -> Vec { +pub fn serialize_stripped_channel_announcement(announcement: &UnsignedChannelAnnouncement, funding_sats: u64, node_id_a_index: usize, node_id_b_index: usize, previous_scid: u64, version: u8) -> Vec { let mut stripped_announcement = vec![]; announcement.features.write(&mut stripped_announcement).unwrap(); @@ -279,7 +280,19 @@ pub fn serialize_stripped_channel_announcement(announcement: &UnsignedChannelAnn // write indices of node ids rather than the node IDs themselves BigSize(node_id_a_index as u64).write(&mut stripped_announcement).unwrap(); - BigSize(node_id_b_index as u64).write(&mut stripped_announcement).unwrap(); + + let mut node_id_b_index = node_id_b_index as u64; + if version >= 2 { + // Set the "extra data" bit so that we can write the funding amount below. + node_id_b_index |= 1 << 63; + } + BigSize(node_id_b_index).write(&mut stripped_announcement).unwrap(); + + if version >= 2 { + let mut funding_sats_vec = Vec::with_capacity(8); + BigSize(funding_sats).write(&mut funding_sats_vec).unwrap(); + funding_sats_vec.write(&mut stripped_announcement).unwrap(); + } // println!("serialized CA: {}, \n{:?}\n{:?}\n", announcement.short_channel_id, announcement.node_id_1, announcement.node_id_2); stripped_announcement