Skip to content

Commit

Permalink
Clippy + fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
grarco committed Jun 5, 2023
1 parent f02c6e7 commit 7b89045
Show file tree
Hide file tree
Showing 11 changed files with 321 additions and 202 deletions.
34 changes: 21 additions & 13 deletions apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1598,9 +1598,11 @@ mod test_finalize_block {
// won't receive votes from TM since we receive votes at a 1-block
// delay, so votes will be empty here
next_block_for_inflation(&mut shell, pkh1.clone(), vec![]);
assert!(rewards_accumulator_handle()
.is_empty(&shell.wl_storage)
.unwrap());
assert!(
rewards_accumulator_handle()
.is_empty(&shell.wl_storage)
.unwrap()
);

// FINALIZE BLOCK 2. Tell Namada that val1 is the block proposer.
// Include votes that correspond to block 1. Make val2 the next block's
Expand All @@ -1610,9 +1612,11 @@ mod test_finalize_block {
assert!(rewards_prod_2.is_empty(&shell.wl_storage).unwrap());
assert!(rewards_prod_3.is_empty(&shell.wl_storage).unwrap());
assert!(rewards_prod_4.is_empty(&shell.wl_storage).unwrap());
assert!(!rewards_accumulator_handle()
.is_empty(&shell.wl_storage)
.unwrap());
assert!(
!rewards_accumulator_handle()
.is_empty(&shell.wl_storage)
.unwrap()
);
// Val1 was the proposer, so its reward should be larger than all
// others, which should themselves all be equal
let acc_sum = get_rewards_sum(&shell.wl_storage);
Expand Down Expand Up @@ -1713,9 +1717,11 @@ mod test_finalize_block {
);
next_block_for_inflation(&mut shell, pkh1.clone(), votes.clone());
}
assert!(rewards_accumulator_handle()
.is_empty(&shell.wl_storage)
.unwrap());
assert!(
rewards_accumulator_handle()
.is_empty(&shell.wl_storage)
.unwrap()
);
let rp1 = rewards_prod_1
.get(&shell.wl_storage, &Epoch::default())
.unwrap()
Expand Down Expand Up @@ -1841,10 +1847,12 @@ 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
Expand Down
39 changes: 25 additions & 14 deletions apps/src/lib/node/ledger/shell/process_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,27 +363,33 @@ where
}

// Tx gas (partial check)
let tx_hash = if tx.code_or_hash.len()
== HASH_LENGTH
{
match Hash::try_from(tx.code_or_hash.as_slice()) {
let tx_hash =
if tx.code_or_hash.len() == HASH_LENGTH {
match Hash::try_from(
tx.code_or_hash.as_slice(),
) {
Ok(hash) => hash,
Err(_) => return TxResult {
code: ErrorCodes::DecryptedTxGasLimit.into(),
info: format!("Failed conversion of transaction's hash")
}
code:
ErrorCodes::DecryptedTxGasLimit
.into(),
info: "Failed conversion of \
transaction's hash"
.to_string(),
},
}
} else {
Hash(tx.code_hash())
};
} else {
Hash(tx.code_hash())
};
let tx_gas = match gas_table.get(
&tx_hash.to_string().to_ascii_lowercase(),
) {
Some(gas) => gas.to_owned(),
#[cfg(test)]
None => 1_000,
#[cfg(not(test))]
None => 0, // VPs will rejected the non-whitelisted tx
None => 0, /* VPs will rejected the
* non-whitelisted tx */
};
let inner_tx_gas_limit = temp_wl_storage
.storage
Expand All @@ -394,9 +400,14 @@ where
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)
};
code: ErrorCodes::DecryptedTxGasLimit
.into(),
info: format!(
"Decrypted transaction gas error: \
{}",
e
),
};
}
}

Expand Down
4 changes: 2 additions & 2 deletions apps/src/lib/wasm_loader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub async fn pre_fetch_wasm(wasm_directory: impl AsRef<Path>) {
join_all(checksums.0.into_iter().map(|(name, map)| {
let wasm_directory = wasm_directory.as_ref().to_owned();
let full_name =
name.replace(".", &format!(".{}.", map.get("hash").unwrap()));
name.replace('.', &format!(".{}.", map.get("hash").unwrap()));

// Async check and download (if needed) each file
tokio::spawn(async move {
Expand Down Expand Up @@ -270,7 +270,7 @@ pub fn read_wasm(
if let Some(name) = os_name.to_str() {
let wasm_path = match checksums.0.get(name) {
Some(map) => wasm_directory.as_ref().join(name.replace(
".",
'.',
&format!(
".{}.",
map.get("hash").ok_or_else(|| eyre!(
Expand Down
2 changes: 1 addition & 1 deletion benches/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use std::collections::BTreeMap;
use std::ops::{Deref, DerefMut};
use std::str::FromStr;

use borsh::BorshSerialize;
use ibc_proto::google::protobuf::Any;
Expand Down Expand Up @@ -88,7 +89,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::str::FromStr;
use tempfile::TempDir;

pub const WASM_DIR: &str = "../wasm";
Expand Down
48 changes: 27 additions & 21 deletions benches/native_vps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,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()
)
})
});
}
Expand Down Expand Up @@ -254,13 +256,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()
)
})
});
}
Expand All @@ -279,7 +283,7 @@ fn ibc(c: &mut Criterion) {
)
.unwrap(),
counterparty: Counterparty::new(
ClientId::from_str(&"01-tendermint-1").unwrap(),
ClientId::from_str("01-tendermint-1").unwrap(),
Some(ConnectionId::new(1)),
CommitmentPrefix::try_from(b"ibc".to_vec()).unwrap(),
),
Expand Down Expand Up @@ -360,13 +364,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()
)
})
});
}
Expand Down Expand Up @@ -419,13 +424,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()
)
})
});
}
Expand Down
3 changes: 2 additions & 1 deletion benches/process_wrapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ use namada_benches::{generate_tx, BenchShell, TX_TRANSFER_WASM};

fn process_tx(c: &mut Criterion) {
let mut shell = BenchShell::default();
// Advance chain height to allow the inclusion of wrapper txs by the block space allocator
// Advance chain height to allow the inclusion of wrapper txs by the block
// space allocator
shell.wl_storage.storage.last_height = BlockHeight(2);
let tx = generate_tx(
TX_TRANSFER_WASM,
Expand Down
Loading

0 comments on commit 7b89045

Please sign in to comment.