- // We expect to emit a query_short_channel_ids message with scids in our query range
- let events = net_graph_msg_handler.get_and_clear_pending_msg_events();
- assert_eq!(events.len(), 1);
- match &events[0] {
- MessageSendEvent::SendShortIdsQuery { node_id, msg } => {
- assert_eq!(node_id, &node_id_1);
- assert_eq!(msg.chain_hash, chain_hash);
- assert_eq!(msg.short_channel_ids, vec![0x0003e8_000000_0000,0x0003e9_000000_0000,0x0003f0_000000_0000]);
- },
- _ => panic!("expected MessageSendEvent::SendShortIdsQuery"),
- }
-
- // Clean up scid_task
- net_graph_msg_handler.scid_query_tasks.lock().unwrap().clear();
- }
-
- // Test receipt of a single reply_channel_range for a query that has a u32 overflow. We expect
- // it sends a query_short_channel_ids with the returned scids and removes the pending task.
- {
- // Initiate a channel range query to create a query task
- let result = net_graph_msg_handler.query_channel_range(&node_id_1, chain_hash, 1000, 0xffff_ffff);
- assert!(result.is_ok());
-
- // Clear the SendRangeQuery event
- net_graph_msg_handler.get_and_clear_pending_msg_events();
-
- // Handle a single successful reply that matches the queried channel range
- let result = net_graph_msg_handler.handle_reply_channel_range(&node_id_1, &ReplyChannelRange {
- chain_hash,
- full_information: true,
- first_blocknum: 1000,
- number_of_blocks: 0xffff_ffff,
- short_channel_ids: vec![
- 0x0003e8_000000_0000, // 1000x0x0
- 0x0003e9_000000_0000, // 1001x0x0
- 0x0003f0_000000_0000 // 1008x0x0
- ],
- });
- assert!(result.is_ok());
-
- // The query is now complete, so we expect the task to be removed
- assert!(net_graph_msg_handler.chan_range_query_tasks.lock().unwrap().is_empty());
-
- // We expect to emit a query_short_channel_ids message with scids in our query range
- let events = net_graph_msg_handler.get_and_clear_pending_msg_events();
- assert_eq!(events.len(), 1);
- match &events[0] {
- MessageSendEvent::SendShortIdsQuery { node_id, msg } => {
- assert_eq!(node_id, &node_id_1);
- assert_eq!(msg.chain_hash, chain_hash);
- assert_eq!(msg.short_channel_ids, vec![0x0003e8_000000_0000,0x0003e9_000000_0000,0x0003f0_000000_0000]);
- },
- _ => panic!("expected MessageSendEvent::SendShortIdsQuery"),
- }
-
- // Clean up scid_task
- net_graph_msg_handler.scid_query_tasks.lock().unwrap().clear();
- }
-
- // Test receipt of a single reply that encompasses the queried channel range. This is allowed
- // since a reply must contain at least part of the query range. Receipt of the reply should
- // send a query_short_channel_ids message with scids filtered to the query range and remove
- // the pending task.
- {
- // Initiate a channel range query to create a query task
- let result = net_graph_msg_handler.query_channel_range(&node_id_1, chain_hash, 1000, 100);
- assert!(result.is_ok());
-
- // Clear the SendRangeQuery event
- net_graph_msg_handler.get_and_clear_pending_msg_events();
-
- // Handle a single successful reply that encompasses the queried channel range
- let result = net_graph_msg_handler.handle_reply_channel_range(&node_id_1, &ReplyChannelRange {
- chain_hash,
- full_information: true,
- first_blocknum: 0,
- number_of_blocks: 2000,
- short_channel_ids: vec![
- 0x0003e0_000000_0000, // 992x0x0
- 0x0003e8_000000_0000, // 1000x0x0
- 0x0003e9_000000_0000, // 1001x0x0
- 0x0003f0_000000_0000, // 1008x0x0
- 0x00044c_000000_0000, // 1100x0x0
- 0x0006e0_000000_0000, // 1760x0x0
- ],
- });
- assert!(result.is_ok());
-
- // The query is now complete, so we expect the task to be removed
- assert!(net_graph_msg_handler.chan_range_query_tasks.lock().unwrap().is_empty());
-
- // We expect to emit a query_short_channel_ids message with scids filtered to those
- // within the original query range.
- let events = net_graph_msg_handler.get_and_clear_pending_msg_events();
- assert_eq!(events.len(), 1);
- match &events[0] {
- MessageSendEvent::SendShortIdsQuery { node_id, msg } => {
- assert_eq!(node_id, &node_id_1);
- assert_eq!(msg.chain_hash, chain_hash);
- assert_eq!(msg.short_channel_ids, vec![0x0003e8_000000_0000,0x0003e9_000000_0000,0x0003f0_000000_0000]);
- },
- _ => panic!("expected MessageSendEvent::SendShortIdsQuery"),
- }
-
- // Clean up scid_task
- net_graph_msg_handler.scid_query_tasks.lock().unwrap().clear();
- }
-
- // Test receipt of multiple reply messages for a single query. This happens when the number
- // of scids in the query range exceeds the size limits of a single reply message. We expect
- // to initiate a query_short_channel_ids for the first batch of scids and we enqueue the
- // remaining scids for later processing. We remove the range query task after receipt of all
- // reply messages.
- {
- // Initiate a channel range query to create a query task
- let result = net_graph_msg_handler.query_channel_range(&node_id_1, chain_hash, 1000, 100);
- assert!(result.is_ok());
-
- // Clear the SendRangeQuery event
- net_graph_msg_handler.get_and_clear_pending_msg_events();
-
- // Handle the first reply message
- let reply_1_scids = vec![
- 0x0003e8_000000_0000, // 1000x0x0
- 0x0003e9_000000_0000, // 1001x0x0
- 0x000419_000000_0000, // 1049x0x0
- ];
- let result = net_graph_msg_handler.handle_reply_channel_range(&node_id_1, &ReplyChannelRange {
- chain_hash,
- full_information: true,
- first_blocknum: 1000,
- number_of_blocks: 50,
- short_channel_ids: reply_1_scids.clone(),
- });
- assert!(result.is_ok());
-
- // Handle the next reply in the sequence, which must start at the previous message's
- // first_blocknum plus number_of_blocks. The scids in this reply will be queued.
- let reply_2_scids = vec![
- 0x00041a_000000_0000, // 1050x0x0
- 0x000432_000000_0000, // 1074x0x0
- ];
- let result = net_graph_msg_handler.handle_reply_channel_range(&node_id_1, &ReplyChannelRange {
- chain_hash,
- full_information: true,
- first_blocknum: 1050,
- number_of_blocks: 25,
- short_channel_ids: reply_2_scids.clone(),
- });
- assert!(result.is_ok());
-
- // Handle the final reply in the sequence, which must meet or exceed the initial query's
- // first_blocknum plus number_of_blocks. The scids in this reply will be queued.
- let reply_3_scids = vec![
- 0x000433_000000_0000, // 1075x0x0
- 0x00044b_000000_0000, // 1099x0x0
- ];
- let result = net_graph_msg_handler.handle_reply_channel_range(&node_id_1, &ReplyChannelRange {
- chain_hash,
- full_information: true,
- first_blocknum: 1075,
- number_of_blocks: 25,
- short_channel_ids: reply_3_scids.clone(),
- });
- assert!(result.is_ok());