Skip to content

Commit

Permalink
Clippy + fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
grarco committed Mar 24, 2023
1 parent c63faff commit 7103311
Show file tree
Hide file tree
Showing 28 changed files with 632 additions and 439 deletions.
12 changes: 6 additions & 6 deletions apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
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/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
48 changes: 28 additions & 20 deletions apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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();
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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",
);
}
}

Expand Down Expand Up @@ -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::*;
Expand Down Expand Up @@ -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();
Expand All @@ -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,
Expand All @@ -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(),
Expand All @@ -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],
Expand All @@ -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!(
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 @@ -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();
Expand All @@ -679,11 +679,11 @@ where
.read_storage_key(&parameters::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;
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
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 @@ -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::<DateTimeUtc>::try_into(block_time)
Expand Down Expand Up @@ -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;

Expand All @@ -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()),
Expand All @@ -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(),
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(&parameters::storage::get_max_block_gas_key())
Expand Down Expand Up @@ -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();

Expand Down
Loading

0 comments on commit 7103311

Please sign in to comment.