diff --git a/apps/src/lib/cli.rs b/apps/src/lib/cli.rs index cb657f0ec0a..266f52ca61d 100644 --- a/apps/src/lib/cli.rs +++ b/apps/src/lib/cli.rs @@ -2918,14 +2918,14 @@ pub mod args { address joined with a number.", )) .arg(FEE_AMOUNT.def().about( - "The amount being paid, per gas unit, for the inclusion of this transaction", + "The amount being paid, per gas unit, for the inclusion of \ + this transaction", )) .arg(FEE_TOKEN.def().about("The token for paying the gas")) - .arg( - GAS_LIMIT.def().about( - "The multiplier of the gas limit resolution definying the maximum amount of gas needed to run transaction", - ), - ) + .arg(GAS_LIMIT.def().about( + "The multiplier of the gas limit resolution definying the \ + maximum amount of gas needed to run transaction", + )) .arg(EXPIRATION_OPT.def().about( "The expiration datetime of the transaction, after which the \ tx won't be accepted anymore. All of these examples are \ diff --git a/apps/src/lib/cli/context.rs b/apps/src/lib/cli/context.rs index 726f822740d..e7c92e6a44b 100644 --- a/apps/src/lib/cli/context.rs +++ b/apps/src/lib/cli/context.rs @@ -13,10 +13,8 @@ use namada::types::masp::*; use super::args; use crate::client::tx::ShieldedContext; -use crate::config::genesis; -use crate::config::genesis::genesis_config; use crate::config::global::GlobalConfig; -use crate::config::{self, Config}; +use crate::config::{self, genesis, Config}; use crate::wallet::Wallet; use crate::wasm_loader; diff --git a/apps/src/lib/client/rpc.rs b/apps/src/lib/client/rpc.rs index 1f74366aacd..dcad3754ad7 100644 --- a/apps/src/lib/client/rpc.rs +++ b/apps/src/lib/client/rpc.rs @@ -32,7 +32,7 @@ use namada::ledger::parameters::{storage as param_storage, EpochDuration}; use namada::ledger::pos::{ self, BondId, BondsAndUnbondsDetail, CommissionPair, PosParams, Slash, }; -use namada::ledger::queries::{self, RPC}; +use namada::ledger::queries::RPC; use namada::ledger::storage::ConversionState; use namada::proto::{SignedTxData, Tx}; use namada::types::address::{masp, tokens, Address}; diff --git a/apps/src/lib/config/genesis.rs b/apps/src/lib/config/genesis.rs index 2070704d534..74b1d71e79c 100644 --- a/apps/src/lib/config/genesis.rs +++ b/apps/src/lib/config/genesis.rs @@ -925,7 +925,7 @@ pub fn genesis() -> Genesis { }, max_expected_time_per_block: namada::types::time::DurationSecs(30), max_proposal_bytes: Default::default(), - max_block_gas: 100_000_000, //FIXME: adjust this value + max_block_gas: 100_000_000, // FIXME: adjust this value vp_whitelist: vec![], tx_whitelist: vec![], implicit_vp_code_path: vp_implicit_path.into(), diff --git a/apps/src/lib/node/ledger/shell/finalize_block.rs b/apps/src/lib/node/ledger/shell/finalize_block.rs index c4b747dc1d2..0c294545ed7 100644 --- a/apps/src/lib/node/ledger/shell/finalize_block.rs +++ b/apps/src/lib/node/ledger/shell/finalize_block.rs @@ -264,7 +264,12 @@ where ( tx_event, None, - TxGasMeter::new(spare_gas), // This is just for logging/events purposes, no more gas is actually used by the wrapper + TxGasMeter::new(spare_gas), /* This is just for + * logging/events + * purposes, no more + * gas is actually + * used by the + * wrapper */ ) } TxType::Decrypted(inner) => { @@ -290,9 +295,9 @@ where ); } DecryptedTx::Undecryptable(_) => { - event["log"] = - "Transaction could not be decrypted." - .into(); + event["log"] = "Transaction could not be \ + decrypted." + .into(); event["code"] = ErrorCodes::Undecryptable.into(); } @@ -307,14 +312,14 @@ where TxType::Raw(_) => { tracing::error!( "Internal logic error: FinalizeBlock received a \ - TxType::Raw transaction" + TxType::Raw transaction" ); continue; } TxType::Protocol(_) => { tracing::error!( "Internal logic error: FinalizeBlock received a \ - TxType::Protocol transaction" + TxType::Protocol transaction" ); continue; } @@ -409,8 +414,9 @@ where .storage .delete(&tx_hash_key) .expect( - "Error while deleting tx hash key from storage", - ); + "Error while deleting tx hash key from \ + storage", + ); } } @@ -591,7 +597,6 @@ mod test_finalize_block { InitProposalData, VoteProposalData, }; use namada::types::transaction::{EncryptionKey, Fee, WrapperTx, MIN_FEE}; - use tendermint_proto::abci::RequestInitChain; use super::*; use crate::node::ledger::shell::test_utils::*; @@ -1138,15 +1143,17 @@ mod test_finalize_block { let code = event.attributes.get("code").expect("Testfailed").as_str(); assert_eq!(code, String::from(ErrorCodes::WasmRuntimeError).as_str()); - assert!(!shell - .shell - .wl_storage - .has_key(&inner_hash_key) - .expect("Test failed")) + assert!( + !shell + .shell + .wl_storage + .has_key(&inner_hash_key) + .expect("Test failed") + ) } - /// Test that a wrapper transaction rejected by [`process_proposal`] because of gas, - /// still pays the fee + /// Test that a wrapper transaction rejected by [`process_proposal`] because + /// of gas, still pays the fee #[test] fn test_rejected_wrapper_for_gas_pays_fee() { let (mut shell, _) = setup(); @@ -1172,7 +1179,7 @@ mod test_finalize_block { &keypair, Epoch(0), 1.into(), - raw_tx.clone(), + raw_tx, Default::default(), #[cfg(not(feature = "mainnet"))] None, @@ -1182,7 +1189,7 @@ mod test_finalize_block { .sign(&keypair, shell.chain_id.clone(), None) .expect("Test failed"); - let processed_tx = ProcessedTx { + let _processed_tx = ProcessedTx { tx: wrapper.to_bytes(), result: TxResult { code: ErrorCodes::TxGasLimit.into(), @@ -1198,7 +1205,7 @@ mod test_finalize_block { .write(&balance_key, initial_balance.try_to_vec().unwrap()) .unwrap(); - //FIXME: uncomment when variable fees + // FIXME: uncomment when variable fees // let event = &shell // .finalize_block(FinalizeBlock { // txs: vec![processed_tx], @@ -1207,7 +1214,8 @@ mod test_finalize_block { // .expect("Test failed")[0]; // assert_eq!(event.event_type.to_string(), String::from("accepted")); - // let code = event.attributes.get("code").expect("Testfailed").as_str(); + // let code = + // event.attributes.get("code").expect("Testfailed").as_str(); // assert_eq!(code, String::from(ErrorCodes::TxGasLimit).as_str()); // assert_eq!( diff --git a/apps/src/lib/node/ledger/shell/governance.rs b/apps/src/lib/node/ledger/shell/governance.rs index 899126c56a9..00e3429bfae 100644 --- a/apps/src/lib/node/ledger/shell/governance.rs +++ b/apps/src/lib/node/ledger/shell/governance.rs @@ -97,7 +97,9 @@ where let tx_result = protocol::apply_tx( tx_type, TxIndex::default(), - &mut TxGasMeter::new(u64::MAX), // No gas limit for governance proposals + &mut TxGasMeter::new(u64::MAX), /* No gas limit + * for governance + * proposals */ gas_table, &mut shell.wl_storage.write_log, &shell.wl_storage.storage, diff --git a/apps/src/lib/node/ledger/shell/mod.rs b/apps/src/lib/node/ledger/shell/mod.rs index 0d8a18b23fe..21c70eb270e 100644 --- a/apps/src/lib/node/ledger/shell/mod.rs +++ b/apps/src/lib/node/ledger/shell/mod.rs @@ -667,7 +667,7 @@ where if let TxType::Wrapper(wrapper) = tx_type { // Tx gas limit let mut gas_meter = TxGasMeter::new(u64::from(&wrapper.gas_limit)); - if let Err(_) = gas_meter.add_tx_size_gas(tx_bytes.len()) { + if gas_meter.add_tx_size_gas(tx_bytes.len()).is_err() { response.code = ErrorCodes::TxGasLimit.into(); response.log = "Wrapper transactions exceeds its gas limit".to_string(); @@ -679,11 +679,11 @@ where .read_storage_key(¶meters::storage::get_max_block_gas_key()) .expect("Missing max_block_gas parameter in storage"); let mut block_gas_meter = BlockGasMeter::new(block_gas_limit); - if let Err(_) = block_gas_meter.finalize_transaction(gas_meter) { + if block_gas_meter.finalize_transaction(gas_meter).is_err() { response.code = ErrorCodes::BlockGasLimit.into(); - response.log = - "Wrapper transaction exceeds the maximum block gas limit" - .to_string(); + response.log = "Wrapper transaction exceeds the maximum block \ + gas limit" + .to_string(); return response; } @@ -1064,8 +1064,8 @@ mod test_utils { } /// Add a wrapper tx to the queue of txs to be decrypted - /// in the current block proposal. Takes the length of the encoded wrapper - /// as parameter. + /// in the current block proposal. Takes the length of the encoded + /// wrapper as parameter. #[cfg(test)] pub fn enqueue_tx(&mut self, wrapper: WrapperTx, inner_tx_gas: u64) { self.shell @@ -1221,13 +1221,13 @@ mod test_utils { /// Test the failure cases of [`mempool_validate`] #[cfg(test)] mod test_mempool_validate { - use crate::facade::tendermint_proto::abci::RequestInitChain; use namada::proof_of_stake::Epoch; use namada::proto::SignedTxData; - use namada::types::transaction::{Fee, GasLimit, WrapperTx}; + use namada::types::transaction::{Fee, WrapperTx}; use super::test_utils::TestShell; use super::{MempoolTxType, *}; + use crate::facade::tendermint_proto::abci::RequestInitChain; /// Mempool validation must reject unsigned wrappers #[test] diff --git a/apps/src/lib/node/ledger/shell/prepare_proposal.rs b/apps/src/lib/node/ledger/shell/prepare_proposal.rs index b1aab8e61d8..dc6a2719fa7 100644 --- a/apps/src/lib/node/ledger/shell/prepare_proposal.rs +++ b/apps/src/lib/node/ledger/shell/prepare_proposal.rs @@ -166,8 +166,11 @@ fn validate_tx_bytes( // Check tx expiration against proposed block // Cases in which the expiration is valid: // - Tx does not have an expiration - // - Time cannot be retrieved from proposed block (in this case default to last block datetime which has already been checked in mempool) - // - Error in conversion (in this case default to last block datetime which has already been checked in mempool) + // - Time cannot be retrieved from proposed block (in this case + // default to last block datetime which has already been checked in + // mempool) + // - Error in conversion (in this case default to last block datetime + // which has already been checked in mempool) if let (Some(block_time), Some(tx_exp)) = (block_time, tx_expiration) { if let Ok(block_datetime) = TryInto::::try_into(block_time) @@ -230,13 +233,10 @@ mod test_prepare_proposal { use borsh::BorshSerialize; use namada::proof_of_stake::Epoch; - use namada::types::chain::ChainId; use namada::types::transaction::{Fee, WrapperTx}; use super::*; - use crate::node::ledger::shell::test_utils::{ - gen_keypair, setup, TestShell, - }; + use crate::node::ledger::shell::test_utils::{gen_keypair, setup}; const GAS_LIMIT_MULTIPLIER: u64 = 1; @@ -245,7 +245,7 @@ mod test_prepare_proposal { /// proposed block. #[test] fn test_prepare_proposal_rejects_non_wrapper_tx() { - let (mut shell, _) = setup(); + let (shell, _) = setup(); let tx = Tx::new( "wasm_code".as_bytes().to_owned(), Some("transaction_data".as_bytes().to_owned()), @@ -271,7 +271,7 @@ mod test_prepare_proposal { /// we simply exclude it from the proposal #[test] fn test_error_in_processing_tx() { - let (mut shell, _) = setup(); + let (shell, _) = setup(); let keypair = gen_keypair(); let tx = Tx::new( "wasm_code".as_bytes().to_owned(), @@ -427,7 +427,7 @@ mod test_prepare_proposal { /// Test that expired wrapper transactions are not included in the block #[test] fn test_expired_wrapper_tx() { - let (mut shell, _) = setup(); + let (shell, _) = setup(); let keypair = gen_keypair(); let tx_time = DateTimeUtc::now(); let tx = Tx::new( @@ -478,10 +478,11 @@ mod test_prepare_proposal { } } - /// Check that a tx requiring more gas than the block limit is not included in the block + /// Check that a tx requiring more gas than the block limit is not included + /// in the block #[test] fn test_exceeding_max_block_gas_tx() { - let (mut shell, _) = setup(); + let (shell, _) = setup(); let block_gas_limit: u64 = shell .read_storage_key(¶meters::storage::get_max_block_gas_key()) @@ -530,10 +531,11 @@ mod test_prepare_proposal { } } - // Check that a wrapper requiring more gas than its limit is not included in the block + // Check that a wrapper requiring more gas than its limit is not included in + // the block #[test] fn test_exceeding_gas_limit_wrapper() { - let (mut shell, _) = setup(); + let (shell, _) = setup(); let keypair = gen_keypair(); diff --git a/apps/src/lib/node/ledger/shell/process_proposal.rs b/apps/src/lib/node/ledger/shell/process_proposal.rs index 6b4a3fb2cf5..a2fd2bad988 100644 --- a/apps/src/lib/node/ledger/shell/process_proposal.rs +++ b/apps/src/lib/node/ledger/shell/process_proposal.rs @@ -5,7 +5,6 @@ use std::collections::BTreeMap; use namada::core::types::hash::Hash; use namada::ledger::storage::TempWlStorage; -use namada::types::chain::ProposalBytes; use namada::types::internal::WrapperTxInQueue; use super::*; @@ -83,7 +82,7 @@ where &mut temp_block_gas_meter, block_time, &gas_table, - &mut wrapper_index + &mut wrapper_index, ); if let ErrorCodes::Ok = ErrorCodes::from_u32(result.code).unwrap() @@ -117,6 +116,7 @@ where /// INVARIANT: Any changes applied in this method must be reverted if the /// proposal is rejected (unless we can simply overwrite them in the /// next block). + #[allow(clippy::too_many_arguments)] pub fn process_single_tx<'a>( &self, tx_bytes: &[u8], @@ -194,7 +194,7 @@ where TxType::Decrypted(tx) => { // Increase wrapper index let tx_index = *wrapper_index; - *wrapper_index += 1; + *wrapper_index += 1; match tx_queue_iter.next() { Some(wrapper) => { @@ -243,27 +243,45 @@ where let tx_hash = Hash::sha256(tx.code) .to_string() .to_ascii_lowercase(); - let tx_gas = match gas_table.get(tx_hash.as_str()) { + let tx_gas = match gas_table + .get(tx_hash.as_str()) + { Some(gas) => gas.to_owned(), - #[cfg(any(test, feature = "testing"))] - None => 1000, - #[cfg(not(any(test, feature = "testing")))] - None => return TxResult { - // Tx is not whitelisted - code: ErrorCodes::Undecryptable.into(), - info: "Tx is not whitelisted".to_string() + #[cfg(any(test, feature = "testing"))] + None => 1000, + #[cfg(not(any( + test, + feature = "testing" + )))] + None => { + return TxResult { + // Tx is not whitelisted + code: ErrorCodes::Undecryptable + .into(), + info: "Tx is not whitelisted" + .to_string(), + }; } }; - let inner_tx_gas_limit = temp_wl_storage.storage.tx_queue.get(tx_index).map_or(0, |wrapper| wrapper.gas); - let mut tx_gas_meter = TxGasMeter::new(inner_tx_gas_limit); - if let Err(e) = tx_gas_meter.add(tx_gas) { - - return TxResult { - code: ErrorCodes::DecryptedTxGasLimit.into(), - info: format!("Decrypted transaction gas error: {}", e) + let inner_tx_gas_limit = temp_wl_storage + .storage + .tx_queue + .get(tx_index) + .map_or(0, |wrapper| wrapper.gas); + let mut tx_gas_meter = + TxGasMeter::new(inner_tx_gas_limit); + if let Err(e) = tx_gas_meter.add(tx_gas) { + return TxResult { + code: + ErrorCodes::DecryptedTxGasLimit + .into(), + info: format!( + "Decrypted transaction gas \ + error: {}", + e + ), }; } - } TxResult { @@ -290,26 +308,35 @@ where } } TxType::Wrapper(wrapper) => { - // Account for gas. This is done even if the transaction is later deemed invalid, to incentivize the proposer to - // include only valid transaction and avoid wasting block gas limit - let mut tx_gas_meter = TxGasMeter::new(u64::from(&wrapper.gas_limit)); - if let Err(_) = tx_gas_meter.add_tx_size_gas(tx_bytes.len()) { - // Add the declared tx gas limit to the block gas meter even in case of an error - let _ = temp_block_gas_meter.finalize_transaction(tx_gas_meter); + // Account for gas. This is done even if the transaction is + // later deemed invalid, to incentivize the proposer to + // include only valid transaction and avoid wasting block + // gas limit + let mut tx_gas_meter = + TxGasMeter::new(u64::from(&wrapper.gas_limit)); + if tx_gas_meter.add_tx_size_gas(tx_bytes.len()).is_err() { + // Add the declared tx gas limit to the block gas meter + // even in case of an error + let _ = temp_block_gas_meter + .finalize_transaction(tx_gas_meter); return TxResult { code: ErrorCodes::TxGasLimit.into(), - info: "Wrapper transactions exceeds its gas limit".to_string(), + info: "Wrapper transactions exceeds its gas limit" + .to_string(), }; } - - if let Err(_) = temp_block_gas_meter.finalize_transaction(tx_gas_meter){ + + if temp_block_gas_meter + .finalize_transaction(tx_gas_meter) + .is_err() + { return TxResult { code: ErrorCodes::BlockGasLimit.into(), - - info: - "Wrapper transaction exceeds the maximum block gas limit" - .to_string() + + info: "Wrapper transaction exceeds the maximum \ + block gas limit" + .to_string(), }; } @@ -403,8 +430,10 @@ where ); // check that the fee payer has sufficient balance - let balance = - self.get_balance(&wrapper.fee.token, &wrapper.fee_payer()); + let balance = self.get_balance( + &wrapper.fee.token, + &wrapper.fee_payer(), + ); // In testnets, tx is allowed to skip fees if it // includes a valid PoW @@ -460,13 +489,11 @@ mod test_process_proposal { use namada::types::transaction::{EncryptionKey, Fee, WrapperTx}; use super::*; - use crate::facade::tendermint_proto::abci::RequestInitChain; - use crate::facade::tendermint_proto::google::protobuf::Timestamp; use crate::node::ledger::shell::test_utils::{ - gen_keypair, ProcessProposal, TestError, TestShell, setup, + gen_keypair, setup, ProcessProposal, TestError, }; -const GAS_LIMIT_MULTIPLIER: u64 = 1; + const GAS_LIMIT_MULTIPLIER: u64 = 1; /// Test that if a wrapper tx is not signed, the block is rejected /// by [`process_proposal`]. @@ -616,7 +643,7 @@ const GAS_LIMIT_MULTIPLIER: u64 = 1; fn test_wrapper_unknown_address() { let (mut shell, _) = setup(); let keypair = crate::wallet::defaults::keys().remove(0).1; -// reduce address balance to match the 100 token min fee + // reduce address balance to match the 100 token min fee let balance_key = token::balance_key( &shell.wl_storage.storage.native_token, &Address::from(&keypair.ref_to()), @@ -758,9 +785,13 @@ const GAS_LIMIT_MULTIPLIER: u64 = 1; #[cfg(not(feature = "mainnet"))] None, ); - let signed_wrapper = wrapper.sign(&keypair, shell.chain_id.clone(), None).unwrap().to_bytes(); - let gas_limit = u64::from(&wrapper.gas_limit) - signed_wrapper.len() as u64; - shell.enqueue_tx(wrapper, gas_limit); + let signed_wrapper = wrapper + .sign(&keypair, shell.chain_id.clone(), None) + .unwrap() + .to_bytes(); + let gas_limit = + u64::from(&wrapper.gas_limit) - signed_wrapper.len() as u64; + shell.enqueue_tx(wrapper, gas_limit); let mut decrypted_tx = Tx::from(TxType::Decrypted(DecryptedTx::Decrypted { tx, @@ -835,8 +866,14 @@ const GAS_LIMIT_MULTIPLIER: u64 = 1; #[cfg(not(feature = "mainnet"))] None, ); - let signed_wrapper = wrapper.sign(&keypair, shell.chain_id.clone(), None).unwrap().to_bytes(); - shell.enqueue_tx(wrapper.clone(), u64::from(&wrapper.gas_limit) - signed_wrapper.len() as u64); + let signed_wrapper = wrapper + .sign(&keypair, shell.chain_id.clone(), None) + .unwrap() + .to_bytes(); + shell.enqueue_tx( + wrapper.clone(), + u64::from(&wrapper.gas_limit) - signed_wrapper.len() as u64, + ); let mut tx = Tx::from(TxType::Decrypted(DecryptedTx::Undecryptable(wrapper))); @@ -892,9 +929,15 @@ const GAS_LIMIT_MULTIPLIER: u64 = 1; None, ); wrapper.tx_hash = Hash([0; 32]); - let signed_wrapper = wrapper.sign(&keypair, shell.chain_id.clone(), None).unwrap().to_bytes(); + let signed_wrapper = wrapper + .sign(&keypair, shell.chain_id.clone(), None) + .unwrap() + .to_bytes(); - shell.enqueue_tx(wrapper.clone(), u64::from(&wrapper.gas_limit) - signed_wrapper.len() as u64); + shell.enqueue_tx( + wrapper.clone(), + u64::from(&wrapper.gas_limit) - signed_wrapper.len() as u64, + ); let mut tx = Tx::from(TxType::Decrypted(DecryptedTx::Undecryptable( #[allow(clippy::redundant_clone)] wrapper.clone(), @@ -941,8 +984,14 @@ const GAS_LIMIT_MULTIPLIER: u64 = 1; pow_solution: None, }; - let signed_wrapper = wrapper.sign(&keypair, shell.chain_id.clone(), None).unwrap().to_bytes(); - shell.enqueue_tx(wrapper.clone(), u64::from(&wrapper.gas_limit) - signed_wrapper.len() as u64); + let signed_wrapper = wrapper + .sign(&keypair, shell.chain_id.clone(), None) + .unwrap() + .to_bytes(); + shell.enqueue_tx( + wrapper.clone(), + u64::from(&wrapper.gas_limit) - signed_wrapper.len() as u64, + ); let mut signed = Tx::from(TxType::Decrypted(DecryptedTx::Undecryptable( #[allow(clippy::redundant_clone)] @@ -1426,8 +1475,12 @@ const GAS_LIMIT_MULTIPLIER: u64 = 1; #[cfg(not(feature = "mainnet"))] None, ); - let signed_wrapper = wrapper.sign(&keypair, shell.chain_id.clone(), None).unwrap().to_bytes(); - let gas_limit = u64::from(&wrapper.gas_limit) - signed_wrapper.len() as u64; + let signed_wrapper = wrapper + .sign(&keypair, shell.chain_id.clone(), None) + .unwrap() + .to_bytes(); + let gas_limit = + u64::from(&wrapper.gas_limit) - signed_wrapper.len() as u64; let wrapper_in_queue = WrapperTxInQueue { tx: wrapper, gas: gas_limit, @@ -1535,8 +1588,12 @@ const GAS_LIMIT_MULTIPLIER: u64 = 1; #[cfg(not(feature = "mainnet"))] None, ); - let signed_wrapper_tx = wrapper.sign(&keypair, shell.chain_id.clone(), None).unwrap().to_bytes(); - let gas_limit = u64::from(&wrapper.gas_limit) - signed_wrapper_tx.len() as u64; + let signed_wrapper_tx = wrapper + .sign(&keypair, shell.chain_id.clone(), None) + .unwrap() + .to_bytes(); + let gas_limit = + u64::from(&wrapper.gas_limit) - signed_wrapper_tx.len() as u64; let wrapper_in_queue = WrapperTxInQueue { tx: wrapper, gas: gas_limit, @@ -1559,9 +1616,8 @@ const GAS_LIMIT_MULTIPLIER: u64 = 1; } } - - /// Test that a decrypted transaction requiring more gas than the limit imposed - /// by its wrapper is rejected. + /// Test that a decrypted transaction requiring more gas than the limit + /// imposed by its wrapper is rejected. #[test] fn test_decrypted_gas_limit() { let (mut shell, _) = setup(); @@ -1571,7 +1627,7 @@ const GAS_LIMIT_MULTIPLIER: u64 = 1; "wasm_code".as_bytes().to_owned(), Some("new transaction data".as_bytes().to_owned()), shell.chain_id.clone(), - None + None, ); let decrypted: Tx = DecryptedTx::Decrypted { tx: tx.clone(), @@ -1592,7 +1648,7 @@ const GAS_LIMIT_MULTIPLIER: u64 = 1; #[cfg(not(feature = "mainnet"))] None, ); - let gas = u64::from(&wrapper.gas_limit) ; + let gas = u64::from(&wrapper.gas_limit); let wrapper_in_queue = WrapperTxInQueue { tx: wrapper, gas, @@ -1615,7 +1671,8 @@ const GAS_LIMIT_MULTIPLIER: u64 = 1; } } - /// Check that a tx requiring more gas than the block limit causes a block rejection + /// Check that a tx requiring more gas than the block limit causes a block + /// rejection #[test] fn test_exceeding_max_block_gas_tx() { let (mut shell, _) = setup(); @@ -1652,7 +1709,7 @@ const GAS_LIMIT_MULTIPLIER: u64 = 1; let request = ProcessProposal { txs: vec![wrapper.to_bytes()], }; -match shell.process_proposal(request) { + match shell.process_proposal(request) { Ok(_) => panic!("Test failed"), Err(TestError::RejectProposal(response)) => { assert_eq!( @@ -1663,7 +1720,8 @@ match shell.process_proposal(request) { } } -// Check that a wrapper requiring more gas than its limit causes a block rejection + // Check that a wrapper requiring more gas than its limit causes a block + // rejection #[test] fn test_exceeding_gas_limit_wrapper() { let (mut shell, _) = setup(); @@ -1697,7 +1755,7 @@ match shell.process_proposal(request) { let request = ProcessProposal { txs: vec![wrapper.to_bytes()], }; -match shell.process_proposal(request) { + match shell.process_proposal(request) { Ok(_) => panic!("Test failed"), Err(TestError::RejectProposal(response)) => { assert_eq!( @@ -1706,5 +1764,5 @@ match shell.process_proposal(request) { ); } } - } + } } diff --git a/apps/src/lib/wasm_loader/mod.rs b/apps/src/lib/wasm_loader/mod.rs index 4eadf9d565a..7456c9eec50 100644 --- a/apps/src/lib/wasm_loader/mod.rs +++ b/apps/src/lib/wasm_loader/mod.rs @@ -327,8 +327,8 @@ async fn download_wasm(url: String) -> Result, Error> { } } -/// Read the json file containing the gas costs for the whitelisted vps and txsi from -/// the default "gas.json" file in the given directory +/// Read the json file containing the gas costs for the whitelisted vps and txsi +/// from the default "gas.json" file in the given directory pub fn read_gas_file(wasm_directory: impl AsRef) -> HashMap { let gas_path = wasm_directory.as_ref().join("gas.json"); diff --git a/benches/host_env.rs b/benches/host_env.rs index 9c64c503a38..74f4e928f5f 100644 --- a/benches/host_env.rs +++ b/benches/host_env.rs @@ -1,12 +1,11 @@ use borsh::BorshDeserialize; use criterion::{criterion_group, criterion_main, Criterion}; -use namada::core::types::address; -use namada::core::types::token::{Amount, Transfer}; -use namada_bench::{generate_tx, TX_TRANSFER_WASM}; - use namada::core::proto::SignedTxData; +use namada::core::types::address; use namada::core::types::key::RefTo; +use namada::core::types::token::{Amount, Transfer}; use namada_apps::wallet::defaults; +use namada_bench::{generate_tx, TX_TRANSFER_WASM}; fn tx_signature_validation(c: &mut Criterion) { let tx = generate_tx( @@ -24,7 +23,7 @@ fn tx_signature_validation(c: &mut Criterion) { ); let SignedTxData { data: _, ref sig } = - SignedTxData::try_from_slice(&tx.data.as_ref().unwrap()).unwrap(); + SignedTxData::try_from_slice(tx.data.as_ref().unwrap()).unwrap(); c.bench_function("tx_signature_validation", |b| { b.iter(|| { diff --git a/benches/mod.rs b/benches/mod.rs index 00c2a8bfd79..e919eaf164e 100644 --- a/benches/mod.rs +++ b/benches/mod.rs @@ -2,14 +2,19 @@ //! //! Measurements are taken on the elapsed wall-time. //! -//! The benchmarks only focus on sucessfull transactions and vps: in case of failure, -//! the bench function shall panic to avoid timing incomplete execution paths. +//! The benchmarks only focus on sucessfull transactions and vps: in case of +//! failure, the bench function shall panic to avoid timing incomplete execution +//! paths. //! -//! In addition, this module also contains benchmarks for [`WrapperTx`][`namada::core::types::transaction::wrapper::WrapperTx`] validation and -//! [`host_env`][`namada::vm::host_env`] exposed functions that define the gas constants of [`gas`][`namada::core::ledger::gas`]. +//! In addition, this module also contains benchmarks for +//! [`WrapperTx`][`namada::core::types::transaction::wrapper::WrapperTx`] +//! validation and [`host_env`][`namada::vm::host_env`] exposed functions that +//! define the gas constants of [`gas`][`namada::core::ledger::gas`]. //! -//! For more realistic results these benchmarks should be run on all the combination of -//! supported OS/architecture. +//! For more realistic results these benchmarks should be run on all the +//! combination of supported OS/architecture. + +use std::ops::{Deref, DerefMut}; use async_trait::async_trait; use borsh::BorshSerialize; @@ -24,8 +29,9 @@ use namada::core::types::key::common::SecretKey; use namada::core::types::storage::Key; use namada::core::types::token::{Amount, Transfer}; use namada::ibc::applications::ics20_fungible_token_transfer::msgs::transfer::MsgTransfer; -use namada::ibc::clients::ics07_tendermint::client_state::AllowUpdate; -use namada::ibc::clients::ics07_tendermint::client_state::ClientState; +use namada::ibc::clients::ics07_tendermint::client_state::{ + AllowUpdate, ClientState, +}; use namada::ibc::clients::ics07_tendermint::consensus_state::ConsensusState; use namada::ibc::core::ics02_client::client_consensus::AnyConsensusState; use namada::ibc::core::ics02_client::client_state::AnyClientState; @@ -41,9 +47,8 @@ use namada::ibc::core::ics04_channel::channel::{ use namada::ibc::core::ics04_channel::Version as ChannelVersion; use namada::ibc::core::ics23_commitment::commitment::CommitmentRoot; use namada::ibc::core::ics23_commitment::specs::ProofSpecs; -use namada::ibc::core::ics24_host::identifier::ChainId as IbcChainId; use namada::ibc::core::ics24_host::identifier::{ - ChannelId, ClientId, ConnectionId, PortId, + ChainId as IbcChainId, ChannelId, ClientId, ConnectionId, PortId, }; use namada::ibc::core::ics24_host::path::{ChannelEndsPath, ConnectionsPath}; use namada::ibc::core::ics24_host::Path as IbcPath; @@ -53,9 +58,8 @@ use namada::ibc::tx_msg::Msg; use namada::ibc::Height as IbcHeight; use namada::ibc_proto::cosmos::base::v1beta1::Coin; use namada::ledger::gas::TxGasMeter; -use namada::ledger::queries::RPC; use namada::ledger::queries::{ - Client, EncodedResponseQuery, RequestCtx, RequestQuery, Router, + Client, EncodedResponseQuery, RequestCtx, RequestQuery, Router, RPC, }; use namada::proof_of_stake; use namada::proof_of_stake::Epoch; @@ -75,8 +79,9 @@ use namada::types::transaction::GasLimit; use namada::vm::wasm::run; use namada_apps::cli::context::FromContext; use namada_apps::cli::Context; -use namada_apps::client::tx::gen_shielded_transfer; -use namada_apps::client::tx::{find_valid_diversifier, Conversions}; +use namada_apps::client::tx::{ + find_valid_diversifier, gen_shielded_transfer, Conversions, +}; use namada_apps::client::types::{ ParsedTxArgs, ParsedTxTransferArgs, ShieldedTransferContext, }; @@ -89,7 +94,6 @@ use namada_apps::wallet::defaults; use namada_apps::{config, wasm_loader}; use namada_test_utils::tx_data::TxWriteData; use rand_core::OsRng; -use std::ops::{Deref, DerefMut}; use tempfile::TempDir; pub const WASM_DIR: &str = "../wasm"; @@ -111,7 +115,8 @@ const BERTHA_SPENDING_KEY: &str = "bertha_spending"; pub struct BenchShell { pub inner: Shell, - /// NOTE: Temporary directory should be dropped last since Shell need to flush data on drop + /// NOTE: Temporary directory should be dropped last since Shell need to + /// flush data on drop tempdir: TempDir, } @@ -129,8 +134,8 @@ impl DerefMut for BenchShell { } } -impl BenchShell { - pub fn new() -> Self { +impl Default for BenchShell { + fn default() -> Self { let (sender, _) = tokio::sync::mpsc::unbounded_channel(); let tempdir = tempfile::tempdir().unwrap(); let path = tempdir.path().canonicalize().unwrap(); @@ -166,11 +171,8 @@ impl BenchShell { amount: Amount::whole(1000), source: Some(defaults::albert_address()), }; - let signed_tx = generate_tx( - TX_BOND_WASM, - bond.clone(), - &defaults::albert_keypair(), - ); + let signed_tx = + generate_tx(TX_BOND_WASM, bond, &defaults::albert_keypair()); let mut bench_shell = BenchShell { inner: shell, @@ -205,7 +207,9 @@ impl BenchShell { bench_shell } +} +impl BenchShell { pub fn execute_tx(&mut self, tx: &Tx) { run::tx( &self.inner.wl_storage.storage, @@ -294,7 +298,7 @@ impl BenchShell { .write(&cap_key, PortId::transfer().as_bytes()) .unwrap(); - //Set Channel open + // Set Channel open let counterparty = ChannelCounterparty::new( PortId::transfer(), Some(ChannelId::new(5)), @@ -367,7 +371,7 @@ impl BenchShell { let consensus_state = ConsensusState { timestamp: now, - root: CommitmentRoot::from_bytes(&vec![]), + root: CommitmentRoot::from_bytes(&[]), next_validators_hash: Hash::Sha256([0u8; 32]), }; @@ -514,9 +518,9 @@ impl ShieldedTransferContext for BenchShieldedCtx { } } -impl BenchShieldedCtx { - pub fn new() -> Self { - let mut shell = BenchShell::new(); +impl Default for BenchShieldedCtx { + fn default() -> Self { + let mut shell = BenchShell::default(); let mut ctx = Context::new(namada_apps::cli::args::Global { chain_id: None, @@ -569,7 +573,9 @@ impl BenchShieldedCtx { Self { ctx, shell } } +} +impl BenchShieldedCtx { pub fn generate_masp_tx( &mut self, amount: Amount, diff --git a/benches/native_vps.rs b/benches/native_vps.rs index d65dae8fbfb..4d3ef6f0279 100644 --- a/benches/native_vps.rs +++ b/benches/native_vps.rs @@ -1,3 +1,5 @@ +use std::collections::BTreeSet; + use criterion::{criterion_group, criterion_main, Criterion}; use namada::core::ledger::ibc::actions; use namada::core::types::address::{self, Address}; @@ -25,22 +27,20 @@ use namada::proto::Tx; use namada::types::address::InternalAddress; use namada::types::chain::ChainId; use namada::types::storage::TxIndex; +use namada::types::transaction::governance::{ + InitProposalData, VoteProposalData, +}; +use namada_apps::wallet::defaults; use namada_apps::wasm_loader; use namada_bench::{ generate_foreign_key_tx, generate_ibc_transfer_tx, generate_tx, BenchShell, TX_IBC_WASM, TX_INIT_PROPOSAL_WASM, TX_VOTE_PROPOSAL_WASM, WASM_DIR, }; -use std::collections::BTreeSet; - -use namada::types::transaction::governance::{ - InitProposalData, VoteProposalData, -}; -use namada_apps::wallet::defaults; fn replay_protection(c: &mut Criterion) { // Write a random key under the replay protection subspace let tx = generate_foreign_key_tx(&defaults::albert_keypair()); - let mut shell = BenchShell::new(); + let mut shell = BenchShell::default(); shell.execute_tx(&tx); let (verifiers, keys_changed) = shell @@ -64,7 +64,8 @@ fn replay_protection(c: &mut Criterion) { c.bench_function("vp_replay_protection", |b| { b.iter(|| { - // NOTE: thiv VP will always fail when triggered so don't assert here + // NOTE: thiv VP will always fail when triggered so don't assert + // here replay_protection .validate_tx( tx.data.as_ref().unwrap(), @@ -86,7 +87,7 @@ fn governance(c: &mut Criterion) { "minimal_proposal", "complete_proposal", ] { - let mut shell = BenchShell::new(); + let mut shell = BenchShell::default(); let signed_tx = match bench_name { "foreign_key_write" => { @@ -176,13 +177,15 @@ fn governance(c: &mut Criterion) { group.bench_function(bench_name, |b| { b.iter(|| { - assert!(governance - .validate_tx( - signed_tx.data.as_ref().unwrap(), - governance.ctx.keys_changed, - governance.ctx.verifiers, - ) - .unwrap()) + assert!( + governance + .validate_tx( + signed_tx.data.as_ref().unwrap(), + governance.ctx.keys_changed, + governance.ctx.verifiers, + ) + .unwrap() + ) }) }); } @@ -215,7 +218,7 @@ fn slash_fund(c: &mut Criterion) { .into_iter() .zip(["foreign_key_write", "governance_proposal"]) { - let mut shell = BenchShell::new(); + let mut shell = BenchShell::default(); // Run the tx to validate shell.execute_tx(&tx); @@ -241,13 +244,15 @@ fn slash_fund(c: &mut Criterion) { group.bench_function(bench_name, |b| { b.iter(|| { - assert!(slash_fund - .validate_tx( - tx.data.as_ref().unwrap(), - slash_fund.ctx.keys_changed, - slash_fund.ctx.verifiers, - ) - .unwrap()) + assert!( + slash_fund + .validate_tx( + tx.data.as_ref().unwrap(), + slash_fund.ctx.keys_changed, + slash_fund.ctx.verifiers, + ) + .unwrap() + ) }) }); } @@ -299,7 +304,7 @@ fn ibc(c: &mut Criterion) { ); let msg = MsgChannelOpenInit { port_id: PortId::transfer(), - channel: channel.clone(), + channel, signer: Signer::new(defaults::albert_address()), }; @@ -333,7 +338,7 @@ fn ibc(c: &mut Criterion) { "open_channel", "outgoing_transfer", ]) { - let mut shell = BenchShell::new(); + let mut shell = BenchShell::default(); shell.init_ibc_channel(); shell.execute_tx(signed_tx); @@ -358,13 +363,14 @@ fn ibc(c: &mut Criterion) { group.bench_function(bench_name, |b| { b.iter(|| { - assert!(ibc - .validate_tx( + assert!( + ibc.validate_tx( signed_tx.data.as_ref().unwrap(), ibc.ctx.keys_changed, ibc.ctx.verifiers, ) - .unwrap()) + .unwrap() + ) }) }); } @@ -383,10 +389,10 @@ fn ibc_token(c: &mut Criterion) { .iter() .zip(["foreign_key_write", "outgoing_transfer"]) { - let mut shell = BenchShell::new(); + let mut shell = BenchShell::default(); shell.init_ibc_channel(); - shell.execute_tx(&signed_tx); + shell.execute_tx(signed_tx); let (verifiers, keys_changed) = shell .wl_storage @@ -406,7 +412,7 @@ fn ibc_token(c: &mut Criterion) { &internal_address, &shell.wl_storage.storage, &shell.wl_storage.write_log, - &signed_tx, + signed_tx, &TxIndex(0), VpGasMeter::new(u64::MAX, 0), &keys_changed, @@ -417,13 +423,14 @@ fn ibc_token(c: &mut Criterion) { group.bench_function(bench_name, |b| { b.iter(|| { - assert!(ibc - .validate_tx( + assert!( + ibc.validate_tx( signed_tx.data.as_ref().unwrap(), ibc.ctx.keys_changed, ibc.ctx.verifiers, ) - .unwrap()) + .unwrap() + ) }) }); } diff --git a/benches/process_wrapper.rs b/benches/process_wrapper.rs index 27c7fb48114..6d39aa75f46 100644 --- a/benches/process_wrapper.rs +++ b/benches/process_wrapper.rs @@ -1,3 +1,5 @@ +use std::collections::BTreeMap; + use criterion::{criterion_group, criterion_main, Criterion}; use namada::core::types::address::{self}; use namada::core::types::token::{Amount, Transfer}; @@ -5,14 +7,12 @@ use namada::ledger::gas::BlockGasMeter; use namada::ledger::storage::TempWlStorage; use namada::types::chain::ChainId; use namada::types::time::DateTimeUtc; -use namada_bench::{generate_tx, BenchShell, TX_TRANSFER_WASM}; -use std::collections::BTreeMap; - use namada::types::transaction::{Fee, WrapperTx}; use namada_apps::wallet::defaults; +use namada_bench::{generate_tx, BenchShell, TX_TRANSFER_WASM}; fn process_tx(c: &mut Criterion) { - let shell = BenchShell::new(); + let shell = BenchShell::default(); let tx = generate_tx( TX_TRANSFER_WASM, Transfer { diff --git a/benches/txs.rs b/benches/txs.rs index e50bd44954f..d023ba06278 100644 --- a/benches/txs.rs +++ b/benches/txs.rs @@ -14,8 +14,9 @@ use namada::types::transaction::governance::{ InitProposalData, VoteProposalData, }; use namada::types::transaction::pos::{Bond, CommissionChange, Withdraw}; -use namada::types::transaction::EllipticCurve; -use namada::types::transaction::{InitAccount, InitValidator, UpdateVp}; +use namada::types::transaction::{ + EllipticCurve, InitAccount, InitValidator, UpdateVp, +}; use namada_apps::wallet::defaults; use namada_apps::wasm_loader; use namada_bench::{ @@ -41,7 +42,7 @@ fn transfer(c: &mut Criterion) { group.bench_function(bench_name, |b| { b.iter_batched_ref( || { - let mut shielded_ctx = BenchShieldedCtx::new(); + let mut shielded_ctx = BenchShieldedCtx::default(); let albert_spending_key = shielded_ctx .ctx @@ -69,7 +70,6 @@ fn transfer(c: &mut Criterion) { TransferTarget::PaymentAddress(albert_payment_addr), ); shielded_ctx.shell.execute_tx(&shield_tx); - shielded_ctx.shell.wl_storage.commit_tx(); shielded_ctx.shell.commit(); let signed_tx = match bench_name { @@ -103,7 +103,7 @@ fn transfer(c: &mut Criterion) { (shielded_ctx, signed_tx) }, |(shielded_ctx, signed_tx)| { - shielded_ctx.shell.execute_tx(&signed_tx); + shielded_ctx.shell.execute_tx(signed_tx); }, criterion::BatchSize::LargeInput, ) @@ -141,7 +141,7 @@ fn bond(c: &mut Criterion) { { group.bench_function(bench_name, |b| { b.iter_batched_ref( - BenchShell::new, + BenchShell::default, |shell| shell.execute_tx(signed_tx), criterion::BatchSize::LargeInput, ) @@ -179,7 +179,7 @@ fn unbond(c: &mut Criterion) { { group.bench_function(bench_name, |b| { b.iter_batched_ref( - BenchShell::new, + BenchShell::default, |shell| shell.execute_tx(signed_tx), criterion::BatchSize::LargeInput, ) @@ -217,7 +217,7 @@ fn withdraw(c: &mut Criterion) { group.bench_function(bench_name, |b| { b.iter_batched_ref( || { - let mut shell = BenchShell::new(); + let mut shell = BenchShell::default(); // Unbond funds let unbond_tx = match bench_name { @@ -282,7 +282,7 @@ fn reveal_pk(c: &mut Criterion) { c.bench_function("reveal_pk", |b| { b.iter_batched_ref( - BenchShell::new, + BenchShell::default, |shell| shell.execute_tx(&tx), criterion::BatchSize::LargeInput, ) @@ -304,7 +304,7 @@ fn update_vp(c: &mut Criterion) { c.bench_function("update_vp", |b| { b.iter_batched_ref( - BenchShell::new, + BenchShell::default, |shell| shell.execute_tx(&signed_tx), criterion::BatchSize::LargeInput, ) @@ -329,7 +329,7 @@ fn init_account(c: &mut Criterion) { c.bench_function("init_account", |b| { b.iter_batched_ref( - BenchShell::new, + BenchShell::default, |shell| shell.execute_tx(&signed_tx), criterion::BatchSize::LargeInput, ) @@ -343,7 +343,7 @@ fn init_proposal(c: &mut Criterion) { group.bench_function(bench_name, |b| { b.iter_batched_ref( || { - let shell = BenchShell::new(); + let shell = BenchShell::default(); let signed_tx = match bench_name { "minimal_proposal" => generate_tx( @@ -429,7 +429,7 @@ fn vote_proposal(c: &mut Criterion) { { group.bench_function(bench_name, |b| { b.iter_batched_ref( - BenchShell::new, + BenchShell::default, |shell| shell.execute_tx(signed_tx), criterion::BatchSize::LargeInput, ) @@ -478,7 +478,7 @@ fn init_validator(c: &mut Criterion) { c.bench_function("init_validator", |b| { b.iter_batched_ref( - BenchShell::new, + BenchShell::default, |shell| shell.execute_tx(&signed_tx), criterion::BatchSize::LargeInput, ) @@ -497,7 +497,7 @@ fn change_validator_commission(c: &mut Criterion) { c.bench_function("change_validator_commission", |b| { b.iter_batched_ref( - BenchShell::new, + BenchShell::default, |shell| shell.execute_tx(&signed_tx), criterion::BatchSize::LargeInput, ) @@ -510,7 +510,7 @@ fn ibc(c: &mut Criterion) { c.bench_function("ibc_transfer", |b| { b.iter_batched_ref( || { - let mut shell = BenchShell::new(); + let mut shell = BenchShell::default(); shell.init_ibc_channel(); shell diff --git a/benches/vps.rs b/benches/vps.rs index e612fadd8ce..6a4c8c602a7 100644 --- a/benches/vps.rs +++ b/benches/vps.rs @@ -1,3 +1,5 @@ +use std::collections::BTreeSet; + use borsh::BorshSerialize; use criterion::{criterion_group, criterion_main, Criterion}; use namada::core::types::address::{self, Address}; @@ -11,7 +13,11 @@ use namada::types::chain::ChainId; use namada::types::key::ed25519; use namada::types::masp::{TransferSource, TransferTarget}; use namada::types::storage::TxIndex; +use namada::types::transaction::governance::VoteProposalData; +use namada::types::transaction::pos::{Bond, CommissionChange}; +use namada::types::transaction::UpdateVp; use namada::vm::wasm::run; +use namada_apps::wallet::defaults; use namada_apps::wasm_loader; use namada_bench::{ generate_foreign_key_tx, generate_tx, BenchShell, BenchShieldedCtx, @@ -21,12 +27,6 @@ use namada_bench::{ WASM_DIR, }; use rust_decimal::Decimal; -use std::collections::BTreeSet; - -use namada::types::transaction::governance::VoteProposalData; -use namada::types::transaction::pos::{Bond, CommissionChange}; -use namada::types::transaction::UpdateVp; -use namada_apps::wallet::defaults; const VP_USER_WASM: &str = "vp_user.wasm"; const VP_TOKEN_WASM: &str = "vp_token.wasm"; @@ -119,8 +119,8 @@ fn vp_user(c: &mut Criterion) { "pos", "vp", ]) { - let mut shell = BenchShell::new(); - shell.execute_tx(&signed_tx); + let mut shell = BenchShell::default(); + shell.execute_tx(signed_tx); let (verifiers, keys_changed) = shell .wl_storage .write_log @@ -128,20 +128,22 @@ fn vp_user(c: &mut Criterion) { group.bench_function(bench_name, |b| { b.iter(|| { - assert!(run::vp( - &vp_code, - &signed_tx, - &TxIndex(0), - &defaults::albert_address(), - &shell.wl_storage.storage, - &shell.wl_storage.write_log, - &mut VpGasMeter::new(u64::MAX, 0), - &keys_changed, - &verifiers, - shell.vp_wasm_cache.clone(), - false, - ) - .unwrap()); + assert!( + run::vp( + &vp_code, + signed_tx, + &TxIndex(0), + &defaults::albert_address(), + &shell.wl_storage.storage, + &shell.wl_storage.write_log, + &mut VpGasMeter::new(u64::MAX, 0), + &keys_changed, + &verifiers, + shell.vp_wasm_cache.clone(), + false, + ) + .unwrap() + ); }) }); } @@ -213,7 +215,8 @@ fn vp_implicit(c: &mut Criterion) { id: 0, vote: namada::types::governance::ProposalVote::Yay, voter: Address::from(&implicit_account.to_public()), - delegations: vec![], //NOTE: no need to bond tokens because the implicit vp doesn't check that + delegations: vec![], /* NOTE: no need to bond tokens because the + * implicit vp doesn't check that */ }, &implicit_account, ); @@ -235,19 +238,17 @@ fn vp_implicit(c: &mut Criterion) { "pos", "governance_vote", ]) { - let mut shell = BenchShell::new(); + let mut shell = BenchShell::default(); if bench_name != "reveal_pk" { // Reveal publick key shell.execute_tx(&reveal_pk); - shell.wl_storage.commit_tx(); shell.commit(); } if bench_name == "transfer" { // Transfer some tokens to the implicit address shell.execute_tx(&received_transfer); - shell.wl_storage.commit_tx(); shell.commit(); } @@ -260,20 +261,22 @@ fn vp_implicit(c: &mut Criterion) { group.bench_function(bench_name, |b| { b.iter(|| { - assert!(run::vp( - &vp_code, - tx, - &TxIndex(0), - &Address::from(&implicit_account.to_public()), - &shell.wl_storage.storage, - &shell.wl_storage.write_log, - &mut VpGasMeter::new(u64::MAX, 0), - &keys_changed, - &verifiers, - shell.vp_wasm_cache.clone(), - false, + assert!( + run::vp( + &vp_code, + tx, + &TxIndex(0), + &Address::from(&implicit_account.to_public()), + &shell.wl_storage.storage, + &shell.wl_storage.write_log, + &mut VpGasMeter::new(u64::MAX, 0), + &keys_changed, + &verifiers, + shell.vp_wasm_cache.clone(), + false, + ) + .unwrap() ) - .unwrap()) }) }); } @@ -377,9 +380,9 @@ fn vp_validator(c: &mut Criterion) { "commission_rate", "vp", ]) { - let mut shell = BenchShell::new(); + let mut shell = BenchShell::default(); - shell.execute_tx(&signed_tx); + shell.execute_tx(signed_tx); let (verifiers, keys_changed) = shell .wl_storage .write_log @@ -387,20 +390,22 @@ fn vp_validator(c: &mut Criterion) { group.bench_function(bench_name, |b| { b.iter(|| { - assert!(run::vp( - &vp_code, - &signed_tx, - &TxIndex(0), - &defaults::validator_address(), - &shell.wl_storage.storage, - &shell.wl_storage.write_log, - &mut VpGasMeter::new(u64::MAX, 0), - &keys_changed, - &verifiers, - shell.vp_wasm_cache.clone(), - false, - ) - .unwrap()); + assert!( + run::vp( + &vp_code, + signed_tx, + &TxIndex(0), + &defaults::validator_address(), + &shell.wl_storage.storage, + &shell.wl_storage.write_log, + &mut VpGasMeter::new(u64::MAX, 0), + &keys_changed, + &verifiers, + shell.vp_wasm_cache.clone(), + false, + ) + .unwrap() + ); }) }); } @@ -433,8 +438,8 @@ fn vp_token(c: &mut Criterion) { .iter() .zip(["foreign_key_write", "transfer"]) { - let mut shell = BenchShell::new(); - shell.execute_tx(&signed_tx); + let mut shell = BenchShell::default(); + shell.execute_tx(signed_tx); let (verifiers, keys_changed) = shell .wl_storage .write_log @@ -442,20 +447,22 @@ fn vp_token(c: &mut Criterion) { group.bench_function(bench_name, |b| { b.iter(|| { - assert!(run::vp( - &vp_code, - &signed_tx, - &TxIndex(0), - &defaults::albert_address(), - &shell.wl_storage.storage, - &shell.wl_storage.write_log, - &mut VpGasMeter::new(u64::MAX, 0), - &keys_changed, - &verifiers, - shell.vp_wasm_cache.clone(), - false, - ) - .unwrap()); + assert!( + run::vp( + &vp_code, + signed_tx, + &TxIndex(0), + &defaults::albert_address(), + &shell.wl_storage.storage, + &shell.wl_storage.write_log, + &mut VpGasMeter::new(u64::MAX, 0), + &keys_changed, + &verifiers, + shell.vp_wasm_cache.clone(), + false, + ) + .unwrap() + ); }) }); } @@ -469,7 +476,7 @@ fn vp_masp(c: &mut Criterion) { for bench_name in ["shielding", "unshielding", "shielded"] { group.bench_function(bench_name, |b| { - let mut shielded_ctx = BenchShieldedCtx::new(); + let mut shielded_ctx = BenchShieldedCtx::default(); let albert_spending_key = shielded_ctx .ctx @@ -497,7 +504,6 @@ fn vp_masp(c: &mut Criterion) { TransferTarget::PaymentAddress(albert_payment_addr), ); shielded_ctx.shell.execute_tx(&shield_tx); - shielded_ctx.shell.wl_storage.commit_tx(); shielded_ctx.shell.commit(); let signed_tx = match bench_name { @@ -526,20 +532,22 @@ fn vp_masp(c: &mut Criterion) { .verifiers_and_changed_keys(&BTreeSet::default()); b.iter(|| { - assert!(run::vp( - &vp_code, - &signed_tx, - &TxIndex(0), - &defaults::validator_address(), - &shielded_ctx.shell.wl_storage.storage, - &shielded_ctx.shell.wl_storage.write_log, - &mut VpGasMeter::new(u64::MAX, 0), - &keys_changed, - &verifiers, - shielded_ctx.shell.vp_wasm_cache.clone(), - false, - ) - .unwrap()); + assert!( + run::vp( + &vp_code, + &signed_tx, + &TxIndex(0), + &defaults::validator_address(), + &shielded_ctx.shell.wl_storage.storage, + &shielded_ctx.shell.wl_storage.write_log, + &mut VpGasMeter::new(u64::MAX, 0), + &keys_changed, + &verifiers, + shielded_ctx.shell.vp_wasm_cache.clone(), + false, + ) + .unwrap() + ); }) }); } diff --git a/core/src/ledger/gas.rs b/core/src/ledger/gas.rs index 746260e93f6..cce06200b75 100644 --- a/core/src/ledger/gas.rs +++ b/core/src/ledger/gas.rs @@ -29,11 +29,12 @@ pub const WASM_VALIDATION_GAS_PER_BYTE: u64 = 1; /// Gas module result for functions that may fail pub type Result = std::result::Result; -/// Gas metering in a block. The amount of gas consumed in a block is based on the -/// tx_gas_limit declared by each [`TxGasMeter`] +/// Gas metering in a block. The amount of gas consumed in a block is based on +/// the tx_gas_limit declared by each [`TxGasMeter`] #[derive(Debug, Clone)] pub struct BlockGasMeter { - /// The max amount of gas allowed per block, defined by the protocol parameter + /// The max amount of gas allowed per block, defined by the protocol + /// parameter pub block_gas_limit: u64, block_gas: u64, } @@ -77,7 +78,8 @@ impl BlockGasMeter { /// Add the transaction gas limit to the block's total gas. It will return /// error when the consumed gas exceeds the block gas limit, but the state - /// will still be updated. This function consumes the [`TxGasMeter`] which shouldn't be updated after this point. + /// will still be updated. This function consumes the [`TxGasMeter`] which + /// shouldn't be updated after this point. pub fn finalize_transaction( &mut self, tx_gas_meter: TxGasMeter, @@ -94,7 +96,9 @@ impl BlockGasMeter { } /// Tries to add the transaction gas limit to the block's total gas. - /// If the operation returns an error, propagates this errors without updating the state. This function consumes the [`TxGasMeter`] which shouldn't be updated after this point. + /// If the operation returns an error, propagates this errors without + /// updating the state. This function consumes the [`TxGasMeter`] which + /// shouldn't be updated after this point. pub fn try_finalize_transaction( &mut self, tx_gas_meter: TxGasMeter, @@ -115,7 +119,8 @@ impl BlockGasMeter { } impl TxGasMeter { - /// Initialize a new Tx gas meter. Requires the gas limit for the specific transaction + /// Initialize a new Tx gas meter. Requires the gas limit for the specific + /// transaction pub fn new(tx_gas_limit: u64) -> Self { Self { tx_gas_limit, @@ -124,8 +129,8 @@ impl TxGasMeter { } /// Add gas cost for the current transaction. It will return error when the - /// consumed gas exceeds the provided transaction gas limit, but the state will still - /// be updated. + /// consumed gas exceeds the provided transaction gas limit, but the state + /// will still be updated. pub fn add(&mut self, gas: u64) -> Result<()> { self.transaction_gas = self .transaction_gas @@ -201,7 +206,8 @@ impl VpGasMeter { } impl VpsGas { - /// Set the gas cost from a single VP run. It consumes the [`VpGasMeter`] instance which shouldn't be accessed passed this point. + /// Set the gas cost from a single VP run. It consumes the [`VpGasMeter`] + /// instance which shouldn't be accessed passed this point. pub fn set(&mut self, vp_gas_meter: VpGasMeter) -> Result<()> { debug_assert_eq!(self.max, None); debug_assert!(self.rest.is_empty()); diff --git a/core/src/ledger/storage_api/collections/lazy_map.rs b/core/src/ledger/storage_api/collections/lazy_map.rs index 79f7846c6d9..80072f24864 100644 --- a/core/src/ledger/storage_api/collections/lazy_map.rs +++ b/core/src/ledger/storage_api/collections/lazy_map.rs @@ -366,11 +366,11 @@ where storage: &'iter impl StorageRead, ) -> Result< impl Iterator< - Item = Result<( - ::SubKey, - ::Value, - )>, - > + 'iter, + Item = Result<( + ::SubKey, + ::Value, + )>, + > + 'iter, > { let iter = storage_api::iter_prefix(storage, &self.get_data_prefix())?; Ok(iter.map(|key_val_res| { diff --git a/core/src/ledger/testnet_pow.rs b/core/src/ledger/testnet_pow.rs index 4eccaab40f4..bed2273a706 100644 --- a/core/src/ledger/testnet_pow.rs +++ b/core/src/ledger/testnet_pow.rs @@ -297,10 +297,14 @@ pub fn is_counter_key<'a>( faucet_address: &Address, ) -> Option<&'a Address> { match &key.segments[..] { - [DbKeySeg::AddressSeg(address), DbKeySeg::StringSeg(sub_key), DbKeySeg::StringSeg(data), DbKeySeg::AddressSeg(owner)] - if address == faucet_address - && sub_key.as_str() == Keys::VALUES.counters - && data.as_str() == lazy_map::DATA_SUBKEY => + [ + DbKeySeg::AddressSeg(address), + DbKeySeg::StringSeg(sub_key), + DbKeySeg::StringSeg(data), + DbKeySeg::AddressSeg(owner), + ] if address == faucet_address + && sub_key.as_str() == Keys::VALUES.counters + && data.as_str() == lazy_map::DATA_SUBKEY => { Some(owner) } @@ -413,11 +417,7 @@ pub struct Difficulty(u8); impl Difficulty { /// The value must be between `0..=9` (inclusive upper bound). pub fn try_new(raw: u8) -> Option { - if raw > 9 { - None - } else { - Some(Self(raw)) - } + if raw > 9 { None } else { Some(Self(raw)) } } } diff --git a/core/src/types/internal.rs b/core/src/types/internal.rs index 4534832c693..3987b18e95e 100644 --- a/core/src/types/internal.rs +++ b/core/src/types/internal.rs @@ -40,11 +40,7 @@ impl HostEnvResult { impl From for HostEnvResult { fn from(success: bool) -> Self { - if success { - Self::Success - } else { - Self::Fail - } + if success { Self::Success } else { Self::Fail } } } diff --git a/shared/src/ledger/ibc/vp/mod.rs b/shared/src/ledger/ibc/vp/mod.rs index 31e6f8f0374..e14e65da5cd 100644 --- a/shared/src/ledger/ibc/vp/mod.rs +++ b/shared/src/ledger/ibc/vp/mod.rs @@ -634,9 +634,14 @@ mod tests { let ibc = Ibc { ctx }; // this should return true because state has been stored - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -763,9 +768,14 @@ mod tests { ); let ibc = Ibc { ctx }; // this should return true because state has been stored - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -828,9 +838,14 @@ mod tests { ); let ibc = Ibc { ctx }; // this should return true because state has been stored - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -977,9 +992,14 @@ mod tests { ); let ibc = Ibc { ctx }; // this should return true because state has been stored - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1076,9 +1096,14 @@ mod tests { vp_wasm_cache, ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1160,9 +1185,14 @@ mod tests { vp_wasm_cache, ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1230,9 +1260,14 @@ mod tests { vp_wasm_cache, ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1319,9 +1354,14 @@ mod tests { vp_wasm_cache, ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1419,9 +1459,14 @@ mod tests { vp_wasm_cache, ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1516,9 +1561,14 @@ mod tests { vp_wasm_cache, ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1557,9 +1607,14 @@ mod tests { vp_wasm_cache, ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1601,9 +1656,14 @@ mod tests { ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1691,9 +1751,14 @@ mod tests { vp_wasm_cache, ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1788,9 +1853,14 @@ mod tests { vp_wasm_cache, ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1893,9 +1963,14 @@ mod tests { vp_wasm_cache, ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -1989,9 +2064,14 @@ mod tests { vp_wasm_cache, ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -2096,9 +2176,14 @@ mod tests { ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } #[test] @@ -2150,8 +2235,13 @@ mod tests { ); let ibc = Ibc { ctx }; - assert!(ibc - .validate_tx(tx.data.as_ref().unwrap(), &keys_changed, &verifiers) - .expect("validation failed")); + assert!( + ibc.validate_tx( + tx.data.as_ref().unwrap(), + &keys_changed, + &verifiers + ) + .expect("validation failed") + ); } } diff --git a/shared/src/ledger/protocol/mod.rs b/shared/src/ledger/protocol/mod.rs index 99185de2868..fd61183990c 100644 --- a/shared/src/ledger/protocol/mod.rs +++ b/shared/src/ledger/protocol/mod.rs @@ -146,6 +146,7 @@ where } /// Execute a transaction code. Returns verifiers requested by the transaction. +#[allow(clippy::too_many_arguments)] fn execute_tx( tx: &Tx, tx_index: &TxIndex, @@ -287,8 +288,10 @@ where vp_hash.as_str(), )?; - // NOTE: because of the whitelisted gas and the gas metering for the exposed vm env functions, - // the first signature verification (if any) is accounted twice + // NOTE: because of the whitelisted gas and the gas metering + // for the exposed vm env functions, + // the first signature verification (if any) is accounted + // twice wasm::run::vp( vp, tx, diff --git a/shared/src/ledger/queries/mod.rs b/shared/src/ledger/queries/mod.rs index 9c75edbada8..343dfe41d67 100644 --- a/shared/src/ledger/queries/mod.rs +++ b/shared/src/ledger/queries/mod.rs @@ -193,7 +193,7 @@ mod testing { { #[allow(dead_code)] /// Initialize a test client for the given root RPC router - pub fn new(rpc: RPC) -> Self { + pub fn new(rpc: RPC) -> Self { // Initialize the `TestClient` let mut wl_storage = TestWlStorage::default(); @@ -202,7 +202,7 @@ mod testing { &std::fs::read("../wasm/checksums.json").unwrap(), ) .unwrap(); - + let gas_file: BTreeMap = serde_json::from_slice( &std::fs::read("../wasm/gas.json").unwrap(), ) @@ -210,35 +210,35 @@ mod testing { let mut gas_table = BTreeMap::::new(); - for id in checksums.keys().chain(gas_file.keys()){ + for id in checksums.keys().chain(gas_file.keys()) { // Get tx/vp hash (or name if native) let hash = match checksums.get(id.as_str()) { - Some(v) => { -v - .split_once('.') - .unwrap() - .1 - .split_once('.') - .unwrap() - .0.to_owned() - } - None => { - id.to_owned() - } + Some(v) => v + .split_once('.') + .unwrap() + .1 + .split_once('.') + .unwrap() + .0 + .to_owned(), + None => id.to_owned(), }; - let gas = gas_file.get(id).unwrap_or(&1_000).to_owned(); + let gas = gas_file.get(id).unwrap_or(&1_000).to_owned(); gas_table.insert(hash, gas); } - + let gas_table_key = namada_core::ledger::parameters::storage::get_gas_table_storage_key(); wl_storage .storage - .write(&gas_table_key, - namada_core::ledger::storage::types::encode(&gas_table)) + .write( + &gas_table_key, + namada_core::ledger::storage::types::encode(&gas_table), + ) .expect( - "Gas table parameter must be initialized in the genesis block", - ); + "Gas table parameter must be initialized in the genesis \ + block", + ); let max_block_gas_key = namada_core::ledger::parameters::storage::get_max_block_gas_key( diff --git a/shared/src/ledger/queries/shell.rs b/shared/src/ledger/queries/shell.rs index 551916be98f..078ed61a360 100644 --- a/shared/src/ledger/queries/shell.rs +++ b/shared/src/ledger/queries/shell.rs @@ -1,3 +1,6 @@ +#[cfg(all(feature = "wasm-runtime", feature = "ferveo-tpke"))] +use std::collections::BTreeMap; + use borsh::{BorshDeserialize, BorshSerialize}; use masp_primitives::asset_type::AssetType; use masp_primitives::merkle_tree::MerklePath; @@ -5,7 +8,6 @@ use masp_primitives::sapling::Node; use namada_core::types::address::Address; use namada_core::types::hash::Hash; use namada_core::types::storage::BlockResults; -use std::collections::BTreeMap; use crate::ledger::events::log::dumb_queries; use crate::ledger::events::Event; diff --git a/shared/src/vm/host_env.rs b/shared/src/vm/host_env.rs index 7337cbf1906..df9c3728f66 100644 --- a/shared/src/vm/host_env.rs +++ b/shared/src/vm/host_env.rs @@ -1757,7 +1757,7 @@ where let tx = unsafe { env.ctx.tx.get() }; Ok(HostEnvResult::from(vp_host_fns::verify_tx_signature( - gas_meter, &tx, &pk, &sig, + gas_meter, tx, &pk, &sig, )?) .to_i64()) } diff --git a/tests/src/native_vp/pos.rs b/tests/src/native_vp/pos.rs index e88e974fe09..1286fb3607b 100644 --- a/tests/src/native_vp/pos.rs +++ b/tests/src/native_vp/pos.rs @@ -1539,29 +1539,31 @@ pub mod testing { let arb_delta = prop_oneof![(-(u32::MAX as i128)..0), (1..=u32::MAX as i128),]; - prop_oneof![( - arb_address_or_validator.clone(), - arb_address_or_validator, - arb_offset, - arb_delta, - ) - .prop_map(|(validator, owner, offset, delta)| { - vec![ - // We have to ensure that the addresses exists - PosStorageChange::SpawnAccount { - address: validator.clone(), - }, - PosStorageChange::SpawnAccount { - address: owner.clone(), - }, - PosStorageChange::Bond { - owner, - validator, - delta, - offset, - }, - ] - })] + prop_oneof![ + ( + arb_address_or_validator.clone(), + arb_address_or_validator, + arb_offset, + arb_delta, + ) + .prop_map(|(validator, owner, offset, delta)| { + vec![ + // We have to ensure that the addresses exists + PosStorageChange::SpawnAccount { + address: validator.clone(), + }, + PosStorageChange::SpawnAccount { + address: owner.clone(), + }, + PosStorageChange::Bond { + owner, + validator, + delta, + offset, + }, + ] + }) + ] } impl InvalidPosAction { diff --git a/tests/src/vm_host_env/ibc.rs b/tests/src/vm_host_env/ibc.rs index e7740716b9f..f8c21cd2300 100644 --- a/tests/src/vm_host_env/ibc.rs +++ b/tests/src/vm_host_env/ibc.rs @@ -207,8 +207,8 @@ pub fn init_storage() -> (Address, Address) { (token, account) } -pub fn prepare_client( -) -> (ClientId, AnyClientState, HashMap>) { +pub fn prepare_client() +-> (ClientId, AnyClientState, HashMap>) { let mut writes = HashMap::new(); let msg = msg_create_client(); diff --git a/tests/src/vm_host_env/mod.rs b/tests/src/vm_host_env/mod.rs index d41c33ccf9a..f87a1e1c3ba 100644 --- a/tests/src/vm_host_env/mod.rs +++ b/tests/src/vm_host_env/mod.rs @@ -135,11 +135,13 @@ mod tests { // Trying to delete a validity predicate should fail let key = storage::Key::validity_predicate(&test_account); - assert!(panic::catch_unwind(|| { tx::ctx().delete(&key).unwrap() }) - .err() - .map(|a| a.downcast_ref::().cloned().unwrap()) - .unwrap() - .contains("CannotDeleteVp")); + assert!( + panic::catch_unwind(|| { tx::ctx().delete(&key).unwrap() }) + .err() + .map(|a| a.downcast_ref::().cloned().unwrap()) + .unwrap() + .contains("CannotDeleteVp") + ); } #[test] @@ -465,17 +467,21 @@ mod tests { .expect("decoding signed data we just signed") }); assert_eq!(&signed_tx_data.data, data); - assert!(vp::CTX - .verify_tx_signature(&pk, &signed_tx_data.sig) - .unwrap()); + assert!( + vp::CTX + .verify_tx_signature(&pk, &signed_tx_data.sig) + .unwrap() + ); let other_keypair = key::testing::keypair_2(); - assert!(!vp::CTX - .verify_tx_signature( - &other_keypair.ref_to(), - &signed_tx_data.sig - ) - .unwrap()); + assert!( + !vp::CTX + .verify_tx_signature( + &other_keypair.ref_to(), + &signed_tx_data.sig + ) + .unwrap() + ); } }