Skip to content

Commit

Permalink
sys: ensure an exchange deposit transaction is actually successful
Browse files Browse the repository at this point in the history
  • Loading branch information
mvines committed Nov 14, 2024
1 parent eda2f64 commit d0aa3bd
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,14 @@ async fn process_sync_exchange(
response.context.slot, epoch_info.absolute_slot
);
}
let confirmed = response.value[0]
let (confirmed, ok) = response.value[0]
.as_ref()
.map(|status| status.satisfies_commitment(rpc_client.commitment()))
.map(|status| {
(
status.satisfies_commitment(rpc_client.commitment()),
status.err.is_none(),
)
})
.unwrap_or_default();

assert_eq!(
Expand All @@ -242,7 +247,7 @@ async fn process_sync_exchange(
);
let token = pending_deposit.transfer.to_token;

if confirmed {
if confirmed && ok {
metrics::push(dp::exchange_deposit(
exchange,
token,
Expand Down Expand Up @@ -321,9 +326,16 @@ async fn process_sync_exchange(
}
}
}
} else if !ok {
println!(
"Pending {} deposit failed: {}",
token, pending_deposit.transfer.signature
);
db.cancel_deposit(pending_deposit.transfer.signature)
.expect("cancel_deposit");
} else if epoch_info.block_height > pending_deposit.transfer.last_valid_block_height {
println!(
"Pending {} deposit cancelled: {}",
"Pending {} deposit expired: {}",
token, pending_deposit.transfer.signature
);
db.cancel_deposit(pending_deposit.transfer.signature)
Expand Down

0 comments on commit d0aa3bd

Please sign in to comment.