Use constant in QueryChannelRange::end_blocknum
[rust-lightning] / lightning / src / routing / network_graph.rs
index 34859cf07c462311ee1623bae195e7527ddb4205..44ee21ab8270b73c02e516112d75dd6126f0c930 100644 (file)
@@ -30,7 +30,7 @@ use ln::msgs;
 use util::ser::{Writeable, Readable, Writer};
 use util::logger::Logger;
 use util::events::{MessageSendEvent, MessageSendEventsProvider};
-use util::scid_utils::{block_from_scid, scid_from_parts};
+use util::scid_utils::{block_from_scid, scid_from_parts, MAX_SCID_BLOCK};
 
 use std::{cmp, fmt};
 use std::sync::{RwLock, RwLockReadGuard};
@@ -329,11 +329,11 @@ impl<C: Deref + Sync + Send, L: Deref + Sync + Send> RoutingMessageHandler for N
 
                let network_graph = self.network_graph.read().unwrap();
 
-               let start_scid = scid_from_parts(msg.first_blocknum, 0, 0);
+               let start_scid = scid_from_parts(msg.first_blocknum as u64, 0, 0);
 
                // We receive valid queries with end_blocknum that would overflow SCID conversion.
                // Manually cap the ending block to avoid this overflow.
-               let exclusive_end_scid = scid_from_parts(cmp::min(msg.end_blocknum(), 0xffffff), 0, 0);
+               let exclusive_end_scid = scid_from_parts(cmp::min(msg.end_blocknum() as u64, MAX_SCID_BLOCK), 0, 0);
 
                // Per spec, we must reply to a query. Send an empty message when things are invalid.
                if msg.chain_hash != network_graph.genesis_hash || start_scid.is_err() || exclusive_end_scid.is_err() {
@@ -369,9 +369,8 @@ impl<C: Deref + Sync + Send, L: Deref + Sync + Send> RoutingMessageHandler for N
                drop(network_graph);
 
                let mut pending_events = self.pending_events.lock().unwrap();
-               let mut batch_index = 0;
                let batch_count = batches.len();
-               for batch in batches.into_iter() {
+               for (batch_index, batch) in batches.into_iter().enumerate() {
                        // Per spec, the initial first_blocknum needs to be <= the query's first_blocknum.
                        // Use the query's values since we don't use pre-processed reply ranges.
                        let first_blocknum = if batch_index == 0 {
@@ -409,8 +408,6 @@ impl<C: Deref + Sync + Send, L: Deref + Sync + Send> RoutingMessageHandler for N
                                        short_channel_ids: batch,
                                }
                        });
-
-                       batch_index += 1;
                }
 
                Ok(())