From: Yuntai Kyong Date: Sun, 14 Oct 2018 13:11:21 +0000 (+0900) Subject: Add is_permanent field to ChannelClosed message and add NodeFailure X-Git-Tag: v0.0.12~291^2~4 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=ba30061c87fca9d808e9e13569b8ea914503fae6;p=rust-lightning Add is_permanent field to ChannelClosed message and add NodeFailure message --- diff --git a/fuzz/fuzz_targets/router_target.rs b/fuzz/fuzz_targets/router_target.rs index 52f9a235f..f7b373cdb 100644 --- a/fuzz/fuzz_targets/router_target.rs +++ b/fuzz/fuzz_targets/router_target.rs @@ -187,7 +187,7 @@ pub fn do_test(data: &[u8]) { }, 1 => { let short_channel_id = slice_to_be64(get_slice!(8)); - router.handle_htlc_fail_channel_update(&msgs::HTLCFailChannelUpdate::ChannelClosed {short_channel_id}); + router.handle_htlc_fail_channel_update(&msgs::HTLCFailChannelUpdate::ChannelClosed {short_channel_id, is_permanent: false}); }, _ => return, } diff --git a/src/ln/channelmanager.rs b/src/ln/channelmanager.rs index 033fdbd61..5e5d531fa 100644 --- a/src/ln/channelmanager.rs +++ b/src/ln/channelmanager.rs @@ -1825,7 +1825,8 @@ impl ChannelManager { // No such next-hop. We know this came from the // current node as the HMAC validated. res = Some(msgs::HTLCFailChannelUpdate::ChannelClosed { - short_channel_id: route_hop.short_channel_id + short_channel_id: route_hop.short_channel_id, + is_permanent: true, }); }, _ => {}, //TODO: Enumerate all of these! @@ -5145,7 +5146,7 @@ mod tests { let as_chan = a_channel_lock.by_id.get(&chan_announcement.3).unwrap(); let bs_chan = b_channel_lock.by_id.get(&chan_announcement.3).unwrap(); - let _ = nodes[0].router.handle_htlc_fail_channel_update(&msgs::HTLCFailChannelUpdate::ChannelClosed { short_channel_id : as_chan.get_short_channel_id().unwrap() } ); + 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 } ); let as_bitcoin_key = PublicKey::from_secret_key(&secp_ctx, &as_chan.get_local_keys().funding_key); let bs_bitcoin_key = PublicKey::from_secret_key(&secp_ctx, &bs_chan.get_local_keys().funding_key); @@ -5192,7 +5193,7 @@ mod tests { let unsigned_msg = dummy_unsigned_msg!(); sign_msg!(unsigned_msg); assert_eq!(nodes[0].router.handle_channel_announcement(&chan_announcement).unwrap(), true); - let _ = nodes[0].router.handle_htlc_fail_channel_update(&msgs::HTLCFailChannelUpdate::ChannelClosed { short_channel_id : as_chan.get_short_channel_id().unwrap() } ); + 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 } ); // Configured with Network::Testnet let mut unsigned_msg = dummy_unsigned_msg!(); diff --git a/src/ln/msgs.rs b/src/ln/msgs.rs index 5b3d57aae..610158503 100644 --- a/src/ln/msgs.rs +++ b/src/ln/msgs.rs @@ -485,7 +485,19 @@ pub enum HTLCFailChannelUpdate { ChannelClosed { /// The short_channel_id which has now closed. short_channel_id: u64, + /// when this true, this channel should be permanently removed from the + /// consideration. Otherwise, this channel can be restored as new channel_update is received + is_permanent: bool, }, + /// We received an error which indicated only that a node has failed + NodeFailure { + /// The node_id that has failed. + node_id: PublicKey, + /// when this true, node should be permanently removed from the + /// consideration. Otherwise, the channels connected to this node can be + /// restored as new channel_update is received + is_permanent: bool, + } } /// A trait to describe an object which can receive channel messages. diff --git a/src/ln/router.rs b/src/ln/router.rs index 4a55df88c..4c3bcb980 100644 --- a/src/ln/router.rs +++ b/src/ln/router.rs @@ -349,12 +349,19 @@ impl RoutingMessageHandler for Router { &msgs::HTLCFailChannelUpdate::ChannelUpdateMessage { ref msg } => { let _ = self.handle_channel_update(msg); }, - &msgs::HTLCFailChannelUpdate::ChannelClosed { ref short_channel_id } => { + &msgs::HTLCFailChannelUpdate::ChannelClosed { ref short_channel_id, is_permanent:_ } => { +//XXX let mut network = self.network_map.write().unwrap(); if let Some(chan) = network.channels.remove(short_channel_id) { Self::remove_channel_in_nodes(&mut network.nodes, &chan, *short_channel_id); } }, + &msgs::HTLCFailChannelUpdate::NodeFailure { ref node_id, is_permanent:_ } => { +//XXX + //let mut network = self.network_map.write().unwrap(); + //TODO: check _blamed_upstream_node + self.mark_node_bad(node_id, false); + }, } }