Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lightning/src/ln/channel_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,12 +496,12 @@ impl ChannelDetails {
/// This should be used in [`Route`]s to describe the first hop or in other contexts where
/// we're sending or forwarding a payment outbound over this channel.
///
/// This is either the [`ChannelDetails::short_channel_id`], if set, or the
/// [`ChannelDetails::outbound_scid_alias`]. See those for more information.
/// This is either the [`ChannelDetails::outbound_scid_alias`], if set, or the
/// [`ChannelDetails::short_channel_id`]. See those for more information.
///
/// [`Route`]: crate::routing::router::Route
pub fn get_outbound_payment_scid(&self) -> Option<u64> {
self.short_channel_id.or(self.outbound_scid_alias)
self.outbound_scid_alias.or(self.short_channel_id)
}

/// Gets the funding output for this channel, if available.
Expand Down
218 changes: 194 additions & 24 deletions lightning/src/ln/onion_route_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,14 @@ fn test_fee_failures() {
// malleated the payment before forwarding, taking funds when they shouldn't have. However,
// because we ignore channel update contents, we will still blame the 2nd channel.
let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
let short_channel_id = channels[1].0.contents.short_channel_id;
let short_channel_id = nodes[1]
.node
.list_channels()
.iter()
.find(|c| c.counterparty.node_id == nodes[2].node.get_our_node_id())
.unwrap()
.short_channel_id
.unwrap();
run_onion_failure_test(
"fee_insufficient",
100,
Expand Down Expand Up @@ -510,7 +517,14 @@ fn test_onion_failure() {
};

// intermediate node failure
let short_channel_id = channels[1].0.contents.short_channel_id;
let short_channel_id = nodes[1]
.node
.list_channels()
.iter()
.find(|c| c.counterparty.node_id == nodes[2].node.get_our_node_id())
.unwrap()
.short_channel_id
.unwrap();
run_onion_failure_test(
"invalid_realm",
0,
Expand Down Expand Up @@ -552,7 +566,14 @@ fn test_onion_failure() {
);

// final node failure
let short_channel_id = channels[1].0.contents.short_channel_id;
let short_channel_id = nodes[1]
.node
.list_channels()
.iter()
.find(|c| c.counterparty.node_id == nodes[2].node.get_our_node_id())
.unwrap()
.short_channel_id
.unwrap();
run_onion_failure_test(
"invalid_realm",
3,
Expand Down Expand Up @@ -633,6 +654,14 @@ fn test_onion_failure() {
);

// final node failure
let hop_1_scid = nodes[1]
.node
.list_channels()
.iter()
.find(|c| c.counterparty.node_id == nodes[2].node.get_our_node_id())
.unwrap()
.short_channel_id
.unwrap();
run_onion_failure_test_with_fail_intercept(
"temporary_node_failure",
200,
Expand Down Expand Up @@ -664,7 +693,7 @@ fn test_onion_failure() {
node_id: route.paths[0].hops[1].pubkey,
is_permanent: false,
}),
Some(route.paths[0].hops[1].short_channel_id),
Some(hop_1_scid),
None,
);
let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
Expand Down Expand Up @@ -735,7 +764,16 @@ fn test_onion_failure() {
node_id: route.paths[0].hops[1].pubkey,
is_permanent: true,
}),
Some(route.paths[0].hops[1].short_channel_id),
Some(
nodes[1]
.node
.list_channels()
.iter()
.find(|c| c.counterparty.node_id == nodes[2].node.get_our_node_id())
.unwrap()
.short_channel_id
.unwrap(),
),
None,
);
let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);
Expand Down Expand Up @@ -808,14 +846,23 @@ fn test_onion_failure() {
node_id: route.paths[0].hops[1].pubkey,
is_permanent: true,
}),
Some(route.paths[0].hops[1].short_channel_id),
Some(
nodes[1]
.node
.list_channels()
.iter()
.find(|c| c.counterparty.node_id == nodes[2].node.get_our_node_id())
.unwrap()
.short_channel_id
.unwrap(),
),
None,
);
let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[2]);

// Our immediate peer sent UpdateFailMalformedHTLC because it couldn't understand the onion in
// the UpdateAddHTLC that we sent.
let short_channel_id = channels[0].0.contents.short_channel_id;
let short_channel_id = route.paths[0].hops[0].short_channel_id;
run_onion_failure_test(
"invalid_onion_version",
0,
Expand Down Expand Up @@ -870,7 +917,14 @@ fn test_onion_failure() {
Some(HTLCHandlingFailureType::InvalidOnion),
);

let short_channel_id = channels[1].0.contents.short_channel_id;
let short_channel_id = nodes[1]
.node
.list_channels()
.iter()
.find(|c| c.counterparty.node_id == nodes[2].node.get_our_node_id())
.unwrap()
.short_channel_id
.unwrap();
let chan_update = ChannelUpdate::dummy(short_channel_id);

let mut err_data = Vec::new();
Expand Down Expand Up @@ -941,7 +995,14 @@ fn test_onion_failure() {
Some(next_hop_failure.clone()),
);

let short_channel_id = channels[1].0.contents.short_channel_id;
let short_channel_id = nodes[1]
.node
.list_channels()
.iter()
.find(|c| c.counterparty.node_id == nodes[2].node.get_our_node_id())
.unwrap()
.short_channel_id
.unwrap();
run_onion_failure_test_with_fail_intercept(
"permanent_channel_failure",
100,
Expand Down Expand Up @@ -974,7 +1035,14 @@ fn test_onion_failure() {
Some(next_hop_failure.clone()),
);

let short_channel_id = channels[1].0.contents.short_channel_id;
let short_channel_id = nodes[1]
.node
.list_channels()
.iter()
.find(|c| c.counterparty.node_id == nodes[2].node.get_our_node_id())
.unwrap()
.short_channel_id
.unwrap();
run_onion_failure_test_with_fail_intercept(
"required_channel_feature_missing",
100,
Expand Down Expand Up @@ -1008,8 +1076,16 @@ fn test_onion_failure() {
);

let mut bogus_route = route.clone();
bogus_route.paths[0].hops[1].short_channel_id -= 1;
let short_channel_id = bogus_route.paths[0].hops[1].short_channel_id;
let short_channel_id = nodes[1]
.node
.list_channels()
.iter()
.find(|c| c.counterparty.node_id == nodes[2].node.get_our_node_id())
.unwrap()
.short_channel_id
.unwrap()
- 1;
bogus_route.paths[0].hops[1].short_channel_id = short_channel_id;
run_onion_failure_test(
"unknown_next_peer",
100,
Expand All @@ -1026,7 +1102,14 @@ fn test_onion_failure() {
Some(HTLCHandlingFailureType::InvalidForward { requested_forward_scid: short_channel_id }),
);

let short_channel_id = channels[1].0.contents.short_channel_id;
let short_channel_id = nodes[1]
.node
.list_channels()
.iter()
.find(|c| c.counterparty.node_id == nodes[2].node.get_our_node_id())
.unwrap()
.short_channel_id
.unwrap();
let amt_to_forward = {
let (per_peer_state, mut peer_state);
let chan = get_channel_ref!(nodes[1], nodes[2], per_peer_state, peer_state, channels[1].2);
Expand Down Expand Up @@ -1064,7 +1147,14 @@ fn test_onion_failure() {

// We ignore channel update contents in onion errors, so will blame the 2nd channel even though
// the first node is the one that messed up.
let short_channel_id = channels[1].0.contents.short_channel_id;
let short_channel_id = nodes[1]
.node
.list_channels()
.iter()
.find(|c| c.counterparty.node_id == nodes[2].node.get_our_node_id())
.unwrap()
.short_channel_id
.unwrap();
run_onion_failure_test(
"fee_insufficient",
100,
Expand All @@ -1083,7 +1173,14 @@ fn test_onion_failure() {
Some(next_hop_failure.clone()),
);

let short_channel_id = channels[1].0.contents.short_channel_id;
let short_channel_id = nodes[1]
.node
.list_channels()
.iter()
.find(|c| c.counterparty.node_id == nodes[2].node.get_our_node_id())
.unwrap()
.short_channel_id
.unwrap();
run_onion_failure_test(
"incorrect_cltv_expiry",
100,
Expand All @@ -1103,7 +1200,14 @@ fn test_onion_failure() {
Some(next_hop_failure.clone()),
);

let short_channel_id = channels[1].0.contents.short_channel_id;
let short_channel_id = nodes[1]
.node
.list_channels()
.iter()
.find(|c| c.counterparty.node_id == nodes[2].node.get_our_node_id())
.unwrap()
.short_channel_id
.unwrap();
run_onion_failure_test(
"expiry_too_soon",
100,
Expand Down Expand Up @@ -1190,7 +1294,16 @@ fn test_onion_failure() {
true,
Some(LocalHTLCFailureReason::FinalIncorrectCLTVExpiry),
None,
Some(channels[1].0.contents.short_channel_id),
Some(
nodes[1]
.node
.list_channels()
.iter()
.find(|c| c.counterparty.node_id == nodes[2].node.get_our_node_id())
.unwrap()
.short_channel_id
.unwrap(),
),
Some(HTLCHandlingFailureType::Receive { payment_hash }),
);

Expand Down Expand Up @@ -1220,11 +1333,27 @@ fn test_onion_failure() {
true,
Some(LocalHTLCFailureReason::FinalIncorrectHTLCAmount),
None,
Some(channels[1].0.contents.short_channel_id),
Some(
nodes[1]
.node
.list_channels()
.iter()
.find(|c| c.counterparty.node_id == nodes[2].node.get_our_node_id())
.unwrap()
.short_channel_id
.unwrap(),
),
Some(HTLCHandlingFailureType::Receive { payment_hash }),
);

let short_channel_id = channels[1].0.contents.short_channel_id;
let short_channel_id = nodes[1]
.node
.list_channels()
.iter()
.find(|c| c.counterparty.node_id == nodes[2].node.get_our_node_id())
.unwrap()
.short_channel_id
.unwrap();
run_onion_failure_test(
"channel_disabled",
100,
Expand Down Expand Up @@ -1386,7 +1515,16 @@ fn test_onion_failure() {
node_id: route.paths[0].hops[1].pubkey,
is_permanent: true,
}),
Some(channels[1].0.contents.short_channel_id),
Some(
nodes[1]
.node
.list_channels()
.iter()
.find(|c| c.counterparty.node_id == nodes[2].node.get_our_node_id())
.unwrap()
.short_channel_id
.unwrap(),
),
None,
);

Expand Down Expand Up @@ -1455,10 +1593,26 @@ fn test_onion_failure() {
true,
Some(LocalHTLCFailureReason::TemporaryChannelFailure),
Some(NetworkUpdate::ChannelFailure {
short_channel_id: channels[1].0.contents.short_channel_id,
short_channel_id: nodes[1]
.node
.list_channels()
.iter()
.find(|c| c.counterparty.node_id == nodes[2].node.get_our_node_id())
.unwrap()
.short_channel_id
.unwrap(),
is_permanent: false,
}),
Some(channels[1].0.contents.short_channel_id),
Some(
nodes[1]
.node
.list_channels()
.iter()
.find(|c| c.counterparty.node_id == nodes[2].node.get_our_node_id())
.unwrap()
.short_channel_id
.unwrap(),
),
Some(next_hop_failure.clone()),
);
run_onion_failure_test_with_fail_intercept(
Expand Down Expand Up @@ -1505,10 +1659,26 @@ fn test_onion_failure() {
true,
Some(LocalHTLCFailureReason::TemporaryChannelFailure),
Some(NetworkUpdate::ChannelFailure {
short_channel_id: channels[1].0.contents.short_channel_id,
short_channel_id: nodes[1]
.node
.list_channels()
.iter()
.find(|c| c.counterparty.node_id == nodes[2].node.get_our_node_id())
.unwrap()
.short_channel_id
.unwrap(),
is_permanent: false,
}),
Some(channels[1].0.contents.short_channel_id),
Some(
nodes[1]
.node
.list_channels()
.iter()
.find(|c| c.counterparty.node_id == nodes[2].node.get_our_node_id())
.unwrap()
.short_channel_id
.unwrap(),
),
None,
);
run_onion_failure_test(
Expand Down
Loading