Skip to content

Commit 3f97cb3

Browse files
committed
Create test ensuring that a previously unannounced channel would not send incremental updates.
1 parent 6f4ab6f commit 3f97cb3

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed

src/tests/mod.rs

+84
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![allow(unused_variables)]
2+
#![allow(unused_imports)]
13
//! Multi-module tests that use database fixtures
24
35
use std::sync::Arc;
@@ -170,3 +172,85 @@ async fn test_trivial_setup() {
170172
assert_eq!(last_update_seen_a, update_result - CLIENT_BACKDATE_INTERVAL);
171173
assert_eq!(last_update_seen_b, update_result - CLIENT_BACKDATE_INTERVAL);
172174
}
175+
176+
/// If a channel has only seen updates in one direction, it should not be announced
177+
#[tokio::test]
178+
async fn test_unidirectional_intermediate_update_consideration() {
179+
// start off with a clean slate
180+
clean_test_db().await;
181+
182+
let logger = Arc::new(TestLogger::new());
183+
let network_graph = NetworkGraph::new(Network::Bitcoin, logger.clone());
184+
let network_graph_arc = Arc::new(network_graph);
185+
let (mut persister, receiver) = GossipPersister::new(network_graph_arc.clone(), logger.clone());
186+
187+
let short_channel_id = 1;
188+
let current_timestamp = current_time() - 10;
189+
190+
{ // seed the db
191+
let announcement = generate_announcement(short_channel_id);
192+
let update_1 = generate_update(short_channel_id, false, current_timestamp - 4, 0, 0, 0, 5, 0);
193+
let update_2 = generate_update(short_channel_id, false, current_timestamp - 3, 0, 0, 0, 4, 0);
194+
let update_3 = generate_update(short_channel_id, false, current_timestamp - 2, 0, 0, 0, 3, 0);
195+
let update_4 = generate_update(short_channel_id, true, current_timestamp, 0, 0, 0, 5, 0);
196+
197+
network_graph_arc.update_channel_from_announcement_no_lookup(&announcement).unwrap();
198+
network_graph_arc.update_channel_unsigned(&update_1.contents).unwrap();
199+
network_graph_arc.update_channel_unsigned(&update_2.contents).unwrap();
200+
network_graph_arc.update_channel_unsigned(&update_3.contents).unwrap();
201+
network_graph_arc.update_channel_unsigned(&update_4.contents).unwrap();
202+
203+
receiver.send(GossipMessage::ChannelAnnouncement(announcement)).await.unwrap();
204+
receiver.send(GossipMessage::ChannelUpdate(update_1)).await.unwrap();
205+
receiver.send(GossipMessage::ChannelUpdate(update_2)).await.unwrap();
206+
receiver.send(GossipMessage::ChannelUpdate(update_3)).await.unwrap();
207+
receiver.send(GossipMessage::ChannelUpdate(update_4)).await.unwrap();
208+
drop(receiver);
209+
persister.persist_gossip().await;
210+
}
211+
212+
let channel_count = network_graph_arc.read_only().channels().len();
213+
assert_eq!(channel_count, 1);
214+
215+
let client_graph = NetworkGraph::new(Network::Bitcoin, logger.clone());
216+
let client_graph_arc = Arc::new(client_graph);
217+
let rgs = RapidGossipSync::new(client_graph_arc.clone(), logger.clone());
218+
219+
let last_sync_timestamp = current_timestamp - 3;
220+
let serialization = serialize_delta(network_graph_arc.clone(), last_sync_timestamp, logger.clone()).await;
221+
println!(
222+
"serialization data: \nmessages: {}\n\tannouncements: {}\n\tupdates: {}\n\t\tfull: {}\n\t\tincremental: {}",
223+
serialization.message_count,
224+
serialization.announcement_count,
225+
serialization.update_count,
226+
serialization.update_count_full,
227+
serialization.update_count_incremental
228+
);
229+
230+
logger.assert_log_contains("rapid_gossip_sync_server::lookup", &format!("Channel IDs: [{}]", short_channel_id), 1);
231+
logger.assert_log_contains("rapid_gossip_sync_server::lookup", "Fetched 1 announcement rows", 1);
232+
logger.assert_log_contains("rapid_gossip_sync_server::lookup", "Processed 1 reference rows", 1);
233+
logger.assert_log_contains("rapid_gossip_sync_server::lookup", &format!("Channel {} last update before seen: 1/false/{}", short_channel_id, current_timestamp - 4), 1);
234+
logger.assert_log_contains("rapid_gossip_sync_server::lookup", "Processed intermediate rows (3)", 1);
235+
println!("current_timestamp: {}", current_timestamp);
236+
logger.assert_log_contains("rapid_gossip_sync_server::lookup", &format!("Channel {} latest update in direction 0: {}", short_channel_id, current_timestamp - 2), 1);
237+
logger.assert_log_contains("rapid_gossip_sync_server::lookup", &format!("Channel {} latest update in direction 1: {}", short_channel_id, current_timestamp), 1);
238+
logger.assert_log_contains("rapid_gossip_sync_server::lookup", &format!("Channel {} first update to complete bidirectional data seen at: {}", short_channel_id, current_timestamp), 1);
239+
240+
assert_eq!(serialization.message_count, 3);
241+
assert_eq!(serialization.announcement_count, 1);
242+
assert_eq!(serialization.update_count, 2);
243+
assert_eq!(serialization.update_count_full, 2);
244+
assert_eq!(serialization.update_count_incremental, 0);
245+
246+
let next_timestamp = rgs.update_network_graph(&serialization.data).unwrap();
247+
println!("last sync timestamp: {}", last_sync_timestamp);
248+
println!("next timestamp: {}", next_timestamp);
249+
// the update result must be a multiple of our snapshot granularity
250+
assert_eq!(next_timestamp % config::SNAPSHOT_CALCULATION_INTERVAL, 0);
251+
252+
let readonly_graph = client_graph_arc.read_only();
253+
let channels = readonly_graph.channels();
254+
let client_channel_count = channels.len();
255+
assert_eq!(client_channel_count, 1);
256+
}

0 commit comments

Comments
 (0)