Skip to content

Commit

Permalink
clippy for all targets enabled (#1479)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergeytimoshin authored Jan 13, 2025
1 parent fd21574 commit 63b0da7
Show file tree
Hide file tree
Showing 41 changed files with 272 additions and 354 deletions.
2 changes: 1 addition & 1 deletion forester/src/send_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const TIMEOUT_CHECK_ENABLED: bool = false;
///
/// Strategy:
/// 1. Execute transaction batches until max number of batches is
/// reached or light slot ended (global timeout).
/// reached or light slot ended (global timeout).
/// 2. Fetch queue items.
/// 3. If work items is empty, await minimum batch time.
/// 4. Fetch recent blockhash.
Expand Down
49 changes: 17 additions & 32 deletions program-libs/batched-merkle-tree/src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ mod tests {
let mut root_index = 20;
let root_history_length = 23;
for i in 0..batch.get_num_zkp_batches() {
sequence_number += i as u64;
sequence_number += i;
root_index += i as u32;
batch
.mark_as_inserted_in_merkle_tree(sequence_number, root_index, root_history_length)
Expand Down Expand Up @@ -383,10 +383,7 @@ mod tests {
assert_eq!(*value_store.get(i as usize).unwrap(), value);
}
let result = batch.store_and_hash_value(&[1u8; 32], &mut value_store, &mut hashchain_store);
assert_eq!(
result.unwrap_err(),
BatchedMerkleTreeError::BatchNotReady.into()
);
assert_eq!(result.unwrap_err(), BatchedMerkleTreeError::BatchNotReady);
assert_eq!(batch.get_state(), BatchState::Full);
assert_eq!(batch.get_num_inserted(), 0);
assert_eq!(batch.get_current_zkp_batch_index(), 5);
Expand Down Expand Up @@ -541,33 +538,21 @@ mod tests {
let highest_eligible_value =
batch.start_index + batch.get_num_zkp_batches() * batch.zkp_batch_size - 1;
// 1. Failing test lowest value in eligble range - 1
assert_eq!(
batch
.value_is_inserted_in_batch(lowest_eligible_value - 1)
.unwrap(),
false
);
assert!(!batch
.value_is_inserted_in_batch(lowest_eligible_value - 1)
.unwrap());
// 2. Functional test lowest value in eligble range
assert_eq!(
batch
.value_is_inserted_in_batch(lowest_eligible_value)
.unwrap(),
true
);
assert!(batch
.value_is_inserted_in_batch(lowest_eligible_value)
.unwrap());
// 3. Functional test highest value in eligble range
assert_eq!(
batch
.value_is_inserted_in_batch(highest_eligible_value)
.unwrap(),
true
);
assert!(batch
.value_is_inserted_in_batch(highest_eligible_value)
.unwrap());
// 4. Failing test eligble range + 1
assert_eq!(
batch
.value_is_inserted_in_batch(highest_eligible_value + 1)
.unwrap(),
false
);
assert!(!batch
.value_is_inserted_in_batch(highest_eligible_value + 1)
.unwrap());
}

/// 1. Failing: empty batch
Expand All @@ -578,7 +563,7 @@ mod tests {
let mut batch = get_test_batch();
assert_eq!(
batch.get_first_ready_zkp_batch(),
Err(BatchedMerkleTreeError::BatchNotReady.into())
Err(BatchedMerkleTreeError::BatchNotReady)
);
let mut value_store_bytes =
vec![0u8; ZeroCopyVecU64::<[u8; 32]>::required_size_for_capacity(batch.batch_size)];
Expand Down Expand Up @@ -613,12 +598,12 @@ mod tests {
} else if i >= batch.batch_size {
assert_eq!(
batch.get_first_ready_zkp_batch(),
Err(BatchedMerkleTreeError::BatchAlreadyInserted.into())
Err(BatchedMerkleTreeError::BatchAlreadyInserted)
);
} else {
assert_eq!(
batch.get_first_ready_zkp_batch(),
Err(BatchedMerkleTreeError::BatchNotReady.into())
Err(BatchedMerkleTreeError::BatchNotReady)
);
}
}
Expand Down
8 changes: 4 additions & 4 deletions program-libs/batched-merkle-tree/src/merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ impl<'a> BatchedMerkleTreeAccount<'a> {
/// - value is committed to bloom_filter for non-inclusion proof
/// - nullifier is Hash(value, tx_hash), committed to leaves hashchain
/// - tx_hash is hash of all inputs and outputs
/// -> we can access the history of how commitments are spent in zkps for example fraud proofs
/// -> we can access the history of how commitments are spent in zkps for example fraud proofs
pub fn insert_nullifier_into_current_batch(
&mut self,
compressed_account_hash: &[u8; 32],
Expand Down Expand Up @@ -782,9 +782,9 @@ impl<'a> BatchedMerkleTreeAccount<'a> {
/// 1. Previous batch must be inserted and bloom filter must not be wiped.
/// 2. Current batch must be 50% full
/// 3. if yes
/// 3.1 zero out bloom filter
/// 3.2 mark bloom filter as wiped
/// 3.3 zero out roots if needed
/// 3.1 zero out bloom filter
/// 3.2 mark bloom filter as wiped
/// 3.3 zero out roots if needed
pub fn wipe_previous_batch_bloom_filter(&mut self) -> Result<(), BatchedMerkleTreeError> {
let current_batch = self
.get_metadata()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,8 @@ fn test_account_init() {
let params = InitAddressTreeAccountsInstructionData::test_default();
let mt_params = CreateTreeParams::from_address_ix_params(params, owner);
let ref_mt_account = BatchedMerkleTreeMetadata::new_address_tree(mt_params, merkle_tree_rent);
init_batched_address_merkle_tree_account(
owner.into(),
params.clone(),
&mut mt_account_data,
merkle_tree_rent,
)
.unwrap();
init_batched_address_merkle_tree_account(owner, params, &mut mt_account_data, merkle_tree_rent)
.unwrap();

assert_address_mt_zero_copy_inited(
&mut mt_account_data,
Expand Down Expand Up @@ -115,7 +110,7 @@ fn test_rnd_account_init() {

init_batched_address_merkle_tree_account(
owner,
params.clone(),
params,
&mut mt_account_data,
merkle_tree_rent,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fn test_different_parameters() {
let additional_bytes_rent = 1000;
init_batched_state_merkle_tree_accounts(
owner,
params.clone(),
params,
&mut output_queue_account_data,
output_queue_pubkey,
queue_rent,
Expand Down Expand Up @@ -105,7 +105,7 @@ fn test_account_init() {
let additional_bytes_rent = 1000;
init_batched_state_merkle_tree_accounts(
owner,
params.clone(),
params,
&mut output_queue_account_data,
output_queue_pubkey,
queue_rent,
Expand Down Expand Up @@ -252,7 +252,7 @@ fn test_rnd_account_init() {
let additional_bytes_rent = rng.gen_range(0..10000000);
init_batched_state_merkle_tree_accounts(
owner,
params.clone(),
params,
&mut output_queue_account_data,
output_queue_pubkey,
queue_rent,
Expand Down
Loading

0 comments on commit 63b0da7

Please sign in to comment.