mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-25 15:20:24 +01:00
Util-func channel removal (fixing a bug in HTLC failure updates)
This commit is contained in:
parent
91b23a0754
commit
3b4c1a3662
1 changed files with 20 additions and 6 deletions
|
@ -306,12 +306,7 @@ impl RoutingMessageHandler for Router {
|
||||||
&msgs::HTLCFailChannelUpdate::ChannelClosed { ref short_channel_id } => {
|
&msgs::HTLCFailChannelUpdate::ChannelClosed { ref short_channel_id } => {
|
||||||
let mut network = self.network_map.write().unwrap();
|
let mut network = self.network_map.write().unwrap();
|
||||||
if let Some(chan) = network.channels.remove(short_channel_id) {
|
if let Some(chan) = network.channels.remove(short_channel_id) {
|
||||||
network.nodes.get_mut(&chan.one_to_two.src_node_id).unwrap().channels.retain(|chan_id| {
|
Self::remove_channel_in_nodes(&mut network.nodes, &chan, *short_channel_id);
|
||||||
chan_id != NetworkMap::get_short_id(chan_id)
|
|
||||||
});
|
|
||||||
network.nodes.get_mut(&chan.two_to_one.src_node_id).unwrap().channels.retain(|chan_id| {
|
|
||||||
chan_id != NetworkMap::get_short_id(chan_id)
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -462,6 +457,25 @@ impl Router {
|
||||||
unimplemented!();
|
unimplemented!();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn remove_channel_in_nodes(nodes: &mut HashMap<PublicKey, NodeInfo>, chan: &ChannelInfo, short_channel_id: u64) {
|
||||||
|
macro_rules! remove_from_node {
|
||||||
|
($node_id: expr) => {
|
||||||
|
if let Entry::Occupied(mut entry) = nodes.entry($node_id) {
|
||||||
|
entry.get_mut().channels.retain(|chan_id| {
|
||||||
|
short_channel_id != *NetworkMap::get_short_id(chan_id)
|
||||||
|
});
|
||||||
|
if entry.get().channels.is_empty() {
|
||||||
|
entry.remove_entry();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
panic!("Had channel that pointed to unknown node (ie inconsistent network map)!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
remove_from_node!(chan.one_to_two.src_node_id);
|
||||||
|
remove_from_node!(chan.two_to_one.src_node_id);
|
||||||
|
}
|
||||||
|
|
||||||
/// Gets a route from us to the given target node.
|
/// Gets a route from us to the given target node.
|
||||||
/// Extra routing hops between known nodes and the target will be used if they are included in
|
/// Extra routing hops between known nodes and the target will be used if they are included in
|
||||||
/// last_hops.
|
/// last_hops.
|
||||||
|
|
Loading…
Add table
Reference in a new issue