Skip to content

Commit adb39ae

Browse files
committed
Handle-initial_routing_sync-requests-from-peers-in-their-Init-messages
1 parent b297d5b commit adb39ae

File tree

4 files changed

+143
-18
lines changed

4 files changed

+143
-18
lines changed

src/ln/msgs.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ pub struct AnnouncementSignatures {
333333
}
334334

335335
/// An address which can be used to connect to a remote peer
336-
#[derive(Clone)]
336+
#[derive(Clone, PartialEq)]
337337
pub enum NetAddress {
338338
/// An IPv4 address/port on which the peer is listenting.
339339
IPv4 {
@@ -380,7 +380,7 @@ impl NetAddress {
380380
}
381381
}
382382
}
383-
383+
#[derive(Clone, PartialEq)]
384384
// Only exposed as broadcast of node_announcement should be filtered by node_id
385385
/// The unsigned part of a node_announcement
386386
pub struct UnsignedNodeAnnouncement {
@@ -397,6 +397,7 @@ pub struct UnsignedNodeAnnouncement {
397397
pub(crate) excess_address_data: Vec<u8>,
398398
pub(crate) excess_data: Vec<u8>,
399399
}
400+
#[derive(Clone, PartialEq)]
400401
/// A node_announcement message to be sent or received from a peer
401402
pub struct NodeAnnouncement {
402403
pub(crate) signature: Signature,
@@ -585,6 +586,8 @@ pub trait RoutingMessageHandler : Send + Sync {
585586
fn handle_channel_update(&self, msg: &ChannelUpdate) -> Result<bool, HandleError>;
586587
/// Handle some updates to the route graph that we learned due to an outbound failed payment.
587588
fn handle_htlc_fail_channel_update(&self, update: &HTLCFailChannelUpdate);
589+
///This returns a vec of vec's, one for ChannelAnnouncements, one for ChannelUpdates and one for NodeAnnouncements. It also returns the id of the last channel passed through
590+
fn get_next_announcements(&self, starting_point: i64, batch_amount: u8)->(Vec<(ChannelAnnouncement, ChannelUpdate, NodeAnnouncement, NodeAnnouncement)>, i64);
588591
}
589592

590593
pub(crate) struct OnionRealm0HopData {

src/ln/peer_handler.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ struct Peer {
102102
pending_read_buffer: Vec<u8>,
103103
pending_read_buffer_pos: usize,
104104
pending_read_is_header: bool,
105+
last_synced_channel : i64,
105106
}
106107

107108
struct PeerHolder<Descriptor: SocketDescriptor> {
@@ -221,6 +222,7 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
221222
pending_read_buffer: pending_read_buffer,
222223
pending_read_buffer_pos: 0,
223224
pending_read_is_header: false,
225+
last_synced_channel : -1,
224226
}).is_some() {
225227
panic!("PeerManager driver duplicated descriptors!");
226228
};
@@ -255,6 +257,7 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
255257
pending_read_buffer: pending_read_buffer,
256258
pending_read_buffer_pos: 0,
257259
pending_read_is_header: false,
260+
last_synced_channel : -1,
258261
}).is_some() {
259262
panic!("PeerManager driver duplicated descriptors!");
260263
};
@@ -348,6 +351,22 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
348351
peer.pending_read_buffer_pos = 0;
349352

350353
macro_rules! encode_and_send_msg {
354+
($msg: expr, $msg_code: expr) => {
355+
{
356+
encode_and_send_actual_msg!($msg, $msg_code);
357+
if peer.last_synced_channel > -1{
358+
let all_messages_tuple = self.message_handler.route_handler.get_next_announcements(peer.last_synced_channel,5);
359+
for i in 0..all_messages_tuple.0.len(){
360+
encode_and_send_actual_msg!(all_messages_tuple.0[i].0.clone(), 256);
361+
encode_and_send_actual_msg!(all_messages_tuple.0[i].2.clone(), 257);
362+
encode_and_send_actual_msg!(all_messages_tuple.0[i].3.clone(), 257);
363+
encode_and_send_actual_msg!(all_messages_tuple.0[i].1.clone(), 258);
364+
}
365+
peer.last_synced_channel = all_messages_tuple.1;
366+
}
367+
}
368+
}
369+
}macro_rules! encode_and_send_actual_msg {
351370
($msg: expr, $msg_code: expr) => {
352371
{
353372
log_trace!(self, "Encoding and sending message of type {} to {}", $msg_code, log_pubkey!(peer.their_node_id.unwrap()));
@@ -511,6 +530,7 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
511530
if msg.local_features.supports_unknown_bits() { "present" } else { "none" },
512531
if msg.global_features.supports_unknown_bits() { "present" } else { "none" });
513532

533+
let do_they_require_sync = msg.local_features.initial_routing_sync();
514534
peer.their_global_features = Some(msg.global_features);
515535
peer.their_local_features = Some(msg.local_features);
516536

@@ -520,6 +540,10 @@ impl<Descriptor: SocketDescriptor> PeerManager<Descriptor> {
520540
self.initial_syncs_sent.fetch_add(1, Ordering::AcqRel);
521541
local_features.set_initial_routing_sync();
522542
}
543+
544+
if do_they_require_sync {
545+
peer.last_synced_channel = 0; //set to larger than -1, means next sent message will trigger slow trickle of sync data
546+
}
523547
encode_and_send_msg!(msgs::Init {
524548
global_features: msgs::GlobalFeatures::new(),
525549
local_features,

0 commit comments

Comments
 (0)