Skip to content

Commit

Permalink
Satisfy clippy in gas-price-analysis (#2418)
Browse files Browse the repository at this point in the history
## Description
This PR applies the Clippy suggestions for the "gas-price-analysis"
crate.

### Before requesting review
- [X] I have reviewed the code myself
  • Loading branch information
rafal-ch authored Oct 31, 2024
1 parent 612d867 commit 7a80407
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 23 deletions.
19 changes: 8 additions & 11 deletions crates/fuel-gas-price-algorithm/gas-price-analysis/src/charts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ pub fn draw_gas_prices(
da_gas_prices: &[u64],
title: &str,
) -> anyhow::Result<()> {
let gas_prices_gwei: Vec<_> = gas_prices.into_iter().map(|x| x / ONE_GWEI).collect();
let gas_prices_gwei: Vec<_> = gas_prices.iter().map(|x| x / ONE_GWEI).collect();
let _exec_gas_prices_gwei: Vec<_> =
_exec_gas_prices.into_iter().map(|x| x / ONE_GWEI).collect();
let da_gas_prices_gwei: Vec<_> =
da_gas_prices.into_iter().map(|x| x / ONE_GWEI).collect();
_exec_gas_prices.iter().map(|x| x / ONE_GWEI).collect();
let da_gas_prices_gwei: Vec<_> = da_gas_prices.iter().map(|x| x / ONE_GWEI).collect();
// const GAS_PRICE_COLOR: RGBColor = BLACK;
// const EXEC_GAS_PRICE_COLOR: RGBColor = RED;
const DA_GAS_PRICE_COLOR: RGBColor = BLUE;
Expand Down Expand Up @@ -146,7 +145,7 @@ pub fn draw_gas_prices(

pub fn draw_fullness(
drawing_area: &DrawingArea<BitMapBackend, Shift>,
fullness: &Vec<(u64, u64)>,
fullness: &[(u64, u64)],
title: &str,
) -> anyhow::Result<()> {
const FULLNESS_COLOR: RGBColor = BLACK;
Expand Down Expand Up @@ -267,16 +266,14 @@ pub fn draw_profit(
const ACTUAL_PROFIT_COLOR: RGBColor = BLACK;
const PROJECTED_PROFIT_COLOR: RGBColor = RED;
const PESSIMISTIC_BLOCK_COST_COLOR: RGBColor = BLUE;
let actual_profit_gwei: Vec<_> = actual_profit
.into_iter()
.map(|x| x / ONE_GWEI as i128)
.collect();
let actual_profit_gwei: Vec<_> =
actual_profit.iter().map(|x| x / ONE_GWEI as i128).collect();
let projected_profit_gwei: Vec<_> = projected_profit
.into_iter()
.iter()
.map(|x| x / ONE_GWEI as i128)
.collect();
let pessimistic_block_costs_gwei: Vec<_> = pessimistic_block_costs
.into_iter()
.iter()
.map(|x| x / ONE_GWEI as u128)
.collect();
let min = *std::cmp::min(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Simulator {
// Scales the gas price internally, value is arbitrary
let gas_price_factor = 100;
let always_normal_activity = L2ActivityTracker::new_always_normal();
let updater = AlgorithmUpdaterV1 {
AlgorithmUpdaterV1 {
min_exec_gas_price: 10,
min_da_gas_price: 10,
// Change to adjust where the exec gas price starts on block 0
Expand All @@ -114,11 +114,10 @@ impl Simulator {
last_profit: 0,
second_to_last_profit: 0,
l2_activity: always_normal_activity,
};
updater
}
}

fn execute_simulation<'a>(
fn execute_simulation(
&self,
capacity: u64,
max_block_bytes: u64,
Expand Down Expand Up @@ -161,7 +160,7 @@ impl Simulator {

// Update DA blocks on the occasion there is one
if let Some((range, cost)) = da_block {
for height in range.to_owned() {
for height in range {
updater
.update_da_record_data(height..(height + 1), cost)
.unwrap();
Expand All @@ -178,7 +177,7 @@ impl Simulator {
let bytes_and_costs: Vec<_> = bytes
.iter()
.zip(self.da_cost_per_byte.iter())
.map(|(bytes, da_cost_per_byte)| (*bytes, (*bytes * da_cost_per_byte) as u64))
.map(|(bytes, da_cost_per_byte)| (*bytes, *bytes * da_cost_per_byte))
.collect();

let actual_profit: Vec<i128> = actual_costs
Expand Down Expand Up @@ -209,7 +208,7 @@ impl Simulator {
&self,
da_recording_rate: usize,
da_finalization_rate: usize,
fullness_and_bytes: &Vec<(u64, u64)>,
fullness_and_bytes: &[(u64, u64)],
) -> Vec<Option<(Range<u32>, u128)>> {
let l2_blocks_with_no_da_blocks =
std::iter::repeat(None).take(da_finalization_rate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ pub fn get_da_cost_per_byte_from_source(
let original = get_costs_from_csv_file(&file_path, sample_size);
original
.into_iter()
.map(|x| std::iter::repeat(x).take(update_period))
.flatten()
.flat_map(|x| iter::repeat(x).take(update_period))
.collect()
}
}
Expand Down Expand Up @@ -89,8 +88,7 @@ fn arbitrary_cost_per_byte(size: usize, update_period: usize) -> Vec<u64> {
.map(|x| x * ROUGH_COST_AVG + ROUGH_COST_AVG) // Sine wave is between -1 and 1, scale and shift
.map(|x| x as u64)
.map(|x| std::cmp::max(x, 1))
.map(|x| iter::repeat(x).take(update_period as usize))
.flatten()
.take(size as usize)
.flat_map(|x| iter::repeat(x).take(update_period))
.take(size)
.collect()
}

0 comments on commit 7a80407

Please sign in to comment.