Skip to content

Commit

Permalink
Clippy + fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
grarco committed Mar 31, 2023
1 parent 78b0b13 commit 62287b2
Show file tree
Hide file tree
Showing 29 changed files with 598 additions and 421 deletions.
12 changes: 6 additions & 6 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
4 changes: 1 addition & 3 deletions apps/src/lib/cli/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
2 changes: 1 addition & 1 deletion apps/src/lib/client/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
51 changes: 27 additions & 24 deletions apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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();
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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",
);
}
}

Expand Down Expand Up @@ -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::*;
Expand Down Expand Up @@ -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();
Expand All @@ -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,
Expand All @@ -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(),
Expand All @@ -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],
Expand All @@ -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!(
Expand Down
4 changes: 3 additions & 1 deletion apps/src/lib/node/ledger/shell/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 9 additions & 9 deletions apps/src/lib/node/ledger/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
28 changes: 15 additions & 13 deletions apps/src/lib/node/ledger/shell/prepare_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<DateTimeUtc>::try_into(block_time)
Expand Down Expand Up @@ -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;

Expand All @@ -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()),
Expand All @@ -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(),
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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();

Expand Down
Loading

0 comments on commit 62287b2

Please sign in to comment.