X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=inline;f=lightning%2Fsrc%2Fln%2Fonion_route_tests.rs;h=a26e68e728212054fafe3b67559e697063579b0f;hb=3ecc5aee4a60b855ffdd3d80b7f6f841d41600f5;hp=2362593a3dfd53a472640843062e2f9913c0d4e2;hpb=6777ab643cc4d930b79c3e0f60ff55ce02680e30;p=rust-lightning diff --git a/lightning/src/ln/onion_route_tests.rs b/lightning/src/ln/onion_route_tests.rs index 2362593a..a26e68e7 100644 --- a/lightning/src/ln/onion_route_tests.rs +++ b/lightning/src/ln/onion_route_tests.rs @@ -19,7 +19,7 @@ use crate::ln::channelmanager::{self, ChannelManager, ChannelManagerReadArgs, HT use crate::ln::onion_utils; use crate::routing::gossip::{NetworkUpdate, RoutingFees}; use crate::routing::router::{get_route, PaymentParameters, Route, RouteHint, RouteHintHop}; -use crate::ln::features::InitFeatures; +use crate::ln::features::{InitFeatures, InvoiceFeatures}; use crate::ln::msgs; use crate::ln::msgs::{ChannelMessageHandler, ChannelUpdate}; use crate::ln::wire::Encode; @@ -344,7 +344,7 @@ fn test_onion_failure() { // break the first (non-final) hop payload by swapping the realm (0) byte for a byte // describing a length-1 TLV payload, which is obviously bogus. new_payloads[0].data[0] = 1; - msg.onion_routing_packet = onion_utils::construct_onion_packet_bogus_hopdata(new_payloads, onion_keys, [0; 32], &payment_hash); + msg.onion_routing_packet = onion_utils::construct_onion_packet_with_writable_hopdata(new_payloads, onion_keys, [0; 32], &payment_hash); }, ||{}, true, Some(PERM|22), Some(NetworkUpdate::ChannelFailure{short_channel_id, is_permanent: true}), Some(short_channel_id)); // final node failure @@ -361,7 +361,7 @@ fn test_onion_failure() { // break the last-hop payload by swapping the realm (0) byte for a byte describing a // length-1 TLV payload, which is obviously bogus. new_payloads[1].data[0] = 1; - msg.onion_routing_packet = onion_utils::construct_onion_packet_bogus_hopdata(new_payloads, onion_keys, [0; 32], &payment_hash); + msg.onion_routing_packet = onion_utils::construct_onion_packet_with_writable_hopdata(new_payloads, onion_keys, [0; 32], &payment_hash); }, ||{}, false, Some(PERM|22), Some(NetworkUpdate::ChannelFailure{short_channel_id, is_permanent: true}), Some(short_channel_id)); // the following three with run_onion_failure_test_with_fail_intercept() test only the origin node @@ -790,6 +790,56 @@ fn test_onion_failure_stale_channel_update() { do_test_onion_failure_stale_channel_update(true); } +#[test] +fn test_always_create_tlv_format_onion_payloads() { + // Verify that we always generate tlv onion format payloads, even if the features specifically + // specifies no support for variable length onions, as the legacy payload format has been + // deprecated in BOLT4. + let chanmon_cfgs = create_chanmon_cfgs(3); + let mut node_cfgs = create_node_cfgs(3, &chanmon_cfgs); + + // Set `node[1]`'s config features to features which return `false` for + // `supports_variable_length_onion()` + let mut no_variable_length_onion_features = InitFeatures::empty(); + no_variable_length_onion_features.set_static_remote_key_required(); + let mut node_1_cfg = &mut node_cfgs[1]; + node_1_cfg.features = no_variable_length_onion_features; + + let node_chanmgrs = create_node_chanmgrs(3, &node_cfgs, &[None, None, None]); + let mut nodes = create_network(3, &node_cfgs, &node_chanmgrs); + + create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::empty(), InitFeatures::empty()); + create_announced_chan_between_nodes(&nodes, 1, 2, InitFeatures::empty(), InitFeatures::empty()); + + let payment_params = PaymentParameters::from_node_id(nodes[2].node.get_our_node_id()) + .with_features(InvoiceFeatures::empty()); + let (route, _payment_hash, _payment_preimage, _payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[2], payment_params, 40000, TEST_FINAL_CLTV); + + let hops = &route.paths[0]; + // Asserts that the first hop to `node[1]` signals no support for variable length onions. + assert!(!hops[0].node_features.supports_variable_length_onion()); + // Asserts that the first hop to `node[1]` signals no support for variable length onions. + assert!(!hops[1].node_features.supports_variable_length_onion()); + + let cur_height = nodes[0].best_block_info().1 + 1; + let (onion_payloads, _htlc_msat, _htlc_cltv) = onion_utils::build_onion_payloads(&route.paths[0], 40000, &None, cur_height, &None).unwrap(); + + match onion_payloads[0].format { + msgs::OnionHopDataFormat::NonFinalNode {..} => {}, + _ => { panic!( + "Should have generated a `msgs::OnionHopDataFormat::NonFinalNode` payload for `hops[0]`, + despite that the features signals no support for variable length onions" + )} + } + match onion_payloads[1].format { + msgs::OnionHopDataFormat::FinalNode {..} => {}, + _ => {panic!( + "Should have generated a `msgs::OnionHopDataFormat::FinalNode` payload for `hops[1]`, + despite that the features signals no support for variable length onions" + )} + } +} + macro_rules! get_phantom_route { ($nodes: expr, $amt: expr, $channel: expr) => {{ let secp_ctx = Secp256k1::new();