diff --git a/crates/fuel-gas-price-algorithm/src/v1.rs b/crates/fuel-gas-price-algorithm/src/v1.rs index 069cd6c5e69..a1a5f7dd536 100644 --- a/crates/fuel-gas-price-algorithm/src/v1.rs +++ b/crates/fuel-gas-price-algorithm/src/v1.rs @@ -193,8 +193,6 @@ impl AlgorithmUpdaterV1 { if !height_range.is_empty() { self.da_block_update(height_range, range_cost)?; self.recalculate_projected_cost(); - // TODO: https://github.com/FuelLabs/fuel-core/issues/2264 - // self.normalize_rewards_and_costs(); } Ok(()) } @@ -445,37 +443,4 @@ impl AlgorithmUpdaterV1 { for_height: self.l2_block_height, } } - - // TODO: This breaks our simulation now that we are using an extended finalization period. We - // can either keep this function and fix the simulation, or we might decide to remove it. - // https://github.com/FuelLabs/fuel-core/issues/2264 - // We only need to track the difference between the rewards and costs after we have true DA data - // Normalize, or zero out the lower value and subtract it from the higher value - fn _normalize_rewards_and_costs(&mut self) { - let (excess, projected_cost_excess) = - if self.total_da_rewards_excess > self.latest_known_total_da_cost_excess { - ( - self.total_da_rewards_excess - .saturating_sub(self.latest_known_total_da_cost_excess), - self.projected_total_da_cost - .saturating_sub(self.latest_known_total_da_cost_excess), - ) - } else { - ( - self.latest_known_total_da_cost_excess - .saturating_sub(self.total_da_rewards_excess), - self.projected_total_da_cost - .saturating_sub(self.total_da_rewards_excess), - ) - }; - - self.projected_total_da_cost = projected_cost_excess; - if self.total_da_rewards_excess > self.latest_known_total_da_cost_excess { - self.total_da_rewards_excess = excess; - self.latest_known_total_da_cost_excess = 0; - } else { - self.total_da_rewards_excess = 0; - self.latest_known_total_da_cost_excess = excess; - } - } } diff --git a/crates/fuel-gas-price-algorithm/src/v1/tests/update_da_record_data_tests.rs b/crates/fuel-gas-price-algorithm/src/v1/tests/update_da_record_data_tests.rs index 1c1628be60a..123520b4e99 100644 --- a/crates/fuel-gas-price-algorithm/src/v1/tests/update_da_record_data_tests.rs +++ b/crates/fuel-gas-price-algorithm/src/v1/tests/update_da_record_data_tests.rs @@ -5,13 +5,6 @@ use crate::v1::{ }, Error, }; -use proptest::{ - prelude::Rng, - prop_compose, - proptest, -}; -use rand::SeedableRng; -use std::ops::Range; #[test] fn update_da_record_data__increases_block() { @@ -277,162 +270,3 @@ fn update_da_record_data__da_block_updates_projected_total_cost_with_known_and_g let expected = new_known_total_cost + guessed_part; assert_eq!(actual, expected as u128); } - -#[derive(Debug, Clone)] -pub struct RecordedBlock { - pub height: u32, - pub block_cost: u64, -} - -prop_compose! { - fn arb_vec_of_da_blocks()(last_da_block: u32, count in 1..123usize, rng_seed: u64) -> (Vec, (Range, u128)) { - let rng = &mut rand::rngs::StdRng::seed_from_u64(rng_seed); - let mut unrecorded_blocks = Vec::with_capacity(count); - let mut recorded_blocks = Vec::with_capacity(count); - for i in 0..count { - let height = last_da_block + 1 + i as u32; - let block_bytes = rng.gen_range(100..131_072); - let cost_per_byte = rng.gen_range(1..1000000); - let block_cost = block_bytes * cost_per_byte; - unrecorded_blocks.push(BlockBytes { - height, - block_bytes, - }); - recorded_blocks.push(RecordedBlock { - height, - block_cost, - }); - } - let recorded_heights = recorded_blocks - .iter() - .map(|block| block.height) - .collect::>(); - let min = recorded_heights.iter().min().unwrap(); - let max = recorded_heights.iter().max().unwrap(); - let recorded_range = *min..(max + 1); - let recorded_cost = recorded_blocks - .iter() - .map(|block| block.block_cost as u128) - .sum(); - - (unrecorded_blocks, (recorded_range, recorded_cost)) - } -} - -prop_compose! { - fn reward_greater_than_cost_with_da_blocks()(cost: u64, extra: u64, (unrecorded_blocks, (recorded_range, recorded_cost)) in arb_vec_of_da_blocks()) -> (u128, u128, Vec, (Range, u128)) { - let reward = cost as u128 + recorded_cost + extra as u128; - (cost as u128, reward, unrecorded_blocks, (recorded_range, recorded_cost)) - } -} - -proptest! { - // https://github.com/FuelLabs/fuel-core/issues/2264 - #[ignore] - #[test] - fn update_da_record_data__when_reward_is_greater_than_cost_will_zero_cost_and_subtract_from_reward( - (cost, reward, unrecorded_blocks, (recorded_range, recorded_cost)) in reward_greater_than_cost_with_da_blocks() - ) { - _update_da_record_data__when_reward_is_greater_than_cost_will_zero_cost_and_subtract_from_reward( - cost, - reward, - unrecorded_blocks, - recorded_range, - recorded_cost - ) - } -} - -fn _update_da_record_data__when_reward_is_greater_than_cost_will_zero_cost_and_subtract_from_reward( - known_total_cost: u128, - total_rewards: u128, - unrecorded_blocks: Vec, - recorded_range: Range, - recorded_cost: u128, -) { - // given - let da_cost_per_byte = 20; - let da_recorded_block_height = recorded_range.start - 1; - let l2_block_height = 15; - let mut updater = UpdaterBuilder::new() - .with_da_cost_per_byte(da_cost_per_byte) - .with_da_recorded_block_height(da_recorded_block_height) - .with_l2_block_height(l2_block_height) - .with_known_total_cost(known_total_cost) - .with_total_rewards(total_rewards) - .with_unrecorded_blocks(unrecorded_blocks) - .build(); - - // when - updater - .update_da_record_data(recorded_range, recorded_cost) - .unwrap(); - - // then - let expected = total_rewards - recorded_cost - known_total_cost; - let actual = updater.total_da_rewards_excess; - assert_eq!(actual, expected); - - let expected = 0; - let actual = updater.latest_known_total_da_cost_excess; - assert_eq!(actual, expected); -} - -prop_compose! { - fn cost_greater_than_reward_with_da_blocks()(reward: u64, extra: u64, (unrecorded_blocks, (recorded_range, recorded_cost)) in arb_vec_of_da_blocks()) -> (u128, u128, Vec, (Range, u128)) { - let cost = reward as u128 + recorded_cost + extra as u128; - (cost, reward as u128, unrecorded_blocks, (recorded_range, recorded_cost)) - } -} - -proptest! { - // https://github.com/FuelLabs/fuel-core/issues/2264 - #[ignore] - #[test] - fn update_da_record_data__when_cost_is_greater_than_reward_will_zero_reward_and_subtract_from_cost( - (cost, reward, unrecorded_blocks, (recorded_range, recorded_cost)) in cost_greater_than_reward_with_da_blocks() - ) { - _update_da_record_data__when_cost_is_greater_than_reward_will_zero_reward_and_subtract_from_cost( - cost, - reward, - unrecorded_blocks, - recorded_range, - recorded_cost - ) - } -} - -fn _update_da_record_data__when_cost_is_greater_than_reward_will_zero_reward_and_subtract_from_cost( - known_total_cost: u128, - total_rewards: u128, - unrecorded_blocks: Vec, - recorded_range: Range, - recorded_cost: u128, -) { - // given - let da_cost_per_byte = 20; - let da_recorded_block_height = recorded_range.start - 1; - let l2_block_height = 15; - let mut updater = UpdaterBuilder::new() - .with_da_cost_per_byte(da_cost_per_byte) - .with_da_recorded_block_height(da_recorded_block_height) - .with_l2_block_height(l2_block_height) - .with_known_total_cost(known_total_cost) - .with_total_rewards(total_rewards) - .with_unrecorded_blocks(unrecorded_blocks) - .build(); - - // when - updater - .update_da_record_data(recorded_range, recorded_cost) - .unwrap(); - - // then - let expected = 0; - let actual = updater.total_da_rewards_excess; - assert_eq!(actual, expected); - - let expected = known_total_cost + recorded_cost - total_rewards; - let actual = updater.latest_known_total_da_cost_excess; - assert_eq!(actual, expected); -}