Skip to content

Commit c9c9415

Browse files
authored
Merge pull request #570 from naumenkogs/2020_04_routing_message_handler_tests
Add tests for routing message handler
2 parents 60dd37d + 79c8491 commit c9c9415

File tree

6 files changed

+820
-18
lines changed

6 files changed

+820
-18
lines changed

lightning-net-tokio/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ mod tests {
507507
fn handle_channel_announcement(&self, _msg: &ChannelAnnouncement) -> Result<bool, LightningError> { Ok(false) }
508508
fn handle_channel_update(&self, _msg: &ChannelUpdate) -> Result<bool, LightningError> { Ok(false) }
509509
fn handle_htlc_fail_channel_update(&self, _update: &HTLCFailChannelUpdate) { }
510-
fn get_next_channel_announcements(&self, _starting_point: u64, _batch_amount: u8) -> Vec<(ChannelAnnouncement, ChannelUpdate, ChannelUpdate)> { Vec::new() }
510+
fn get_next_channel_announcements(&self, _starting_point: u64, _batch_amount: u8) -> Vec<(ChannelAnnouncement, Option<ChannelUpdate>, Option<ChannelUpdate>)> { Vec::new() }
511511
fn get_next_node_announcements(&self, _starting_point: Option<&PublicKey>, _batch_amount: u8) -> Vec<NodeAnnouncement> { Vec::new() }
512512
fn should_request_full_sync(&self, _node_id: &PublicKey) -> bool { false }
513513
}

lightning/src/chain/chaininterface.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use std::marker::PhantomData;
2222
use std::ptr;
2323

2424
/// Used to give chain error details upstream
25+
#[derive(Clone)]
2526
pub enum ChainError {
2627
/// Client doesn't support UTXO lookup (but the chain hash matches our genesis block hash)
2728
NotSupported,

lightning/src/ln/msgs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ pub trait RoutingMessageHandler : Send + Sync {
601601
/// Gets a subset of the channel announcements and updates required to dump our routing table
602602
/// to a remote node, starting at the short_channel_id indicated by starting_point and
603603
/// including the batch_amount entries immediately higher in numerical value than starting_point.
604-
fn get_next_channel_announcements(&self, starting_point: u64, batch_amount: u8) -> Vec<(ChannelAnnouncement, ChannelUpdate, ChannelUpdate)>;
604+
fn get_next_channel_announcements(&self, starting_point: u64, batch_amount: u8) -> Vec<(ChannelAnnouncement, Option<ChannelUpdate>, Option<ChannelUpdate>)>;
605605
/// Gets a subset of the node announcements required to dump our routing table to a remote node,
606606
/// starting at the node *after* the provided publickey and including batch_amount entries
607607
/// immediately higher (as defined by <PublicKey as Ord>::cmp) than starting_point.

lightning/src/ln/peer_handler.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,10 +355,14 @@ impl<Descriptor: SocketDescriptor, CM: Deref> PeerManager<Descriptor, CM> where
355355
InitSyncTracker::ChannelsSyncing(c) if c < 0xffff_ffff_ffff_ffff => {
356356
let steps = ((MSG_BUFF_SIZE - peer.pending_outbound_buffer.len() + 2) / 3) as u8;
357357
let all_messages = self.message_handler.route_handler.get_next_channel_announcements(c, steps);
358-
for &(ref announce, ref update_a, ref update_b) in all_messages.iter() {
358+
for &(ref announce, ref update_a_option, ref update_b_option) in all_messages.iter() {
359359
encode_and_send_msg!(announce);
360-
encode_and_send_msg!(update_a);
361-
encode_and_send_msg!(update_b);
360+
if let &Some(ref update_a) = update_a_option {
361+
encode_and_send_msg!(update_a);
362+
}
363+
if let &Some(ref update_b) = update_b_option {
364+
encode_and_send_msg!(update_b);
365+
}
362366
peer.sync_status = InitSyncTracker::ChannelsSyncing(announce.contents.short_channel_id + 1);
363367
}
364368
if all_messages.is_empty() || all_messages.len() != steps as usize {
@@ -1313,7 +1317,7 @@ mod tests {
13131317
Err(msgs::LightningError { err: "", action: msgs::ErrorAction::IgnoreError })
13141318
}
13151319
fn handle_htlc_fail_channel_update(&self, _update: &msgs::HTLCFailChannelUpdate) {}
1316-
fn get_next_channel_announcements(&self, starting_point: u64, batch_amount: u8) -> Vec<(msgs::ChannelAnnouncement, msgs::ChannelUpdate,msgs::ChannelUpdate)> {
1320+
fn get_next_channel_announcements(&self, starting_point: u64, batch_amount: u8) -> Vec<(msgs::ChannelAnnouncement, Option<msgs::ChannelUpdate>, Option<msgs::ChannelUpdate>)> {
13171321
let mut chan_anns = Vec::new();
13181322
const TOTAL_UPDS: u64 = 100;
13191323
let end: u64 = min(starting_point + batch_amount as u64, TOTAL_UPDS - self.chan_anns_sent.load(Ordering::Acquire) as u64);
@@ -1322,7 +1326,7 @@ mod tests {
13221326
let chan_upd_2 = get_dummy_channel_update(i);
13231327
let chan_ann = get_dummy_channel_announcement(i);
13241328

1325-
chan_anns.push((chan_ann, chan_upd_1, chan_upd_2));
1329+
chan_anns.push((chan_ann, Some(chan_upd_1), Some(chan_upd_2)));
13261330
}
13271331

13281332
self.chan_anns_sent.fetch_add(chan_anns.len(), Ordering::AcqRel);

0 commit comments

Comments
 (0)