From 50bf63a01beb24295919bafbf0d40b4cbbd2d540 Mon Sep 17 00:00:00 2001 From: yito88 Date: Mon, 20 May 2024 23:59:56 +0200 Subject: [PATCH] tx_ibc wasm again --- crates/ibc/src/actions.rs | 93 ++----------------- crates/ibc/src/context/storage.rs | 9 +- crates/ibc/src/lib.rs | 14 ++- .../src/ledger/native_vp/ibc/context.rs | 23 ++--- crates/namada/src/vm/host_env.rs | 66 ------------- crates/namada/src/vm/wasm/host_env.rs | 1 - crates/tests/src/vm_host_env/mod.rs | 71 +++++--------- crates/tx_prelude/src/ibc.rs | 18 ++-- crates/tx_prelude/src/lib.rs | 13 --- crates/vm_env/src/lib.rs | 4 - wasm/tx_ibc/src/lib.rs | 15 ++- 11 files changed, 67 insertions(+), 260 deletions(-) diff --git a/crates/ibc/src/actions.rs b/crates/ibc/src/actions.rs index d2529b76260..07e9393b2c0 100644 --- a/crates/ibc/src/actions.rs +++ b/crates/ibc/src/actions.rs @@ -17,8 +17,8 @@ use namada_events::{EmitEvents, EventTypeBuilder}; use namada_governance::storage::proposal::PGFIbcTarget; use namada_parameters::read_epoch_duration_parameter; use namada_state::{ - DBIter, Epochs, ResultExt, State, StateRead, StorageError, StorageHasher, - StorageRead, StorageResult, StorageWrite, TxHostEnvState, WlState, DB, + DBIter, Epochs, ResultExt, State, StorageError, StorageHasher, StorageRead, + StorageResult, StorageWrite, WlState, DB, }; use namada_token as token; use token::DenominatedAmount; @@ -114,80 +114,6 @@ where } } -impl IbcStorageContext for TxHostEnvState<'_, D, H> -where - D: 'static + DB + for<'iter> DBIter<'iter>, - H: 'static + StorageHasher, -{ - fn emit_ibc_event(&mut self, event: IbcEvent) -> Result<(), StorageError> { - let gas = self.write_log_mut().emit_event(event); - self.charge_gas(gas).into_storage_result()?; - Ok(()) - } - - fn get_ibc_events( - &self, - event_type: impl AsRef, - ) -> Result, StorageError> { - let event_type = EventTypeBuilder::new_of::() - .with_segment(event_type) - .build(); - - Ok(self - .write_log() - .lookup_events_with_prefix(&event_type) - .filter_map(|event| IbcEvent::try_from(event).ok()) - .collect()) - } - - fn transfer_token( - &mut self, - src: &Address, - dest: &Address, - token: &Address, - amount: Amount, - ) -> Result<(), StorageError> { - token::transfer(self, token, src, dest, amount) - } - - fn handle_masp_tx( - &mut self, - shielded: &masp_primitives::transaction::Transaction, - ) -> Result<(), StorageError> { - namada_token::utils::handle_masp_tx(self, shielded)?; - namada_token::utils::update_note_commitment_tree(self, shielded) - } - - fn mint_token( - &mut self, - target: &Address, - token: &Address, - amount: Amount, - ) -> Result<(), StorageError> { - ibc_storage::mint_tokens(self, target, token, amount) - } - - fn burn_token( - &mut self, - target: &Address, - token: &Address, - amount: Amount, - ) -> Result<(), StorageError> { - ibc_storage::burn_tokens(self, target, token, amount) - } - - fn log_string(&self, message: String) { - tracing::trace!(message); - } -} - -impl IbcCommonContext for TxHostEnvState<'_, D, H> -where - D: 'static + DB + for<'iter> DBIter<'iter>, - H: 'static + StorageHasher, -{ -} - impl IbcStorageContext for IbcProtocolContext<'_, S> where S: State + EmitEvents, @@ -225,14 +151,6 @@ where token::transfer(self.state, token, src, dest, amount) } - /// Handle masp tx - fn handle_masp_tx( - &mut self, - _shielded: &masp_primitives::transaction::Transaction, - ) -> Result<(), StorageError> { - unimplemented!("No MASP transfer in an IBC protocol transaction") - } - /// Mint token fn mint_token( &mut self, @@ -253,6 +171,13 @@ where ibc_storage::burn_tokens(self.state, target, token, amount) } + fn insert_verifier( + &mut self, + _verifier: &Address, + ) -> Result<(), StorageError> { + Ok(()) + } + fn log_string(&self, message: String) { tracing::trace!(message); } diff --git a/crates/ibc/src/context/storage.rs b/crates/ibc/src/context/storage.rs index 7aae70b5d19..4db283e5671 100644 --- a/crates/ibc/src/context/storage.rs +++ b/crates/ibc/src/context/storage.rs @@ -27,12 +27,6 @@ pub trait IbcStorageContext: StorageRead + StorageWrite { amount: Amount, ) -> Result<(), Error>; - /// Handle masp tx - fn handle_masp_tx( - &mut self, - shielded: &masp_primitives::transaction::Transaction, - ) -> Result<(), Error>; - /// Mint token fn mint_token( &mut self, @@ -49,6 +43,9 @@ pub trait IbcStorageContext: StorageRead + StorageWrite { amount: Amount, ) -> Result<(), Error>; + /// Insert the verifier + fn insert_verifier(&mut self, verifier: &Address) -> Result<(), Error>; + /// Logging fn log_string(&self, message: String); } diff --git a/crates/ibc/src/lib.rs b/crates/ibc/src/lib.rs index b7efdbc268a..6f53da37e6b 100644 --- a/crates/ibc/src/lib.rs +++ b/crates/ibc/src/lib.rs @@ -80,8 +80,8 @@ pub enum Error { Trace(String), #[error("Invalid chain ID: {0}")] ChainId(IdentifierError), - #[error("Handling MASP transaction error: {0}")] - MaspTx(String), + #[error("Verifier insertion error: {0}")] + Verifier(namada_storage::Error), } /// IBC actions to handle IBC operations @@ -133,6 +133,7 @@ where self.ctx.inner.clone(), self.verifiers.clone(), ); + self.insert_verifiers()?; send_transfer_execute( &mut self.ctx, &mut token_transfer_ctx, @@ -349,6 +350,7 @@ where self.ctx.inner.clone(), verifiers.clone(), ); + self.insert_verifiers()?; send_transfer_validate( &self.ctx, &token_transfer_ctx, @@ -390,6 +392,14 @@ where } } } + + fn insert_verifiers(&self) -> Result<(), Error> { + let mut ctx = self.ctx.inner.borrow_mut(); + for verifier in self.verifiers.borrow().iter() { + ctx.insert_verifier(verifier).map_err(Error::Verifier)?; + } + Ok(()) + } } fn is_ack_successful(ack: &Acknowledgement) -> Result { diff --git a/crates/namada/src/ledger/native_vp/ibc/context.rs b/crates/namada/src/ledger/native_vp/ibc/context.rs index eb8d74a0582..019c5cb3b49 100644 --- a/crates/namada/src/ledger/native_vp/ibc/context.rs +++ b/crates/namada/src/ledger/native_vp/ibc/context.rs @@ -223,14 +223,6 @@ where transfer(self, token, src, dest, amount) } - fn handle_masp_tx( - &mut self, - shielded: &masp_primitives::transaction::Transaction, - ) -> Result<()> { - crate::token::utils::handle_masp_tx(self, shielded)?; - crate::token::utils::update_note_commitment_tree(self, shielded) - } - fn mint_token( &mut self, target: &Address, @@ -255,6 +247,10 @@ where burn_tokens(self, token, target, amount) } + fn insert_verifier(&mut self, _verifier: &Address) -> Result<()> { + Ok(()) + } + fn log_string(&self, message: String) { tracing::debug!("{message} in the pseudo execution for IBC VP"); } @@ -393,13 +389,6 @@ where unimplemented!("Validation doesn't transfer") } - fn handle_masp_tx( - &mut self, - _shielded: &masp_primitives::transaction::Transaction, - ) -> Result<()> { - unimplemented!("Validation doesn't handle a masp tx") - } - fn mint_token( &mut self, _target: &Address, @@ -418,6 +407,10 @@ where unimplemented!("Validation doesn't burn") } + fn insert_verifier(&mut self, _verifier: &Address) -> Result<()> { + Ok(()) + } + /// Logging fn log_string(&self, message: String) { tracing::debug!("{message} for validation in IBC VP"); diff --git a/crates/namada/src/vm/host_env.rs b/crates/namada/src/vm/host_env.rs index 2b52406f494..b39a69a4a79 100644 --- a/crates/namada/src/vm/host_env.rs +++ b/crates/namada/src/vm/host_env.rs @@ -7,7 +7,6 @@ use std::num::TryFromIntError; use borsh::BorshDeserialize; use borsh_ext::BorshSerializeExt; -use gas::IBC_TX_GAS; use masp_primitives::transaction::Transaction; use namada_core::address::ESTABLISHED_ADDRESS_BYTES_LEN; use namada_core::internal::KeyVal; @@ -75,10 +74,6 @@ pub enum TxRuntimeError { NumConversionError(TryFromIntError), #[error("Memory error: {0}")] MemoryError(Box), - #[error("Missing tx data")] - MissingTxData, - #[error("IBC: {0}")] - Ibc(#[from] namada_ibc::Error), #[error("No value found in result buffer")] NoValueInResultBuffer, #[error("VP code is not allowed in allowlist parameter.")] @@ -2018,67 +2013,6 @@ where Ok(()) } -/// Execute IBC tx. -// Temporarily the IBC tx execution is implemented via a host function to -// workaround wasm issue. -pub fn tx_ibc_execute( - env: &TxVmEnv, -) -> TxResult -where - MEM: VmMemory, - D: 'static + DB + for<'iter> DBIter<'iter>, - H: 'static + StorageHasher, - CA: WasmCacheAccess, -{ - use std::rc::Rc; - - use namada_ibc::{IbcActions, NftTransferModule, TransferModule}; - - tx_charge_gas::(env, IBC_TX_GAS)?; - - let tx = unsafe { env.ctx.tx.get() }; - let tx_data = tx.data().ok_or_else(|| { - let sentinel = unsafe { env.ctx.sentinel.get() }; - sentinel.borrow_mut().set_invalid_commitment(); - TxRuntimeError::MissingTxData - })?; - let state = Rc::new(RefCell::new(env.state())); - // Verifier set populated in tx execution - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - // Scoped to drop `verifiers.clone`s after `actions.execute` - let transfer = { - let mut actions = IbcActions::new(state.clone(), verifiers.clone()); - let module = TransferModule::new(state.clone(), verifiers.clone()); - actions.add_transfer_module(module); - let module = NftTransferModule::new(state); - actions.add_transfer_module(module); - actions.execute(&tx_data)? - }; - // NB: There must be no other strong references to this Rc - let verifiers = Rc::into_inner(verifiers) - .expect("There must be only one strong ref to verifiers set") - .into_inner(); - - // Insert all the verifiers from the tx into the verifier set in env - let verifiers_in_env = unsafe { env.ctx.verifiers.get() }; - for addr in verifiers.into_iter() { - tx_charge_gas::( - env, - ESTABLISHED_ADDRESS_BYTES_LEN as u64 * MEMORY_ACCESS_GAS_PER_BYTE, - )?; - verifiers_in_env.insert(addr); - } - - let value = transfer.serialize_to_vec(); - let len: i64 = value - .len() - .try_into() - .map_err(TxRuntimeError::NumConversionError)?; - let result_buffer = unsafe { env.ctx.result_buffer.get() }; - result_buffer.replace(value); - Ok(len) -} - /// Validate a VP WASM code hash in a tx environment. fn tx_validate_vp_code_hash( env: &TxVmEnv, diff --git a/crates/namada/src/vm/wasm/host_env.rs b/crates/namada/src/vm/wasm/host_env.rs index 855121fc835..1f0e9841b05 100644 --- a/crates/namada/src/vm/wasm/host_env.rs +++ b/crates/namada/src/vm/wasm/host_env.rs @@ -83,7 +83,6 @@ where "namada_tx_get_pred_epochs" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_get_pred_epochs), "namada_tx_get_native_token" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_get_native_token), "namada_tx_log_string" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_log_string), - "namada_tx_ibc_execute" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_ibc_execute), "namada_tx_set_commitment_sentinel" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_set_commitment_sentinel), "namada_tx_verify_tx_section_signature" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_verify_tx_section_signature), "namada_tx_update_masp_note_commitment_tree" => Function::new_native_with_env(wasm_store, env.clone(), host_env::tx_update_masp_note_commitment_tree), diff --git a/crates/tests/src/vm_host_env/mod.rs b/crates/tests/src/vm_host_env/mod.rs index 479c25e5461..382f98a2cf2 100644 --- a/crates/tests/src/vm_host_env/mod.rs +++ b/crates/tests/src/vm_host_env/mod.rs @@ -18,10 +18,8 @@ pub mod vp; #[cfg(test)] mod tests { - use std::cell::RefCell; use std::collections::BTreeSet; use std::panic; - use std::rc::Rc; use borsh_ext::BorshSerializeExt; use itertools::Itertools; @@ -706,8 +704,7 @@ mod tests { .sign_wrapper(keypair.clone()); // create a client with the message - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - tx_host_env::ibc::ibc_actions(tx::ctx(), verifiers) + tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) .expect("creating a client failed"); @@ -737,8 +734,7 @@ mod tests { .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); // update the client with the message - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - tx_host_env::ibc::ibc_actions(tx::ctx(), verifiers) + tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) .expect("updating a client failed"); @@ -778,8 +774,7 @@ mod tests { .sign_raw(keypairs.clone(), pks_map.clone(), None) .sign_wrapper(keypair.clone()); // init a connection with the message - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - tx_host_env::ibc::ibc_actions(tx::ctx(), verifiers) + tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) .expect("creating a connection failed"); @@ -809,8 +804,7 @@ mod tests { .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); // open the connection with the message - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - tx_host_env::ibc::ibc_actions(tx::ctx(), verifiers) + tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) .expect("opening the connection failed"); @@ -851,8 +845,7 @@ mod tests { .sign_raw(keypairs.clone(), pks_map.clone(), None) .sign_wrapper(keypair.clone()); // open try a connection with the message - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - tx_host_env::ibc::ibc_actions(tx::ctx(), verifiers) + tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) .expect("creating a connection failed"); @@ -882,8 +875,7 @@ mod tests { .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); // open the connection with the mssage - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - tx_host_env::ibc::ibc_actions(tx::ctx(), verifiers) + tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) .expect("opening the connection failed"); @@ -926,8 +918,7 @@ mod tests { .sign_raw(keypairs.clone(), pks_map.clone(), None) .sign_wrapper(keypair.clone()); // init a channel with the message - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - tx_host_env::ibc::ibc_actions(tx::ctx(), verifiers) + tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) .expect("creating a channel failed"); @@ -957,8 +948,7 @@ mod tests { .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); // open the channel with the message - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - tx_host_env::ibc::ibc_actions(tx::ctx(), verifiers) + tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) .expect("opening the channel failed"); @@ -1001,8 +991,7 @@ mod tests { .sign_raw(keypairs.clone(), pks_map.clone(), None) .sign_wrapper(keypair.clone()); // try open a channel with the message - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - tx_host_env::ibc::ibc_actions(tx::ctx(), verifiers) + tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) .expect("creating a channel failed"); @@ -1033,8 +1022,7 @@ mod tests { .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); // open a channel with the message - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - tx_host_env::ibc::ibc_actions(tx::ctx(), verifiers) + tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) .expect("opening the channel failed"); @@ -1080,8 +1068,7 @@ mod tests { .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); // close the channel with the message - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - let mut actions = tx_host_env::ibc::ibc_actions(tx::ctx(), verifiers); + let mut actions = tx_host_env::ibc::ibc_actions(tx::ctx()); // the dummy module closes the channel let dummy_module = DummyTransferModule {}; actions.add_transfer_module(dummy_module); @@ -1138,8 +1125,7 @@ mod tests { .sign_wrapper(keypair); // close the channel with the message - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - tx_host_env::ibc::ibc_actions(tx::ctx(), verifiers) + tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) .expect("closing the channel failed"); @@ -1185,8 +1171,7 @@ mod tests { .sign_raw(keypairs.clone(), pks_map.clone(), None) .sign_wrapper(keypair.clone()); // send the token and a packet with the data - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - tx_host_env::ibc::ibc_actions(tx::ctx(), verifiers) + tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) .expect("sending a token failed"); @@ -1230,8 +1215,7 @@ mod tests { .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); // ack the packet with the message - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - tx_host_env::ibc::ibc_actions(tx::ctx(), verifiers) + tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) .expect("ack failed"); @@ -1315,8 +1299,7 @@ mod tests { .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); // send the token and a packet with the data - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - tx_host_env::ibc::ibc_actions(tx::ctx(), verifiers) + tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) .expect("sending a token failed"); @@ -1394,8 +1377,7 @@ mod tests { .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); // receive a packet with the message - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - tx_host_env::ibc::ibc_actions(tx::ctx(), verifiers) + tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) .expect("receiving the token failed"); @@ -1481,8 +1463,7 @@ mod tests { .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); // Receive the packet, but no token is received - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - tx_host_env::ibc::ibc_actions(tx::ctx(), verifiers) + tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) .expect("receiving the token failed"); @@ -1574,8 +1555,7 @@ mod tests { .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); // receive a packet with the message - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - tx_host_env::ibc::ibc_actions(tx::ctx(), verifiers) + tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) .expect("receiving a token failed"); @@ -1673,8 +1653,7 @@ mod tests { .sign_raw(keypairs, pks_map, None) .sign_wrapper(keypair); // receive a packet with the message - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - tx_host_env::ibc::ibc_actions(tx::ctx(), verifiers) + tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) .expect("receiving a token failed"); @@ -1732,8 +1711,7 @@ mod tests { ibc::set_timeout_timestamp(&mut msg.message); let tx_data = msg.serialize_to_vec(); // send a packet with the message - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - tx_host_env::ibc::ibc_actions(tx::ctx(), verifiers) + tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) .expect("sending a token failed"); @@ -1765,8 +1743,7 @@ mod tests { .sign_wrapper(keypair); // timeout the packet - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - tx_host_env::ibc::ibc_actions(tx::ctx(), verifiers) + tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) .expect("timeout failed"); @@ -1813,8 +1790,7 @@ mod tests { ibc::msg_transfer(port_id, channel_id, token.to_string(), &sender); let tx_data = msg.serialize_to_vec(); // send a packet with the message - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - tx_host_env::ibc::ibc_actions(tx::ctx(), verifiers) + tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) .expect("sending a token failed"); @@ -1846,8 +1822,7 @@ mod tests { .sign_wrapper(keypair); // timeout the packet - let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); - tx_host_env::ibc::ibc_actions(tx::ctx(), verifiers) + tx_host_env::ibc::ibc_actions(tx::ctx()) .execute(&tx_data) .expect("timeout on close failed"); diff --git a/crates/tx_prelude/src/ibc.rs b/crates/tx_prelude/src/ibc.rs index 61f470bae6f..2aaa5d04cf3 100644 --- a/crates/tx_prelude/src/ibc.rs +++ b/crates/tx_prelude/src/ibc.rs @@ -23,11 +23,9 @@ use crate::{Ctx, Error}; /// IBC actions to handle an IBC message. The `verifiers` inserted into the set /// must be inserted into the tx context with `Ctx::insert_verifier` after tx /// execution. -pub fn ibc_actions( - ctx: &mut Ctx, - verifiers: Rc>>, -) -> IbcActions { +pub fn ibc_actions(ctx: &mut Ctx) -> IbcActions { let ctx = Rc::new(RefCell::new(ctx.clone())); + let verifiers = Rc::new(RefCell::new(BTreeSet::
::new())); let mut actions = IbcActions::new(ctx.clone(), verifiers.clone()); let module = TransferModule::new(ctx.clone(), verifiers); actions.add_transfer_module(module); @@ -68,14 +66,6 @@ impl IbcStorageContext for Ctx { transfer(self, src, dest, token, amount) } - fn handle_masp_tx( - &mut self, - shielded: &masp_primitives::transaction::Transaction, - ) -> Result<(), Error> { - namada_token::utils::handle_masp_tx(self, shielded)?; - namada_token::utils::update_note_commitment_tree(self, shielded) - } - fn mint_token( &mut self, target: &Address, @@ -94,6 +84,10 @@ impl IbcStorageContext for Ctx { burn_tokens(self, target, token, amount) } + fn insert_verifier(&mut self, addr: &Address) -> Result<(), Error> { + TxEnv::insert_verifier(self, addr) + } + fn log_string(&self, message: String) { super::log_string(message); } diff --git a/crates/tx_prelude/src/lib.rs b/crates/tx_prelude/src/lib.rs index 3948342af80..3f4f3123806 100644 --- a/crates/tx_prelude/src/lib.rs +++ b/crates/tx_prelude/src/lib.rs @@ -410,19 +410,6 @@ impl namada_tx::action::Write for Ctx { } } -/// Execute IBC tx. -// Temp. workaround for -pub fn tx_ibc_execute() -> Result, Error> { - let result = unsafe { namada_tx_ibc_execute() }; - match read_from_buffer(result, namada_tx_result_buffer) { - Some(value) => { - Ok(Option::::try_from_slice(&value[..]) - .expect("The conversion shouldn't fail")) - } - None => Ok(None), - } -} - /// Verify section signatures against the given list of keys pub fn verify_signatures_of_pks( ctx: &Ctx, diff --git a/crates/vm_env/src/lib.rs b/crates/vm_env/src/lib.rs index 26f85aceef0..16d66dfba83 100644 --- a/crates/vm_env/src/lib.rs +++ b/crates/vm_env/src/lib.rs @@ -122,10 +122,6 @@ pub mod tx { /// Charge the provided amount of gas for the current tx pub fn namada_tx_charge_gas(used_gas: u64); - /// Execute IBC tx. - // Temp. workaround for - pub fn namada_tx_ibc_execute() -> i64; - /// Set the sentinel for a wrong tx section commitment pub fn namada_tx_set_commitment_sentinel(); diff --git a/wasm/tx_ibc/src/lib.rs b/wasm/tx_ibc/src/lib.rs index e81f541bd7b..4ac623c459d 100644 --- a/wasm/tx_ibc/src/lib.rs +++ b/wasm/tx_ibc/src/lib.rs @@ -8,16 +8,13 @@ use namada_tx_prelude::*; #[transaction] fn apply_tx(ctx: &mut Ctx, tx_data: Tx) -> TxResult { let signed = tx_data; - // let data = signed.data().ok_or_err_msg("Missing data").or_else(|err| { - // ctx.set_commitment_sentinel(); - // Err(err) - // })?; + let data = signed.data().ok_or_err_msg("Missing data").map_err(|err| { + ctx.set_commitment_sentinel(); + err + })?; - // let transfer = - // ibc::ibc_actions(ctx).execute(&data).into_storage_result()?; - - // Temp. workaround for - let transfer = tx_ibc_execute()?; + let transfer = + ibc::ibc_actions(ctx).execute(&data).into_storage_result()?; if let Some(transfer) = transfer { let shielded = transfer