Skip to content

Commit

Permalink
Refactors shielding retry logic
Browse files Browse the repository at this point in the history
  • Loading branch information
grarco committed Nov 21, 2024
1 parent 5d471e2 commit a268799
Showing 1 changed file with 29 additions and 32 deletions.
61 changes: 29 additions & 32 deletions crates/apps_lib/src/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,42 +866,39 @@ pub async fn submit_shielding_transfer(
)
.await?;

// FIXME: maybe better and if let here since we are only interested in
// one case
match result {
ProcessTxResponse::Applied(resp) => {
if let Some(InnerTxResult::VpsRejected(result)) =
resp.batch_result().get(&compute_inner_tx_hash(
wrapper_hash.as_ref(),
either::Left(&cmt_hash),
))
{
let rejected_vps = &result.vps_result.rejected_vps;
// If a transaction is rejected by the MASP VP only
if rejected_vps.len() == 1 && rejected_vps.contains(&MASP) {
let submission_masp_epoch =
rpc::query_and_print_masp_epoch(namada).await;
// And its submission epoch doesn't match construction
// epoch
if tx_epoch != submission_masp_epoch {
// Then we probably straddled an epoch boundary.
// Let's retry...
edisplay_line!(
namada.io(),
"Shielding transaction rejected and this may \
be due to the epoch changing. Attempting to \
resubmit transaction.",
);
continue;
}
// Check the need for a resubmission
if let ProcessTxResponse::Applied(resp) = result {
if let Some(InnerTxResult::VpsRejected(result)) =
resp.batch_result().get(&compute_inner_tx_hash(
wrapper_hash.as_ref(),
either::Left(&cmt_hash),
))
{
let rejected_vps = &result.vps_result.rejected_vps;
// If the transaction is rejected by the MASP VP only
if rejected_vps.len() == 1 && rejected_vps.contains(&MASP) {
let submission_masp_epoch =
rpc::query_and_print_masp_epoch(namada).await;
// And its submission epoch doesn't match construction
// epoch
if tx_epoch != submission_masp_epoch {
// Then we probably straddled an epoch boundary.
// Let's retry...
edisplay_line!(
namada.io(),
"Shielding transaction rejected and this may be \
due to the epoch changing. Attempting to \
resubmit transaction.",
);
continue;
}
}
break;
}
// Otherwise either the transaction was successful or it will not
// benefit from resubmission
_ => break,
}

// Otherwise either the transaction was successful or it will not
// benefit from resubmission
break;
}
Ok(())
}
Expand Down

0 comments on commit a268799

Please sign in to comment.