Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use bytes from unrecorded_blocks rather from the block from DA #2252

Merged
merged 22 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ffa4fdb
Fix DA tests to expect unrecorded blocks to exist and to take the byt…
MitchTurner Sep 25, 2024
e82170c
Merge branch 'master' into fix/use-bytes-from-l2-blocks-not-da
MitchTurner Sep 25, 2024
fc3cf91
Remove regression for unimportant failure mode
MitchTurner Sep 25, 2024
8cd972f
Move struct that is only used in tests
MitchTurner Sep 25, 2024
8fd6616
Remove unused struct
MitchTurner Sep 26, 2024
49e521e
Change interface of `update_da_record_data`
MitchTurner Sep 26, 2024
cc28922
Move `RecordedBlock` into tests
MitchTurner Sep 26, 2024
e00319c
Merge branch 'master' into fix/use-bytes-from-l2-blocks-not-da
MitchTurner Sep 26, 2024
93a6e98
Use BTreeMap instead of HashMap
MitchTurner Sep 26, 2024
41c26f0
Use `pop_first` instead of `remove`
MitchTurner Sep 26, 2024
364ce4a
Fix compilation errors
MitchTurner Sep 26, 2024
e40a857
Kinda fix the analyzer I think
MitchTurner Sep 26, 2024
ea5469f
Cleanup prints
MitchTurner Sep 26, 2024
6a845ba
Merge branch 'master' into fix/use-bytes-from-l2-blocks-not-da
MitchTurner Sep 27, 2024
bfafd03
Fix test compilation
MitchTurner Sep 27, 2024
97fcc32
Fix profit chart length
MitchTurner Sep 27, 2024
a51a32c
Remove normalization function to fix simulation
MitchTurner Sep 27, 2024
dd8a252
Remove comment, add todo
MitchTurner Sep 30, 2024
7880500
Merge branch 'master' into fix/use-bytes-from-l2-blocks-not-da
MitchTurner Oct 1, 2024
76b904a
Merge remote-tracking branch 'origin' into fix/use-bytes-from-l2-bloc…
MitchTurner Oct 2, 2024
5848462
clean up function signature
MitchTurner Oct 2, 2024
8ec9c18
revert file inclusion from botched merge
MitchTurner Oct 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -307,10 +307,10 @@ pub fn draw_profit(
.x_label_area_size(40)
.y_label_area_size(100)
.right_y_label_area_size(100)
.build_cartesian_2d(0..actual_profit_gwei.len(), min..max)
.build_cartesian_2d(0..projected_profit.len(), min..max)
.unwrap()
.set_secondary_coord(
0..actual_profit_gwei.len(),
0..projected_profit.len(),
0..*pessimistic_block_costs_gwei.iter().max().unwrap(),
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use fuel_gas_price_algorithm::v1::{
AlgorithmUpdaterV1,
RecordedBlock,
};
use std::num::NonZeroU64;

use super::*;
use fuel_gas_price_algorithm::v1::AlgorithmUpdaterV1;
use std::{
collections::BTreeMap,
num::NonZeroU64,
ops::Range,
};

pub mod da_cost_per_byte;

Expand All @@ -24,6 +24,13 @@ pub struct Simulator {
da_cost_per_byte: Vec<u64>,
}

// (usize, ((u64, u64), &'a Option<(Range<u32>, u128)
struct BlockData {
fullness: u64,
bytes: u64,
maybe_da_block: Option<(Range<u32>, u128)>,
}

impl Simulator {
pub fn new(da_cost_per_byte: Vec<u64>) -> Self {
Simulator { da_cost_per_byte }
Expand All @@ -49,7 +56,14 @@ impl Simulator {
&fullness_and_bytes,
);

let blocks = l2_blocks.zip(da_blocks.iter()).enumerate();
let blocks = l2_blocks
.zip(da_blocks.iter())
.map(|((fullness, bytes), maybe_da_block)| BlockData {
fullness,
bytes,
maybe_da_block: maybe_da_block.clone(),
})
.enumerate();

let updater = self.build_updater(da_p_component, da_d_component);

Expand Down Expand Up @@ -90,7 +104,7 @@ impl Simulator {
latest_da_cost_per_byte: 0,
projected_total_da_cost: 0,
latest_known_total_da_cost_excess: 0,
unrecorded_blocks: vec![],
unrecorded_blocks: BTreeMap::new(),
da_p_component,
da_d_component,
last_profit: 0,
Expand All @@ -104,8 +118,7 @@ impl Simulator {
capacity: u64,
max_block_bytes: u64,
fullness_and_bytes: Vec<(u64, u64)>,
// blocks: Enumerate<Zip<Iter<(u64, u64)>, Iter<Option<Vec<RecordedBlock>>>>>,
blocks: impl Iterator<Item = (usize, ((u64, u64), &'a Option<Vec<RecordedBlock>>))>,
blocks: impl Iterator<Item = (usize, BlockData)>,
mut updater: AlgorithmUpdaterV1,
) -> SimulationResults {
let mut gas_prices = vec![];
Expand All @@ -115,13 +128,18 @@ impl Simulator {
let mut projected_cost_totals = vec![];
let mut actual_costs = vec![];
let mut pessimistic_costs = vec![];
for (index, ((fullness, bytes), da_block)) in blocks {
for (index, block_data) in blocks {
let BlockData {
fullness,
bytes,
maybe_da_block: da_block,
} = block_data;
let height = index as u32 + 1;
exec_gas_prices.push(updater.new_scaled_exec_price);
da_gas_prices.push(updater.new_scaled_da_gas_price);
let gas_price = updater.algorithm().calculate();
gas_prices.push(gas_price);
let total_fee = gas_price * fullness;
let total_fee = gas_price as u128 * fullness as u128;
updater
.update_l2_block_data(
height,
Expand All @@ -137,13 +155,13 @@ impl Simulator {
projected_cost_totals.push(updater.projected_total_da_cost);

// Update DA blocks on the occasion there is one
if let Some(da_blocks) = &da_block {
let mut total_cost = updater.latest_known_total_da_cost_excess;
for block in da_blocks {
total_cost += block.block_cost as u128;
actual_costs.push(total_cost);
if let Some((range, cost)) = da_block {
for height in range.to_owned() {
updater
.update_da_record_data(height..(height + 1), cost)
.unwrap();
actual_costs.push(updater.latest_known_total_da_cost_excess)
}
updater.update_da_record_data(&da_blocks).unwrap();
}
}
let (fullness_without_capacity, bytes): (Vec<_>, Vec<_>) =
Expand Down Expand Up @@ -187,7 +205,7 @@ impl Simulator {
da_recording_rate: usize,
da_finalization_rate: usize,
fullness_and_bytes: &Vec<(u64, u64)>,
) -> Vec<Option<Vec<RecordedBlock>>> {
) -> Vec<Option<(Range<u32>, u128)>> {
let l2_blocks_with_no_da_blocks =
std::iter::repeat(None).take(da_finalization_rate);
let (_, da_blocks) = fullness_and_bytes
Expand All @@ -199,12 +217,9 @@ impl Simulator {
|(mut delayed, mut recorded),
(index, ((_fullness, bytes), cost_per_byte))| {
let total_cost = *bytes * cost_per_byte;

let height = index as u32 + 1;
let converted = RecordedBlock {
height,
block_bytes: *bytes,
block_cost: total_cost as u64,
};
let converted = (height, bytes, total_cost);
delayed.push(converted);
if delayed.len() == da_recording_rate {
recorded.push(Some(delayed));
Expand All @@ -215,7 +230,16 @@ impl Simulator {
}
},
);
l2_blocks_with_no_da_blocks.chain(da_blocks).collect()
let da_block_ranges = da_blocks.into_iter().map(|maybe_recorded_blocks| {
maybe_recorded_blocks.map(|list| {
let heights_iter = list.iter().map(|(height, _, _)| *height);
let min = heights_iter.clone().min().unwrap();
let max = heights_iter.max().unwrap();
rafal-ch marked this conversation as resolved.
Show resolved Hide resolved
let cost: u128 = list.iter().map(|(_, _, cost)| *cost as u128).sum();
(min..(max + 1), cost)
})
});
l2_blocks_with_no_da_blocks.chain(da_block_ranges).collect()
}
}

Expand Down
6 changes: 0 additions & 6 deletions crates/fuel-gas-price-algorithm/src/v0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,6 @@ pub struct AlgorithmUpdaterV0 {
pub l2_block_fullness_threshold_percent: u64,
}

#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)]
pub struct BlockBytes {
pub height: u32,
pub block_bytes: u64,
}

impl AlgorithmUpdaterV0 {
pub fn new(
new_exec_price: u64,
Expand Down
Loading
Loading