X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=inline;f=lightning%2Fsrc%2Frouting%2Frouter.rs;h=90618e743001e23ac53390253bb5569e2ac82ad5;hb=f30694bd8c39a967848a84752e3b7d8d520cd0b1;hp=ba964d734c670e4cfbbc4d12eca1ea9e71f37491;hpb=3a0356fe308ba29916d00f3376cd57ce6613f3d0;p=rust-lightning diff --git a/lightning/src/routing/router.rs b/lightning/src/routing/router.rs index ba964d73..90618e74 100644 --- a/lightning/src/routing/router.rs +++ b/lightning/src/routing/router.rs @@ -21,8 +21,10 @@ use routing::network_graph::{NetworkGraph, RoutingFees}; use util::ser::{Writeable, Readable}; use util::logger::Logger; +use prelude::*; +use alloc::collections::BinaryHeap; use core::cmp; -use std::collections::{HashMap, BinaryHeap}; +use std::collections::HashMap; use core::ops::Deref; /// A hop in a route @@ -95,23 +97,30 @@ pub struct Route { pub paths: Vec>, } +const SERIALIZATION_VERSION: u8 = 1; +const MIN_SERIALIZATION_VERSION: u8 = 1; + impl Writeable for Route { fn write(&self, writer: &mut W) -> Result<(), ::std::io::Error> { + write_ver_prefix!(writer, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION); (self.paths.len() as u64).write(writer)?; for hops in self.paths.iter() { hops.write(writer)?; } + write_tlv_fields!(writer, {}, {}); Ok(()) } } impl Readable for Route { fn read(reader: &mut R) -> Result { + let _ver = read_ver_prefix!(reader, SERIALIZATION_VERSION); let path_count: u64 = Readable::read(reader)?; let mut paths = Vec::with_capacity(cmp::min(path_count, 128) as usize); for _ in 0..path_count { paths.push(Readable::read(reader)?); } + read_tlv_fields!(reader, {}, {}); Ok(Route { paths }) } } @@ -1186,6 +1195,7 @@ mod tests { use bitcoin::secp256k1::key::{PublicKey,SecretKey}; use bitcoin::secp256k1::{Secp256k1, All}; + use prelude::*; use std::sync::Arc; // Using the same keys for LN and BTC ids @@ -3883,7 +3893,7 @@ mod tests { let mut d = match get_route_file() { Ok(f) => f, Err(_) => { - eprintln!("Please fetch https://bitcoin.ninja/ldk-net_graph-879e309c128-2020-02-12.bin and place it at lightning/net_graph-2021-02-12.bin"); + eprintln!("Please fetch https://bitcoin.ninja/ldk-net_graph-05f0c5a0d772-2020-02-12.bin and place it at lightning/net_graph-2021-02-12.bin"); return; }, }; @@ -3910,7 +3920,7 @@ mod tests { let mut d = match get_route_file() { Ok(f) => f, Err(_) => { - eprintln!("Please fetch https://bitcoin.ninja/ldk-net_graph-879e309c128-2020-02-12.bin and place it at lightning/net_graph-2021-02-12.bin"); + eprintln!("Please fetch https://bitcoin.ninja/ldk-net_graph-05f0c5a0d772-2020-02-12.bin and place it at lightning/net_graph-2021-02-12.bin"); return; }, }; @@ -3938,6 +3948,7 @@ mod benches { use super::*; use util::logger::{Logger, Record}; + use prelude::*; use test::Bencher; struct DummyLogger {} @@ -3948,7 +3959,7 @@ mod benches { #[bench] fn generate_routes(bench: &mut Bencher) { let mut d = tests::get_route_file() - .expect("Please fetch https://bitcoin.ninja/ldk-net_graph-879e309c128-2020-02-12.bin and place it at lightning/net_graph-2021-02-12.bin"); + .expect("Please fetch https://bitcoin.ninja/ldk-net_graph-05f0c5a0d772-2020-02-12.bin and place it at lightning/net_graph-2021-02-12.bin"); let graph = NetworkGraph::read(&mut d).unwrap(); // First, get 100 (source, destination) pairs for which route-getting actually succeeds... @@ -3980,7 +3991,7 @@ mod benches { #[bench] fn generate_mpp_routes(bench: &mut Bencher) { let mut d = tests::get_route_file() - .expect("Please fetch https://bitcoin.ninja/ldk-net_graph-879e309c128-2020-02-12.bin and place it at lightning/net_graph-2021-02-12.bin"); + .expect("Please fetch https://bitcoin.ninja/ldk-net_graph-05f0c5a0d772-2020-02-12.bin and place it at lightning/net_graph-2021-02-12.bin"); let graph = NetworkGraph::read(&mut d).unwrap(); // First, get 100 (source, destination) pairs for which route-getting actually succeeds...