Skip to content

Commit

Permalink
feat: Retry all payment session with actor message (#430)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang authored Jan 8, 2025
1 parent 66886f0 commit b8e3056
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions src/fiber/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1498,12 +1498,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 All @@ -1530,11 +1528,13 @@ where
..
}) = &tcl_error_detail.extra_data
{
let _ = network.send_message(NetworkActorMessage::new_command(
NetworkActorCommand::ProcessBroadcastMessage(BroadcastMessage::ChannelUpdate(
channel_update.clone(),
)),
));
network
.send_message(NetworkActorMessage::new_command(
NetworkActorCommand::BroadcastMessages(vec![
BroadcastMessageWithTimestamp::ChannelUpdate(channel_update.clone()),
]),
))
.expect(ASSUME_NETWORK_MYSELF_ALIVE);
}
}
match tcl_error_detail.error_code() {
Expand Down Expand Up @@ -1756,14 +1756,10 @@ where
Err(err) => {
let need_retry = matches!(err, Error::SendPaymentFirstHopError(_, true));
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(err);
Expand All @@ -1781,6 +1777,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 Expand Up @@ -2811,15 +2813,15 @@ where
);
// Notify outside observers.
network
.send_message(NetworkActorMessage::new_event( NetworkActorEvent::FundingTransactionFailed(outpoint)
.send_message(NetworkActorMessage::new_event(NetworkActorEvent::FundingTransactionFailed(outpoint)
))
.expect(ASSUME_NETWORK_MYSELF_ALIVE);
}
Err(err) => {
error!("Failed to trace transaction {:?}: {:?}", &tx_hash, &err);
// Notify outside observers.
network
.send_message(NetworkActorMessage::new_event( NetworkActorEvent::FundingTransactionFailed(outpoint)
.send_message(NetworkActorMessage::new_event(NetworkActorEvent::FundingTransactionFailed(outpoint)
))
.expect(ASSUME_NETWORK_MYSELF_ALIVE);
}
Expand Down

0 comments on commit b8e3056

Please sign in to comment.