Skip to content

Commit 17d3e8d

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 rename NetworkGraph methods close_channel_from_update and fail_node to channel_failed and node_failed, respectively.
1 parent dcffefa commit 17d3e8d

File tree

5 files changed

+27
-27
lines changed

5 files changed

+27
-27
lines changed

fuzz/src/router.rs

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

lightning/src/ln/functional_test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1512,7 +1512,7 @@ macro_rules! expect_payment_failed_conditions {
15121512
}
15131513
assert_eq!(msg.contents.flags & 2, 0);
15141514
},
1515-
&Some($crate::routing::network_graph::NetworkUpdate::ChannelClosed { short_channel_id, is_permanent }) if chan_closed => {
1515+
&Some($crate::routing::network_graph::NetworkUpdate::ChannelFailure { short_channel_id, is_permanent }) if chan_closed => {
15161516
if let Some(scid) = $conditions.expected_blamed_scid {
15171517
assert_eq!(short_channel_id, scid);
15181518
}

lightning/src/ln/onion_route_tests.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ fn run_onion_failure_test_with_fail_intercept<F1,F2,F3>(_name: &str, test_case:
177177
panic!("channel_update not found!");
178178
}
179179
},
180-
&NetworkUpdate::ChannelClosed { ref short_channel_id, ref is_permanent } => {
181-
if let NetworkUpdate::ChannelClosed { short_channel_id: ref expected_short_channel_id, is_permanent: ref expected_is_permanent } = expected_channel_update.unwrap() {
180+
&NetworkUpdate::ChannelFailure { ref short_channel_id, ref is_permanent } => {
181+
if let NetworkUpdate::ChannelFailure { short_channel_id: ref expected_short_channel_id, is_permanent: ref expected_is_permanent } = expected_channel_update.unwrap() {
182182
assert!(*short_channel_id == *expected_short_channel_id);
183183
assert!(*is_permanent == *expected_is_permanent);
184184
} else {
@@ -283,7 +283,7 @@ fn test_fee_failures() {
283283
let short_channel_id = channels[0].0.contents.short_channel_id;
284284
run_onion_failure_test("fee_insufficient", 0, &nodes, &route, &payment_hash, &payment_secret, |msg| {
285285
msg.amount_msat -= 1;
286-
}, || {}, true, Some(UPDATE|12), Some(NetworkUpdate::ChannelClosed { short_channel_id, is_permanent: true}), Some(short_channel_id));
286+
}, || {}, true, Some(UPDATE|12), Some(NetworkUpdate::ChannelFailure { short_channel_id, is_permanent: true}), Some(short_channel_id));
287287

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

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

365365
// the following three with run_onion_failure_test_with_fail_intercept() test only the origin node
366366
// receiving simulated fail messages
@@ -471,7 +471,7 @@ fn test_onion_failure() {
471471
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap();
472472
msg.reason = onion_utils::build_first_hop_failure_packet(onion_keys[0].shared_secret.as_ref(), PERM|8, &[0;0]);
473473
// short_channel_id from the processing node
474-
}, ||{}, true, Some(PERM|8), Some(NetworkUpdate::ChannelClosed{short_channel_id, is_permanent: true}), Some(short_channel_id));
474+
}, ||{}, true, Some(PERM|8), Some(NetworkUpdate::ChannelFailure{short_channel_id, is_permanent: true}), Some(short_channel_id));
475475

476476
let short_channel_id = channels[1].0.contents.short_channel_id;
477477
run_onion_failure_test_with_fail_intercept("required_channel_feature_missing", 100, &nodes, &route, &payment_hash, &payment_secret, |msg| {
@@ -481,13 +481,13 @@ fn test_onion_failure() {
481481
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap();
482482
msg.reason = onion_utils::build_first_hop_failure_packet(onion_keys[0].shared_secret.as_ref(), PERM|9, &[0;0]);
483483
// short_channel_id from the processing node
484-
}, ||{}, true, Some(PERM|9), Some(NetworkUpdate::ChannelClosed{short_channel_id, is_permanent: true}), Some(short_channel_id));
484+
}, ||{}, true, Some(PERM|9), Some(NetworkUpdate::ChannelFailure{short_channel_id, is_permanent: true}), Some(short_channel_id));
485485

486486
let mut bogus_route = route.clone();
487487
bogus_route.paths[0][1].short_channel_id -= 1;
488488
let short_channel_id = bogus_route.paths[0][1].short_channel_id;
489489
run_onion_failure_test("unknown_next_peer", 0, &nodes, &bogus_route, &payment_hash, &payment_secret, |_| {}, ||{}, true, Some(PERM|10),
490-
Some(NetworkUpdate::ChannelClosed{short_channel_id, is_permanent:true}), Some(short_channel_id));
490+
Some(NetworkUpdate::ChannelFailure{short_channel_id, is_permanent:true}), Some(short_channel_id));
491491

492492
let short_channel_id = channels[1].0.contents.short_channel_id;
493493
let amt_to_forward = nodes[1].node.channel_state.lock().unwrap().by_id.get(&channels[1].2).unwrap().get_counterparty_htlc_minimum_msat() - 1;
@@ -511,13 +511,13 @@ fn test_onion_failure() {
511511
let short_channel_id = channels[0].0.contents.short_channel_id;
512512
run_onion_failure_test("fee_insufficient", 0, &nodes, &route, &payment_hash, &payment_secret, |msg| {
513513
msg.amount_msat -= 1;
514-
}, || {}, true, Some(UPDATE|12), Some(NetworkUpdate::ChannelClosed { short_channel_id, is_permanent: true}), Some(short_channel_id));
514+
}, || {}, true, Some(UPDATE|12), Some(NetworkUpdate::ChannelFailure { short_channel_id, is_permanent: true}), Some(short_channel_id));
515515

516516
let short_channel_id = channels[0].0.contents.short_channel_id;
517517
run_onion_failure_test("incorrect_cltv_expiry", 0, &nodes, &route, &payment_hash, &payment_secret, |msg| {
518518
// need to violate: cltv_expiry - cltv_expiry_delta >= outgoing_cltv_value
519519
msg.cltv_expiry -= 1;
520-
}, || {}, true, Some(UPDATE|13), Some(NetworkUpdate::ChannelClosed { short_channel_id, is_permanent: true}), Some(short_channel_id));
520+
}, || {}, true, Some(UPDATE|13), Some(NetworkUpdate::ChannelFailure { short_channel_id, is_permanent: true}), Some(short_channel_id));
521521

522522
let short_channel_id = channels[1].0.contents.short_channel_id;
523523
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
@@ -395,7 +395,7 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(secp_ctx: &
395395
}
396396
else if error_code & PERM == PERM {
397397
if !payment_failed {
398-
network_update = Some(NetworkUpdate::ChannelClosed {
398+
network_update = Some(NetworkUpdate::ChannelFailure {
399399
short_channel_id: failing_route_hop.short_channel_id,
400400
is_permanent: true,
401401
});
@@ -440,7 +440,7 @@ pub(super) fn process_onion_failure<T: secp256k1::Signing, L: Deref>(secp_ctx: &
440440
if is_chan_update_invalid {
441441
// This probably indicates the node which forwarded
442442
// to the node in question corrupted something.
443-
network_update = Some(NetworkUpdate::ChannelClosed {
443+
network_update = Some(NetworkUpdate::ChannelFailure {
444444
short_channel_id: route_hop.short_channel_id,
445445
is_permanent: true,
446446
});

lightning/src/routing/network_graph.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,17 @@ pub enum NetworkUpdate {
162162
/// The update to apply via [`NetworkGraph::update_channel`].
163163
msg: ChannelUpdate,
164164
},
165-
/// An error indicating only that a channel has been closed, which should be applied via
166-
/// [`NetworkGraph::close_channel_from_update`].
167-
ChannelClosed {
165+
/// An error indicating only that a channel has failed, which should be applied via
166+
/// [`NetworkGraph::channel_failed`].
167+
ChannelFailure {
168168
/// The short channel id of the closed channel.
169169
short_channel_id: u64,
170170
/// Whether the channel should be permanently removed or temporarily disabled until a new
171171
/// `channel_update` message is received.
172172
is_permanent: bool,
173173
},
174174
/// An error indicating only that a node has failed, which should be applied via
175-
/// [`NetworkGraph::fail_node`].
175+
/// [`NetworkGraph::node_failed`].
176176
NodeFailure {
177177
/// The node id of the failed node.
178178
node_id: PublicKey,
@@ -186,7 +186,7 @@ impl_writeable_tlv_based_enum_upgradable!(NetworkUpdate,
186186
(0, ChannelUpdateMessage) => {
187187
(0, msg, required),
188188
},
189-
(2, ChannelClosed) => {
189+
(2, ChannelFailure) => {
190190
(0, short_channel_id, required),
191191
(2, is_permanent, required),
192192
},
@@ -282,15 +282,15 @@ where C::Target: chain::Access, L::Target: Logger
282282
log_debug!(self.logger, "Updating channel with channel_update from a payment failure. Channel {} is {}.", short_channel_id, status);
283283
let _ = self.network_graph.update_channel(msg, &self.secp_ctx);
284284
},
285-
NetworkUpdate::ChannelClosed { short_channel_id, is_permanent } => {
285+
NetworkUpdate::ChannelFailure { short_channel_id, is_permanent } => {
286286
let action = if is_permanent { "Removing" } else { "Disabling" };
287287
log_debug!(self.logger, "{} channel graph entry for {} due to a payment failure.", action, short_channel_id);
288-
self.network_graph.close_channel_from_update(short_channel_id, is_permanent);
288+
self.network_graph.channel_failed(short_channel_id, is_permanent);
289289
},
290290
NetworkUpdate::NodeFailure { ref node_id, is_permanent } => {
291291
let action = if is_permanent { "Removing" } else { "Disabling" };
292292
log_debug!(self.logger, "{} node graph entry for {} due to a payment failure.", action, node_id);
293-
self.network_graph.fail_node(node_id, is_permanent);
293+
self.network_graph.node_failed(node_id, is_permanent);
294294
},
295295
}
296296
}
@@ -1328,11 +1328,11 @@ impl NetworkGraph {
13281328
self.add_channel_between_nodes(msg.short_channel_id, chan_info, utxo_value)
13291329
}
13301330

1331-
/// Close a channel if a corresponding HTLC fail was sent.
1331+
/// Marks a channel in the graph as failed if a corresponding HTLC fail was sent.
13321332
/// If permanent, removes a channel from the local storage.
13331333
/// May cause the removal of nodes too, if this was their last channel.
13341334
/// If not permanent, makes channels unavailable for routing.
1335-
pub fn close_channel_from_update(&self, short_channel_id: u64, is_permanent: bool) {
1335+
pub fn channel_failed(&self, short_channel_id: u64, is_permanent: bool) {
13361336
let mut channels = self.channels.write().unwrap();
13371337
if is_permanent {
13381338
if let Some(chan) = channels.remove(&short_channel_id) {
@@ -1352,7 +1352,7 @@ impl NetworkGraph {
13521352
}
13531353

13541354
/// Marks a node in the graph as failed.
1355-
pub fn fail_node(&self, _node_id: &PublicKey, is_permanent: bool) {
1355+
pub fn node_failed(&self, _node_id: &PublicKey, is_permanent: bool) {
13561356
if is_permanent {
13571357
// TODO: Wholly remove the node
13581358
} else {
@@ -2120,7 +2120,7 @@ mod tests {
21202120
rejected_by_dest: false,
21212121
all_paths_failed: true,
21222122
path: vec![],
2123-
network_update: Some(NetworkUpdate::ChannelClosed {
2123+
network_update: Some(NetworkUpdate::ChannelFailure {
21242124
short_channel_id,
21252125
is_permanent: false,
21262126
}),
@@ -2145,7 +2145,7 @@ mod tests {
21452145
rejected_by_dest: false,
21462146
all_paths_failed: true,
21472147
path: vec![],
2148-
network_update: Some(NetworkUpdate::ChannelClosed {
2148+
network_update: Some(NetworkUpdate::ChannelFailure {
21492149
short_channel_id,
21502150
is_permanent: true,
21512151
}),

0 commit comments

Comments
 (0)