Skip to content

Commit

Permalink
retry tx submission on shielding
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraccaman committed Jun 3, 2024
1 parent 7ca3717 commit 21c9d36
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
32 changes: 16 additions & 16 deletions crates/apps_lib/src/client/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,21 +775,6 @@ pub async fn submit_shielded_transfer(
pub async fn submit_shielding_transfer(
namada: &impl Namada,
args: args::TxShieldingTransfer,
) -> Result<(), error::Error> {
let (mut tx, signing_data) = args.clone().build(namada).await?;

if args.tx.dump_tx {
tx::dump_tx(namada.io(), &args.tx, tx);
} else {
sign(namada, &mut tx, &args.tx, signing_data).await?;
namada.submit(tx, &args.tx).await?;
}
Ok(())
}

pub async fn submit_unshielding_transfer(
namada: &impl Namada,
args: args::TxUnshieldingTransfer,
) -> Result<(), error::Error> {
// Repeat once if the tx fails on a crossover of an epoch
for _ in 0..2 {
Expand All @@ -813,7 +798,7 @@ pub async fn submit_unshielding_transfer(
if tx_epoch != submission_epoch {
// Then we probably straddled an epoch boundary. Let's retry...
edisplay_line!(namada.io(),
"Unshielding transaction rejected and this may be due to the \
"Shielding transaction rejected and this may be due to the \
epoch changing. Attempting to resubmit transaction.",
);
continue;
Expand All @@ -828,6 +813,21 @@ pub async fn submit_unshielding_transfer(
Ok(())
}

pub async fn submit_unshielding_transfer(
namada: &impl Namada,
args: args::TxUnshieldingTransfer,
) -> Result<(), error::Error> {
let (mut tx, signing_data) = args.clone().build(namada).await?;

if args.tx.dump_tx {
tx::dump_tx(namada.io(), &args.tx, tx);
} else {
sign(namada, &mut tx, &args.tx, signing_data).await?;
namada.submit(tx, &args.tx).await?;
}
Ok(())
}

pub async fn submit_ibc_transfer<N: Namada>(
namada: &N,
args: args::TxIbcTransfer,
Expand Down
4 changes: 2 additions & 2 deletions crates/sdk/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl TxShieldingTransfer {
pub async fn build(
&mut self,
context: &impl Namada,
) -> crate::error::Result<(namada_tx::Tx, SigningTxData)> {
) -> crate::error::Result<(namada_tx::Tx, SigningTxData, Epoch)> {
tx::build_shielding_transfer(context, self).await
}
}
Expand All @@ -374,7 +374,7 @@ impl TxUnshieldingTransfer {
pub async fn build(
&mut self,
context: &impl Namada,
) -> crate::error::Result<(namada_tx::Tx, SigningTxData, Epoch)> {
) -> crate::error::Result<(namada_tx::Tx, SigningTxData)> {
tx::build_unshielding_transfer(context, self).await
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/sdk/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2989,7 +2989,7 @@ pub async fn build_shielded_transfer<N: Namada>(
pub async fn build_shielding_transfer<N: Namada>(
context: &N,
args: &mut args::TxShieldingTransfer,
) -> Result<(Tx, SigningTxData)> {
) -> Result<(Tx, SigningTxData, Epoch)> {
let source = &args.source;
let default_signer = Some(source.clone());
let signing_data = signing::aux_signing_data(
Expand Down Expand Up @@ -3044,6 +3044,7 @@ pub async fn build_shielding_transfer<N: Namada>(
)
.await?
.expect("Shielding transfer must have shielded parts");
let shielded_tx_epoch = shielded_parts.0.epoch;

let add_shielded_parts =
|tx: &mut Tx, data: &mut token::ShieldingTransfer| {
Expand Down Expand Up @@ -3093,14 +3094,14 @@ pub async fn build_shielding_transfer<N: Namada>(
&signing_data.fee_payer,
)
.await?;
Ok((tx, signing_data))
Ok((tx, signing_data, shielded_tx_epoch))
}

/// Build an unshielding transfer
pub async fn build_unshielding_transfer<N: Namada>(
context: &N,
args: &mut args::TxUnshieldingTransfer,
) -> Result<(Tx, SigningTxData, Epoch)> {
) -> Result<(Tx, SigningTxData)> {
let default_signer = Some(MASP);
let signing_data = signing::aux_signing_data(
context,
Expand Down Expand Up @@ -3130,7 +3131,6 @@ pub async fn build_unshielding_transfer<N: Namada>(
)
.await?
.expect("Shielding transfer must have shielded parts");
let shielded_tx_epoch = shielded_parts.0.epoch;

let add_shielded_parts =
|tx: &mut Tx, data: &mut token::UnshieldingTransfer| {
Expand Down Expand Up @@ -3179,7 +3179,7 @@ pub async fn build_unshielding_transfer<N: Namada>(
&signing_data.fee_payer,
)
.await?;
Ok((tx, signing_data, shielded_tx_epoch))
Ok((tx, signing_data))
}

// Construct the shielded part of the transaction, if any
Expand Down

0 comments on commit 21c9d36

Please sign in to comment.