diff --git a/.changelog/unreleased/improvements/3428-better-gas-interface.md b/.changelog/unreleased/improvements/3428-better-gas-interface.md new file mode 100644 index 0000000000..fbc0d58202 --- /dev/null +++ b/.changelog/unreleased/improvements/3428-better-gas-interface.md @@ -0,0 +1,2 @@ +- Improved the interface of the gas type. Removed the duplicated gas used from + events. ([\#3428](https://github.com/anoma/namada/pull/3428)) \ No newline at end of file diff --git a/.github/workflows/scripts/hermes.txt b/.github/workflows/scripts/hermes.txt index 7669eaf98a..27439ea78e 100644 --- a/.github/workflows/scripts/hermes.txt +++ b/.github/workflows/scripts/hermes.txt @@ -1 +1 @@ -1.9.0-namada-beta13-rc2 +1.9.0-namada-beta14-rc diff --git a/crates/gas/src/event.rs b/crates/gas/src/event.rs index d76889fece..340e59a9a0 100644 --- a/crates/gas/src/event.rs +++ b/crates/gas/src/event.rs @@ -2,13 +2,13 @@ use namada_events::extend::EventAttributeEntry; -use super::Gas; +use crate::WholeGas; /// Extend an [`namada_events::Event`] with gas used data. -pub struct GasUsed(pub Gas); +pub struct GasUsed(pub WholeGas); impl EventAttributeEntry<'static> for GasUsed { - type Value = Gas; + type Value = WholeGas; type ValueOwned = Self::Value; const KEY: &'static str = "gas_used"; diff --git a/crates/gas/src/lib.rs b/crates/gas/src/lib.rs index 57468a2e8e..f404df7ee8 100644 --- a/crates/gas/src/lib.rs +++ b/crates/gas/src/lib.rs @@ -116,9 +116,10 @@ pub const MASP_PARALLEL_GAS_DIVIDER: u64 = PARALLEL_GAS_DIVIDER / 2; /// Gas module result for functions that may fail pub type Result = std::result::Result; -/// Representation of gas in sub-units. This effectively decouples gas metering -/// from fee payment, allowing higher resolution when accounting for gas while, -/// at the same time, providing a contained gas value when paying fees. +/// Representation of tracking gas in sub-units. This effectively decouples gas +/// metering from fee payment, allowing higher resolution when accounting for +/// gas while, at the same time, providing a contained gas value when paying +/// fees. #[derive( Clone, Copy, @@ -154,8 +155,8 @@ impl Gas { } /// Converts the sub gas units to whole ones. If the sub units are not a - /// multiple of the `SCALE` than ceil the quotient - pub fn get_whole_gas_units(&self, scale: u64) -> u64 { + /// multiple of the scale than ceil the quotient + pub fn get_whole_gas_units(&self, scale: u64) -> WholeGas { let quotient = self .sub .checked_div(scale) @@ -166,18 +167,18 @@ impl Gas { .expect("Gas quotient remainder should not overflow") == 0 { - quotient + quotient.into() } else { quotient .checked_add(1) .expect("Cannot overflow as the quotient is scaled down u64") + .into() } } - /// Generates a `Gas` instance from a whole amount - pub fn from_whole_units(whole: u64, scale: u64) -> Option { - let sub = whole.checked_mul(scale)?; - Some(Self { sub }) + /// Generates a `Gas` instance from a `WholeGas` amount + pub fn from_whole_units(whole: WholeGas, scale: u64) -> Option { + scale.checked_mul(whole.into()).map(|sub| Self { sub }) } } @@ -193,20 +194,46 @@ impl From for u64 { } } -impl Display for Gas { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - // Need to do this now that the gas scale is a parameter. Should - // manually scale gas first before calling this - write!(f, "{}", self.sub) +/// Gas represented in whole units. Used for fee payment and to display +/// information to the user. +#[derive( + Debug, + Clone, + Copy, + PartialEq, + BorshSerialize, + BorshDeserialize, + BorshDeserializer, + BorshSchema, + Serialize, + Deserialize, + Eq, +)] +pub struct WholeGas(u64); + +impl From for WholeGas { + fn from(amount: u64) -> WholeGas { + Self(amount) } } -impl FromStr for Gas { +impl From for u64 { + fn from(whole: WholeGas) -> u64 { + whole.0 + } +} + +impl FromStr for WholeGas { type Err = GasParseError; fn from_str(s: &str) -> std::result::Result { - let raw: u64 = s.parse().map_err(GasParseError::Parse)?; - Ok(Self { sub: raw }) + Ok(Self(s.parse().map_err(GasParseError::Parse)?)) + } +} + +impl Display for WholeGas { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.0) } } diff --git a/crates/light_sdk/src/reading/asynchronous/tx.rs b/crates/light_sdk/src/reading/asynchronous/tx.rs index 57e79ea49b..c14d674644 100644 --- a/crates/light_sdk/src/reading/asynchronous/tx.rs +++ b/crates/light_sdk/src/reading/asynchronous/tx.rs @@ -1,6 +1,6 @@ use namada_sdk::events::Event; use namada_sdk::rpc::{TxEventQuery, TxResponse}; -use namada_sdk::tx::data::TxResult; +use namada_sdk::tx::data::DryRunResult; use super::*; @@ -25,7 +25,7 @@ pub async fn query_tx_events( pub async fn dry_run_tx( tendermint_addr: &str, tx_bytes: Vec, -) -> Result, Error> { +) -> Result { let client = HttpClient::new( TendermintAddress::from_str(tendermint_addr) .map_err(|e| Error::Other(e.to_string()))?, diff --git a/crates/light_sdk/src/reading/blocking/tx.rs b/crates/light_sdk/src/reading/blocking/tx.rs index 6e98d9adb2..27aa61ef40 100644 --- a/crates/light_sdk/src/reading/blocking/tx.rs +++ b/crates/light_sdk/src/reading/blocking/tx.rs @@ -26,7 +26,7 @@ pub fn query_tx_events( pub fn dry_run_tx( tendermint_addr: &str, tx_bytes: Vec, -) -> Result { +) -> Result { let client = HttpClient::new( TendermintAddress::from_str(tendermint_addr) .map_err(|e| Error::Other(e.to_string()))?, diff --git a/crates/namada/src/ledger/mod.rs b/crates/namada/src/ledger/mod.rs index 71304bc1e8..36572ac4ae 100644 --- a/crates/namada/src/ledger/mod.rs +++ b/crates/namada/src/ledger/mod.rs @@ -25,7 +25,7 @@ mod dry_run_tx { use namada_sdk::queries::{EncodedResponseQuery, RequestCtx, RequestQuery}; use namada_state::{DBIter, ResultExt, StorageHasher, DB}; - use namada_tx::data::{ExtendedTxResult, GasLimit, TxResult}; + use namada_tx::data::{DryRunResult, ExtendedTxResult, GasLimit, TxResult}; use super::protocol; use crate::vm::wasm::{TxCache, VpCache}; @@ -132,18 +132,22 @@ mod dry_run_tx { } else { temp_state.write_log_mut().drop_tx(); } - tx_result.batch_results.insert_inner_tx_result( + tx_result.insert_inner_tx_result( wrapper_hash.as_ref(), either::Right(cmt), batched_tx_result, ); } // Account gas for both batch and wrapper - tx_result.gas_used = tx_gas_meter.borrow().get_tx_consumed_gas(); + let gas_used = tx_gas_meter + .borrow() + .get_tx_consumed_gas() + .get_whole_gas_units(gas_scale); let tx_result_string = tx_result.to_result_string(); - let data = tx_result_string.serialize_to_vec(); + let dry_run_result = DryRunResult(tx_result_string, gas_used); + Ok(EncodedResponseQuery { - data, + data: dry_run_result.serialize_to_vec(), proof: None, info: Default::default(), height: ctx.state.in_mem().get_last_block_height(), @@ -331,7 +335,7 @@ mod test { assert!( result .data - .batch_results + .0 .get_inner_tx_result(None, either::Right(cmt)) .unwrap() .as_ref() diff --git a/crates/namada/src/ledger/protocol/mod.rs b/crates/namada/src/ledger/protocol/mod.rs index 97616f3b34..58751b00a4 100644 --- a/crates/namada/src/ledger/protocol/mod.rs +++ b/crates/namada/src/ledger/protocol/mod.rs @@ -19,8 +19,8 @@ use namada_token::utils::is_masp_transfer; use namada_tx::action::Read; use namada_tx::data::protocol::{ProtocolTx, ProtocolTxType}; use namada_tx::data::{ - BatchResults, BatchedTxResult, ExtendedTxResult, TxResult, VpStatusFlags, - VpsResult, WrapperTx, + BatchedTxResult, ExtendedTxResult, TxResult, VpStatusFlags, VpsResult, + WrapperTx, }; use namada_tx::{BatchedTxRef, Tx, TxCommitments}; use namada_vote_ext::EthereumTxData; @@ -275,17 +275,14 @@ where }, )?; - Ok(TxResult { - gas_used: tx_gas_meter.borrow().get_tx_consumed_gas(), - batch_results: { - let mut batch_results = BatchResults::new(); - batch_results.insert_inner_tx_result( - wrapper_hash, - either::Right(cmt), - Ok(batched_tx_result), - ); - batch_results - }, + Ok({ + let mut batch_results = TxResult::new(); + batch_results.insert_inner_tx_result( + wrapper_hash, + either::Right(cmt), + Ok(batched_tx_result), + ); + batch_results } .to_extended_result(None)) } @@ -296,17 +293,14 @@ where let batched_tx_result = apply_protocol_tx(protocol_tx.tx, tx.data(cmt), state)?; - Ok(TxResult { - batch_results: { - let mut batch_results = BatchResults::new(); - batch_results.insert_inner_tx_result( - None, - either::Right(cmt), - Ok(batched_tx_result), - ); - batch_results - }, - ..Default::default() + Ok({ + let mut batch_results = TxResult::new(); + batch_results.insert_inner_tx_result( + None, + either::Right(cmt), + Ok(batched_tx_result), + ); + batch_results } .to_extended_result(None)) } @@ -382,16 +376,11 @@ where ) { Err(Error::GasError(ref msg)) => { // Gas error aborts the execution of the entire batch - extended_tx_result.tx_result.gas_used = - tx_gas_meter.borrow().get_tx_consumed_gas(); - extended_tx_result - .tx_result - .batch_results - .insert_inner_tx_result( - wrapper_hash, - either::Right(cmt), - Err(Error::GasError(msg.to_owned())), - ); + extended_tx_result.tx_result.insert_inner_tx_result( + wrapper_hash, + either::Right(cmt), + Err(Error::GasError(msg.to_owned())), + ); state.write_log_mut().drop_tx(); return Err(DispatchError { error: Error::GasError(msg.to_owned()), @@ -402,16 +391,11 @@ where let is_accepted = matches!(&res, Ok(result) if result.is_accepted()); - extended_tx_result - .tx_result - .batch_results - .insert_inner_tx_result( - wrapper_hash, - either::Right(cmt), - res, - ); - extended_tx_result.tx_result.gas_used = - tx_gas_meter.borrow().get_tx_consumed_gas(); + extended_tx_result.tx_result.insert_inner_tx_result( + wrapper_hash, + either::Right(cmt), + res, + ); if is_accepted { // If the transaction was a masp one append the // transaction refs for the events @@ -488,9 +472,9 @@ where shell_params.state.write_log_mut().commit_batch(); let (batch_results, masp_tx_refs) = payment_result.map_or_else( - || (BatchResults::default(), None), + || (TxResult::default(), None), |(batched_result, masp_section_ref)| { - let mut batch = BatchResults::default(); + let mut batch = TxResult::default(); 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 @@ -508,11 +492,7 @@ where .add_wrapper_gas(tx_bytes) .map_err(|err| Error::GasError(err.to_string()))?; - Ok(TxResult { - gas_used: tx_gas_meter.borrow().get_tx_consumed_gas(), - batch_results, - } - .to_extended_result(masp_tx_refs)) + Ok(batch_results.to_extended_result(masp_tx_refs)) } /// Perform the actual transfer of fees from the fee payer to the block @@ -702,7 +682,7 @@ where 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, gas_scale) + namada_gas::Gas::from_whole_units(max_gas_limit.into(), gas_scale) .ok_or_else(|| { Error::GasError("Overflow in gas expansion".to_string()) })?, diff --git a/crates/node/src/bench_utils.rs b/crates/node/src/bench_utils.rs index d4f9bf6334..3dde72bd71 100644 --- a/crates/node/src/bench_utils.rs +++ b/crates/node/src/bench_utils.rs @@ -77,9 +77,7 @@ use namada::masp::MaspTxRefs; use namada::state::StorageRead; use namada::token::{Amount, DenominatedAmount, Transfer}; use namada::tx::data::pos::Bond; -use namada::tx::data::{ - BatchResults, BatchedTxResult, Fee, TxResult, VpsResult, -}; +use namada::tx::data::{BatchedTxResult, Fee, TxResult, VpsResult}; use namada::tx::event::{new_tx_event, Batch}; use namada::tx::{ Authorization, BatchedTx, BatchedTxRef, Code, Data, Section, Tx, @@ -919,24 +917,19 @@ impl Client for BenchShell { .iter() .enumerate() .map(|(idx, (tx, changed_keys))| { - let tx_result = TxResult:: { - gas_used: 0.into(), - batch_results: { - let mut batch_results = BatchResults::new(); - batch_results.insert_inner_tx_result( - tx.wrapper_hash().as_ref(), - either::Right( - tx.first_commitments().unwrap(), - ), - Ok(BatchedTxResult { - changed_keys: changed_keys.to_owned(), - vps_result: VpsResult::default(), - initialized_accounts: vec![], - events: BTreeSet::default(), - }), - ); - batch_results - }, + let tx_result = { + let mut batch_results = TxResult::new(); + batch_results.insert_inner_tx_result( + tx.wrapper_hash().as_ref(), + either::Right(tx.first_commitments().unwrap()), + Ok(BatchedTxResult { + changed_keys: changed_keys.to_owned(), + vps_result: VpsResult::default(), + initialized_accounts: vec![], + events: BTreeSet::default(), + }), + ); + batch_results }; let event: Event = new_tx_event(tx, height.value()) .with(Batch(&tx_result)) diff --git a/crates/node/src/shell/finalize_block.rs b/crates/node/src/shell/finalize_block.rs index c32ab0d12c..14dd759b1f 100644 --- a/crates/node/src/shell/finalize_block.rs +++ b/crates/node/src/shell/finalize_block.rs @@ -374,12 +374,10 @@ where ); let gas_scale = get_gas_scale(&self.state) .expect("Failed to get gas scale from parameters"); - let scaled_gas = Gas::from( - tx_data - .tx_gas_meter - .get_tx_consumed_gas() - .get_whole_gas_units(gas_scale), - ); + let scaled_gas = tx_data + .tx_gas_meter + .get_tx_consumed_gas() + .get_whole_gas_units(gas_scale); tx_logs .tx_event .extend(GasUsed(scaled_gas)) @@ -409,12 +407,10 @@ where let gas_scale = get_gas_scale(&self.state) .expect("Failed to get gas scale from parameters"); - let scaled_gas = Gas::from( - tx_data - .tx_gas_meter - .get_tx_consumed_gas() - .get_whole_gas_units(gas_scale), - ); + let scaled_gas = tx_data + .tx_gas_meter + .get_tx_consumed_gas() + .get_whole_gas_units(gas_scale); tx_logs .tx_event @@ -462,10 +458,8 @@ where let unrun_txs = tx_data .commitments_len .checked_sub( - u64::try_from( - extended_tx_result.tx_result.batch_results.len(), - ) - .expect("Should be able to convert to u64"), + u64::try_from(extended_tx_result.tx_result.len()) + .expect("Should be able to convert to u64"), ) .expect("Shouldn't underflow"); temp_log.stats.set_failing_atomic_batch(unrun_txs); @@ -494,12 +488,10 @@ where let gas_scale = get_gas_scale(&self.state) .expect("Failed to get gas scale from parameters"); - let scaled_gas = Gas::from( - tx_data - .tx_gas_meter - .get_tx_consumed_gas() - .get_whole_gas_units(gas_scale), - ); + let scaled_gas = tx_data + .tx_gas_meter + .get_tx_consumed_gas() + .get_whole_gas_units(gas_scale); tx_logs .tx_event @@ -530,7 +522,7 @@ where let unrun_txs = tx_data .commitments_len .checked_sub( - u64::try_from(extended_tx_result.tx_result.batch_results.len()) + u64::try_from(extended_tx_result.tx_result.len()) .expect("Should be able to convert to u64"), ) .expect("Shouldn't underflow"); @@ -983,9 +975,7 @@ impl<'finalize> TempTxLogs { ) -> ValidityFlags { let mut flags = ValidityFlags::default(); - for (cmt_hash, batched_result) in - extended_tx_result.tx_result.batch_results.iter() - { + for (cmt_hash, batched_result) in extended_tx_result.tx_result.iter() { match batched_result { Ok(result) => { if result.is_accepted() { @@ -1207,7 +1197,7 @@ mod test_finalize_block { FinalizeBlock, ProcessedTx, }; - const WRAPPER_GAS_LIMIT: u64 = 11_000; + const WRAPPER_GAS_LIMIT: u64 = 150_000; const STORAGE_VALUE: &str = "test_value"; /// Make a wrapper tx and a processed tx from the wrapped tx that can be @@ -3278,7 +3268,6 @@ mod test_finalize_block { assert_eq!(code, ResultCode::Ok); let inner_tx_result = event[0].read_attribute::>().unwrap(); let first_tx_result = inner_tx_result - .batch_results .get_inner_tx_result( Some(&wrapper.header_hash()), either::Right(wrapper.first_commitments().unwrap()), @@ -3429,7 +3418,6 @@ mod test_finalize_block { assert_eq!(code, ResultCode::Ok); let inner_tx_result = event[1].read_attribute::>().unwrap(); let inner_result = inner_tx_result - .batch_results .get_inner_tx_result( Some(&unsigned_wrapper.header_hash()), either::Right(unsigned_wrapper.first_commitments().unwrap()), @@ -3441,7 +3429,6 @@ mod test_finalize_block { assert_eq!(code, ResultCode::Ok); let inner_tx_result = event[2].read_attribute::>().unwrap(); let inner_result = inner_tx_result - .batch_results .get_inner_tx_result( Some(&wrong_commitment_wrapper.header_hash()), either::Right( @@ -3455,7 +3442,6 @@ mod test_finalize_block { assert_eq!(code, ResultCode::Ok); let inner_tx_result = event[3].read_attribute::>().unwrap(); let inner_result = inner_tx_result - .batch_results .get_inner_tx_result( Some(&failing_wrapper.header_hash()), either::Right(failing_wrapper.first_commitments().unwrap()), @@ -3660,7 +3646,6 @@ mod test_finalize_block { assert_eq!(code, ResultCode::Ok); let inner_tx_result = event.read_attribute::>().unwrap(); let inner_result = inner_tx_result - .batch_results .get_inner_tx_result( Some(&wrapper.header_hash()), either::Right(wrapper.first_commitments().unwrap()), @@ -5566,7 +5551,7 @@ mod test_finalize_block { let code = event[0].read_attribute::().unwrap(); assert_eq!(code, ResultCode::Ok); let inner_tx_result = event[0].read_attribute::>().unwrap(); - let inner_results = inner_tx_result.batch_results; + let inner_results = inner_tx_result; for cmt in batch.commitments() { assert!( @@ -5614,7 +5599,7 @@ mod test_finalize_block { let code = event[0].read_attribute::().unwrap(); assert_eq!(code, ResultCode::WasmRuntimeError); let inner_tx_result = event[0].read_attribute::>().unwrap(); - let inner_results = inner_tx_result.batch_results; + let inner_results = inner_tx_result; assert!( inner_results @@ -5673,7 +5658,7 @@ mod test_finalize_block { let code = event[0].read_attribute::().unwrap(); assert_eq!(code, ResultCode::Ok); let inner_tx_result = event[0].read_attribute::>().unwrap(); - let inner_results = inner_tx_result.batch_results; + let inner_results = inner_tx_result; assert!( inner_results @@ -5750,7 +5735,7 @@ mod test_finalize_block { let code = event[0].read_attribute::().unwrap(); assert_eq!(code, ResultCode::WasmRuntimeError); let inner_tx_result = event[0].read_attribute::>().unwrap(); - let inner_results = inner_tx_result.batch_results; + let inner_results = inner_tx_result; assert!( inner_results @@ -5808,7 +5793,7 @@ mod test_finalize_block { let code = event[0].read_attribute::().unwrap(); assert_eq!(code, ResultCode::WasmRuntimeError); let inner_tx_result = event[0].read_attribute::>().unwrap(); - let inner_results = inner_tx_result.batch_results; + let inner_results = inner_tx_result; assert!( inner_results @@ -5917,10 +5902,10 @@ mod test_finalize_block { // multiple tx results (2) let tx_results = event.read_attribute::>().unwrap(); - assert_eq!(tx_results.batch_results.len(), 2); + assert_eq!(tx_results.len(), 2); // all txs should have succeeded - assert!(tx_results.batch_results.are_results_ok()); + assert!(tx_results.are_results_ok()); } #[test] @@ -5990,10 +5975,10 @@ mod test_finalize_block { // multiple tx results (2) let tx_results = event.read_attribute::>().unwrap(); - assert_eq!(tx_results.batch_results.len(), 2); + assert_eq!(tx_results.len(), 2); // check one succeeded and the other failed - assert!(tx_results.batch_results.are_any_ok()); - assert!(tx_results.batch_results.are_any_err()); + assert!(tx_results.are_any_ok()); + assert!(tx_results.are_any_err()); } } diff --git a/crates/node/src/shell/governance.rs b/crates/node/src/shell/governance.rs index fefa43fa55..c3112ba49b 100644 --- a/crates/node/src/shell/governance.rs +++ b/crates/node/src/shell/governance.rs @@ -428,7 +428,6 @@ where match dispatch_result { Ok(extended_tx_result) => match extended_tx_result .tx_result - .batch_results .get_inner_tx_result(None, either::Right(&cmt)) { Some(Ok(batched_result)) if batched_result.is_accepted() => { diff --git a/crates/node/src/shell/mod.rs b/crates/node/src/shell/mod.rs index 742c42e7ed..1556fa967a 100644 --- a/crates/node/src/shell/mod.rs +++ b/crates/node/src/shell/mod.rs @@ -1177,7 +1177,9 @@ where // Max block gas let block_gas_limit: Gas = Gas::from_whole_units( - namada::parameters::get_max_block_gas(&self.state).unwrap(), + namada::parameters::get_max_block_gas(&self.state) + .unwrap() + .into(), gas_scale, ) .expect("Gas limit from parameter must not overflow"); diff --git a/crates/node/src/storage/mod.rs b/crates/node/src/storage/mod.rs index 07e56dec08..057337a3f2 100644 --- a/crates/node/src/storage/mod.rs +++ b/crates/node/src/storage/mod.rs @@ -174,7 +174,7 @@ mod tests { epochs_per_year: 365, masp_epoch_multiplier: 2, masp_fee_payment_gas_limit: 0, - gas_scale: 100_000_000, + gas_scale: 10_000_000, minimum_gas_price: Default::default(), is_native_token_transferable: true, }; diff --git a/crates/parameters/src/lib.rs b/crates/parameters/src/lib.rs index 3ec0fdbdfe..595df8fa05 100644 --- a/crates/parameters/src/lib.rs +++ b/crates/parameters/src/lib.rs @@ -433,7 +433,7 @@ where epochs_per_year: 365, masp_epoch_multiplier: 2, masp_fee_payment_gas_limit: 0, - gas_scale: 100_000_000, + gas_scale: 10_000_000, minimum_gas_price: Default::default(), is_native_token_transferable: true, }; diff --git a/crates/proof_of_stake/src/lib.rs b/crates/proof_of_stake/src/lib.rs index 3486c25948..fb2cfc93c3 100644 --- a/crates/proof_of_stake/src/lib.rs +++ b/crates/proof_of_stake/src/lib.rs @@ -2725,7 +2725,7 @@ pub mod test_utils { epochs_per_year: 10000000, masp_epoch_multiplier: 2, masp_fee_payment_gas_limit: 10000, - gas_scale: 100_000_000, + gas_scale: 10_000_000, minimum_gas_price: BTreeMap::new(), is_native_token_transferable: true, }; diff --git a/crates/sdk/src/lib.rs b/crates/sdk/src/lib.rs index 1b0b8a344c..63bd4eb85a 100644 --- a/crates/sdk/src/lib.rs +++ b/crates/sdk/src/lib.rs @@ -80,7 +80,7 @@ use tx::{ use wallet::{Wallet, WalletIo, WalletStorage}; /// Default gas-limit -pub const DEFAULT_GAS_LIMIT: u64 = 25_000; +pub const DEFAULT_GAS_LIMIT: u64 = 100_000; #[allow(missing_docs)] #[cfg(not(feature = "async-send"))] diff --git a/crates/sdk/src/queries/shell.rs b/crates/sdk/src/queries/shell.rs index 2a8b22e717..403cc80851 100644 --- a/crates/sdk/src/queries/shell.rs +++ b/crates/sdk/src/queries/shell.rs @@ -25,7 +25,7 @@ use namada_state::{DBIter, LastBlock, StateRead, StorageHasher, DB}; use namada_storage::{ResultExt, StorageRead}; use namada_token::storage_key::masp_token_map_key; #[cfg(any(test, feature = "async-client"))] -use namada_tx::data::TxResult; +use namada_tx::data::DryRunResult; use self::eth_bridge::{EthBridge, ETH_BRIDGE}; use crate::events::log::dumb_queries; @@ -84,7 +84,7 @@ router! {SHELL, -> Vec = (with_options storage_value), // Dry run a transaction - ( "dry_run_tx" ) -> TxResult = (with_options dry_run_tx), + ( "dry_run_tx" ) -> DryRunResult = (with_options dry_run_tx), // Raw storage access - prefix iterator ( "prefix" / [storage_key: storage::Key] ) diff --git a/crates/sdk/src/rpc.rs b/crates/sdk/src/rpc.rs index 4856ef12a2..e43575d64e 100644 --- a/crates/sdk/src/rpc.rs +++ b/crates/sdk/src/rpc.rs @@ -25,7 +25,7 @@ use namada_core::token::{ }; use namada_core::{storage, token}; use namada_gas::event::GasUsed as GasUsedAttr; -use namada_gas::Gas; +use namada_gas::WholeGas; use namada_governance::parameters::GovernanceParameters; use namada_governance::pgf::parameters::PgfParameters; use namada_governance::pgf::storage::steward::StewardDetail; @@ -42,7 +42,7 @@ use namada_proof_of_stake::types::{ BondsAndUnbondsDetails, CommissionPair, ValidatorMetaData, }; use namada_state::LastBlock; -use namada_tx::data::{BatchedTxResult, ResultCode, TxResult}; +use namada_tx::data::{BatchedTxResult, DryRunResult, ResultCode, TxResult}; use namada_tx::event::{Batch as BatchAttr, Code as CodeAttr}; use serde::Serialize; @@ -549,7 +549,7 @@ pub async fn query_tx_events( pub async fn dry_run_tx( context: &N, tx_bytes: Vec, -) -> Result, Error> { +) -> Result { let (data, height, prove) = (Some(tx_bytes), None, false); let result = convert_response::( RPC.shell() @@ -557,10 +557,10 @@ pub async fn dry_run_tx( .await, )? .data; - let result_str = format!("Transaction consumed {} gas", result.gas_used); + let result_str = format!("Transaction consumed {} gas", result.1); let mut cmt_result_str = String::new(); - for (inner_hash, cmt_result) in result.batch_results.iter() { + for (inner_hash, cmt_result) in result.0.iter() { match cmt_result { Ok(result) => { if result.is_accepted() { @@ -631,7 +631,7 @@ pub struct TxResponse { /// Response code pub code: ResultCode, /// Gas used. - pub gas_used: Gas, + pub gas_used: WholeGas, } /// Determines a result of an inner tx from @@ -692,9 +692,9 @@ impl TxResponse { /// Check the result of the batch. This should not be used with wrapper /// txs. pub fn batch_result(&self) -> HashMap> { - if let Some(tx) = self.batch.as_ref() { + if let Some(tx_result) = self.batch.as_ref() { let mut result = HashMap::default(); - for (inner_hash, cmt_result) in tx.batch_results.iter() { + for (inner_hash, cmt_result) in tx_result.iter() { let value = match cmt_result { Ok(res) => { if res.is_accepted() { diff --git a/crates/sdk/src/tx.rs b/crates/sdk/src/tx.rs index 403b99248e..2f587c4dcb 100644 --- a/crates/sdk/src/tx.rs +++ b/crates/sdk/src/tx.rs @@ -66,7 +66,7 @@ use namada_token::DenominatedAmount; use namada_tx::data::pgf::UpdateStewardCommission; use namada_tx::data::pos::{BecomeValidator, ConsensusKeyChange}; use namada_tx::data::{ - compute_inner_tx_hash, pos, BatchedTxResult, ResultCode, TxResult, + compute_inner_tx_hash, pos, BatchedTxResult, DryRunResult, ResultCode, }; pub use namada_tx::{Authorization, *}; use num_traits::Zero; @@ -158,7 +158,7 @@ pub enum ProcessTxResponse { /// Result of submitting a transaction to the mempool Broadcast(Response), /// Result of dry running transaction - DryRun(TxResult), + DryRun(DryRunResult), } impl ProcessTxResponse { diff --git a/crates/state/src/lib.rs b/crates/state/src/lib.rs index 97686574d3..55897043c8 100644 --- a/crates/state/src/lib.rs +++ b/crates/state/src/lib.rs @@ -764,7 +764,7 @@ mod tests { epochs_per_year: 100, masp_epoch_multiplier: 2, masp_fee_payment_gas_limit: 20_000, - gas_scale: 100_000_000, + gas_scale: 10_000_000, minimum_gas_price: BTreeMap::default(), is_native_token_transferable: true, }; diff --git a/crates/tests/src/e2e/ibc_tests.rs b/crates/tests/src/e2e/ibc_tests.rs index 808288b812..e4c7bcef06 100644 --- a/crates/tests/src/e2e/ibc_tests.rs +++ b/crates/tests/src/e2e/ibc_tests.rs @@ -1966,6 +1966,8 @@ fn submit_ibc_tx( signer, "--gas-token", NAM, + "--gas-limit", + "150000", "--node", &rpc ], @@ -2013,6 +2015,8 @@ fn transfer( &channel_id, "--port-id", &port_id, + "--gas-limit", + "150000", "--node", &rpc, ]; diff --git a/crates/tests/src/integration/masp.rs b/crates/tests/src/integration/masp.rs index 3897ea66ba..336a4fe711 100644 --- a/crates/tests/src/integration/masp.rs +++ b/crates/tests/src/integration/masp.rs @@ -13,6 +13,7 @@ use namada_node::shell::testing::client::run; use namada_node::shell::testing::node::NodeResults; use namada_node::shell::testing::utils::{Bin, CapturedOutput}; use namada_sdk::masp::fs::FsShieldedUtils; +use namada_sdk::DEFAULT_GAS_LIMIT; use test_log::test; use super::setup; @@ -1504,7 +1505,7 @@ fn multiple_unfetched_txs_same_block() -> Result<()> { token: native_token.clone(), }, pk.clone(), - 20000.into(), + DEFAULT_GAS_LIMIT.into(), ); tx.sign_wrapper(sk.clone()); @@ -2183,10 +2184,7 @@ fn masp_fee_payment() -> Result<()> { let validator_one_rpc = "http://127.0.0.1:26567"; // Download the shielded pool parameters before starting node let _ = FsShieldedUtils::new(PathBuf::new()); - let (mut node, _services) = setup::initialize_genesis(|mut genesis| { - genesis.parameters.parameters.masp_fee_payment_gas_limit = 20_000; - genesis - })?; + let (mut node, _services) = setup::setup()?; _ = node.next_masp_epoch(); // Add the relevant viewing keys to the wallet otherwise the shielded @@ -2231,7 +2229,7 @@ fn masp_fee_payment() -> Result<()> { "--token", NAM, "--amount", - "50000", + "500000", "--ledger-address", validator_one_rpc, ], @@ -2261,7 +2259,7 @@ fn masp_fee_payment() -> Result<()> { ) }); assert!(captured.result.is_ok()); - assert!(captured.contains("nam: 50000")); + assert!(captured.contains("nam: 500000")); // 1. Out of gas for masp fee payment let captured = CapturedOutput::of(|| { @@ -2279,7 +2277,7 @@ fn masp_fee_payment() -> Result<()> { "--amount", "1", "--gas-limit", - "2000", + "20000", "--gas-price", "1", "--disposable-gas-payer", @@ -2312,7 +2310,7 @@ fn masp_fee_payment() -> Result<()> { ) }); assert!(captured.result.is_ok()); - assert!(captured.contains("nam: 50000")); + assert!(captured.contains("nam: 500000")); // 2. Valid masp fee payment run( @@ -2329,7 +2327,7 @@ fn masp_fee_payment() -> Result<()> { "--amount", "10000", "--gas-limit", - "20000", + "200000", "--gas-price", "1", "--disposable-gas-payer", @@ -2363,7 +2361,7 @@ fn masp_fee_payment() -> Result<()> { ) }); assert!(captured.result.is_ok()); - assert!(captured.contains("nam: 20000")); + assert!(captured.contains("nam: 290000")); let captured = CapturedOutput::of(|| { run( &node, @@ -2396,7 +2394,7 @@ fn masp_fee_payment_gas_limit() -> Result<()> { let (mut node, _services) = setup::initialize_genesis(|mut genesis| { // Set an insufficient gas limit for masp fee payment to force all // transactions to fail - genesis.parameters.parameters.masp_fee_payment_gas_limit = 3_000; + genesis.parameters.parameters.masp_fee_payment_gas_limit = 10_000; genesis })?; _ = node.next_masp_epoch(); @@ -2548,10 +2546,7 @@ fn masp_fee_payment_with_non_disposable() -> Result<()> { let validator_one_rpc = "http://127.0.0.1:26567"; // Download the shielded pool parameters before starting node let _ = FsShieldedUtils::new(PathBuf::new()); - let (mut node, _services) = setup::initialize_genesis(|mut genesis| { - genesis.parameters.parameters.masp_fee_payment_gas_limit = 20_000; - genesis - })?; + let (mut node, _services) = setup::setup()?; _ = node.next_masp_epoch(); // Add the relevant viewing keys to the wallet otherwise the shielded @@ -2596,7 +2591,7 @@ fn masp_fee_payment_with_non_disposable() -> Result<()> { "--token", NAM, "--amount", - // Drain balance of fee payer + // Decrease payer's balance to 1 "1999999", // Pay gas transparently "--gas-payer", @@ -2635,6 +2630,24 @@ fn masp_fee_payment_with_non_disposable() -> Result<()> { assert!(captured.result.is_ok()); assert!(captured.contains("nam: 1999999")); + let captured = CapturedOutput::of(|| { + run( + &node, + Bin::Client, + vec![ + "balance", + "--owner", + ALBERT_KEY, + "--token", + NAM, + "--node", + validator_one_rpc, + ], + ) + }); + assert!(captured.result.is_ok()); + assert!(captured.contains("nam: 1")); + // Masp fee payment to non-disposable address let captured = CapturedOutput::of(|| { run( @@ -2651,7 +2664,7 @@ fn masp_fee_payment_with_non_disposable() -> Result<()> { "--amount", "1", "--gas-limit", - "20000", + "200000", "--gas-price", "1", "--gas-payer", @@ -2690,7 +2703,7 @@ fn masp_fee_payment_with_non_disposable() -> Result<()> { ) }); assert!(captured.result.is_ok()); - assert!(captured.contains("nam: 1979999")); + assert!(captured.contains("nam: 1799999")); let captured = CapturedOutput::of(|| { run( @@ -2722,10 +2735,7 @@ fn masp_fee_payment_with_custom_spending_key() -> Result<()> { let validator_one_rpc = "http://127.0.0.1:26567"; // Download the shielded pool parameters before starting node let _ = FsShieldedUtils::new(PathBuf::new()); - let (mut node, _services) = setup::initialize_genesis(|mut genesis| { - genesis.parameters.parameters.masp_fee_payment_gas_limit = 20_000; - genesis - })?; + let (mut node, _services) = setup::setup()?; _ = node.next_masp_epoch(); // Add the relevant viewing keys to the wallet otherwise the shielded @@ -2801,7 +2811,7 @@ fn masp_fee_payment_with_custom_spending_key() -> Result<()> { "--token", NAM, "--amount", - "30000", + "300000", "--ledger-address", validator_one_rpc, ], @@ -2851,7 +2861,7 @@ fn masp_fee_payment_with_custom_spending_key() -> Result<()> { ) }); assert!(captured.result.is_ok()); - assert!(captured.contains("nam: 30000")); + assert!(captured.contains("nam: 300000")); // Masp fee payment with custom gas payer let captured = CapturedOutput::of(|| { @@ -2869,7 +2879,7 @@ fn masp_fee_payment_with_custom_spending_key() -> Result<()> { "--amount", "9000", "--gas-limit", - "20000", + "200000", "--gas-price", "1", "--gas-spending-key", @@ -2927,7 +2937,7 @@ fn masp_fee_payment_with_custom_spending_key() -> Result<()> { ) }); assert!(captured.result.is_ok()); - assert!(captured.contains("nam: 11000")); + assert!(captured.contains("nam: 101000")); let captured = CapturedOutput::of(|| { run( @@ -2959,7 +2969,6 @@ fn masp_fee_payment_with_different_token() -> Result<()> { // Download the shielded pool parameters before starting node let _ = FsShieldedUtils::new(PathBuf::new()); let (mut node, _services) = setup::initialize_genesis(|mut genesis| { - genesis.parameters.parameters.masp_fee_payment_gas_limit = 20_000; // Whitelist BTC for gas payment genesis.parameters.parameters.minimum_gas_price.insert( "btc".into(), @@ -3049,7 +3058,7 @@ fn masp_fee_payment_with_different_token() -> Result<()> { "--token", BTC, "--amount", - "20000", + "200000", "--gas-payer", ALBERT_KEY, "--ledger-address", @@ -3118,7 +3127,7 @@ fn masp_fee_payment_with_different_token() -> Result<()> { ) }); assert!(captured.result.is_ok()); - assert!(captured.contains("btc: 20000")); + assert!(captured.contains("btc: 200000")); // Masp fee payment with custom token and gas payer let captured = CapturedOutput::of(|| { @@ -3138,7 +3147,7 @@ fn masp_fee_payment_with_different_token() -> Result<()> { "--gas-token", BTC, "--gas-limit", - "20000", + "200000", "--gas-price", "1", "--gas-spending-key", diff --git a/crates/tx/src/data/mod.rs b/crates/tx/src/data/mod.rs index 2cf49ec745..29162b10e2 100644 --- a/crates/tx/src/data/mod.rs +++ b/crates/tx/src/data/mod.rs @@ -25,7 +25,7 @@ use namada_core::hash::Hash; use namada_core::masp::MaspTxRefs; use namada_core::storage; use namada_events::Event; -use namada_gas::{Gas, VpsGas}; +use namada_gas::{VpsGas, WholeGas}; use namada_macros::BorshDeserializer; #[cfg(feature = "migrations")] use namada_migrations::*; @@ -166,81 +166,6 @@ pub fn hash_tx(tx_bytes: &[u8]) -> Hash { Hash(*digest.as_ref()) } -/// The set of inner tx results indexed by the inner tx hash -// The generic is only used to return typed errors in protocol for error -// management with regards to replay protection, whereas for logging we use -// strings -#[derive(Clone, Debug, BorshSerialize, BorshDeserialize)] -pub struct BatchResults(BTreeMap>); - -impl BatchResults { - /// Return a new set of batch results. - pub const fn new() -> Self { - Self(BTreeMap::new()) - } - - /// Insert an inner tx result into this [`BatchResults`]. - #[inline] - pub fn insert_inner_tx_result( - &mut self, - wrapper_hash: Option<&Hash>, - commitments: Either<&Hash, &TxCommitments>, - result: Result, - ) { - self.0 - .insert(compute_inner_tx_hash(wrapper_hash, commitments), result); - } - - /// Retrieve an inner tx result, if it exists. - #[inline] - pub fn get_inner_tx_result( - &self, - wrapper_hash: Option<&Hash>, - commitments: Either<&Hash, &TxCommitments>, - ) -> Option<&Result> { - self.0 - .get(&compute_inner_tx_hash(wrapper_hash, commitments)) - } - - /// Iterate over all the inner tx results. - #[inline] - pub fn iter( - &self, - ) -> impl Iterator)> + '_ { - self.0.iter() - } - - /// Return the length of the collecction of inner tx results. - #[inline] - pub fn len(&self) -> usize { - self.0.len() - } - - /// Check if the collecction of inner tx results is empty. - #[inline] - pub fn is_empty(&self) -> bool { - self.0.is_empty() - } - - /// Check if the collecction of inner tx results contains no errors. - #[inline] - pub fn are_results_ok(&self) -> bool { - self.iter().all(|(_, res)| res.is_ok()) - } - - /// Check if the collecction of inner tx results contains any ok results. - #[inline] - pub fn are_any_ok(&self) -> bool { - self.iter().any(|(_, res)| res.is_ok()) - } - - /// Check if the collecction of inner tx results contains any errors. - #[inline] - pub fn are_any_err(&self) -> bool { - self.iter().any(|(_, res)| res.is_err()) - } -} - /// Compute the hash of the some inner tx in a batch. pub fn compute_inner_tx_hash( wrapper_hash: Option<&Hash>, @@ -258,13 +183,48 @@ pub fn compute_inner_tx_hash( Hash(state.finalize_reset().into()) } -impl Default for BatchResults { +/// The extended transaction result, containing the references to masp +/// sections (if any) +pub struct ExtendedTxResult { + /// The transaction result + pub tx_result: TxResult, + /// The optional references to masp sections + pub masp_tx_refs: MaspTxRefs, + /// The flag for IBC shielding transfer + pub is_ibc_shielding: bool, +} + +impl Default for ExtendedTxResult { + fn default() -> Self { + Self { + tx_result: Default::default(), + masp_tx_refs: Default::default(), + is_ibc_shielding: Default::default(), + } + } +} + +#[derive(Debug, BorshSerialize, BorshDeserialize, Serialize, Deserialize)] +/// The result of a dry run, included the actual transaction result and the gas +/// used +pub struct DryRunResult(pub TxResult, pub WholeGas); + +/// Transaction application result. More specifically the set of inner tx +/// results indexed by the inner tx hash +// The generic is only used to return typed errors in protocol for error +// management with regards to replay protection, whereas for logging we use +// strings +// TODO derive BorshSchema after +#[derive(Clone, Debug, BorshSerialize, BorshDeserialize)] +pub struct TxResult(pub BTreeMap>); + +impl Default for TxResult { fn default() -> Self { - Self(BTreeMap::default()) + Self(Default::default()) } } -impl Serialize for BatchResults { +impl Serialize for TxResult { fn serialize(&self, serializer: S) -> Result where S: serde::Serializer, @@ -278,11 +238,11 @@ impl Serialize for BatchResults { } } -struct BatchResultVisitor { +struct TxResultVisitor { _phantom: PhantomData, } -impl BatchResultVisitor { +impl TxResultVisitor { fn new() -> Self { Self { _phantom: PhantomData, @@ -290,21 +250,21 @@ impl BatchResultVisitor { } } -impl<'de, T> serde::de::Visitor<'de> for BatchResultVisitor +impl<'de, T> serde::de::Visitor<'de> for TxResultVisitor where T: serde::Deserialize<'de>, { - type Value = BatchResults; + type Value = TxResult; fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result { - formatter.write_str("BatchResult") + formatter.write_str("a transaction's result") } fn visit_map(self, mut map: V) -> Result where V: serde::de::MapAccess<'de>, { - let mut result = BatchResults::::default(); + let mut result = TxResult::::default(); while let Some((key, value)) = map.next_entry()? { result.0.insert( @@ -317,53 +277,12 @@ where } } -impl<'de, T: Deserialize<'de>> serde::Deserialize<'de> for BatchResults { +impl<'de, T: Deserialize<'de>> serde::Deserialize<'de> for TxResult { fn deserialize(deserializer: D) -> Result where D: serde::Deserializer<'de>, { - deserializer.deserialize_map(BatchResultVisitor::new()) - } -} - -/// The extended transaction result, containing the references to masp -/// sections (if any) -pub struct ExtendedTxResult { - /// The transaction result - pub tx_result: TxResult, - /// The optional references to masp sections - pub masp_tx_refs: MaspTxRefs, - /// The flag for IBC shielding transfer - pub is_ibc_shielding: bool, -} - -impl Default for ExtendedTxResult { - fn default() -> Self { - Self { - tx_result: Default::default(), - masp_tx_refs: Default::default(), - is_ibc_shielding: Default::default(), - } - } -} - -/// Transaction application result -#[derive( - Clone, Debug, BorshSerialize, BorshDeserialize, Serialize, Deserialize, -)] -pub struct TxResult { - /// Total gas used by the transaction (includes the gas used by VPs) - pub gas_used: Gas, - /// The results of the batch, indexed by the hash of each inner tx - pub batch_results: BatchResults, -} - -impl Default for TxResult { - fn default() -> Self { - Self { - gas_used: Default::default(), - batch_results: Default::default(), - } + deserializer.deserialize_map(TxResultVisitor::new()) } } @@ -373,7 +292,7 @@ impl TxResult { let mut batch_results: BTreeMap> = BTreeMap::new(); - for (hash, res) in self.batch_results.0 { + for (hash, res) in self.0 { let res = match res { Ok(value) => Ok(value), Err(e) => Err(e.to_string()), @@ -381,10 +300,7 @@ impl TxResult { batch_results.insert(hash, res); } - TxResult { - gas_used: self.gas_used, - batch_results: BatchResults(batch_results), - } + TxResult(batch_results) } /// Converts this result to [`ExtendedTxResult`] @@ -400,6 +316,74 @@ impl TxResult { } } +impl TxResult { + /// Return a new set of tx results. + pub const fn new() -> Self { + Self(BTreeMap::new()) + } + + /// Insert an inner tx result into this [`TxResult`]. + #[inline] + pub fn insert_inner_tx_result( + &mut self, + wrapper_hash: Option<&Hash>, + commitments: Either<&Hash, &TxCommitments>, + result: Result, + ) { + self.0 + .insert(compute_inner_tx_hash(wrapper_hash, commitments), result); + } + + /// Retrieve an inner tx result, if it exists. + #[inline] + pub fn get_inner_tx_result( + &self, + wrapper_hash: Option<&Hash>, + commitments: Either<&Hash, &TxCommitments>, + ) -> Option<&Result> { + self.0 + .get(&compute_inner_tx_hash(wrapper_hash, commitments)) + } + + /// Iterate over all the inner tx results. + #[inline] + pub fn iter( + &self, + ) -> impl Iterator)> + '_ { + self.0.iter() + } + + /// Return the length of the collecction of inner tx results. + #[inline] + pub fn len(&self) -> usize { + self.0.len() + } + + /// Check if the collecction of inner tx results is empty. + #[inline] + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } + + /// Check if the collecction of inner tx results contains no errors. + #[inline] + pub fn are_results_ok(&self) -> bool { + self.iter().all(|(_, res)| res.is_ok()) + } + + /// Check if the collecction of inner tx results contains any ok results. + #[inline] + pub fn are_any_ok(&self) -> bool { + self.iter().any(|(_, res)| res.is_ok()) + } + + /// Check if the collecction of inner tx results contains any errors. + #[inline] + pub fn are_any_err(&self) -> bool { + self.iter().any(|(_, res)| res.is_err()) + } +} + #[cfg(feature = "migrations")] namada_macros::derive_borshdeserializer!(TxResult::); @@ -500,7 +484,7 @@ pub struct VpsResult { impl fmt::Display for TxResult { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if f.alternate() { - write!(f, "Transaction is valid. Gas used: {}", self.gas_used) + write!(f, "Transaction is valid.") } else { write!(f, "{}", serde_json::to_string(self).unwrap()) } diff --git a/crates/tx/src/data/wrapper.rs b/crates/tx/src/data/wrapper.rs index 3a2f1ebcc7..137054ed5a 100644 --- a/crates/tx/src/data/wrapper.rs +++ b/crates/tx/src/data/wrapper.rs @@ -9,7 +9,7 @@ use namada_core::borsh::{ use namada_core::key::*; use namada_core::token::{Amount, DenominatedAmount}; use namada_core::uint::Uint; -use namada_gas::Gas; +use namada_gas::{Gas, WholeGas}; use namada_macros::BorshDeserializer; #[cfg(feature = "migrations")] use namada_migrations::*; @@ -111,10 +111,22 @@ impl From for Amount { } } +impl From for WholeGas { + fn from(value: GasLimit) -> Self { + value.0.into() + } +} + +impl From for GasLimit { + fn from(value: WholeGas) -> Self { + u64::from(value).into() + } +} + impl GasLimit { /// Convert the gas limit into scaled gas - pub fn as_scaled_gas(&self, scale: u64) -> Result { - Gas::from_whole_units(u64::from(*self), scale).ok_or_else(|| { + pub fn as_scaled_gas(self, scale: u64) -> Result { + Gas::from_whole_units(self.into(), scale).ok_or_else(|| { std::io::Error::new( std::io::ErrorKind::InvalidInput, "gas overflow", diff --git a/genesis/localnet/parameters.toml b/genesis/localnet/parameters.toml index 834da9dd08..368ca0f108 100644 --- a/genesis/localnet/parameters.toml +++ b/genesis/localnet/parameters.toml @@ -21,9 +21,9 @@ masp_epoch_multiplier = 2 # Max gas for block max_block_gas = 20000000 # Masp fee payment gas limit -masp_fee_payment_gas_limit = 20000 +masp_fee_payment_gas_limit = 150_000 # Gas scale -gas_scale = 100_000_000 +gas_scale = 10_000_000 # Map of the cost per gas unit for every token allowed for fee payment [parameters.minimum_gas_price] diff --git a/genesis/starter/parameters.toml b/genesis/starter/parameters.toml index b89dd47555..7ab927009c 100644 --- a/genesis/starter/parameters.toml +++ b/genesis/starter/parameters.toml @@ -23,9 +23,9 @@ max_signatures_per_transaction = 15 # Max gas for block max_block_gas = 20000000 # Masp fee payment gas limit -masp_fee_payment_gas_limit = 20000 +masp_fee_payment_gas_limit = 150_000 # Gas scale -gas_scale = 100_000_000 +gas_scale = 10_000_000 # Map of the cost per gas unit for every token allowed for fee payment [parameters.minimum_gas_price] diff --git a/scripts/get_hermes.sh b/scripts/get_hermes.sh index 9ae6c1a829..8c74b20bde 100755 --- a/scripts/get_hermes.sh +++ b/scripts/get_hermes.sh @@ -4,7 +4,7 @@ set -Eo pipefail HERMES_MAJORMINOR="1.9" HERMES_PATCH="0" -HERMES_SUFFIX="-namada-beta13-rc2" +HERMES_SUFFIX="-namada-beta14-rc" HERMES_REPO="https://github.com/heliaxdev/hermes"