]> git.bitcoin.ninja Git - rust-lightning/commitdiff
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)
committerYuntai Kyong <yuntai.kyong@gmail.com>
Sun, 14 Oct 2018 14:00:34 +0000 (23:00 +0900)
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 9bdbc80408245d8c36366b035bd66f7a47e20e61..07ea87f9ddcd43dd3cc806e6cc3986bcb9c4380b 100644 (file)
@@ -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!();
index 9ff62de38c6e6ae950d5f4143b65542698918c17..14760ff88921330e13faae578dc7c8ebc6e887ad 100644 (file)
@@ -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.
index 4a55df88c6f90fd30d309e506377d819a7720a02..33037c12a161432665b0cc423d5bef0f88cf125a 100644 (file)
@@ -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);
+                       },
                }
        }