use bitcoin::secp256k1::PublicKey;
-use ln::channelmanager::ChannelDetails;
-use ln::features::{ChannelFeatures, InvoiceFeatures, NodeFeatures};
-use ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT};
-use routing::gossip::{DirectedChannelInfoWithUpdate, EffectiveCapacity, ReadOnlyNetworkGraph, NetworkGraph, NodeId, RoutingFees};
-use routing::scoring::{ChannelUsage, Score};
-use util::ser::{Writeable, Readable, Writer};
-use util::logger::{Level, Logger};
-use util::chacha20::ChaCha20;
-
-use io;
-use prelude::*;
+use crate::ln::channelmanager::ChannelDetails;
+use crate::ln::features::{ChannelFeatures, InvoiceFeatures, NodeFeatures};
+use crate::ln::msgs::{DecodeError, ErrorAction, LightningError, MAX_VALUE_MSAT};
+use crate::routing::gossip::{DirectedChannelInfoWithUpdate, EffectiveCapacity, ReadOnlyNetworkGraph, NetworkGraph, NodeId, RoutingFees};
+use crate::routing::scoring::{ChannelUsage, Score};
+use crate::util::ser::{Writeable, Readable, Writer};
+use crate::util::logger::{Level, Logger};
+use crate::util::chacha20::ChaCha20;
+
+use crate::io;
+use crate::prelude::*;
use alloc::collections::BinaryHeap;
use core::cmp;
use core::ops::Deref;
const MIN_SERIALIZATION_VERSION: u8 = 1;
impl Writeable for Route {
- fn write<W: ::util::ser::Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
+ fn write<W: crate::util::ser::Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
write_ver_prefix!(writer, SERIALIZATION_VERSION, MIN_SERIALIZATION_VERSION);
(self.paths.len() as u64).write(writer)?;
for hops in self.paths.iter() {
const MEDIAN_HOP_CLTV_EXPIRY_DELTA: u32 = 40;
// During routing, we only consider paths shorter than our maximum length estimate.
-// In the legacy onion format, the maximum number of hops used to be a fixed value of 20.
-// However, in the TLV onion format, there is no fixed maximum length, but the `hop_payloads`
+// In the TLV onion format, there is no fixed maximum length, but the `hop_payloads`
// field is always 1300 bytes. As the `tlv_payload` for each hop may vary in length, we have to
// estimate how many hops the route may have so that it actually fits the `hop_payloads` field.
//
pub struct RouteHint(pub Vec<RouteHintHop>);
impl Writeable for RouteHint {
- fn write<W: ::util::ser::Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
+ fn write<W: crate::util::ser::Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
(self.0.len() as u64).write(writer)?;
for hop in self.0.iter() {
hop.write(writer)?;
lowest_fee_to_peer_through_node: total_fee_msat,
lowest_fee_to_node: $next_hops_fee_msat as u64 + hop_use_fee_msat,
total_cltv_delta: hop_total_cltv_delta,
- value_contribution_msat: value_contribution_msat,
+ value_contribution_msat,
path_htlc_minimum_msat,
path_penalty_msat,
path_length_to_node,
#[cfg(test)]
mod tests {
- use routing::gossip::{NetworkGraph, P2PGossipSync, NodeId, EffectiveCapacity};
- use routing::router::{get_route, build_route_from_hops_internal, add_random_cltv_offset, default_node_features,
+ use crate::routing::gossip::{NetworkGraph, P2PGossipSync, NodeId, EffectiveCapacity};
+ use crate::routing::router::{get_route, build_route_from_hops_internal, add_random_cltv_offset, default_node_features,
PaymentParameters, Route, RouteHint, RouteHintHop, RouteHop, RoutingFees,
DEFAULT_MAX_TOTAL_CLTV_EXPIRY_DELTA, MAX_PATH_LENGTH_ESTIMATE};
- use routing::scoring::{ChannelUsage, Score, ProbabilisticScorer, ProbabilisticScoringParameters};
- use chain::transaction::OutPoint;
- use chain::keysinterface::KeysInterface;
- use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
- use ln::msgs::{ErrorAction, LightningError, UnsignedChannelAnnouncement, ChannelAnnouncement, RoutingMessageHandler,
- NodeAnnouncement, UnsignedNodeAnnouncement, ChannelUpdate, UnsignedChannelUpdate, MAX_VALUE_MSAT};
- use ln::channelmanager;
- use util::test_utils;
- use util::chacha20::ChaCha20;
- use util::ser::Writeable;
+ use crate::routing::scoring::{ChannelUsage, Score, ProbabilisticScorer, ProbabilisticScoringParameters};
+ use crate::routing::test_utils::{add_channel, add_or_update_node, build_graph, build_line_graph, id_to_feature_flags, get_nodes, update_channel};
+ use crate::chain::transaction::OutPoint;
+ use crate::chain::keysinterface::KeysInterface;
+ use crate::ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
+ use crate::ln::msgs::{ErrorAction, LightningError, UnsignedChannelUpdate, MAX_VALUE_MSAT};
+ use crate::ln::channelmanager;
+ use crate::util::test_utils as ln_test_utils;
+ use crate::util::chacha20::ChaCha20;
#[cfg(c_bindings)]
- use util::ser::Writer;
+ use crate::util::ser::{Writeable, Writer};
- use bitcoin::hashes::sha256d::Hash as Sha256dHash;
use bitcoin::hashes::Hash;
use bitcoin::network::constants::Network;
use bitcoin::blockdata::constants::genesis_block;
use hex;
use bitcoin::secp256k1::{PublicKey,SecretKey};
- use bitcoin::secp256k1::{Secp256k1, All};
+ use bitcoin::secp256k1::Secp256k1;
- use prelude::*;
- use sync::{self, Arc};
+ use crate::prelude::*;
+ use crate::sync::Arc;
use core::convert::TryInto;
}
}
- // Using the same keys for LN and BTC ids
- fn add_channel(
- gossip_sync: &P2PGossipSync<Arc<NetworkGraph<Arc<test_utils::TestLogger>>>, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>,
- secp_ctx: &Secp256k1<All>, node_1_privkey: &SecretKey, node_2_privkey: &SecretKey, features: ChannelFeatures, short_channel_id: u64
- ) {
- let node_id_1 = PublicKey::from_secret_key(&secp_ctx, node_1_privkey);
- let node_id_2 = PublicKey::from_secret_key(&secp_ctx, node_2_privkey);
-
- let unsigned_announcement = UnsignedChannelAnnouncement {
- features,
- chain_hash: genesis_block(Network::Testnet).header.block_hash(),
- short_channel_id,
- node_id_1,
- node_id_2,
- bitcoin_key_1: node_id_1,
- bitcoin_key_2: node_id_2,
- excess_data: Vec::new(),
- };
-
- let msghash = hash_to_message!(&Sha256dHash::hash(&unsigned_announcement.encode()[..])[..]);
- let valid_announcement = ChannelAnnouncement {
- node_signature_1: secp_ctx.sign_ecdsa(&msghash, node_1_privkey),
- node_signature_2: secp_ctx.sign_ecdsa(&msghash, node_2_privkey),
- bitcoin_signature_1: secp_ctx.sign_ecdsa(&msghash, node_1_privkey),
- bitcoin_signature_2: secp_ctx.sign_ecdsa(&msghash, node_2_privkey),
- contents: unsigned_announcement.clone(),
- };
- match gossip_sync.handle_channel_announcement(&valid_announcement) {
- Ok(res) => assert!(res),
- _ => panic!()
- };
- }
-
- fn update_channel(
- gossip_sync: &P2PGossipSync<Arc<NetworkGraph<Arc<test_utils::TestLogger>>>, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>,
- secp_ctx: &Secp256k1<All>, node_privkey: &SecretKey, update: UnsignedChannelUpdate
- ) {
- let msghash = hash_to_message!(&Sha256dHash::hash(&update.encode()[..])[..]);
- let valid_channel_update = ChannelUpdate {
- signature: secp_ctx.sign_ecdsa(&msghash, node_privkey),
- contents: update.clone()
- };
-
- match gossip_sync.handle_channel_update(&valid_channel_update) {
- Ok(res) => assert!(res),
- Err(_) => panic!()
- };
- }
-
- fn add_or_update_node(
- gossip_sync: &P2PGossipSync<Arc<NetworkGraph<Arc<test_utils::TestLogger>>>, Arc<test_utils::TestChainSource>, Arc<test_utils::TestLogger>>,
- secp_ctx: &Secp256k1<All>, node_privkey: &SecretKey, features: NodeFeatures, timestamp: u32
- ) {
- let node_id = PublicKey::from_secret_key(&secp_ctx, node_privkey);
- let unsigned_announcement = UnsignedNodeAnnouncement {
- features,
- timestamp,
- node_id,
- rgb: [0; 3],
- alias: [0; 32],
- addresses: Vec::new(),
- excess_address_data: Vec::new(),
- excess_data: Vec::new(),
- };
- let msghash = hash_to_message!(&Sha256dHash::hash(&unsigned_announcement.encode()[..])[..]);
- let valid_announcement = NodeAnnouncement {
- signature: secp_ctx.sign_ecdsa(&msghash, node_privkey),
- contents: unsigned_announcement.clone()
- };
-
- match gossip_sync.handle_node_announcement(&valid_announcement) {
- Ok(_) => (),
- Err(_) => panic!()
- };
- }
-
- fn get_nodes(secp_ctx: &Secp256k1<All>) -> (SecretKey, PublicKey, Vec<SecretKey>, Vec<PublicKey>) {
- let privkeys: Vec<SecretKey> = (2..22).map(|i| {
- SecretKey::from_slice(&hex::decode(format!("{:02x}", i).repeat(32)).unwrap()[..]).unwrap()
- }).collect();
-
- let pubkeys = privkeys.iter().map(|secret| PublicKey::from_secret_key(&secp_ctx, secret)).collect();
-
- let our_privkey = SecretKey::from_slice(&hex::decode("01".repeat(32)).unwrap()[..]).unwrap();
- let our_id = PublicKey::from_secret_key(&secp_ctx, &our_privkey);
-
- (our_privkey, our_id, privkeys, pubkeys)
- }
-
- fn id_to_feature_flags(id: u8) -> Vec<u8> {
- // Set the feature flags to the id'th odd (ie non-required) feature bit so that we can
- // test for it later.
- let idx = (id - 1) * 2 + 1;
- if idx > 8*3 {
- vec![1 << (idx - 8*3), 0, 0, 0]
- } else if idx > 8*2 {
- vec![1 << (idx - 8*2), 0, 0]
- } else if idx > 8*1 {
- vec![1 << (idx - 8*1), 0]
- } else {
- vec![1 << idx]
- }
- }
-
- fn build_line_graph() -> (
- Secp256k1<All>, sync::Arc<NetworkGraph<Arc<test_utils::TestLogger>>>,
- P2PGossipSync<sync::Arc<NetworkGraph<Arc<test_utils::TestLogger>>>, sync::Arc<test_utils::TestChainSource>, sync::Arc<test_utils::TestLogger>>,
- sync::Arc<test_utils::TestChainSource>, sync::Arc<test_utils::TestLogger>,
- ) {
- let secp_ctx = Secp256k1::new();
- let logger = Arc::new(test_utils::TestLogger::new());
- let chain_monitor = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
- let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
- let network_graph = Arc::new(NetworkGraph::new(genesis_hash, Arc::clone(&logger)));
- let gossip_sync = P2PGossipSync::new(Arc::clone(&network_graph), None, Arc::clone(&logger));
-
- // Build network from our_id to node 19:
- // our_id -1(1)2- node0 -1(2)2- node1 - ... - node19
- let (our_privkey, _, privkeys, _) = get_nodes(&secp_ctx);
-
- for (idx, (cur_privkey, next_privkey)) in core::iter::once(&our_privkey)
- .chain(privkeys.iter()).zip(privkeys.iter()).enumerate() {
- let cur_short_channel_id = (idx as u64) + 1;
- add_channel(&gossip_sync, &secp_ctx, &cur_privkey, &next_privkey,
- ChannelFeatures::from_le_bytes(id_to_feature_flags(1)), cur_short_channel_id);
- update_channel(&gossip_sync, &secp_ctx, &cur_privkey, UnsignedChannelUpdate {
- chain_hash: genesis_block(Network::Testnet).header.block_hash(),
- short_channel_id: cur_short_channel_id,
- timestamp: idx as u32,
- flags: 0,
- cltv_expiry_delta: 0,
- htlc_minimum_msat: 0,
- htlc_maximum_msat: MAX_VALUE_MSAT,
- fee_base_msat: 0,
- fee_proportional_millionths: 0,
- excess_data: Vec::new()
- });
- update_channel(&gossip_sync, &secp_ctx, &next_privkey, UnsignedChannelUpdate {
- chain_hash: genesis_block(Network::Testnet).header.block_hash(),
- short_channel_id: cur_short_channel_id,
- timestamp: (idx as u32)+1,
- flags: 1,
- cltv_expiry_delta: 0,
- htlc_minimum_msat: 0,
- htlc_maximum_msat: MAX_VALUE_MSAT,
- fee_base_msat: 0,
- fee_proportional_millionths: 0,
- excess_data: Vec::new()
- });
- add_or_update_node(&gossip_sync, &secp_ctx, next_privkey,
- NodeFeatures::from_le_bytes(id_to_feature_flags(1)), 0);
- }
-
- (secp_ctx, network_graph, gossip_sync, chain_monitor, logger)
- }
-
- fn build_graph() -> (
- Secp256k1<All>,
- sync::Arc<NetworkGraph<Arc<test_utils::TestLogger>>>,
- P2PGossipSync<sync::Arc<NetworkGraph<Arc<test_utils::TestLogger>>>, sync::Arc<test_utils::TestChainSource>, sync::Arc<test_utils::TestLogger>>,
- sync::Arc<test_utils::TestChainSource>,
- sync::Arc<test_utils::TestLogger>,
- ) {
- let secp_ctx = Secp256k1::new();
- let logger = Arc::new(test_utils::TestLogger::new());
- let chain_monitor = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
- let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
- let network_graph = Arc::new(NetworkGraph::new(genesis_hash, Arc::clone(&logger)));
- let gossip_sync = P2PGossipSync::new(Arc::clone(&network_graph), None, Arc::clone(&logger));
- // Build network from our_id to node6:
- //
- // -1(1)2- node0 -1(3)2-
- // / \
- // our_id -1(12)2- node7 -1(13)2--- node2
- // \ /
- // -1(2)2- node1 -1(4)2-
- //
- //
- // chan1 1-to-2: disabled
- // chan1 2-to-1: enabled, 0 fee
- //
- // chan2 1-to-2: enabled, ignored fee
- // chan2 2-to-1: enabled, 0 fee
- //
- // chan3 1-to-2: enabled, 0 fee
- // chan3 2-to-1: enabled, 100 msat fee
- //
- // chan4 1-to-2: enabled, 100% fee
- // chan4 2-to-1: enabled, 0 fee
- //
- // chan12 1-to-2: enabled, ignored fee
- // chan12 2-to-1: enabled, 0 fee
- //
- // chan13 1-to-2: enabled, 200% fee
- // chan13 2-to-1: enabled, 0 fee
- //
- //
- // -1(5)2- node3 -1(8)2--
- // | 2 |
- // | (11) |
- // / 1 \
- // node2--1(6)2- node4 -1(9)2--- node6 (not in global route map)
- // \ /
- // -1(7)2- node5 -1(10)2-
- //
- // Channels 5, 8, 9 and 10 are private channels.
- //
- // chan5 1-to-2: enabled, 100 msat fee
- // chan5 2-to-1: enabled, 0 fee
- //
- // chan6 1-to-2: enabled, 0 fee
- // chan6 2-to-1: enabled, 0 fee
- //
- // chan7 1-to-2: enabled, 100% fee
- // chan7 2-to-1: enabled, 0 fee
- //
- // chan8 1-to-2: enabled, variable fee (0 then 1000 msat)
- // chan8 2-to-1: enabled, 0 fee
- //
- // chan9 1-to-2: enabled, 1001 msat fee
- // chan9 2-to-1: enabled, 0 fee
- //
- // chan10 1-to-2: enabled, 0 fee
- // chan10 2-to-1: enabled, 0 fee
- //
- // chan11 1-to-2: enabled, 0 fee
- // chan11 2-to-1: enabled, 0 fee
-
- let (our_privkey, _, privkeys, _) = get_nodes(&secp_ctx);
-
- add_channel(&gossip_sync, &secp_ctx, &our_privkey, &privkeys[0], ChannelFeatures::from_le_bytes(id_to_feature_flags(1)), 1);
- update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
- chain_hash: genesis_block(Network::Testnet).header.block_hash(),
- short_channel_id: 1,
- timestamp: 1,
- flags: 1,
- cltv_expiry_delta: 0,
- htlc_minimum_msat: 0,
- htlc_maximum_msat: MAX_VALUE_MSAT,
- fee_base_msat: 0,
- fee_proportional_millionths: 0,
- excess_data: Vec::new()
- });
-
- add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[0], NodeFeatures::from_le_bytes(id_to_feature_flags(1)), 0);
-
- add_channel(&gossip_sync, &secp_ctx, &our_privkey, &privkeys[1], ChannelFeatures::from_le_bytes(id_to_feature_flags(2)), 2);
- update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
- chain_hash: genesis_block(Network::Testnet).header.block_hash(),
- short_channel_id: 2,
- timestamp: 1,
- flags: 0,
- cltv_expiry_delta: (5 << 4) | 3,
- htlc_minimum_msat: 0,
- htlc_maximum_msat: MAX_VALUE_MSAT,
- fee_base_msat: u32::max_value(),
- fee_proportional_millionths: u32::max_value(),
- excess_data: Vec::new()
- });
- update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
- chain_hash: genesis_block(Network::Testnet).header.block_hash(),
- short_channel_id: 2,
- timestamp: 1,
- flags: 1,
- cltv_expiry_delta: 0,
- htlc_minimum_msat: 0,
- htlc_maximum_msat: MAX_VALUE_MSAT,
- fee_base_msat: 0,
- fee_proportional_millionths: 0,
- excess_data: Vec::new()
- });
-
- add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[1], NodeFeatures::from_le_bytes(id_to_feature_flags(2)), 0);
-
- add_channel(&gossip_sync, &secp_ctx, &our_privkey, &privkeys[7], ChannelFeatures::from_le_bytes(id_to_feature_flags(12)), 12);
- update_channel(&gossip_sync, &secp_ctx, &our_privkey, UnsignedChannelUpdate {
- chain_hash: genesis_block(Network::Testnet).header.block_hash(),
- short_channel_id: 12,
- timestamp: 1,
- flags: 0,
- cltv_expiry_delta: (5 << 4) | 3,
- htlc_minimum_msat: 0,
- htlc_maximum_msat: MAX_VALUE_MSAT,
- fee_base_msat: u32::max_value(),
- fee_proportional_millionths: u32::max_value(),
- excess_data: Vec::new()
- });
- update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate {
- chain_hash: genesis_block(Network::Testnet).header.block_hash(),
- short_channel_id: 12,
- timestamp: 1,
- flags: 1,
- cltv_expiry_delta: 0,
- htlc_minimum_msat: 0,
- htlc_maximum_msat: MAX_VALUE_MSAT,
- fee_base_msat: 0,
- fee_proportional_millionths: 0,
- excess_data: Vec::new()
- });
-
- add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[7], NodeFeatures::from_le_bytes(id_to_feature_flags(8)), 0);
-
- add_channel(&gossip_sync, &secp_ctx, &privkeys[0], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(3)), 3);
- update_channel(&gossip_sync, &secp_ctx, &privkeys[0], UnsignedChannelUpdate {
- chain_hash: genesis_block(Network::Testnet).header.block_hash(),
- short_channel_id: 3,
- timestamp: 1,
- flags: 0,
- cltv_expiry_delta: (3 << 4) | 1,
- htlc_minimum_msat: 0,
- htlc_maximum_msat: MAX_VALUE_MSAT,
- fee_base_msat: 0,
- fee_proportional_millionths: 0,
- excess_data: Vec::new()
- });
- update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
- chain_hash: genesis_block(Network::Testnet).header.block_hash(),
- short_channel_id: 3,
- timestamp: 1,
- flags: 1,
- cltv_expiry_delta: (3 << 4) | 2,
- htlc_minimum_msat: 0,
- htlc_maximum_msat: MAX_VALUE_MSAT,
- fee_base_msat: 100,
- fee_proportional_millionths: 0,
- excess_data: Vec::new()
- });
-
- add_channel(&gossip_sync, &secp_ctx, &privkeys[1], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(4)), 4);
- update_channel(&gossip_sync, &secp_ctx, &privkeys[1], UnsignedChannelUpdate {
- chain_hash: genesis_block(Network::Testnet).header.block_hash(),
- short_channel_id: 4,
- timestamp: 1,
- flags: 0,
- cltv_expiry_delta: (4 << 4) | 1,
- htlc_minimum_msat: 0,
- htlc_maximum_msat: MAX_VALUE_MSAT,
- fee_base_msat: 0,
- fee_proportional_millionths: 1000000,
- excess_data: Vec::new()
- });
- update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
- chain_hash: genesis_block(Network::Testnet).header.block_hash(),
- short_channel_id: 4,
- timestamp: 1,
- flags: 1,
- cltv_expiry_delta: (4 << 4) | 2,
- htlc_minimum_msat: 0,
- htlc_maximum_msat: MAX_VALUE_MSAT,
- fee_base_msat: 0,
- fee_proportional_millionths: 0,
- excess_data: Vec::new()
- });
-
- add_channel(&gossip_sync, &secp_ctx, &privkeys[7], &privkeys[2], ChannelFeatures::from_le_bytes(id_to_feature_flags(13)), 13);
- update_channel(&gossip_sync, &secp_ctx, &privkeys[7], UnsignedChannelUpdate {
- chain_hash: genesis_block(Network::Testnet).header.block_hash(),
- short_channel_id: 13,
- timestamp: 1,
- flags: 0,
- cltv_expiry_delta: (13 << 4) | 1,
- htlc_minimum_msat: 0,
- htlc_maximum_msat: MAX_VALUE_MSAT,
- fee_base_msat: 0,
- fee_proportional_millionths: 2000000,
- excess_data: Vec::new()
- });
- update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
- chain_hash: genesis_block(Network::Testnet).header.block_hash(),
- short_channel_id: 13,
- timestamp: 1,
- flags: 1,
- cltv_expiry_delta: (13 << 4) | 2,
- htlc_minimum_msat: 0,
- htlc_maximum_msat: MAX_VALUE_MSAT,
- fee_base_msat: 0,
- fee_proportional_millionths: 0,
- excess_data: Vec::new()
- });
-
- add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[2], NodeFeatures::from_le_bytes(id_to_feature_flags(3)), 0);
-
- add_channel(&gossip_sync, &secp_ctx, &privkeys[2], &privkeys[4], ChannelFeatures::from_le_bytes(id_to_feature_flags(6)), 6);
- update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
- chain_hash: genesis_block(Network::Testnet).header.block_hash(),
- short_channel_id: 6,
- timestamp: 1,
- flags: 0,
- cltv_expiry_delta: (6 << 4) | 1,
- htlc_minimum_msat: 0,
- htlc_maximum_msat: MAX_VALUE_MSAT,
- fee_base_msat: 0,
- fee_proportional_millionths: 0,
- excess_data: Vec::new()
- });
- update_channel(&gossip_sync, &secp_ctx, &privkeys[4], UnsignedChannelUpdate {
- chain_hash: genesis_block(Network::Testnet).header.block_hash(),
- short_channel_id: 6,
- timestamp: 1,
- flags: 1,
- cltv_expiry_delta: (6 << 4) | 2,
- htlc_minimum_msat: 0,
- htlc_maximum_msat: MAX_VALUE_MSAT,
- fee_base_msat: 0,
- fee_proportional_millionths: 0,
- excess_data: Vec::new(),
- });
-
- add_channel(&gossip_sync, &secp_ctx, &privkeys[4], &privkeys[3], ChannelFeatures::from_le_bytes(id_to_feature_flags(11)), 11);
- update_channel(&gossip_sync, &secp_ctx, &privkeys[4], UnsignedChannelUpdate {
- chain_hash: genesis_block(Network::Testnet).header.block_hash(),
- short_channel_id: 11,
- timestamp: 1,
- flags: 0,
- cltv_expiry_delta: (11 << 4) | 1,
- htlc_minimum_msat: 0,
- htlc_maximum_msat: MAX_VALUE_MSAT,
- fee_base_msat: 0,
- fee_proportional_millionths: 0,
- excess_data: Vec::new()
- });
- update_channel(&gossip_sync, &secp_ctx, &privkeys[3], UnsignedChannelUpdate {
- chain_hash: genesis_block(Network::Testnet).header.block_hash(),
- short_channel_id: 11,
- timestamp: 1,
- flags: 1,
- cltv_expiry_delta: (11 << 4) | 2,
- htlc_minimum_msat: 0,
- htlc_maximum_msat: MAX_VALUE_MSAT,
- fee_base_msat: 0,
- fee_proportional_millionths: 0,
- excess_data: Vec::new()
- });
-
- add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[4], NodeFeatures::from_le_bytes(id_to_feature_flags(5)), 0);
-
- add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[3], NodeFeatures::from_le_bytes(id_to_feature_flags(4)), 0);
-
- add_channel(&gossip_sync, &secp_ctx, &privkeys[2], &privkeys[5], ChannelFeatures::from_le_bytes(id_to_feature_flags(7)), 7);
- update_channel(&gossip_sync, &secp_ctx, &privkeys[2], UnsignedChannelUpdate {
- chain_hash: genesis_block(Network::Testnet).header.block_hash(),
- short_channel_id: 7,
- timestamp: 1,
- flags: 0,
- cltv_expiry_delta: (7 << 4) | 1,
- htlc_minimum_msat: 0,
- htlc_maximum_msat: MAX_VALUE_MSAT,
- fee_base_msat: 0,
- fee_proportional_millionths: 1000000,
- excess_data: Vec::new()
- });
- update_channel(&gossip_sync, &secp_ctx, &privkeys[5], UnsignedChannelUpdate {
- chain_hash: genesis_block(Network::Testnet).header.block_hash(),
- short_channel_id: 7,
- timestamp: 1,
- flags: 1,
- cltv_expiry_delta: (7 << 4) | 2,
- htlc_minimum_msat: 0,
- htlc_maximum_msat: MAX_VALUE_MSAT,
- fee_base_msat: 0,
- fee_proportional_millionths: 0,
- excess_data: Vec::new()
- });
-
- add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[5], NodeFeatures::from_le_bytes(id_to_feature_flags(6)), 0);
-
- (secp_ctx, network_graph, gossip_sync, chain_monitor, logger)
- }
-
#[test]
fn simple_route_test() {
let (secp_ctx, network_graph, _, _, logger) = build_graph();
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
let payment_params = PaymentParameters::from_node_id(nodes[2]);
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
// Simple route to 2 via 1
let (secp_ctx, network_graph, _, _, logger) = build_graph();
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
let payment_params = PaymentParameters::from_node_id(nodes[2]);
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
// Simple route to 2 via 1
let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph();
let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
let payment_params = PaymentParameters::from_node_id(nodes[2]);
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
// Simple route to 2 via 1
let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph();
let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(channelmanager::provided_invoice_features());
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
// A route to node#2 via two paths.
let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph();
let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
let payment_params = PaymentParameters::from_node_id(nodes[2]);
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
// // Disable channels 4 and 12 by flags=2
let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph();
let (_, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
let payment_params = PaymentParameters::from_node_id(nodes[2]);
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
// Disable nodes 1, 2, and 8 by requiring unknown feature bits
- let mut unknown_features = NodeFeatures::known();
+ let mut unknown_features = NodeFeatures::empty();
unknown_features.set_unknown_feature_required();
add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[0], unknown_features.clone(), 1);
add_or_update_node(&gossip_sync, &secp_ctx, &privkeys[1], unknown_features.clone(), 1);
fn our_chans_test() {
let (secp_ctx, network_graph, _, _, logger) = build_graph();
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
// Route to 1 via 2 and 3 because our channel to 1 is disabled
fn partial_route_hint_test() {
let (secp_ctx, network_graph, _, _, logger) = build_graph();
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
// Simple test across 2, 3, 5, and 4 via a last_hop channel
let (secp_ctx, network_graph, _, _, logger) = build_graph();
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
let payment_params = PaymentParameters::from_node_id(nodes[6]).with_route_hints(empty_last_hop(&nodes));
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
// Test handling of an empty RouteHint passed in Invoice.
let (_, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
let last_hops = multi_hop_last_hops_hint([nodes[2], nodes[3]]);
let payment_params = PaymentParameters::from_node_id(nodes[6]).with_route_hints(last_hops.clone());
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
// Test through channels 2, 3, 0xff00, 0xff01.
// Test shows that multiple hop hints are considered.
let last_hops = multi_hop_last_hops_hint([nodes[2], non_announced_pubkey]);
let payment_params = PaymentParameters::from_node_id(nodes[6]).with_route_hints(last_hops.clone());
- let scorer = test_utils::TestScorer::with_penalty(0);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
// Test through channels 2, 3, 0xff00, 0xff01.
// Test shows that multiple hop hints are considered.
let (secp_ctx, network_graph, _, _, logger) = build_graph();
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
let payment_params = PaymentParameters::from_node_id(nodes[6]).with_route_hints(last_hops_with_public_channel(&nodes));
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
// This test shows that public routes can be present in the invoice
// which would be handled in the same manner.
fn our_chans_last_hop_connect_test() {
let (secp_ctx, network_graph, _, _, logger) = build_graph();
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
// Simple test with outbound channel to 4 to test that last_hops and first_hops connect
}]);
let payment_params = PaymentParameters::from_node_id(target_node_id).with_route_hints(vec![last_hops]);
let our_chans = vec![get_channel_details(Some(42), middle_node_id, InitFeatures::from_le_bytes(vec![0b11]), outbound_capacity_msat)];
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
- let logger = test_utils::TestLogger::new();
+ let logger = ln_test_utils::TestLogger::new();
let network_graph = NetworkGraph::new(genesis_hash, &logger);
let route = get_route(&source_node_id, &payment_params, &network_graph.read_only(),
Some(&our_chans.iter().collect::<Vec<_>>()), route_val, 42, &logger, &scorer, &random_seed_bytes);
let (secp_ctx, network_graph, mut gossip_sync, chain_monitor, logger) = build_graph();
let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(channelmanager::provided_invoice_features());
// one of the latter hops is limited.
let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph();
let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
let payment_params = PaymentParameters::from_node_id(nodes[3]).with_features(channelmanager::provided_invoice_features());
fn ignore_fee_first_hop_test() {
let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph();
let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
let payment_params = PaymentParameters::from_node_id(nodes[2]);
fn simple_mpp_route_test() {
let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph();
let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
let payment_params = PaymentParameters::from_node_id(nodes[2])
.with_features(channelmanager::provided_invoice_features());
fn long_mpp_route_test() {
let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph();
let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
let payment_params = PaymentParameters::from_node_id(nodes[3]).with_features(channelmanager::provided_invoice_features());
fn mpp_cheaper_route_test() {
let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph();
let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
let payment_params = PaymentParameters::from_node_id(nodes[3]).with_features(channelmanager::provided_invoice_features());
// if the fee is not properly accounted for, the behavior is different.
let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph();
let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
let payment_params = PaymentParameters::from_node_id(nodes[3]).with_features(channelmanager::provided_invoice_features());
// This bug appeared in production in some specific channel configurations.
let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph();
let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
let payment_params = PaymentParameters::from_node_id(PublicKey::from_slice(&[02; 33]).unwrap()).with_features(channelmanager::provided_invoice_features())
.with_route_hints(vec![RouteHint(vec![RouteHintHop {
// path finding we realize that we found more capacity than we need.
let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph();
let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(channelmanager::provided_invoice_features())
.with_max_channel_saturation_power_of_half(0);
// "previous hop" being set to node 3, creating a loop in the path.
let secp_ctx = Secp256k1::new();
let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
- let logger = Arc::new(test_utils::TestLogger::new());
+ let logger = Arc::new(ln_test_utils::TestLogger::new());
let network = Arc::new(NetworkGraph::new(genesis_hash, Arc::clone(&logger)));
let gossip_sync = P2PGossipSync::new(Arc::clone(&network), None, Arc::clone(&logger));
let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
let payment_params = PaymentParameters::from_node_id(nodes[6]);
// we calculated fees on a higher value, resulting in us ignoring such paths.
let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph();
let (our_privkey, our_id, _, nodes) = get_nodes(&secp_ctx);
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
let payment_params = PaymentParameters::from_node_id(nodes[2]);
// resulting in us thinking there is no possible path, even if other paths exist.
let (secp_ctx, network_graph, gossip_sync, _, logger) = build_graph();
let (our_privkey, our_id, privkeys, nodes) = get_nodes(&secp_ctx);
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(channelmanager::provided_invoice_features());
let secp_ctx = Secp256k1::new();
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
let genesis_hash = genesis_block(Network::Testnet).header.block_hash();
- let logger = Arc::new(test_utils::TestLogger::new());
+ let logger = Arc::new(ln_test_utils::TestLogger::new());
let network_graph = NetworkGraph::new(genesis_hash, Arc::clone(&logger));
- let scorer = test_utils::TestScorer::with_penalty(0);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
let payment_params = PaymentParameters::from_node_id(nodes[0]).with_features(channelmanager::provided_invoice_features());
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
{
let payment_params = PaymentParameters::from_node_id(nodes[6]).with_route_hints(last_hops(&nodes));
// Without penalizing each hop 100 msats, a longer path with lower fees is chosen.
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
let route = get_route(
&our_id, &payment_params, &network_graph.read_only(), None, 100, 42,
// Applying a 100 msat penalty to each hop results in taking channels 7 and 10 to nodes[6]
// from nodes[2] rather than channel 6, 11, and 8, even though the longer path is cheaper.
- let scorer = test_utils::TestScorer::with_penalty(100);
+ let scorer = ln_test_utils::TestScorer::with_penalty(100);
let route = get_route(
&our_id, &payment_params, &network_graph.read_only(), None, 100, 42,
Arc::clone(&logger), &scorer, &random_seed_bytes
#[cfg(c_bindings)]
impl Writeable for BadChannelScorer {
- fn write<W: Writer>(&self, _w: &mut W) -> Result<(), ::io::Error> { unimplemented!() }
+ fn write<W: Writer>(&self, _w: &mut W) -> Result<(), crate::io::Error> { unimplemented!() }
}
impl Score for BadChannelScorer {
fn channel_penalty_msat(&self, short_channel_id: u64, _: &NodeId, _: &NodeId, _: ChannelUsage) -> u64 {
#[cfg(c_bindings)]
impl Writeable for BadNodeScorer {
- fn write<W: Writer>(&self, _w: &mut W) -> Result<(), ::io::Error> { unimplemented!() }
+ fn write<W: Writer>(&self, _w: &mut W) -> Result<(), crate::io::Error> { unimplemented!() }
}
impl Score for BadNodeScorer {
let network_graph = network.read_only();
// A path to nodes[6] exists when no penalties are applied to any channel.
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
let route = get_route(
&our_id, &payment_params, &network_graph, None, 100, 42,
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
let network_graph = network.read_only();
- let scorer = test_utils::TestScorer::with_penalty(0);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
// Make sure that generally there is at least one route available
let feasible_max_total_cltv_delta = 1008;
let feasible_payment_params = PaymentParameters::from_node_id(nodes[6]).with_route_hints(last_hops(&nodes))
.with_max_total_cltv_expiry_delta(feasible_max_total_cltv_delta);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
let route = get_route(&our_id, &feasible_payment_params, &network_graph, None, 100, 0, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap();
let path = route.paths[0].iter().map(|hop| hop.short_channel_id).collect::<Vec<_>>();
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
let network_graph = network.read_only();
- let scorer = test_utils::TestScorer::with_penalty(0);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
let mut payment_params = PaymentParameters::from_node_id(nodes[6]).with_route_hints(last_hops(&nodes))
.with_max_path_count(1);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
// We should be able to find a route initially, and then after we fail a few random
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
let network_graph = network.read_only();
- let scorer = test_utils::TestScorer::with_penalty(0);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
// First check we can actually create a long route on this graph.
let (secp_ctx, network_graph, _, _, logger) = build_graph();
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
- let scorer = test_utils::TestScorer::with_penalty(0);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
let payment_params = PaymentParameters::from_node_id(nodes[6]).with_route_hints(last_hops(&nodes));
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
let route = get_route(&our_id, &payment_params, &network_graph.read_only(), None, 100, 42, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap();
assert_eq!(route.paths.len(), 1);
let network_graph = network.read_only();
let network_nodes = network_graph.nodes();
let network_channels = network_graph.channels();
- let scorer = test_utils::TestScorer::with_penalty(0);
+ let scorer = ln_test_utils::TestScorer::with_penalty(0);
let payment_params = PaymentParameters::from_node_id(nodes[3]);
- let keys_manager = test_utils::TestKeysInterface::new(&[4u8; 32], Network::Testnet);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[4u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
let mut route = get_route(&our_id, &payment_params, &network_graph, None, 100, 0,
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
let network_graph = network.read_only();
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
let payment_params = PaymentParameters::from_node_id(nodes[3]);
});
let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(channelmanager::provided_invoice_features());
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
// 100,000 sats is less than the available liquidity on each channel, set above.
let route = get_route(&our_id, &payment_params, &network_graph.read_only(), None, 100_000_000, 42, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap();
seed
}
#[cfg(not(feature = "no-std"))]
- use util::ser::ReadableArgs;
+ use crate::util::ser::ReadableArgs;
#[test]
#[cfg(not(feature = "no-std"))]
fn generate_routes() {
- use routing::scoring::{ProbabilisticScorer, ProbabilisticScoringParameters};
+ use crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringParameters};
- let mut d = match super::test_utils::get_route_file() {
+ let mut d = match super::bench_utils::get_route_file() {
Ok(f) => f,
Err(e) => {
eprintln!("{}", e);
return;
},
};
- let logger = test_utils::TestLogger::new();
+ let logger = ln_test_utils::TestLogger::new();
let graph = NetworkGraph::read(&mut d, &logger).unwrap();
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
// First, get 100 (source, destination) pairs for which route-getting actually succeeds...
#[test]
#[cfg(not(feature = "no-std"))]
fn generate_routes_mpp() {
- use routing::scoring::{ProbabilisticScorer, ProbabilisticScoringParameters};
+ use crate::routing::scoring::{ProbabilisticScorer, ProbabilisticScoringParameters};
- let mut d = match super::test_utils::get_route_file() {
+ let mut d = match super::bench_utils::get_route_file() {
Ok(f) => f,
Err(e) => {
eprintln!("{}", e);
return;
},
};
- let logger = test_utils::TestLogger::new();
+ let logger = ln_test_utils::TestLogger::new();
let graph = NetworkGraph::read(&mut d, &logger).unwrap();
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
// First, get 100 (source, destination) pairs for which route-getting actually succeeds...
let (secp_ctx, network_graph, _, _, logger) = build_line_graph();
let (_, our_id, _, nodes) = get_nodes(&secp_ctx);
- let keys_manager = test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
+ let keys_manager = ln_test_utils::TestKeysInterface::new(&[0u8; 32], Network::Testnet);
let random_seed_bytes = keys_manager.get_secure_random_bytes();
let scorer_params = ProbabilisticScoringParameters::default();
}
#[cfg(all(test, not(feature = "no-std")))]
-pub(crate) mod test_utils {
+pub(crate) mod bench_utils {
use std::fs::File;
/// Tries to open a network graph file, or panics with a URL to fetch it.
pub(crate) fn get_route_file() -> Result<std::fs::File, &'static str> {
use super::*;
use bitcoin::hashes::Hash;
use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
- use chain::transaction::OutPoint;
- use chain::keysinterface::{KeysManager,KeysInterface};
- use ln::channelmanager::{self, ChannelCounterparty, ChannelDetails};
- use ln::features::{InitFeatures, InvoiceFeatures};
- use routing::gossip::NetworkGraph;
- use routing::scoring::{FixedPenaltyScorer, ProbabilisticScorer, ProbabilisticScoringParameters};
- use util::logger::{Logger, Record};
- use util::ser::ReadableArgs;
+ use crate::chain::transaction::OutPoint;
+ use crate::chain::keysinterface::{KeysManager,KeysInterface};
+ use crate::ln::channelmanager::{self, ChannelCounterparty, ChannelDetails};
+ use crate::ln::features::InvoiceFeatures;
+ use crate::routing::gossip::NetworkGraph;
+ use crate::routing::scoring::{FixedPenaltyScorer, ProbabilisticScorer, ProbabilisticScoringParameters};
+ use crate::util::logger::{Logger, Record};
+ use crate::util::ser::ReadableArgs;
use test::Bencher;
}
fn read_network_graph(logger: &DummyLogger) -> NetworkGraph<&DummyLogger> {
- let mut d = test_utils::get_route_file().unwrap();
+ let mut d = bench_utils::get_route_file().unwrap();
NetworkGraph::read(&mut d, logger).unwrap()
}