From 9c9aece62b9fd367e72c6c257fb9b293c82a8d98 Mon Sep 17 00:00:00 2001 From: YI Date: Fri, 10 Jan 2025 19:38:54 +0800 Subject: [PATCH] Remove old loading channel from store code --- src/fiber/graph.rs | 19 ------------------- src/fiber/network.rs | 15 ++++++++++----- src/fiber/tests/payment.rs | 32 ++++---------------------------- 3 files changed, 14 insertions(+), 52 deletions(-) diff --git a/src/fiber/graph.rs b/src/fiber/graph.rs index 75a34455..ebfeadb8 100644 --- a/src/fiber/graph.rs +++ b/src/fiber/graph.rs @@ -836,25 +836,6 @@ where self.source = source; } - pub fn load_owned_channel_info(&mut self) { - for (_peer_id, channel_id, _state) in self.store.get_active_channel_states(None) { - match self.store.get_channel_actor_state(&channel_id) { - Some(channel_actor_state) => { - assert_eq!(channel_actor_state.local_pubkey, self.source); - match ChannelInfo::try_from(&channel_actor_state) { - Ok(channel_info) => { - self.channels - .insert(channel_info.channel_outpoint.clone(), channel_info); - } - Err(_) => {} - }; - } - // It is possible that after we obtained the list of channels, the channel is deleted. - None => {} - } - } - } - /// Returns a list of `PaymentHopData` for all nodes in the route, /// including the origin and the target node. pub fn build_route( diff --git a/src/fiber/network.rs b/src/fiber/network.rs index 7d289ce1..3c6d762e 100644 --- a/src/fiber/network.rs +++ b/src/fiber/network.rs @@ -959,7 +959,16 @@ where } NetworkActorEvent::OwnedChannelUpdateEvent(owned_channel_update_event) => { let mut graph = self.network_graph.write().await; + debug!( + "Received owned channel update event: {:?}", + owned_channel_update_event + ); + let is_down = + matches!(owned_channel_update_event, OwnedChannelUpdateEvent::Down(_)); graph.process_owned_channel_update_event(owned_channel_update_event); + if is_down { + debug!("Owned channel is down"); + } } } Ok(()) @@ -1591,11 +1600,7 @@ where payment_session: &mut PaymentSession, payment_data: &SendPaymentData, ) -> Result, Error> { - // Load owned channel info before building route, so that we use private channels and also the - // exact balance of the channels. - let mut rwgraph = self.network_graph.write().await; - rwgraph.load_owned_channel_info(); - let graph = tokio::sync::RwLockWriteGuard::downgrade(rwgraph); + let graph = self.network_graph.read().await; match graph.build_route(payment_data.clone()) { Err(e) => { let error = format!("Failed to build route, {}", e); diff --git a/src/fiber/tests/payment.rs b/src/fiber/tests/payment.rs index 5ba85cf9..01b1b39b 100644 --- a/src/fiber/tests/payment.rs +++ b/src/fiber/tests/payment.rs @@ -1491,7 +1491,7 @@ async fn test_send_payment_middle_hop_stopped() { true, ) .await; - let [mut node_0, _node_1, mut node_2, node_3, mut node_4] = nodes.try_into().expect("5 nodes"); + let [mut node_0, _node_1, _node_2, node_3, mut node_4] = nodes.try_into().expect("5 nodes"); // dry run node_0 -> node_3 will select 0 -> 4 -> 3 let res = node_0 @@ -1505,32 +1505,8 @@ async fn test_send_payment_middle_hop_stopped() { node_4.stop().await; tokio::time::sleep(tokio::time::Duration::from_millis(1000)).await; - let res = node_0 - .send_payment_keysend(&node_3, 1000, true) - .await - .unwrap(); - eprintln!("res: {:?}", res); - // when node_4 stopped, the first try path is still 0 -> 4 -> 3 - // so the fee is 1 - assert_eq!(res.fee, 1); - - let res = node_0 - .send_payment_keysend(&node_3, 1000, false) - .await - .unwrap(); - eprintln!("res: {:?}", res); - assert_eq!(res.fee, 1); - - node_0.wait_until_success(res.payment_hash).await; - - // after the first payment try failed, the payment session will find another path - // 0 -> 1 -> 2 -> 3, so it will succeed, but the fee change from 1 to 3 - let payment = node_0.get_payment_result(res.payment_hash).await; - assert_eq!(payment.fee, 3); - eprintln!("payment: {:?}", payment); - - // node_2 stopped, payment will fail - node_2.stop().await; + // when node_4 stopped, node 0 learned that channel 0 -> 4 was not available + // so it will try another path 0 -> 1 -> 2 -> 3 let res = node_0 .send_payment_keysend(&node_3, 1000, false) .await @@ -1538,7 +1514,7 @@ async fn test_send_payment_middle_hop_stopped() { eprintln!("res: {:?}", res); assert_eq!(res.fee, 3); - node_0.wait_until_failed(res.payment_hash).await; + node_0.wait_until_success(res.payment_hash).await; } #[tokio::test]