Skip to content

Commit 7af701f

Browse files
committed
Rename ChannelClosed to ChannelFailure
A NetworkUpdate indicating ChannelClosed actually corresponds to a channel failure as described in BOLT 4: 0x2000 (NODE): node failure (otherwise channel) Rename the enum variant to ChannelFailure and close_channel_from_update to fail_channel in NetworkGraph.
1 parent 458bca5 commit 7af701f

File tree

5 files changed

+24
-24
lines changed

5 files changed

+24
-24
lines changed

fuzz/src/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
195195
},
196196
4 => {
197197
let short_channel_id = slice_to_be64(get_slice!(8));
198-
net_graph.close_channel_from_update(short_channel_id, false);
198+
net_graph.fail_channel(short_channel_id, false);
199199
},
200200
_ if node_pks.is_empty() => {},
201201
_ => {

lightning/src/ln/functional_test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1134,7 +1134,7 @@ macro_rules! expect_payment_failed_with_update {
11341134
assert_eq!(msg.contents.short_channel_id, $scid);
11351135
assert_eq!(msg.contents.flags & 2, 0);
11361136
},
1137-
&Some(NetworkUpdate::ChannelClosed { short_channel_id, is_permanent }) if $chan_closed => {
1137+
&Some(NetworkUpdate::ChannelFailure { short_channel_id, is_permanent }) if $chan_closed => {
11381138
assert_eq!(short_channel_id, $scid);
11391139
assert!(is_permanent);
11401140
},

lightning/src/ln/onion_route_tests.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ fn run_onion_failure_test_with_fail_intercept<F1,F2,F3>(_name: &str, test_case:
174174
panic!("channel_update not found!");
175175
}
176176
},
177-
&NetworkUpdate::ChannelClosed { ref short_channel_id, ref is_permanent } => {
178-
if let NetworkUpdate::ChannelClosed { short_channel_id: ref expected_short_channel_id, is_permanent: ref expected_is_permanent } = expected_channel_update.unwrap() {
177+
&NetworkUpdate::ChannelFailure { ref short_channel_id, ref is_permanent } => {
178+
if let NetworkUpdate::ChannelFailure { short_channel_id: ref expected_short_channel_id, is_permanent: ref expected_is_permanent } = expected_channel_update.unwrap() {
179179
assert!(*short_channel_id == *expected_short_channel_id);
180180
assert!(*is_permanent == *expected_is_permanent);
181181
} else {
@@ -280,7 +280,7 @@ fn test_fee_failures() {
280280
let short_channel_id = channels[0].0.contents.short_channel_id;
281281
run_onion_failure_test("fee_insufficient", 0, &nodes, &route, &payment_hash, &payment_secret, |msg| {
282282
msg.amount_msat -= 1;
283-
}, || {}, true, Some(UPDATE|12), Some(NetworkUpdate::ChannelClosed { short_channel_id, is_permanent: true}), Some(short_channel_id));
283+
}, || {}, true, Some(UPDATE|12), Some(NetworkUpdate::ChannelFailure { short_channel_id, is_permanent: true}), Some(short_channel_id));
284284

285285
// In an earlier version, we spuriously failed to forward payments if the expected feerate
286286
// changed between the channel open and the payment.
@@ -340,7 +340,7 @@ fn test_onion_failure() {
340340
// describing a length-1 TLV payload, which is obviously bogus.
341341
new_payloads[0].data[0] = 1;
342342
msg.onion_routing_packet = onion_utils::construct_onion_packet_bogus_hopdata(new_payloads, onion_keys, [0; 32], &payment_hash);
343-
}, ||{}, true, Some(PERM|22), Some(NetworkUpdate::ChannelClosed{short_channel_id, is_permanent: true}), Some(short_channel_id));
343+
}, ||{}, true, Some(PERM|22), Some(NetworkUpdate::ChannelFailure{short_channel_id, is_permanent: true}), Some(short_channel_id));
344344

345345
// final node failure
346346
let short_channel_id = channels[1].0.contents.short_channel_id;
@@ -357,7 +357,7 @@ fn test_onion_failure() {
357357
// length-1 TLV payload, which is obviously bogus.
358358
new_payloads[1].data[0] = 1;
359359
msg.onion_routing_packet = onion_utils::construct_onion_packet_bogus_hopdata(new_payloads, onion_keys, [0; 32], &payment_hash);
360-
}, ||{}, false, Some(PERM|22), Some(NetworkUpdate::ChannelClosed{short_channel_id, is_permanent: true}), Some(short_channel_id));
360+
}, ||{}, false, Some(PERM|22), Some(NetworkUpdate::ChannelFailure{short_channel_id, is_permanent: true}), Some(short_channel_id));
361361

362362
// the following three with run_onion_failure_test_with_fail_intercept() test only the origin node
363363
// receiving simulated fail messages
@@ -452,7 +452,7 @@ fn test_onion_failure() {
452452
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap();
453453
msg.reason = onion_utils::build_first_hop_failure_packet(&onion_keys[0].shared_secret[..], PERM|8, &[0;0]);
454454
// short_channel_id from the processing node
455-
}, ||{}, true, Some(PERM|8), Some(NetworkUpdate::ChannelClosed{short_channel_id, is_permanent: true}), Some(short_channel_id));
455+
}, ||{}, true, Some(PERM|8), Some(NetworkUpdate::ChannelFailure{short_channel_id, is_permanent: true}), Some(short_channel_id));
456456

457457
let short_channel_id = channels[1].0.contents.short_channel_id;
458458
run_onion_failure_test_with_fail_intercept("required_channel_feature_missing", 100, &nodes, &route, &payment_hash, &payment_secret, |msg| {
@@ -462,13 +462,13 @@ fn test_onion_failure() {
462462
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap();
463463
msg.reason = onion_utils::build_first_hop_failure_packet(&onion_keys[0].shared_secret[..], PERM|9, &[0;0]);
464464
// short_channel_id from the processing node
465-
}, ||{}, true, Some(PERM|9), Some(NetworkUpdate::ChannelClosed{short_channel_id, is_permanent: true}), Some(short_channel_id));
465+
}, ||{}, true, Some(PERM|9), Some(NetworkUpdate::ChannelFailure{short_channel_id, is_permanent: true}), Some(short_channel_id));
466466

467467
let mut bogus_route = route.clone();
468468
bogus_route.paths[0][1].short_channel_id -= 1;
469469
let short_channel_id = bogus_route.paths[0][1].short_channel_id;
470470
run_onion_failure_test("unknown_next_peer", 0, &nodes, &bogus_route, &payment_hash, &payment_secret, |_| {}, ||{}, true, Some(PERM|10),
471-
Some(NetworkUpdate::ChannelClosed{short_channel_id, is_permanent:true}), Some(short_channel_id));
471+
Some(NetworkUpdate::ChannelFailure{short_channel_id, is_permanent:true}), Some(short_channel_id));
472472

473473
let short_channel_id = channels[1].0.contents.short_channel_id;
474474
let amt_to_forward = nodes[1].node.channel_state.lock().unwrap().by_id.get(&channels[1].2).unwrap().get_counterparty_htlc_minimum_msat() - 1;
@@ -487,13 +487,13 @@ fn test_onion_failure() {
487487
let short_channel_id = channels[0].0.contents.short_channel_id;
488488
run_onion_failure_test("fee_insufficient", 0, &nodes, &route, &payment_hash, &payment_secret, |msg| {
489489
msg.amount_msat -= 1;
490-
}, || {}, true, Some(UPDATE|12), Some(NetworkUpdate::ChannelClosed { short_channel_id, is_permanent: true}), Some(short_channel_id));
490+
}, || {}, true, Some(UPDATE|12), Some(NetworkUpdate::ChannelFailure { short_channel_id, is_permanent: true}), Some(short_channel_id));
491491

492492
let short_channel_id = channels[0].0.contents.short_channel_id;
493493
run_onion_failure_test("incorrect_cltv_expiry", 0, &nodes, &route, &payment_hash, &payment_secret, |msg| {
494494
// need to violate: cltv_expiry - cltv_expiry_delta >= outgoing_cltv_value
495495
msg.cltv_expiry -= 1;
496-
}, || {}, true, Some(UPDATE|13), Some(NetworkUpdate::ChannelClosed { short_channel_id, is_permanent: true}), Some(short_channel_id));
496+
}, || {}, true, Some(UPDATE|13), Some(NetworkUpdate::ChannelFailure { short_channel_id, is_permanent: true}), Some(short_channel_id));
497497

498498
let short_channel_id = channels[1].0.contents.short_channel_id;
499499
run_onion_failure_test("expiry_too_soon", 0, &nodes, &route, &payment_hash, &payment_secret, |msg| {

lightning/src/ln/onion_utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(secp_ctx: &
394394
}
395395
else if error_code & PERM == PERM {
396396
if !payment_failed {
397-
network_update = Some(NetworkUpdate::ChannelClosed {
397+
network_update = Some(NetworkUpdate::ChannelFailure {
398398
short_channel_id: failing_route_hop.short_channel_id,
399399
is_permanent: true,
400400
});
@@ -425,7 +425,7 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(secp_ctx: &
425425
if is_chan_update_invalid {
426426
// This probably indicates the node which forwarded
427427
// to the node in question corrupted something.
428-
network_update = Some(NetworkUpdate::ChannelClosed {
428+
network_update = Some(NetworkUpdate::ChannelFailure {
429429
short_channel_id: route_hop.short_channel_id,
430430
is_permanent: true,
431431
});

lightning/src/routing/network_graph.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ pub enum NetworkUpdate {
152152
/// The update to apply via [`NetworkGraph::update_channel`].
153153
msg: ChannelUpdate,
154154
},
155-
/// An error indicating only that a channel has been closed, which should be applied via
156-
/// [`NetworkGraph::close_channel_from_update`].
157-
ChannelClosed {
155+
/// An error indicating only that a channel has failed, which should be applied via
156+
/// [`NetworkGraph::fail_channel`].
157+
ChannelFailure {
158158
/// The short channel id of the closed channel.
159159
short_channel_id: u64,
160160
/// Whether the channel should be permanently removed or temporarily disabled until a new
@@ -176,7 +176,7 @@ impl_writeable_tlv_based_enum_upgradable!(NetworkUpdate,
176176
(0, ChannelUpdateMessage) => {
177177
(0, msg, required),
178178
},
179-
(2, ChannelClosed) => {
179+
(2, ChannelFailure) => {
180180
(0, short_channel_id, required),
181181
(2, is_permanent, required),
182182
},
@@ -264,10 +264,10 @@ where C::Target: chain::Access, L::Target: Logger
264264
log_debug!(self.logger, "Updating channel with channel_update from a payment failure. Channel {} is {}.", short_channel_id, status);
265265
let _ = self.network_graph.update_channel(msg, &self.secp_ctx);
266266
},
267-
NetworkUpdate::ChannelClosed { short_channel_id, is_permanent } => {
267+
NetworkUpdate::ChannelFailure { short_channel_id, is_permanent } => {
268268
let action = if is_permanent { "Removing" } else { "Disabling" };
269269
log_debug!(self.logger, "{} channel graph entry for {} due to a payment failure.", action, short_channel_id);
270-
self.network_graph.close_channel_from_update(short_channel_id, is_permanent);
270+
self.network_graph.fail_channel(short_channel_id, is_permanent);
271271
},
272272
NetworkUpdate::NodeFailure { ref node_id, is_permanent } => {
273273
let action = if is_permanent { "Removing" } else { "Disabling" };
@@ -1008,11 +1008,11 @@ impl NetworkGraph {
10081008
Ok(())
10091009
}
10101010

1011-
/// Close a channel if a corresponding HTLC fail was sent.
1011+
/// Marks a channel in the graph as failed if a corresponding HTLC fail was sent.
10121012
/// If permanent, removes a channel from the local storage.
10131013
/// May cause the removal of nodes too, if this was their last channel.
10141014
/// If not permanent, makes channels unavailable for routing.
1015-
pub fn close_channel_from_update(&self, short_channel_id: u64, is_permanent: bool) {
1015+
pub fn fail_channel(&self, short_channel_id: u64, is_permanent: bool) {
10161016
let mut channels = self.channels.write().unwrap();
10171017
if is_permanent {
10181018
if let Some(chan) = channels.remove(&short_channel_id) {
@@ -1839,7 +1839,7 @@ mod tests {
18391839
rejected_by_dest: false,
18401840
all_paths_failed: true,
18411841
path: vec![],
1842-
network_update: Some(NetworkUpdate::ChannelClosed {
1842+
network_update: Some(NetworkUpdate::ChannelFailure {
18431843
short_channel_id,
18441844
is_permanent: false,
18451845
}),
@@ -1865,7 +1865,7 @@ mod tests {
18651865
rejected_by_dest: false,
18661866
all_paths_failed: true,
18671867
path: vec![],
1868-
network_update: Some(NetworkUpdate::ChannelClosed {
1868+
network_update: Some(NetworkUpdate::ChannelFailure {
18691869
short_channel_id,
18701870
is_permanent: true,
18711871
}),

0 commit comments

Comments
 (0)