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-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=8f6ae418635ee3760e4f7461c269d8d82f5e53a7;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 9bdbc8040..07ea87f9d 100644 --- a/src/ln/channelmanager.rs +++ b/src/ln/channelmanager.rs @@ -1804,7 +1804,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! @@ -4810,7 +4811,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); @@ -4857,7 +4858,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 9ff62de38..14760ff88 100644 --- a/src/ln/msgs.rs +++ b/src/ln/msgs.rs @@ -484,7 +484,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..33037c12a 100644 --- a/src/ln/router.rs +++ b/src/ln/router.rs @@ -349,12 +349,17 @@ 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:_ } => { 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:_ } => { + //let mut network = self.network_map.write().unwrap(); + //TODO: check _blamed_upstream_node + self.mark_node_bad(node_id, false); + }, } }