Fix TLV serialization to work with large types.
[rust-lightning] / lightning / src / routing / router.rs
index 9f4b8ac3589a27ef7c713751eb1d98ad18596978..12374bad58bc396ddfdec7e4014abf2eb854c7c2 100644 (file)
@@ -24,7 +24,6 @@ use util::logger::Logger;
 use prelude::*;
 use alloc::collections::BinaryHeap;
 use core::cmp;
-use std::collections::HashMap;
 use core::ops::Deref;
 
 /// A hop in a route
@@ -50,13 +49,13 @@ pub struct RouteHop {
 }
 
 impl_writeable_tlv_based!(RouteHop, {
-       (0, pubkey),
-       (2, node_features),
-       (4, short_channel_id),
-       (6, channel_features),
-       (8, fee_msat),
-       (10, cltv_expiry_delta),
-}, {}, {});
+       (0, pubkey, required),
+       (2, node_features, required),
+       (4, short_channel_id, required),
+       (6, channel_features, required),
+       (8, fee_msat, required),
+       (10, cltv_expiry_delta, required),
+});
 
 /// A route directs a payment from the sender (us) to the recipient. If the recipient supports MPP,
 /// it can take multiple paths. Each path is composed of one or more hops through the network.
@@ -84,7 +83,7 @@ impl Writeable for Route {
                                hop.write(writer)?;
                        }
                }
-               write_tlv_fields!(writer, {}, {});
+               write_tlv_fields!(writer, {});
                Ok(())
        }
 }
@@ -102,7 +101,7 @@ impl Readable for Route {
                        }
                        paths.push(hops);
                }
-               read_tlv_fields!(reader, {}, {});
+               read_tlv_fields!(reader, {});
                Ok(Route { paths })
        }
 }
@@ -3843,6 +3842,7 @@ mod tests {
                }
        }
 
+       #[cfg(not(feature = "no_std"))]
        pub(super) fn random_init_seed() -> u64 {
                // Because the default HashMap in std pulls OS randomness, we can use it as a (bad) RNG.
                use core::hash::{BuildHasher, Hasher};
@@ -3850,9 +3850,11 @@ mod tests {
                println!("Using seed of {}", seed);
                seed
        }
+       #[cfg(not(feature = "no_std"))]
        use util::ser::Readable;
 
        #[test]
+       #[cfg(not(feature = "no_std"))]
        fn generate_routes() {
                let mut d = match super::test_utils::get_route_file() {
                        Ok(f) => f,
@@ -3880,6 +3882,7 @@ mod tests {
        }
 
        #[test]
+       #[cfg(not(feature = "no_std"))]
        fn generate_routes_mpp() {
                let mut d = match super::test_utils::get_route_file() {
                        Ok(f) => f,
@@ -3907,7 +3910,7 @@ mod tests {
        }
 }
 
-#[cfg(test)]
+#[cfg(all(test, not(feature = "no_std")))]
 pub(crate) mod test_utils {
        use std::fs::File;
        /// Tries to open a network graph file, or panics with a URL to fetch it.
@@ -3934,7 +3937,7 @@ pub(crate) mod test_utils {
        }
 }
 
-#[cfg(all(test, feature = "unstable"))]
+#[cfg(all(test, feature = "unstable", not(feature = "no_std")))]
 mod benches {
        use super::*;
        use util::logger::{Logger, Record};