Skip to content

Commit

Permalink
Fix refund logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Nov 19, 2024
1 parent 529081f commit 49762ac
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions crates/packet-forward/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,21 +344,26 @@ where
inflight_packet: InFlightPacket,
acknowledgement: &Acknowledgement,
) -> Result<(), MiddlewareError> {
self.next
.receive_refund_execute(packet, transfer_pkt)
.map_err(|err| {
MiddlewareError::Message(format!(
"Failed to refund transfer sent to next hop: {err}"
))
})?;
let ack: AcknowledgementStatus = serde_json::from_slice(acknowledgement.as_bytes())
.map_err(|err| MiddlewareError::Message(format!("Failed to parse ack: {err}")))?;

self.next
.send_refund_execute(&inflight_packet)
.map_err(|err| {
MiddlewareError::Message(format!(
"Failed to refund transfer received from previous hop: {err}"
))
})?;
if !ack.is_successful() {
self.next
.receive_refund_execute(packet, transfer_pkt)
.map_err(|err| {
MiddlewareError::Message(format!(
"Failed to refund transfer sent to next hop: {err}"
))
})?;

self.next
.send_refund_execute(&inflight_packet)
.map_err(|err| {
MiddlewareError::Message(format!(
"Failed to refund transfer received from previous hop: {err}"
))
})?;
}

self.next
.write_ack_and_events(&inflight_packet.into(), acknowledgement)
Expand Down

0 comments on commit 49762ac

Please sign in to comment.