Swap `Vec<&RouteHop>` parameters for slices
[rust-lightning] / lightning-rapid-gossip-sync / src / processing.rs
index 09693a76d6f3b4868424d863ddd97399802974f9..18f9916316a5ffe9c7e0bf4dde7231bfea626789 100644 (file)
@@ -1,18 +1,17 @@
-use std::cmp::max;
-use std::io;
-use std::io::Read;
-use std::ops::Deref;
-use std::sync::atomic::Ordering;
+use core::cmp::max;
+use core::ops::Deref;
+use core::sync::atomic::Ordering;
 
 use bitcoin::BlockHash;
 use bitcoin::secp256k1::PublicKey;
 
 use lightning::ln::msgs::{
-       DecodeError, ErrorAction, LightningError, OptionalField, UnsignedChannelUpdate,
+       DecodeError, ErrorAction, LightningError, UnsignedChannelUpdate,
 };
 use lightning::routing::gossip::NetworkGraph;
 use lightning::util::logger::Logger;
 use lightning::util::ser::{BigSize, Readable};
+use lightning::io;
 
 use crate::error::GraphSyncError;
 use crate::RapidGossipSync;
@@ -28,19 +27,7 @@ const GOSSIP_PREFIX: [u8; 4] = [76, 68, 75, 1];
 const MAX_INITIAL_NODE_ID_VECTOR_CAPACITY: u32 = 50_000;
 
 impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L::Target: Logger {
-       /// Update network graph from binary data.
-       /// Returns the last sync timestamp to be used the next time rapid sync data is queried.
-       ///
-       /// `network_graph`: network graph to be updated
-       ///
-       /// `update_data`: `&[u8]` binary stream that comprises the update data
-       pub fn update_network_graph(&self, update_data: &[u8]) -> Result<u32, GraphSyncError> {
-               let mut read_cursor = io::Cursor::new(update_data);
-               self.update_network_graph_from_byte_stream(&mut read_cursor)
-       }
-
-
-       pub(crate) fn update_network_graph_from_byte_stream<R: Read>(
+       pub(crate) fn update_network_graph_from_byte_stream<R: io::Read>(
                &self,
                mut read_cursor: &mut R,
        ) -> Result<u32, GraphSyncError> {
@@ -119,12 +106,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
                let default_htlc_minimum_msat: u64 = Readable::read(&mut read_cursor)?;
                let default_fee_base_msat: u32 = Readable::read(&mut read_cursor)?;
                let default_fee_proportional_millionths: u32 = Readable::read(&mut read_cursor)?;
-               let tentative_default_htlc_maximum_msat: u64 = Readable::read(&mut read_cursor)?;
-               let default_htlc_maximum_msat = if tentative_default_htlc_maximum_msat == u64::max_value() {
-                       OptionalField::Absent
-               } else {
-                       OptionalField::Present(tentative_default_htlc_maximum_msat)
-               };
+               let default_htlc_maximum_msat: u64 = Readable::read(&mut read_cursor)?;
 
                for _ in 0..update_count {
                        let scid_delta: BigSize = Readable::read(read_cursor)?;
@@ -147,7 +129,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
                                        flags: standard_channel_flags,
                                        cltv_expiry_delta: default_cltv_expiry_delta,
                                        htlc_minimum_msat: default_htlc_minimum_msat,
-                                       htlc_maximum_msat: default_htlc_maximum_msat.clone(),
+                                       htlc_maximum_msat: default_htlc_maximum_msat,
                                        fee_base_msat: default_fee_base_msat,
                                        fee_proportional_millionths: default_fee_proportional_millionths,
                                        excess_data: vec![],
@@ -170,13 +152,6 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
                                                action: ErrorAction::IgnoreError,
                                        })?;
 
-                               let htlc_maximum_msat =
-                                       if let Some(htlc_maximum_msat) = directional_info.htlc_maximum_msat {
-                                               OptionalField::Present(htlc_maximum_msat)
-                                       } else {
-                                               OptionalField::Absent
-                                       };
-
                                UnsignedChannelUpdate {
                                        chain_hash,
                                        short_channel_id,
@@ -184,7 +159,7 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
                                        flags: standard_channel_flags,
                                        cltv_expiry_delta: directional_info.cltv_expiry_delta,
                                        htlc_minimum_msat: directional_info.htlc_minimum_msat,
-                                       htlc_maximum_msat,
+                                       htlc_maximum_msat: directional_info.htlc_maximum_msat,
                                        fee_base_msat: directional_info.fees.base_msat,
                                        fee_proportional_millionths: directional_info.fees.proportional_millionths,
                                        excess_data: vec![],
@@ -212,13 +187,8 @@ impl<NG: Deref<Target=NetworkGraph<L>>, L: Deref> RapidGossipSync<NG, L> where L
                        }
 
                        if channel_flags & 0b_0000_0100 > 0 {
-                               let tentative_htlc_maximum_msat: u64 = Readable::read(read_cursor)?;
-                               synthetic_update.htlc_maximum_msat = if tentative_htlc_maximum_msat == u64::max_value()
-                               {
-                                       OptionalField::Absent
-                               } else {
-                                       OptionalField::Present(tentative_htlc_maximum_msat)
-                               };
+                               let htlc_maximum_msat: u64 = Readable::read(read_cursor)?;
+                               synthetic_update.htlc_maximum_msat = htlc_maximum_msat;
                        }
 
                        network_graph.update_channel_unsigned(&synthetic_update)?;