Skip to content

Commit 05d5420

Browse files
authored
Merge pull request #102 from TheBlueMatt/main
Include funding amounts in channel announcements
2 parents b8b718b + b4e8434 commit 05d5420

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ jobs:
3333
- name: Pin dependencies
3434
if: ${{ matrix.toolchain == '1.63.0' }}
3535
run: |
36-
cargo update -p tokio --precise "1.37.0" --verbose
37-
cargo update -p tokio-macros --precise "2.2.0" --verbose
36+
cargo update -p tokio --precise "1.38.1" --verbose
3837
cargo update -p postgres-types --precise "0.2.6" --verbose
38+
cargo update -p [email protected] --precise "0.12.3" --verbose
39+
cargo update -p [email protected] --precise "0.9.10" --verbose
40+
cargo update -p lock_api --precise "0.4.12" --verbose
3941
- name: Build on Rust ${{ matrix.toolchain }}
4042
run: |
4143
cargo build --verbose --color always

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,10 @@ fn serialize_delta<L: Deref + Clone>(serialization_details: &SerializationSet, s
248248
let announcement_count = serialization_details.announcements.len() as u32;
249249
announcement_count.write(&mut output).unwrap();
250250
let mut previous_announcement_scid = 0;
251-
for current_announcement in &serialization_details.announcements {
251+
for (current_announcement, funding_sats) in &serialization_details.announcements {
252252
let id_index_1 = get_node_id_index(current_announcement.node_id_1);
253253
let id_index_2 = get_node_id_index(current_announcement.node_id_2);
254-
let mut stripped_announcement = serialization::serialize_stripped_channel_announcement(&current_announcement, id_index_1, id_index_2, previous_announcement_scid);
254+
let mut stripped_announcement = serialization::serialize_stripped_channel_announcement(&current_announcement, *funding_sats, id_index_1, id_index_2, previous_announcement_scid, serialization_version);
255255
output.append(&mut stripped_announcement);
256256

257257
previous_announcement_scid = current_announcement.short_channel_id;

src/lookup.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub(super) type NodeDeltaSet = HashMap<NodeId, NodeDelta>;
2727
pub(super) struct AnnouncementDelta {
2828
pub(super) seen: u32,
2929
pub(super) announcement: UnsignedChannelAnnouncement,
30+
pub(super) funding_sats: u64,
3031
}
3132

3233
pub(super) struct UpdateDelta {
@@ -148,7 +149,7 @@ pub(super) async fn fetch_channel_announcements<L: Deref>(delta_set: &mut DeltaS
148149

149150
log_info!(logger, "Obtaining corresponding database entries");
150151
// get all the channel announcements that are currently in the network graph
151-
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();
152+
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();
152153
let mut pinned_rows = Box::pin(announcement_rows);
153154

154155
let mut announcement_count = 0;
@@ -159,11 +160,13 @@ pub(super) async fn fetch_channel_announcements<L: Deref>(delta_set: &mut DeltaS
159160
let unsigned_announcement = ChannelAnnouncement::read(&mut readable).unwrap().contents;
160161

161162
let scid = unsigned_announcement.short_channel_id;
163+
let funding_sats = current_announcement_row.get::<_, i64>("funding_amount_sats") as u64;
162164
let current_seen_timestamp = current_announcement_row.get::<_, i64>("seen") as u32;
163165

164166
let current_channel_delta = delta_set.entry(scid).or_insert(ChannelDelta::default());
165167
(*current_channel_delta).announcement = Some(AnnouncementDelta {
166168
announcement: unsigned_announcement,
169+
funding_sats,
167170
seen: current_seen_timestamp,
168171
});
169172

src/serialization.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::config;
1111
use crate::lookup::{DeltaSet, DirectedUpdateDelta, NodeDeltaSet};
1212

1313
pub(super) struct SerializationSet {
14-
pub(super) announcements: Vec<UnsignedChannelAnnouncement>,
14+
pub(super) announcements: Vec<(UnsignedChannelAnnouncement, u64)>,
1515
pub(super) updates: Vec<UpdateSerialization>,
1616
pub(super) full_update_defaults: DefaultUpdateValues,
1717
pub(super) node_announcement_feature_defaults: Vec<NodeFeatures>,
@@ -166,7 +166,8 @@ pub(super) fn serialize_delta_set(channel_delta_set: DeltaSet, node_delta_set: N
166166
let send_announcement = is_new_announcement || is_newly_included_announcement;
167167
if send_announcement {
168168
serialization_set.latest_seen = max(serialization_set.latest_seen, current_announcement_seen);
169-
serialization_set.announcements.push(channel_delta.announcement.unwrap().announcement);
169+
let announcement_delta = channel_delta.announcement.unwrap();
170+
serialization_set.announcements.push((announcement_delta.announcement, announcement_delta.funding_sats));
170171
}
171172

172173
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
266267
serialization_set
267268
}
268269

269-
pub fn serialize_stripped_channel_announcement(announcement: &UnsignedChannelAnnouncement, node_id_a_index: usize, node_id_b_index: usize, previous_scid: u64) -> Vec<u8> {
270+
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> {
270271
let mut stripped_announcement = vec![];
271272

272273
announcement.features.write(&mut stripped_announcement).unwrap();
@@ -279,7 +280,19 @@ pub fn serialize_stripped_channel_announcement(announcement: &UnsignedChannelAnn
279280

280281
// write indices of node ids rather than the node IDs themselves
281282
BigSize(node_id_a_index as u64).write(&mut stripped_announcement).unwrap();
282-
BigSize(node_id_b_index as u64).write(&mut stripped_announcement).unwrap();
283+
284+
let mut node_id_b_index = node_id_b_index as u64;
285+
if version >= 2 {
286+
// Set the "extra data" bit so that we can write the funding amount below.
287+
node_id_b_index |= 1 << 63;
288+
}
289+
BigSize(node_id_b_index).write(&mut stripped_announcement).unwrap();
290+
291+
if version >= 2 {
292+
let mut funding_sats_vec = Vec::with_capacity(8);
293+
BigSize(funding_sats).write(&mut funding_sats_vec).unwrap();
294+
funding_sats_vec.write(&mut stripped_announcement).unwrap();
295+
}
283296

284297
// println!("serialized CA: {}, \n{:?}\n{:?}\n", announcement.short_channel_id, announcement.node_id_1, announcement.node_id_2);
285298
stripped_announcement

0 commit comments

Comments
 (0)