From 62287b212c1ea756a0e63ba19c326fe078f9295d Mon Sep 17 00:00:00 2001 From: Marco Granelli Date: Fri, 31 Mar 2023 18:11:26 +0200 Subject: [PATCH] Clippy + fmt --- apps/src/lib/cli.rs | 12 +- apps/src/lib/cli/context.rs | 4 +- apps/src/lib/client/rpc.rs | 2 +- apps/src/lib/client/types.rs | 2 +- .../lib/node/ledger/shell/finalize_block.rs | 51 ++--- apps/src/lib/node/ledger/shell/governance.rs | 4 +- apps/src/lib/node/ledger/shell/mod.rs | 18 +- .../lib/node/ledger/shell/prepare_proposal.rs | 28 +-- .../lib/node/ledger/shell/process_proposal.rs | 134 +++++++----- benches/host_env.rs | 8 +- benches/mod.rs | 63 +++--- benches/native_vps.rs | 77 +++---- benches/process_wrapper.rs | 9 +- benches/txs.rs | 58 ++--- benches/vps.rs | 179 ++++++++-------- core/src/ledger/gas.rs | 24 ++- core/src/ledger/parameters/mod.rs | 2 +- core/src/ledger/storage/mod.rs | 1 + .../storage_api/collections/lazy_map.rs | 10 +- core/src/ledger/testnet_pow.rs | 18 +- core/src/types/internal.rs | 6 +- shared/src/ledger/ibc/vp/mod.rs | 198 +++++++++++++----- shared/src/ledger/protocol/mod.rs | 7 +- shared/src/ledger/queries/mod.rs | 13 +- shared/src/ledger/queries/shell.rs | 3 +- shared/src/vm/host_env.rs | 2 +- tests/src/native_vp/pos.rs | 48 +++-- tests/src/vm_host_env/ibc.rs | 4 +- tests/src/vm_host_env/mod.rs | 34 +-- 29 files changed, 598 insertions(+), 421 deletions(-) diff --git a/apps/src/lib/cli.rs b/apps/src/lib/cli.rs index 53c1ba1a72e..8380096f6cc 100644 --- a/apps/src/lib/cli.rs +++ b/apps/src/lib/cli.rs @@ -2921,14 +2921,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/client/types.rs b/apps/src/lib/client/types.rs index 204a8d9119a..f99117c43ba 100644 --- a/apps/src/lib/client/types.rs +++ b/apps/src/lib/client/types.rs @@ -3,12 +3,12 @@ use masp_primitives::merkle_tree::MerklePath; use masp_primitives::primitives::{Diversifier, Note, ViewingKey}; use masp_primitives::sapling::Node; use masp_primitives::transaction::components::Amount; +use namada::tendermint_rpc::HttpClient; use namada::types::address::Address; use namada::types::masp::{TransferSource, TransferTarget}; use namada::types::storage::Epoch; use namada::types::transaction::GasLimit; use namada::types::{key, token}; -use tendermint_rpc::HttpClient; use super::rpc; use crate::cli::{args, Context}; diff --git a/apps/src/lib/node/ledger/shell/finalize_block.rs b/apps/src/lib/node/ledger/shell/finalize_block.rs index b5ec3e6e34c..a3a1d78cc80 100644 --- a/apps/src/lib/node/ledger/shell/finalize_block.rs +++ b/apps/src/lib/node/ledger/shell/finalize_block.rs @@ -266,12 +266,12 @@ where ( tx_event, None, gas_meter, - /* This is just for - * logging/events - * purposes, no more - * gas is actually - * used by the - * wrapper */ + // This is just for + // logging/events + // purposes, no more + // gas is actually + // used by the + // wrapper ) } TxType::Decrypted(inner) => { @@ -297,9 +297,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(); } @@ -314,14 +314,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; } @@ -416,8 +416,9 @@ where .storage .delete(&tx_hash_key) .expect( - "Error while deleting tx hash key from storage", - ); + "Error while deleting tx hash key from \ + storage", + ); } } @@ -598,7 +599,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::*; @@ -1145,14 +1145,16 @@ 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 - .wl_storage - .has_key(&inner_hash_key) - .expect("Test failed")) + assert!( + !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(); @@ -1178,7 +1180,7 @@ mod test_finalize_block { &keypair, Epoch(0), 1.into(), - raw_tx.clone(), + raw_tx, Default::default(), #[cfg(not(feature = "mainnet"))] None, @@ -1188,7 +1190,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(), @@ -1204,7 +1206,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], @@ -1213,7 +1215,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 4f0e57acfa9..ca58626300a 100644 --- a/apps/src/lib/node/ledger/shell/mod.rs +++ b/apps/src/lib/node/ledger/shell/mod.rs @@ -672,7 +672,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(); @@ -686,11 +686,11 @@ where .expect("Error while reading from storage") .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; } @@ -1071,8 +1071,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 @@ -1214,13 +1214,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 be7c7099fe2..380801d8208 100644 --- a/apps/src/lib/node/ledger/shell/prepare_proposal.rs +++ b/apps/src/lib/node/ledger/shell/prepare_proposal.rs @@ -167,8 +167,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) @@ -231,13 +234,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; @@ -246,7 +246,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()), @@ -272,7 +272,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(), @@ -428,7 +428,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( @@ -479,10 +479,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 .wl_storage @@ -533,10 +534,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 d9fccde193c..883aee5ce8d 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::*; @@ -84,7 +83,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() @@ -118,6 +117,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], @@ -195,7 +195,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) => { @@ -244,14 +244,16 @@ where let tx_hash = Hash::sha256(tx.code) .to_string() .to_ascii_lowercase(); - let tx_gas = - match gas_table.get(tx_hash.as_str()) { - Some(gas) => gas.to_owned(), - #[cfg(test)] - None => 1_000, - #[cfg(not(test))] - None => 0, // VPs will rejected the non-whitelisted tx - }; + let tx_gas = match gas_table + .get(tx_hash.as_str()) + { + Some(gas) => gas.to_owned(), + #[cfg(test)] + None => 1_000, + #[cfg(not(test))] + None => 0, /* VPs will rejected the + * non-whitelisted tx */ + }; let inner_tx_gas_limit = temp_wl_storage .storage .tx_queue @@ -271,7 +273,6 @@ where ), }; } - } TxResult { @@ -312,17 +313,21 @@ where 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(), }; } @@ -416,8 +421,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 @@ -474,13 +481,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`]. @@ -630,7 +635,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()), @@ -770,9 +775,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, @@ -847,8 +856,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))); @@ -904,9 +919,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(), @@ -953,8 +974,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)] @@ -1438,8 +1465,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, @@ -1547,8 +1578,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, @@ -1571,9 +1606,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(); @@ -1583,7 +1617,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(), @@ -1604,7 +1638,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, @@ -1627,7 +1661,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(); @@ -1666,7 +1701,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!( @@ -1677,7 +1712,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(); @@ -1711,7 +1747,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!( @@ -1720,5 +1756,5 @@ match shell.process_proposal(request) { ); } } - } + } } diff --git a/benches/host_env.rs b/benches/host_env.rs index 10ed45f0d16..f936dd81454 100644 --- a/benches/host_env.rs +++ b/benches/host_env.rs @@ -1,14 +1,12 @@ use borsh::BorshDeserialize; use criterion::{criterion_group, criterion_main, Criterion}; +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_benches::{generate_tx, TX_TRANSFER_WASM}; -use namada::core::proto::SignedTxData; -use namada::core::types::key::RefTo; -use namada_apps::wallet::defaults; - fn tx_signature_validation(c: &mut Criterion) { let tx = generate_tx( TX_TRANSFER_WASM, @@ -25,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 b917c10bbf8..6d0c164a04b 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, @@ -206,7 +208,9 @@ impl BenchShell { bench_shell } +} +impl BenchShell { pub fn execute_tx(&mut self, tx: &Tx) { run::tx( &self.inner.wl_storage.storage, @@ -295,7 +299,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)), @@ -368,7 +372,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]), }; @@ -515,9 +519,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, @@ -570,7 +574,8 @@ 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 618c089bb5a..fc4c003f722 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}; @@ -26,22 +28,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_benches::{ 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 @@ -65,7 +65,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(), @@ -87,7 +88,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" => { @@ -185,13 +186,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() + ) }) }); } @@ -224,7 +227,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); @@ -250,13 +253,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() + ) }) }); } @@ -308,7 +313,7 @@ fn ibc(c: &mut Criterion) { ); let msg = MsgChannelOpenInit { port_id: PortId::transfer(), - channel: channel.clone(), + channel, signer: Signer::new(defaults::albert_address()), }; @@ -342,7 +347,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); @@ -367,13 +372,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() + ) }) }); } @@ -392,10 +398,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 @@ -415,7 +421,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, @@ -426,13 +432,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 d8739b6858d..329733c1086 100644 --- a/benches/process_wrapper.rs +++ b/benches/process_wrapper.rs @@ -1,19 +1,18 @@ +use std::collections::BTreeMap; + use criterion::{criterion_group, criterion_main, Criterion}; -use namada::core::types::address::{self}; +use namada::core::types::address; use namada::core::types::token::{Amount, Transfer}; 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_benches::{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 7d8ef063732..b7a0981326b 100644 --- a/benches/txs.rs +++ b/benches/txs.rs @@ -5,6 +5,7 @@ use namada::core::types::key::{ }; use namada::core::types::token::Amount; use namada::ledger::governance; +use namada::ledger::storage_api::StorageRead; use namada::proof_of_stake; use namada::proto::Tx; use namada::types::chain::ChainId; @@ -13,10 +14,10 @@ use namada::types::masp::{TransferSource, TransferTarget}; use namada::types::transaction::governance::{ InitProposalData, VoteProposalData, }; -use namada::ledger::storage_api::StorageRead; 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_benches::{ @@ -42,7 +43,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 @@ -104,7 +105,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, ) @@ -142,7 +143,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, ) @@ -180,7 +181,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, ) @@ -218,7 +219,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 { @@ -284,7 +285,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, ) @@ -306,7 +307,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, ) @@ -331,7 +332,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, ) @@ -345,7 +346,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( @@ -366,15 +367,22 @@ fn init_proposal(c: &mut Criterion) { governance::storage::get_max_proposal_code_size_key(); let max_proposal_content_key = governance::storage::get_max_proposal_content_key(); - let max_code_size = - shell.wl_storage - .read(&max_code_size_key) - .expect("Error while reading from storage") - .expect("Missing max_code_size parameter in storage"); - let max_proposal_content_size = shell.wl_storage - .read(&max_proposal_content_key) - .expect("Error while reading from storage") - .expect("Missing max_proposal_content parameter in storage"); + let max_code_size = shell + .wl_storage + .read(&max_code_size_key) + .expect("Error while reading from storage") + .expect( + "Missing max_code_size parameter in \ + storage", + ); + let max_proposal_content_size = shell + .wl_storage + .read(&max_proposal_content_key) + .expect("Error while reading from storage") + .expect( + "Missing max_proposal_content parameter \ + in storage", + ); generate_tx( TX_INIT_PROPOSAL_WASM, @@ -434,7 +442,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, ) @@ -483,7 +491,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, ) @@ -502,7 +510,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, ) @@ -515,7 +523,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 9839057b6c5..8ac92b9c6eb 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_benches::{ generate_foreign_key_tx, generate_tx, BenchShell, BenchShieldedCtx, @@ -21,12 +27,6 @@ use namada_benches::{ 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,7 +238,7 @@ 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 @@ -260,20 +263,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 +382,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 +392,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 +440,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 +449,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 +478,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 @@ -526,20 +535,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 11e6365c9d8..4895b3bd924 100644 --- a/core/src/ledger/gas.rs +++ b/core/src/ledger/gas.rs @@ -31,11 +31,12 @@ pub const STORAGE_WRITE_GAS_PER_BYTE: u64 = 100; /// 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, } @@ -79,7 +80,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, @@ -96,7 +98,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, @@ -117,7 +121,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, @@ -126,8 +131,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 @@ -203,7 +208,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/parameters/mod.rs b/core/src/ledger/parameters/mod.rs index 31941f0ad9c..96aa6142dbf 100644 --- a/core/src/ledger/parameters/mod.rs +++ b/core/src/ledger/parameters/mod.rs @@ -9,7 +9,7 @@ use thiserror::Error; use super::storage::types; use super::storage_api::{self, ResultExt, StorageRead, StorageWrite}; -use crate::ledger::storage::{self as ledger_storage}; +use crate::ledger::storage as ledger_storage; use crate::types::address::{Address, InternalAddress}; use crate::types::chain::ProposalBytes; use crate::types::time::DurationSecs; diff --git a/core/src/ledger/storage/mod.rs b/core/src/ledger/storage/mod.rs index d05a88b5c01..adae6fe9839 100644 --- a/core/src/ledger/storage/mod.rs +++ b/core/src/ledger/storage/mod.rs @@ -13,6 +13,7 @@ pub mod write_log; use core::fmt::Debug; use std::cmp::Ordering; +#[cfg(any(feature = "tendermint", feature = "tendermint-abcipp"))] use merkle_tree::StorageBytes; pub use merkle_tree::{ MembershipProof, MerkleTree, MerkleTreeStoresRead, MerkleTreeStoresWrite, 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 c83dcd44e9a..131872c1d3b 100644 --- a/shared/src/ledger/protocol/mod.rs +++ b/shared/src/ledger/protocol/mod.rs @@ -144,6 +144,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, @@ -285,8 +286,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 18c0b4f9707..b608572acb4 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(); @@ -203,11 +203,14 @@ mod testing { 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..1b877a95395 100644 --- a/shared/src/ledger/queries/shell.rs +++ b/shared/src/ledger/queries/shell.rs @@ -5,7 +5,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; @@ -70,6 +69,8 @@ where D: 'static + DB + for<'iter> DBIter<'iter> + Sync, H: 'static + StorageHasher + Sync, { + use std::collections::BTreeMap; + use namada_core::ledger::gas::TxGasMeter; use namada_core::ledger::parameters; 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() + ); } }