Skip to content

Commit

Permalink
Fixing clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
ii-cruz committed Dec 5, 2024
1 parent 3cad3a4 commit 4fa5fb2
Show file tree
Hide file tree
Showing 42 changed files with 703 additions and 748 deletions.
901 changes: 487 additions & 414 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion blockchain-proxy/src/blockchain_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub enum BlockchainReadProxy<'a> {
Light(RwLockReadGuard<'a, LightBlockchain>),
}

impl<'a> AbstractBlockchain for BlockchainReadProxy<'a> {
impl AbstractBlockchain for BlockchainReadProxy<'_> {
fn network_id(&self) -> NetworkId {
gen_blockchain_match!(self, BlockchainReadProxy, network_id)
}
Expand Down
48 changes: 15 additions & 33 deletions blockchain/src/history/history_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1062,15 +1062,9 @@ mod tests {
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 1, &hist_txs);

// Those transactions should be part of the valitidy window
assert_eq!(
history_store.tx_in_validity_window(&ext_0.tx_hash(), Some(&txn)),
true
);
assert!(history_store.tx_in_validity_window(&ext_0.tx_hash(), Some(&txn)));

assert_eq!(
history_store.tx_in_validity_window(&ext_1.tx_hash(), Some(&txn)),
true
);
assert!(history_store.tx_in_validity_window(&ext_1.tx_hash(), Some(&txn)));

// Now keep pushing transactions to the history store until we are past the transaction validity window
let validity_window_blocks = Policy::transaction_validity_window_blocks();
Expand All @@ -1083,33 +1077,21 @@ mod tests {
history_store.add_to_history(
&mut txn,
Policy::genesis_block_number() + bn,
&vec![historic_txn],
&[historic_txn],
);
}

// Since we are past the txn in validity window, the first two transaction should no longer be in it
assert_eq!(
history_store.tx_in_validity_window(&ext_0.tx_hash(), Some(&txn)),
false
);
assert!(!history_store.tx_in_validity_window(&ext_0.tx_hash(), Some(&txn)));

assert_eq!(
history_store.tx_in_validity_window(&ext_1.tx_hash(), Some(&txn)),
false
);
assert!(!history_store.tx_in_validity_window(&ext_1.tx_hash(), Some(&txn)));

for txn_hash in &txn_hashes[..8] {
assert_eq!(
history_store.tx_in_validity_window(txn_hash, Some(&txn)),
false
);
assert!(!history_store.tx_in_validity_window(txn_hash, Some(&txn)));
}

for txn_hash in &txn_hashes[8..] {
assert_eq!(
history_store.tx_in_validity_window(txn_hash, Some(&txn)),
true
);
assert!(history_store.tx_in_validity_window(txn_hash, Some(&txn)));
}
}

Expand All @@ -1124,12 +1106,12 @@ mod tests {

// Add historic transactions to History Store.
let mut txn = env.write_transaction();
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 0, &hist_txs[..3]);
history_store.add_to_history(&mut txn, Policy::genesis_block_number(), &hist_txs[..3]);
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 2, &hist_txs[3..]);

// Verify method works.
let real_root_0 =
history_store.get_history_tree_root(Policy::genesis_block_number() + 0, Some(&txn));
history_store.get_history_tree_root(Policy::genesis_block_number(), Some(&txn));
let calc_root_0 = HistoryStore::_root_from_hist_txs(&hist_txs[..3]);

assert_eq!(real_root_0, calc_root_0);
Expand All @@ -1153,7 +1135,7 @@ mod tests {

// Add historic transactions to History Store.
let mut txn = env.write_transaction();
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 0, &hist_txs[..3]);
history_store.add_to_history(&mut txn, Policy::genesis_block_number(), &hist_txs[..3]);
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 2, &hist_txs[3..]);

// Verify method works. Note that the block transactions are returned in the same
Expand Down Expand Up @@ -1313,7 +1295,7 @@ mod tests {

// Add historic transactions to History Store.
let mut txn = env.write_transaction();
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 0, &hist_txs[..3]);
history_store.add_to_history(&mut txn, Policy::genesis_block_number(), &hist_txs[..3]);
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 2, &hist_txs[3..]);

// Verify method works.
Expand Down Expand Up @@ -1417,7 +1399,7 @@ mod tests {

// Add historic transactions to History Store.
let mut txn = env.write_transaction();
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 0, &hist_txs[..3]);
history_store.add_to_history(&mut txn, Policy::genesis_block_number(), &hist_txs[..3]);
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 2, &hist_txs[3..]);

// Verify method works.
Expand Down Expand Up @@ -1573,9 +1555,9 @@ mod tests {

fn gen_hist_txs() -> Vec<HistoricTransaction> {
let genesis_block_number = Policy::genesis_block_number();
let ext_0 = create_transaction(genesis_block_number + 0, 0);
let ext_1 = create_transaction(genesis_block_number + 0, 1);
let ext_2 = create_reward_inherent(genesis_block_number + 0, 2);
let ext_0 = create_transaction(genesis_block_number, 0);
let ext_1 = create_transaction(genesis_block_number, 1);
let ext_2 = create_reward_inherent(genesis_block_number, 2);

let ext_3 = create_transaction(genesis_block_number + 1, 3);
let ext_4 = create_reward_inherent(genesis_block_number + 1, 4);
Expand Down
60 changes: 21 additions & 39 deletions blockchain/src/history/history_store_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ impl<'txn> TxHashIterator<'txn> {
}
}

impl<'txn> Iterator for TxHashIterator<'txn> {
impl Iterator for TxHashIterator<'_> {
type Item = Blake2bHash;

fn next(&mut self) -> Option<Self::Item> {
Expand Down Expand Up @@ -829,15 +829,9 @@ mod tests {
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 1, &hist_txs);

// Those transactions should be part of the valitidy window
assert_eq!(
history_store.tx_in_validity_window(&ext_0.tx_hash(), Some(&txn)),
true
);
assert!(history_store.tx_in_validity_window(&ext_0.tx_hash(), Some(&txn)));

assert_eq!(
history_store.tx_in_validity_window(&ext_1.tx_hash(), Some(&txn)),
true
);
assert!(history_store.tx_in_validity_window(&ext_1.tx_hash(), Some(&txn)));

// Now keep pushing transactions to the history store until we are past the transaction validity window
let validity_window_blocks = Policy::transaction_validity_window_blocks();
Expand All @@ -850,33 +844,21 @@ mod tests {
history_store.add_to_history(
&mut txn,
Policy::genesis_block_number() + bn,
&vec![historic_txn],
&[historic_txn],
);
}

// Since we are past the txn in validity window, the first two transaction should no longer be in it
assert_eq!(
history_store.tx_in_validity_window(&ext_0.tx_hash(), Some(&txn)),
false
);
assert!(!history_store.tx_in_validity_window(&ext_0.tx_hash(), Some(&txn)));

assert_eq!(
history_store.tx_in_validity_window(&ext_1.tx_hash(), Some(&txn)),
false
);
assert!(!history_store.tx_in_validity_window(&ext_1.tx_hash(), Some(&txn)));

for txn_hash in &txn_hashes[..8] {
assert_eq!(
history_store.tx_in_validity_window(txn_hash, Some(&txn)),
false
);
assert!(!history_store.tx_in_validity_window(txn_hash, Some(&txn)));
}

for txn_hash in &txn_hashes[8..] {
assert_eq!(
history_store.tx_in_validity_window(txn_hash, Some(&txn)),
true
);
assert!(history_store.tx_in_validity_window(txn_hash, Some(&txn)));
}
}

Expand All @@ -891,12 +873,12 @@ mod tests {

// Add historic transactions to History Store.
let mut txn = env.write_transaction();
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 0, &hist_txs[..3]);
history_store.add_to_history(&mut txn, Policy::genesis_block_number(), &hist_txs[..3]);
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 2, &hist_txs[3..]);

// Verify method works.
let real_root_0 =
history_store.get_history_tree_root(Policy::genesis_block_number() + 0, Some(&txn));
history_store.get_history_tree_root(Policy::genesis_block_number(), Some(&txn));
let calc_root_0 = HistoryStore::_root_from_hist_txs(&hist_txs[..3]);

assert_eq!(real_root_0, calc_root_0);
Expand All @@ -919,7 +901,7 @@ mod tests {

// Add historic transactions to History Store.
let mut txn = env.write_transaction();
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 0, &hist_txs[..3]);
history_store.add_to_history(&mut txn, Policy::genesis_block_number(), &hist_txs[..3]);
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 2, &hist_txs[3..]);

let hashes: Vec<_> = hist_txs.iter().map(|hist_tx| hist_tx.tx_hash()).collect();
Expand Down Expand Up @@ -967,7 +949,7 @@ mod tests {

// Add historic transactions to History Store.
let mut txn = env.write_transaction();
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 0, &hist_txs[..3]);
history_store.add_to_history(&mut txn, Policy::genesis_block_number(), &hist_txs[..3]);
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 2, &hist_txs[3..]);

// Verify method works. Note that the block transactions are returned in the same
Expand Down Expand Up @@ -1127,7 +1109,7 @@ mod tests {

// Add historic transactions to History Store.
let mut txn = env.write_transaction();
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 0, &hist_txs[..3]);
history_store.add_to_history(&mut txn, Policy::genesis_block_number(), &hist_txs[..3]);
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 2, &hist_txs[3..]);

// Verify method works.
Expand Down Expand Up @@ -1231,7 +1213,7 @@ mod tests {

// Add historic transactions to History Store.
let mut txn = env.write_transaction();
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 0, &hist_txs[..3]);
history_store.add_to_history(&mut txn, Policy::genesis_block_number(), &hist_txs[..3]);
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 2, &hist_txs[3..]);

// Verify method works.
Expand Down Expand Up @@ -1259,7 +1241,7 @@ mod tests {

// Add historic transactions to History Store.
let mut txn = env.write_transaction();
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 0, &hist_txs[..3]);
history_store.add_to_history(&mut txn, Policy::genesis_block_number(), &hist_txs[..3]);
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 2, &hist_txs[3..]);

// Verify method works.
Expand Down Expand Up @@ -1334,14 +1316,14 @@ mod tests {

// Add historic transactions to History Store.
let mut txn = env.write_transaction();
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 0, &hist_txs[..3]);
history_store.add_to_history(&mut txn, Policy::genesis_block_number(), &hist_txs[..3]);
history_store.add_to_history(&mut txn, Policy::genesis_block_number() + 2, &hist_txs[3..]);

let hashes: Vec<_> = hist_txs.iter().map(|hist_tx| hist_tx.tx_hash()).collect();

// Verify method works.
let root = history_store
.get_history_tree_root(Policy::genesis_block_number() + 0, Some(&txn))
.get_history_tree_root(Policy::genesis_block_number(), Some(&txn))
.unwrap();

let proof = history_store
Expand Down Expand Up @@ -1405,7 +1387,7 @@ mod tests {

// Verify method works.
let root = history_store
.get_history_tree_root(Policy::genesis_block_number() + 0, Some(&txn))
.get_history_tree_root(Policy::genesis_block_number(), Some(&txn))
.unwrap();

let proof = history_store.prove(0, vec![], None, Some(&txn)).unwrap();
Expand Down Expand Up @@ -1561,9 +1543,9 @@ mod tests {

fn gen_hist_txs() -> Vec<HistoricTransaction> {
let genesis_block_number = Policy::genesis_block_number();
let ext_0 = create_transaction(genesis_block_number + 0, 0);
let ext_1 = create_transaction(genesis_block_number + 0, 1);
let ext_2 = create_reward_inherent(genesis_block_number + 0, 2);
let ext_0 = create_transaction(genesis_block_number, 0);
let ext_1 = create_transaction(genesis_block_number, 1);
let ext_2 = create_reward_inherent(genesis_block_number, 2);

let ext_3 = create_transaction(genesis_block_number + 1, 3);
let ext_4 = create_reward_inherent(genesis_block_number + 1, 4);
Expand Down
8 changes: 4 additions & 4 deletions blockchain/src/history/merged_history_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,10 +731,10 @@ mod tests {
}

fn gen_hist_txs() -> Vec<HistoricTransaction> {
let start_block_number = Policy::genesis_block_number() + 0;
let ext_0 = create_transaction(start_block_number + 0, 0);
let ext_1 = create_transaction(start_block_number + 0, 1);
let ext_2 = create_reward_inherent(start_block_number + 0, 2);
let start_block_number = Policy::genesis_block_number();
let ext_0 = create_transaction(start_block_number, 0);
let ext_1 = create_transaction(start_block_number, 1);
let ext_2 = create_reward_inherent(start_block_number, 2);

let ext_3 = create_transaction(start_block_number + 1, 3);
let ext_4 = create_reward_inherent(start_block_number + 1, 4);
Expand Down
2 changes: 1 addition & 1 deletion blockchain/src/history/mmr_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fn get_size(
}
}

impl<'a, 'env> Store<Blake2bHash> for MMRStore<'a, 'env> {
impl Store<Blake2bHash> for MMRStore<'_, '_> {
fn push(&mut self, elem: Blake2bHash) {
// This function assumes that there is no higher epoch.
// Otherwise the append method will fail.
Expand Down
2 changes: 1 addition & 1 deletion blockchain/tests/block_production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ fn it_can_produce_micro_blocks_with_equivocation_proofs() {
let equivocation_proofs = if reverse {
equivocation_proofs.iter().cloned().rev().collect()
} else {
equivocation_proofs.iter().cloned().collect()
equivocation_proofs.to_vec()
};

let time = Arc::new(OffsetTime::new());
Expand Down
6 changes: 3 additions & 3 deletions blockchain/tests/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn prune_epoch_micro_blocks() {
producer
.next_micro_block(
&bc_read,
&bc_read.time.now() + 1_u64 * 1000,
&bc_read.time.now() + 1000,
vec![],
vec![],
vec![0x42],
Expand All @@ -40,7 +40,7 @@ fn prune_epoch_micro_blocks() {
producer
.next_micro_block(
&bc_read,
bc_read.time.now() + 1_u64 * 100,
bc_read.time.now() + 100,
vec![],
vec![],
vec![0x32],
Expand All @@ -53,7 +53,7 @@ fn prune_epoch_micro_blocks() {
producer
.next_micro_block(
&bc_read,
bc_read.time.now() + 1_u64 * 10000,
bc_read.time.now() + 10000,
vec![],
vec![],
vec![0x82],
Expand Down
6 changes: 3 additions & 3 deletions blockchain/tests/history_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn revert_block(temp_producer: &TemporaryBlockProducer, hist_tx_pre: &[HistoricT
blockchain.revert_blocks(1, &mut txn).unwrap();
txn.commit();

let hist_tx_revert = get_hist_tx(&temp_producer);
let hist_tx_revert = get_hist_tx(temp_producer);

assert_eq!(hist_tx_pre, &hist_tx_revert);
}
Expand Down Expand Up @@ -215,7 +215,7 @@ fn add_block_assert_history_store(
is_skip_block: bool,
) -> (Vec<HistoricTransaction>, Vec<HistoricTransaction>) {
// Get initial history store.
let hist_tx_pre = get_hist_tx(&temp_producer1);
let hist_tx_pre = get_hist_tx(temp_producer1);

// Add a block with the equivocation proofs.
let skip_block_proof = if is_skip_block {
Expand Down Expand Up @@ -244,7 +244,7 @@ fn add_block_assert_history_store(
);

// Get the new history store after the block push.
let hist_tx_after = get_hist_tx(&temp_producer1);
let hist_tx_after = get_hist_tx(temp_producer1);

// Assert that the jail inherent and equivocation proofs are present in history store.
// There is 1 inherent and 1 event generated per equivocation proof.
Expand Down
6 changes: 3 additions & 3 deletions blockchain/tests/merged_history_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fn revert_block(temp_producer: &TemporaryBlockProducer, hist_tx_pre: &[HistoricT
blockchain.revert_blocks(1, &mut txn).unwrap();
txn.commit();

let hist_tx_revert = get_hist_tx(&temp_producer);
let hist_tx_revert = get_hist_tx(temp_producer);

assert_eq!(hist_tx_pre, &hist_tx_revert);
}
Expand Down Expand Up @@ -215,7 +215,7 @@ fn add_block_assert_history_store(
is_skip_block: bool,
) -> (Vec<HistoricTransaction>, Vec<HistoricTransaction>) {
// Get initial history store.
let hist_tx_pre = get_hist_tx(&temp_producer1);
let hist_tx_pre = get_hist_tx(temp_producer1);

// Add a block with the equivocation proofs.
let skip_block_proof = if is_skip_block {
Expand Down Expand Up @@ -244,7 +244,7 @@ fn add_block_assert_history_store(
);

// Get the new history store after the block push.
let hist_tx_after = get_hist_tx(&temp_producer1);
let hist_tx_after = get_hist_tx(temp_producer1);

// Assert that the jail inherent and equivocation proofs are present in history store.
// There is 1 inherent and 1 event generated per equivocation proof.
Expand Down
Loading

0 comments on commit 4fa5fb2

Please sign in to comment.