#[cfg(test)]
mod tests {
use chain;
+ use ln::channelmanager;
use ln::chan_utils::make_funding_redeemscript;
use ln::PaymentHash;
- use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
+ use ln::features::InitFeatures;
use routing::gossip::{P2PGossipSync, NetworkGraph, NetworkUpdate, NodeAlias, MAX_EXCESS_BYTES_FOR_RELAY, NodeId, RoutingFees, ChannelUpdateInfo, ChannelInfo, NodeAnnouncementInfo, NodeInfo};
use ln::msgs::{RoutingMessageHandler, UnsignedNodeAnnouncement, NodeAnnouncement,
UnsignedChannelAnnouncement, ChannelAnnouncement, UnsignedChannelUpdate, ChannelUpdate,
fn get_signed_node_announcement<F: Fn(&mut UnsignedNodeAnnouncement)>(f: F, node_key: &SecretKey, secp_ctx: &Secp256k1<secp256k1::All>) -> NodeAnnouncement {
let node_id = PublicKey::from_secret_key(&secp_ctx, node_key);
let mut unsigned_announcement = UnsignedNodeAnnouncement {
- features: NodeFeatures::known(),
+ features: channelmanager::provided_node_features(),
timestamp: 100,
node_id: node_id,
rgb: [0; 3],
let node_2_btckey = &SecretKey::from_slice(&[39; 32]).unwrap();
let mut unsigned_announcement = UnsignedChannelAnnouncement {
- features: ChannelFeatures::known(),
+ features: channelmanager::provided_channel_features(),
chain_hash: genesis_block(Network::Testnet).header.block_hash(),
short_channel_id: 0,
node_id_1,
// It should ignore if gossip_queries feature is not enabled
{
- let init_msg = Init { features: InitFeatures::known().clear_gossip_queries(), remote_network_address: None };
+ let init_msg = Init { features: InitFeatures::empty(), remote_network_address: None };
gossip_sync.peer_connected(&node_id_1, &init_msg).unwrap();
let events = gossip_sync.get_and_clear_pending_msg_events();
assert_eq!(events.len(), 0);
// It should send a gossip_timestamp_filter with the correct information
{
- let init_msg = Init { features: InitFeatures::known(), remote_network_address: None };
+ let mut features = InitFeatures::empty();
+ features.set_gossip_queries_optional();
+ let init_msg = Init { features, remote_network_address: None };
gossip_sync.peer_connected(&node_id_1, &init_msg).unwrap();
let events = gossip_sync.get_and_clear_pending_msg_events();
assert_eq!(events.len(), 1);
// 2. Test encoding/decoding of ChannelInfo
// Check we can encode/decode ChannelInfo without ChannelUpdateInfo fields present.
let chan_info_none_updates = ChannelInfo {
- features: ChannelFeatures::known(),
+ features: channelmanager::provided_channel_features(),
node_one: NodeId::from_pubkey(&nodes[0].node.get_our_node_id()),
one_to_two: None,
node_two: NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
// Check we can encode/decode ChannelInfo with ChannelUpdateInfo fields present.
let chan_info_some_updates = ChannelInfo {
- features: ChannelFeatures::known(),
+ features: channelmanager::provided_channel_features(),
node_one: NodeId::from_pubkey(&nodes[0].node.get_our_node_id()),
one_to_two: Some(chan_update_info.clone()),
node_two: NodeId::from_pubkey(&nodes[1].node.get_our_node_id()),
// 1. Check we can read a valid NodeAnnouncementInfo and fail on an invalid one
let valid_netaddr = ::ln::msgs::NetAddress::Hostname { hostname: ::util::ser::Hostname::try_from("A".to_string()).unwrap(), port: 1234 };
let valid_node_ann_info = NodeAnnouncementInfo {
- features: NodeFeatures::known(),
+ features: channelmanager::provided_node_features(),
last_update: 0,
rgb: [0u8; 3],
alias: NodeAlias([0u8; 32]),
use routing::scoring::{ChannelUsage, Score, ProbabilisticScorer, ProbabilisticScoringParameters};
use chain::transaction::OutPoint;
use chain::keysinterface::KeysInterface;
- use ln::features::{ChannelFeatures, InitFeatures, InvoiceFeatures, NodeFeatures};
+ use ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
use ln::msgs::{ErrorAction, LightningError, UnsignedChannelAnnouncement, ChannelAnnouncement, RoutingMessageHandler,
NodeAnnouncement, UnsignedNodeAnnouncement, ChannelUpdate, UnsignedChannelUpdate, MAX_VALUE_MSAT};
use ln::channelmanager;
fn htlc_minimum_overpay_test() {
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(InvoiceFeatures::known());
+ 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 random_seed_bytes = keys_manager.get_secure_random_bytes();
let scorer = test_utils::TestScorer::with_penalty(0);
let keys_manager = 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(InvoiceFeatures::known());
+ let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(channelmanager::provided_invoice_features());
// We will use a simple single-path route from
// our node to node2 via node0: channels {1, 3}.
let scorer = test_utils::TestScorer::with_penalty(0);
let keys_manager = 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(InvoiceFeatures::known());
+ let payment_params = PaymentParameters::from_node_id(nodes[3]).with_features(channelmanager::provided_invoice_features());
// Path via {node7, node2, node4} is channels {12, 13, 6, 11}.
// {12, 13, 11} have the capacities of 100, {6} has a capacity of 50.
let keys_manager = 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(InvoiceFeatures::known());
+ .with_features(channelmanager::provided_invoice_features());
// We need a route consisting of 3 paths:
// From our node to node2 via node0, node7, node1 (three paths one hop each).
let scorer = test_utils::TestScorer::with_penalty(0);
let keys_manager = 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(InvoiceFeatures::known());
+ let payment_params = PaymentParameters::from_node_id(nodes[3]).with_features(channelmanager::provided_invoice_features());
// We need a route consisting of 3 paths:
// From our node to node3 via {node0, node2}, {node7, node2, node4} and {node7, node2}.
let scorer = test_utils::TestScorer::with_penalty(0);
let keys_manager = 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(InvoiceFeatures::known());
+ let payment_params = PaymentParameters::from_node_id(nodes[3]).with_features(channelmanager::provided_invoice_features());
// This test checks that if we have two cheaper paths and one more expensive path,
// so that liquidity-wise any 2 of 3 combination is sufficient,
let scorer = test_utils::TestScorer::with_penalty(0);
let keys_manager = 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(InvoiceFeatures::known());
+ let payment_params = PaymentParameters::from_node_id(nodes[3]).with_features(channelmanager::provided_invoice_features());
// We need a route consisting of 2 paths:
// From our node to node3 via {node0, node2} and {node7, node2, node4}.
let scorer = test_utils::TestScorer::with_penalty(0);
let keys_manager = 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(InvoiceFeatures::known())
+ 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 {
src_node_id: nodes[2],
short_channel_id: 42,
let scorer = test_utils::TestScorer::with_penalty(0);
let keys_manager = 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(InvoiceFeatures::known())
+ let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(channelmanager::provided_invoice_features())
.with_max_channel_saturation_power_of_half(0);
// We need a route consisting of 3 paths:
let scorer = test_utils::TestScorer::with_penalty(0);
let keys_manager = 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(InvoiceFeatures::known());
+ let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(channelmanager::provided_invoice_features());
// We modify the graph to set the htlc_minimum of channel 2 and 4 as needed - channel 2
// gets an htlc_maximum_msat of 80_000 and channel 4 an htlc_minimum_msat of 90_000. We
assert_eq!(route.paths[0][1].short_channel_id, 13);
assert_eq!(route.paths[0][1].fee_msat, 90_000);
assert_eq!(route.paths[0][1].cltv_expiry_delta, 42);
- assert_eq!(route.paths[0][1].node_features.le_flags(), InvoiceFeatures::known().le_flags());
+ assert_eq!(route.paths[0][1].node_features.le_flags(), channelmanager::provided_invoice_features().le_flags());
assert_eq!(route.paths[0][1].channel_features.le_flags(), &id_to_feature_flags(13));
}
}
let logger = Arc::new(test_utils::TestLogger::new());
let network_graph = NetworkGraph::new(genesis_hash, Arc::clone(&logger));
let scorer = test_utils::TestScorer::with_penalty(0);
- let payment_params = PaymentParameters::from_node_id(nodes[0]).with_features(InvoiceFeatures::known());
+ 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 random_seed_bytes = keys_manager.get_secure_random_bytes();
{
let route = get_route(&our_id, &payment_params, &network_graph.read_only(), Some(&[
- &get_channel_details(Some(3), nodes[0], InitFeatures::known(), 200_000),
- &get_channel_details(Some(2), nodes[0], InitFeatures::known(), 10_000),
+ &get_channel_details(Some(3), nodes[0], channelmanager::provided_init_features(), 200_000),
+ &get_channel_details(Some(2), nodes[0], channelmanager::provided_init_features(), 10_000),
]), 100_000, 42, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap();
assert_eq!(route.paths.len(), 1);
assert_eq!(route.paths[0].len(), 1);
}
{
let route = get_route(&our_id, &payment_params, &network_graph.read_only(), Some(&[
- &get_channel_details(Some(3), nodes[0], InitFeatures::known(), 50_000),
- &get_channel_details(Some(2), nodes[0], InitFeatures::known(), 50_000),
+ &get_channel_details(Some(3), nodes[0], channelmanager::provided_init_features(), 50_000),
+ &get_channel_details(Some(2), nodes[0], channelmanager::provided_init_features(), 50_000),
]), 100_000, 42, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap();
assert_eq!(route.paths.len(), 2);
assert_eq!(route.paths[0].len(), 1);
// smallest of them, avoiding further fragmenting our available outbound balance to
// this node.
let route = get_route(&our_id, &payment_params, &network_graph.read_only(), Some(&[
- &get_channel_details(Some(2), nodes[0], InitFeatures::known(), 50_000),
- &get_channel_details(Some(3), nodes[0], InitFeatures::known(), 50_000),
- &get_channel_details(Some(5), nodes[0], InitFeatures::known(), 50_000),
- &get_channel_details(Some(6), nodes[0], InitFeatures::known(), 300_000),
- &get_channel_details(Some(7), nodes[0], InitFeatures::known(), 50_000),
- &get_channel_details(Some(8), nodes[0], InitFeatures::known(), 50_000),
- &get_channel_details(Some(9), nodes[0], InitFeatures::known(), 50_000),
- &get_channel_details(Some(4), nodes[0], InitFeatures::known(), 1_000_000),
+ &get_channel_details(Some(2), nodes[0], channelmanager::provided_init_features(), 50_000),
+ &get_channel_details(Some(3), nodes[0], channelmanager::provided_init_features(), 50_000),
+ &get_channel_details(Some(5), nodes[0], channelmanager::provided_init_features(), 50_000),
+ &get_channel_details(Some(6), nodes[0], channelmanager::provided_init_features(), 300_000),
+ &get_channel_details(Some(7), nodes[0], channelmanager::provided_init_features(), 50_000),
+ &get_channel_details(Some(8), nodes[0], channelmanager::provided_init_features(), 50_000),
+ &get_channel_details(Some(9), nodes[0], channelmanager::provided_init_features(), 50_000),
+ &get_channel_details(Some(4), nodes[0], channelmanager::provided_init_features(), 1_000_000),
]), 100_000, 42, Arc::clone(&logger), &scorer, &random_seed_bytes).unwrap();
assert_eq!(route.paths.len(), 1);
assert_eq!(route.paths[0].len(), 1);
excess_data: Vec::new()
});
- let payment_params = PaymentParameters::from_node_id(nodes[2]).with_features(InvoiceFeatures::known());
+ 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 random_seed_bytes = keys_manager.get_secure_random_bytes();
// 100,000 sats is less than the available liquidity on each channel, set above.
let src = &PublicKey::from_slice(nodes.keys().skip(seed % nodes.len()).next().unwrap().as_slice()).unwrap();
seed = seed.overflowing_mul(0xdeadbeef).0;
let dst = PublicKey::from_slice(nodes.keys().skip(seed % nodes.len()).next().unwrap().as_slice()).unwrap();
- let payment_params = PaymentParameters::from_node_id(dst).with_features(InvoiceFeatures::known());
+ let payment_params = PaymentParameters::from_node_id(dst).with_features(channelmanager::provided_invoice_features());
let amt = seed as u64 % 200_000_000;
let params = ProbabilisticScoringParameters::default();
let scorer = ProbabilisticScorer::new(params, &graph, &logger);
use bitcoin::secp256k1::{PublicKey, Secp256k1, SecretKey};
use chain::transaction::OutPoint;
use chain::keysinterface::{KeysManager,KeysInterface};
- use ln::channelmanager::{ChannelCounterparty, ChannelDetails};
+ use ln::channelmanager::{self, ChannelCounterparty, ChannelDetails};
use ln::features::{InitFeatures, InvoiceFeatures};
use routing::gossip::NetworkGraph;
use routing::scoring::{FixedPenaltyScorer, ProbabilisticScorer, ProbabilisticScoringParameters};
ChannelDetails {
channel_id: [0; 32],
counterparty: ChannelCounterparty {
- features: InitFeatures::known(),
+ features: channelmanager::provided_init_features(),
node_id,
unspendable_punishment_reserve: 0,
forwarding_info: None,
let logger = DummyLogger {};
let network_graph = read_network_graph(&logger);
let scorer = FixedPenaltyScorer::with_penalty(0);
- generate_routes(bench, &network_graph, scorer, InvoiceFeatures::known());
+ generate_routes(bench, &network_graph, scorer, channelmanager::provided_invoice_features());
}
#[bench]
let network_graph = read_network_graph(&logger);
let params = ProbabilisticScoringParameters::default();
let scorer = ProbabilisticScorer::new(params, &network_graph, &logger);
- generate_routes(bench, &network_graph, scorer, InvoiceFeatures::known());
+ generate_routes(bench, &network_graph, scorer, channelmanager::provided_invoice_features());
}
fn generate_routes<S: Score>(