Skip to content

Commit

Permalink
Retry all payment session with actor message
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Jan 1, 2025
1 parent fbf4304 commit 851452f
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/fiber/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1454,12 +1454,10 @@ where
.await
.record_payment_fail(&payment_session, error_detail.clone());
if need_to_retry {
let res = self
.try_payment_session(myself, state, payment_session.payment_hash())
.await;
if res.is_err() {
debug!("Failed to retry payment session: {:?}", res);
}
// If this is the first hop error, like the WaitingTlcAck error,
// we will just retry later, return Ok here for letting endpoint user
// know payment session is created successfully
self.register_payment_retry(myself, payment_hash);
} else {
self.set_payment_fail_with_error(
&mut payment_session,
Expand Down Expand Up @@ -1642,14 +1640,10 @@ where
Ok(payment_session) => return Ok(payment_session),
Err(Error::SendPaymentFirstHopError(err, need_retry)) => {
if need_retry {
// If this is the first hop error, like the WaitingTlcAck error,
// If this is the first hop error, such as the WaitingTlcAck error,
// we will just retry later, return Ok here for letting endpoint user
// know payment session is created successfully
myself.send_after(Duration::from_millis(500), move || {
NetworkActorMessage::new_event(NetworkActorEvent::RetrySendPayment(
payment_hash,
))
});
self.register_payment_retry(myself, payment_hash);
return Ok(payment_session);
} else {
return Err(Error::SendPaymentError(err));
Expand All @@ -1660,11 +1654,7 @@ where
// but we need to retry later to let the actor to process failure,
// so that we can make different choice for later try
let payment_hash = payment_data.payment_hash;
myself.send_after(Duration::from_millis(500), move || {
NetworkActorMessage::new_event(NetworkActorEvent::RetrySendPayment(
payment_hash,
))
});
self.register_payment_retry(myself, payment_hash);
debug!("send payment error: {:?}", e);
return Err(e);
}
Expand All @@ -1680,6 +1670,12 @@ where
}
}

fn register_payment_retry(&self, myself: ActorRef<NetworkActorMessage>, payment_hash: Hash256) {
myself.send_after(Duration::from_millis(500), move || {
NetworkActorMessage::new_event(NetworkActorEvent::RetrySendPayment(payment_hash))
});
}

async fn on_send_payment(
&self,
myself: ActorRef<NetworkActorMessage>,
Expand Down

0 comments on commit 851452f

Please sign in to comment.