Add is_permanent field to ChannelClosed message and add NodeFailure
authorYuntai Kyong <yuntai.kyong@gmail.com>
Sun, 14 Oct 2018 13:11:21 +0000 (22:11 +0900)
committerMatt Corallo <git@bluematt.me>
Tue, 23 Oct 2018 14:30:49 +0000 (10:30 -0400)
message

fuzz/fuzz_targets/router_target.rs
src/ln/channelmanager.rs
src/ln/msgs.rs
src/ln/router.rs

index 52f9a235fe731aa93bfa94b4ccaa913a53df41bf..f7b373cdbc97683057a26df8cd20efc284b0300e 100644 (file)
@@ -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,
                                }
index 033fdbd615985d73b58f4fb5695112d6b874a41a..5e5d531fa4b1eaa578469e4dad611107af33d687 100644 (file)
@@ -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!();
index 5b3d57aae0273c90aad5c4c990a1019e818e9bab..610158503e6656a462d90f25a41e32bd1cbcd6a7 100644 (file)
@@ -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.
index 4a55df88c6f90fd30d309e506377d819a7720a02..4c3bcb98074fd8301941739c9352ce6bef593e05 100644 (file)
@@ -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);
+                       },
                }
        }