diff --git a/.changelog/unreleased/SDK/2775-fix-shielded-context-dry-run.md b/.changelog/unreleased/SDK/2775-fix-shielded-context-dry-run.md new file mode 100644 index 0000000000..8cf07298c7 --- /dev/null +++ b/.changelog/unreleased/SDK/2775-fix-shielded-context-dry-run.md @@ -0,0 +1,3 @@ +- `gen_shielded_transfer` now takes an extra `update_ctx` + argument to conditionally update the shielded context. + ([\#2775](https://github.com/anoma/namada/pull/2775)) \ No newline at end of file diff --git a/.changelog/unreleased/bug-fixes/2775-fix-shielded-context-dry-run.md b/.changelog/unreleased/bug-fixes/2775-fix-shielded-context-dry-run.md new file mode 100644 index 0000000000..94a24de34c --- /dev/null +++ b/.changelog/unreleased/bug-fixes/2775-fix-shielded-context-dry-run.md @@ -0,0 +1,3 @@ +- Fixed a bug in the client for which the speculative + shielded context was updated event in a dry run. + ([\#2775](https://github.com/anoma/namada/pull/2775)) \ No newline at end of file diff --git a/crates/apps/src/lib/bench_utils.rs b/crates/apps/src/lib/bench_utils.rs index 42f57f9a74..7b886eacdb 100644 --- a/crates/apps/src/lib/bench_utils.rs +++ b/crates/apps/src/lib/bench_utils.rs @@ -1020,6 +1020,7 @@ impl BenchShieldedCtx { &target, &address::testing::nam(), denominated_amount, + true, ), ) .unwrap() diff --git a/crates/sdk/src/masp.rs b/crates/sdk/src/masp.rs index 581f548dcb..35315ea39a 100644 --- a/crates/sdk/src/masp.rs +++ b/crates/sdk/src/masp.rs @@ -1944,6 +1944,7 @@ impl ShieldedContext { target: &TransferTarget, token: &Address, amount: token::DenominatedAmount, + update_ctx: bool, ) -> Result, TransferErr> { // No shielded components are needed when neither source nor destination // are shielded @@ -2291,13 +2292,15 @@ impl ShieldedContext { let (masp_tx, metadata) = builder.build(&prover, &FeeRule::non_standard(U64Sum::zero()))?; - // Cache the generated transfer - let mut shielded_ctx = context.shielded_mut().await; - shielded_ctx - .pre_cache_transaction( - context, &masp_tx, source, target, token, epoch, - ) - .await?; + if update_ctx { + // Cache the generated transfer + let mut shielded_ctx = context.shielded_mut().await; + shielded_ctx + .pre_cache_transaction( + context, &masp_tx, source, target, token, epoch, + ) + .await?; + } Ok(Some(ShieldedTransfer { builder: builder_clone, diff --git a/crates/sdk/src/signing.rs b/crates/sdk/src/signing.rs index 82c0c7f4ae..4d05007734 100644 --- a/crates/sdk/src/signing.rs +++ b/crates/sdk/src/signing.rs @@ -516,6 +516,7 @@ pub async fn validate_fee_and_gen_unshield( &target, &args.fee_token, fee_amount, + !(args.dry_run || args.dry_run_wrapper) ) .await { diff --git a/crates/sdk/src/tx.rs b/crates/sdk/src/tx.rs index 1c7e19cbd9..c23b6f09cb 100644 --- a/crates/sdk/src/tx.rs +++ b/crates/sdk/src/tx.rs @@ -2181,6 +2181,7 @@ pub async fn build_ibc_transfer( &TransferTarget::Address(Address::Internal(InternalAddress::Ibc)), &args.token, validated_amount, + !(args.tx.dry_run || args.tx.dry_run_wrapper), ) .await?; let shielded_tx_epoch = shielded_parts.as_ref().map(|trans| trans.0.epoch); @@ -2504,6 +2505,7 @@ pub async fn build_transfer( &args.target, &args.token, validated_amount, + !(args.tx.dry_run || args.tx.dry_run_wrapper), ) .await?; let shielded_tx_epoch = shielded_parts.as_ref().map(|trans| trans.0.epoch); @@ -2570,6 +2572,7 @@ async fn construct_shielded_parts( target: &TransferTarget, token: &Address, amount: token::DenominatedAmount, + update_ctx: bool, ) -> Result)>> { // Precompute asset types to increase chances of success in decoding let token_map = context.wallet().await.get_addresses(); @@ -2581,7 +2584,7 @@ async fn construct_shielded_parts( .await; let stx_result = ShieldedContext::::gen_shielded_transfer( - context, source, target, token, amount, + context, source, target, token, amount, update_ctx, ) .await; @@ -2877,6 +2880,7 @@ pub async fn gen_ibc_shielded_transfer( &args.target, &token, validated_amount, + true, ) .await .map_err(|err| TxSubmitError::MaspError(err.to_string()))?;