Skip to content

Commit

Permalink
fixup! Merge branch 'origin/grarco/masp-fee-payment' (#3393)
Browse files Browse the repository at this point in the history
  • Loading branch information
brentstone committed Jul 4, 2024
1 parent ce2f0e4 commit 65cdd3e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 38 deletions.
2 changes: 2 additions & 0 deletions crates/ibc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,15 @@ pub fn decode_message(tx_data: &[u8]) -> Result<IbcMessage, Error> {
let msg = MsgTransfer {
message,
transfer: None,
fee_unshield: None,
};
return Ok(IbcMessage::Transfer(msg));
}
if let Ok(message) = IbcMsgNftTransfer::try_from(any_msg) {
let msg = MsgNftTransfer {
message,
transfer: None,
fee_unshield: None,
};
return Ok(IbcMessage::NftTransfer(msg));
}
Expand Down
14 changes: 9 additions & 5 deletions crates/namada/src/ledger/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use namada_events::extend::{
};
use namada_events::EventLevel;
use namada_gas::TxGasMeter;
use namada_parameters::get_gas_scale;
use namada_state::TxWrites;
use namada_token::event::{TokenEvent, TokenOperation, UserAccount};
use namada_token::utils::is_masp_transfer;
Expand Down Expand Up @@ -487,10 +488,11 @@ where
|| (BatchResults::default(), None),
|(batched_result, masp_section_ref)| {
let mut batch = BatchResults::default();
batch.0.insert(
batch.insert_inner_tx_result(
// Ok to unwrap cause if we have a batched result it means
// we've executed the first tx in the batch
tx.first_commitments().unwrap().get_hash(),
tx.wrapper_hash().as_ref(),
either::Right(tx.first_commitments().unwrap()),
Ok(batched_result),
);
(batch, Some(MaspTxRefs(vec![masp_section_ref])))
Expand Down Expand Up @@ -694,11 +696,13 @@ where
.expect("Error reading the storage")
.expect("Missing masp fee payment gas limit in storage")
.min(tx_gas_meter.borrow().tx_gas_limit.into());
let gas_scale = get_gas_scale(&**state).map_err(Error::StorageError)?;

let mut gas_meter = TxGasMeter::new(
namada_gas::Gas::from_whole_units(max_gas_limit).ok_or_else(|| {
Error::GasError("Overflow in gas expansion".to_string())
})?,
namada_gas::Gas::from_whole_units(max_gas_limit, gas_scale)
.ok_or_else(|| {
Error::GasError("Overflow in gas expansion".to_string())
})?,
);
gas_meter
.copy_consumed_gas_from(&tx_gas_meter.borrow())
Expand Down
46 changes: 13 additions & 33 deletions crates/sdk/src/masp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ use namada_token::{self as token, Denomination, MaspDigitPos};
use namada_tx::{IndexedTx, Tx};
use rand::rngs::StdRng;
use rand_core::{CryptoRng, OsRng, RngCore, SeedableRng};
use smooth_operator::checked;
use thiserror::Error;

use crate::error::{Error, QueryError};
Expand Down Expand Up @@ -1750,19 +1751,15 @@ impl<U: ShieldedUtils + MaybeSend + MaybeSync> ShieldedContext<U> {
// We add a dummy UTXO to our transaction, but only the source
// of the parent Transfer object is used to
// validate fund availability
let source_enc = source
.address()
let script = source
.t_addr_data()
.ok_or_else(|| {
Error::Other(
"source address should be transparent".to_string(),
)
})?
.serialize_to_vec();
.taddress();

let hash = ripemd::Ripemd160::digest(sha2::Sha256::digest(
source_enc.as_ref(),
));
let script = TransparentAddress(hash.into());
for (digit, asset_type) in
MaspDigitPos::iter().zip(asset_types.iter())
{
Expand Down Expand Up @@ -1809,24 +1806,7 @@ impl<U: ShieldedUtils + MaybeSend + MaybeSync> ShieldedContext<U> {
.await;

let payment_address = target.payment_address();
// If we are sending to a transparent output, then we will need to
// embed the transparent target address into the
// shielded transaction so that it can be signed
let transparent_target_hash = if payment_address.is_none() {
let target_enc = target
.address()
.ok_or_else(|| {
Error::Other(
"target address should be transparent".to_string(),
)
})?
.serialize_to_vec();
Some(ripemd::Ripemd160::digest(sha2::Sha256::digest(
target_enc.as_ref(),
)))
} else {
None
};

// This indicates how many more assets need to be sent to the
// receiver in order to satisfy the requested transfer
// amount.
Expand Down Expand Up @@ -1876,24 +1856,24 @@ impl<U: ShieldedUtils + MaybeSend + MaybeSync> ShieldedContext<U> {
error: builder::Error::SaplingBuild(e),
data: None,
})?;
} else {
} else if let Some(t_addr_data) = target.t_addr_data() {
// If there is a transparent output
let hash = transparent_target_hash
.expect(
"transparent target hash should have been \
computed already",
)
.into();
builder
.add_transparent_output(
&TransparentAddress(hash),
&t_addr_data.taddress(),
*asset_type,
contr,
)
.map_err(|e| TransferErr::Build {
error: builder::Error::TransparentBuild(e),
data: None,
})?;
} else {
return Result::Err(TransferErr::from(Error::Other(
"transaction target must be a payment address or \
Namada address or IBC address"
.to_string(),
)));
}
// Lower what is required of the remaining contribution
*rem_amount -= contr;
Expand Down
1 change: 1 addition & 0 deletions crates/tests/src/e2e/ibc_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ fn run_ledger_ibc_with_hermes() -> Result<()> {
NAM,
10_000,
ALBERT_KEY,
false,
)?;
shielded_sync(&test_a, AA_VIEWING_KEY)?;
// Shieded transfer from Chain A to Chain B
Expand Down

0 comments on commit 65cdd3e

Please sign in to comment.