Skip to content

Commit

Permalink
Merge branch 'yuji/tx-ibc-wasm' (#3275)
Browse files Browse the repository at this point in the history
* origin/yuji/tx-ibc-wasm:
  gas: remove unused ibc tx gas
  remove allowed_txs bench
  add changelog
  enable floating-point support
  tx_ibc wasm again
  • Loading branch information
brentstone committed May 23, 2024
2 parents af0ec45 + e1c2812 commit e7aea38
Show file tree
Hide file tree
Showing 18 changed files with 69 additions and 426 deletions.
3 changes: 3 additions & 0 deletions .changelog/unreleased/improvements/1831-tx-ibc-wasm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- Revert IBC transaction wasm not to use host_env function.
But it required to enable floating-point support again
([\#1831](https://github.com/anoma/namada/issues/1831))
5 changes: 0 additions & 5 deletions crates/benches/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ readme.workspace = true
repository.workspace = true
version.workspace = true

[[bench]]
name = "allowed_txs"
harness = false
path = "txs.rs"

[[bench]]
name = "native_vps"
harness = false
Expand Down
2 changes: 1 addition & 1 deletion crates/benches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ cargo test --bench native_vps
To benchmark a selected bench with a minimum sample size use e.g.:

```shell
cargo bench --bench allowed_txs -- --sample-size 10
cargo bench --bench native_vps -- --sample-size 10
```
129 changes: 0 additions & 129 deletions crates/benches/txs.rs

This file was deleted.

3 changes: 0 additions & 3 deletions crates/gas/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ pub const WASM_MEMORY_PAGE_GAS: u32 =
pub const IBC_ACTION_VALIDATE_GAS: u64 = 1_472_023;
/// The cost to execute an Ibc action
pub const IBC_ACTION_EXECUTE_GAS: u64 = 3_678_745;
/// The cost to execute an ibc transaction TODO: remove once ibc tx goes back to
/// wasm
pub const IBC_TX_GAS: u64 = 111_825_500;
/// The cost to verify a masp spend note
pub const MASP_VERIFY_SPEND_GAS: u64 = 66_822_000;
/// The cost to verify a masp convert note
Expand Down
97 changes: 9 additions & 88 deletions crates/ibc/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +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, OptionExt, 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;
Expand Down Expand Up @@ -115,83 +114,6 @@ where
}
}

impl<D, H> 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)
.ok_or_err_msg("Gas overflow")?;
self.charge_gas(gas).into_storage_result()?;
Ok(())
}

fn get_ibc_events(
&self,
event_type: impl AsRef<str>,
) -> Result<Vec<IbcEvent>, StorageError> {
let event_type = EventTypeBuilder::new_of::<IbcEvent>()
.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<D, H> IbcCommonContext for TxHostEnvState<'_, D, H>
where
D: 'static + DB + for<'iter> DBIter<'iter>,
H: 'static + StorageHasher,
{
}

impl<S> IbcStorageContext for IbcProtocolContext<'_, S>
where
S: State + EmitEvents,
Expand Down Expand Up @@ -230,14 +152,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,
Expand All @@ -258,6 +172,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);
}
Expand Down
9 changes: 3 additions & 6 deletions crates/ibc/src/context/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
}
14 changes: 12 additions & 2 deletions crates/ibc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,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
Expand Down Expand Up @@ -150,6 +150,7 @@ where
self.ctx.inner.clone(),
self.verifiers.clone(),
);
self.insert_verifiers()?;
send_transfer_execute(
&mut self.ctx,
&mut token_transfer_ctx,
Expand Down Expand Up @@ -366,6 +367,7 @@ where
self.ctx.inner.clone(),
verifiers.clone(),
);
self.insert_verifiers()?;
send_transfer_validate(
&self.ctx,
&token_transfer_ctx,
Expand Down Expand Up @@ -407,6 +409,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<bool, Error> {
Expand Down
Loading

0 comments on commit e7aea38

Please sign in to comment.