Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ fn serialize_delta<L: Deref + Clone>(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(&current_announcement, id_index_1, id_index_2, previous_announcement_scid);
let mut stripped_announcement = serialization::serialize_stripped_channel_announcement(&current_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;
Expand Down
5 changes: 4 additions & 1 deletion src/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ pub(super) type NodeDeltaSet = HashMap<NodeId, NodeDelta>;
pub(super) struct AnnouncementDelta {
pub(super) seen: u32,
pub(super) announcement: UnsignedChannelAnnouncement,
pub(super) funding_sats: u64,
}

pub(super) struct UpdateDelta {
Expand Down Expand Up @@ -148,7 +149,7 @@ pub(super) async fn fetch_channel_announcements<L: Deref>(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;
Expand All @@ -159,11 +160,13 @@ pub(super) async fn fetch_channel_announcements<L: Deref>(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,
});

Expand Down
21 changes: 17 additions & 4 deletions src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::config;
use crate::lookup::{DeltaSet, DirectedUpdateDelta, NodeDeltaSet};

pub(super) struct SerializationSet {
pub(super) announcements: Vec<UnsignedChannelAnnouncement>,
pub(super) announcements: Vec<(UnsignedChannelAnnouncement, u64)>,
pub(super) updates: Vec<UpdateSerialization>,
pub(super) full_update_defaults: DefaultUpdateValues,
pub(super) node_announcement_feature_defaults: Vec<NodeFeatures>,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<u8> {
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<u8> {
let mut stripped_announcement = vec![];

announcement.features.write(&mut stripped_announcement).unwrap();
Expand All @@ -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;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I take it we'll always use the second node index for indicating extra data follows?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if version >= 2 {
// Set the "extra data" bit so that we can write the funding amount below.
node_id_b_index |= 1 << 63;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the client reset this bit when looking up the node id?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
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
Expand Down
Loading