Skip to content

Commit

Permalink
clippy lints beta
Browse files Browse the repository at this point in the history
  • Loading branch information
oxarbitrage committed Apr 15, 2024
1 parent 1a38c27 commit aa63ae6
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ fn update_checksum(checksum: &mut u32, item: [u8; 32]) {
}
}

#[allow(unknown_lints, clippy::to_string_trait_impl)]
impl ToString for LongPollId {
/// Exact conversion from LongPollId to a string.
fn to_string(&self) -> String {
Expand Down
36 changes: 15 additions & 21 deletions zebra-state/src/service/non_finalized_state/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -636,13 +636,11 @@ impl Chain {
.next()
.expect("Zebra should never reach the max height in normal operation.");

if self.sprout_trees_by_height.get(&next_height).is_none() {
// TODO: Use `try_insert` once it stabilises.
self.sprout_trees_by_height.insert(
next_height,
highest_removed_tree.expect("There should be a cached removed tree."),
);
}
self.sprout_trees_by_height
.entry(next_height)
.or_insert_with(|| {
highest_removed_tree.expect("There should be a cached removed tree.")
});
}
}

Expand Down Expand Up @@ -839,13 +837,11 @@ impl Chain {
.next()
.expect("Zebra should never reach the max height in normal operation.");

if self.sapling_trees_by_height.get(&next_height).is_none() {
// TODO: Use `try_insert` once it stabilises.
self.sapling_trees_by_height.insert(
next_height,
highest_removed_tree.expect("There should be a cached removed tree."),
);
}
self.sapling_trees_by_height
.entry(next_height)
.or_insert_with(|| {
highest_removed_tree.expect("There should be a cached removed tree.")
});
}
}

Expand Down Expand Up @@ -1048,13 +1044,11 @@ impl Chain {
.next()
.expect("Zebra should never reach the max height in normal operation.");

if self.orchard_trees_by_height.get(&next_height).is_none() {
// TODO: Use `try_insert` once it stabilises.
self.orchard_trees_by_height.insert(
next_height,
highest_removed_tree.expect("There should be a cached removed tree."),
);
}
self.orchard_trees_by_height
.entry(next_height)
.or_insert_with(|| {
highest_removed_tree.expect("There should be a cached removed tree.")
});
}
}

Expand Down
16 changes: 8 additions & 8 deletions zebra-state/src/service/non_finalized_state/tests/prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,15 +611,15 @@ fn different_blocks_different_chains() -> Result<()> {

// blocks, heights, hashes
chain1.blocks = chain2.blocks.clone();
chain1.height_by_hash = chain2.height_by_hash.clone();
chain1.tx_loc_by_hash = chain2.tx_loc_by_hash.clone();
chain1.height_by_hash.clone_from(&chain2.height_by_hash);
chain1.tx_loc_by_hash.clone_from(&chain2.tx_loc_by_hash);

// transparent UTXOs
chain1.created_utxos = chain2.created_utxos.clone();
chain1.spent_utxos = chain2.spent_utxos.clone();
chain1.created_utxos.clone_from(&chain2.created_utxos);
chain1.spent_utxos.clone_from(&chain2.spent_utxos);

// note commitment trees
chain1.sprout_trees_by_anchor = chain2.sprout_trees_by_anchor.clone();
chain1.sprout_trees_by_anchor.clone_from(&chain2.sprout_trees_by_anchor);
chain1.sprout_trees_by_height = chain2.sprout_trees_by_height.clone();
chain1.sapling_trees_by_height = chain2.sapling_trees_by_height.clone();
chain1.orchard_trees_by_height = chain2.orchard_trees_by_height.clone();
Expand All @@ -640,9 +640,9 @@ fn different_blocks_different_chains() -> Result<()> {
chain1.orchard_anchors_by_height = chain2.orchard_anchors_by_height.clone();

// nullifiers
chain1.sprout_nullifiers = chain2.sprout_nullifiers.clone();
chain1.sapling_nullifiers = chain2.sapling_nullifiers.clone();
chain1.orchard_nullifiers = chain2.orchard_nullifiers.clone();
chain1.sprout_nullifiers.clone_from(&chain2.sprout_nullifiers);
chain1.sapling_nullifiers.clone_from(&chain2.sapling_nullifiers);
chain1.orchard_nullifiers.clone_from(&chain2.orchard_nullifiers);

// proof of work
chain1.partial_cumulative_work = chain2.partial_cumulative_work;
Expand Down
10 changes: 7 additions & 3 deletions zebrad/tests/acceptance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ fn ephemeral(cache_dir_config: EphemeralConfig, cache_dir_check: EphemeralCheck)
let ignored_cache_dir = run_dir.path().join("state");
if cache_dir_config == EphemeralConfig::MisconfiguredCacheDir {
// Write a configuration that sets both the cache_dir and ephemeral options
config.state.cache_dir = ignored_cache_dir.clone();
config.state.cache_dir.clone_from(&ignored_cache_dir);
}
if cache_dir_check == EphemeralCheck::ExistingDirectory {
// We set the cache_dir config to a newly created empty temp directory,
Expand Down Expand Up @@ -2950,11 +2950,15 @@ fn scan_start_where_left() -> Result<()> {
config.shielded_scan.sapling_keys_to_scan = keys;

// Add the cache dir to shielded scan, make it the same as the zebrad cache state.
config.shielded_scan.db_config_mut().cache_dir = cache_dir.clone();
config
.shielded_scan
.db_config_mut()
.cache_dir
.clone_from(&cache_dir);
config.shielded_scan.db_config_mut().ephemeral = false;

// Add the cache dir to state.
config.state.cache_dir = cache_dir.clone();
config.state.cache_dir.clone_from(&cache_dir);
config.state.ephemeral = false;

// Remove the scan directory before starting.
Expand Down
5 changes: 4 additions & 1 deletion zebrad/tests/common/shielded_scan/scan_task_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ pub(crate) async fn run() -> Result<()> {
.expect("already checked that there is a cached state path");

let mut scan_config = zebra_scan::Config::default();
scan_config.db_config_mut().cache_dir = zebrad_state_path.clone();
scan_config
.db_config_mut()
.cache_dir
.clone_from(&zebrad_state_path);

// Logs the network as zebrad would as part of the metadata when starting up.
// This is currently needed for the 'Check startup logs' step in CI to pass.
Expand Down

0 comments on commit aa63ae6

Please sign in to comment.