Skip to content

Commit ba30061

Browse files
yuntaiTheBlueMatt
authored andcommitted
Add is_permanent field to ChannelClosed message and add NodeFailure
message
1 parent d318184 commit ba30061

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

fuzz/fuzz_targets/router_target.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ pub fn do_test(data: &[u8]) {
187187
},
188188
1 => {
189189
let short_channel_id = slice_to_be64(get_slice!(8));
190-
router.handle_htlc_fail_channel_update(&msgs::HTLCFailChannelUpdate::ChannelClosed {short_channel_id});
190+
router.handle_htlc_fail_channel_update(&msgs::HTLCFailChannelUpdate::ChannelClosed {short_channel_id, is_permanent: false});
191191
},
192192
_ => return,
193193
}

src/ln/channelmanager.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,7 +1825,8 @@ impl ChannelManager {
18251825
// No such next-hop. We know this came from the
18261826
// current node as the HMAC validated.
18271827
res = Some(msgs::HTLCFailChannelUpdate::ChannelClosed {
1828-
short_channel_id: route_hop.short_channel_id
1828+
short_channel_id: route_hop.short_channel_id,
1829+
is_permanent: true,
18291830
});
18301831
},
18311832
_ => {}, //TODO: Enumerate all of these!
@@ -5145,7 +5146,7 @@ mod tests {
51455146
let as_chan = a_channel_lock.by_id.get(&chan_announcement.3).unwrap();
51465147
let bs_chan = b_channel_lock.by_id.get(&chan_announcement.3).unwrap();
51475148

5148-
let _ = nodes[0].router.handle_htlc_fail_channel_update(&msgs::HTLCFailChannelUpdate::ChannelClosed { short_channel_id : as_chan.get_short_channel_id().unwrap() } );
5149+
let _ = nodes[0].router.handle_htlc_fail_channel_update(&msgs::HTLCFailChannelUpdate::ChannelClosed { short_channel_id : as_chan.get_short_channel_id().unwrap(), is_permanent: false } );
51495150

51505151
let as_bitcoin_key = PublicKey::from_secret_key(&secp_ctx, &as_chan.get_local_keys().funding_key);
51515152
let bs_bitcoin_key = PublicKey::from_secret_key(&secp_ctx, &bs_chan.get_local_keys().funding_key);
@@ -5192,7 +5193,7 @@ mod tests {
51925193
let unsigned_msg = dummy_unsigned_msg!();
51935194
sign_msg!(unsigned_msg);
51945195
assert_eq!(nodes[0].router.handle_channel_announcement(&chan_announcement).unwrap(), true);
5195-
let _ = nodes[0].router.handle_htlc_fail_channel_update(&msgs::HTLCFailChannelUpdate::ChannelClosed { short_channel_id : as_chan.get_short_channel_id().unwrap() } );
5196+
let _ = nodes[0].router.handle_htlc_fail_channel_update(&msgs::HTLCFailChannelUpdate::ChannelClosed { short_channel_id : as_chan.get_short_channel_id().unwrap(), is_permanent: false } );
51965197

51975198
// Configured with Network::Testnet
51985199
let mut unsigned_msg = dummy_unsigned_msg!();

src/ln/msgs.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,19 @@ pub enum HTLCFailChannelUpdate {
485485
ChannelClosed {
486486
/// The short_channel_id which has now closed.
487487
short_channel_id: u64,
488+
/// when this true, this channel should be permanently removed from the
489+
/// consideration. Otherwise, this channel can be restored as new channel_update is received
490+
is_permanent: bool,
488491
},
492+
/// We received an error which indicated only that a node has failed
493+
NodeFailure {
494+
/// The node_id that has failed.
495+
node_id: PublicKey,
496+
/// when this true, node should be permanently removed from the
497+
/// consideration. Otherwise, the channels connected to this node can be
498+
/// restored as new channel_update is received
499+
is_permanent: bool,
500+
}
489501
}
490502

491503
/// A trait to describe an object which can receive channel messages.

src/ln/router.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,12 +349,19 @@ impl RoutingMessageHandler for Router {
349349
&msgs::HTLCFailChannelUpdate::ChannelUpdateMessage { ref msg } => {
350350
let _ = self.handle_channel_update(msg);
351351
},
352-
&msgs::HTLCFailChannelUpdate::ChannelClosed { ref short_channel_id } => {
352+
&msgs::HTLCFailChannelUpdate::ChannelClosed { ref short_channel_id, is_permanent:_ } => {
353+
//XXX
353354
let mut network = self.network_map.write().unwrap();
354355
if let Some(chan) = network.channels.remove(short_channel_id) {
355356
Self::remove_channel_in_nodes(&mut network.nodes, &chan, *short_channel_id);
356357
}
357358
},
359+
&msgs::HTLCFailChannelUpdate::NodeFailure { ref node_id, is_permanent:_ } => {
360+
//XXX
361+
//let mut network = self.network_map.write().unwrap();
362+
//TODO: check _blamed_upstream_node
363+
self.mark_node_bad(node_id, false);
364+
},
358365
}
359366
}
360367

0 commit comments

Comments
 (0)