Struct fuel_gas_price_algorithm::v1::AlgorithmUpdaterV1
source · pub struct AlgorithmUpdaterV1 {Show 18 fields
pub new_exec_price: u64,
pub last_da_gas_price: u64,
pub min_exec_gas_price: u64,
pub exec_gas_price_change_percent: u64,
pub l2_block_height: u32,
pub l2_block_fullness_threshold_percent: u64,
pub min_da_gas_price: u64,
pub max_da_gas_price_change_percent: u8,
pub total_da_rewards: u64,
pub da_recorded_block_height: u32,
pub latest_known_total_da_cost: u64,
pub projected_total_da_cost: u64,
pub da_p_component: i64,
pub da_d_component: i64,
pub profit_avg: i64,
pub avg_window: u32,
pub latest_da_cost_per_byte: u64,
pub unrecorded_blocks: Vec<BlockBytes>,
}Expand description
The state of the algorithm used to update the gas price algorithm for each block
Because there will always be a delay between blocks submitted to the L2 chain and the blocks being recorded on the DA chain, the updater needs to make “projections” about the cost of recording any given block to the DA chain. This is done by tracking the cost per byte of recording for the most recent blocks, and using the known bytes of the unrecorded blocks to estimate the cost for that block. Every time the DA recording is updated, the projections are recalculated.
This projection will inevitably lead to error in the gas price calculation. Special care should be taken to account for the worst case scenario when calculating the parameters of the algorithm.
Fields§
§new_exec_price: u64The gas price to cover the execution of the next block
last_da_gas_price: u64The gas price for the DA portion of the last block. This can be used to calculate the DA portion of the next block
min_exec_gas_price: u64The lowest the algorithm allows the exec gas price to go
exec_gas_price_change_percent: u64The Percentage the execution gas price will change in a single block, either increase or decrease based on the fullness of the last L2 block
l2_block_height: u32The height of the next L2 block
l2_block_fullness_threshold_percent: u64The threshold of gas usage above and below which the gas price will increase or decrease This is a percentage of the total capacity of the L2 block
min_da_gas_price: u64The lowest the algorithm allows the da gas price to go
max_da_gas_price_change_percent: u8The maximum percentage that the DA portion of the gas price can change in a single block
total_da_rewards: u64The cumulative reward from the DA portion of the gas price
da_recorded_block_height: u32The height of the las L2 block recorded on the DA chain
latest_known_total_da_cost: u64The cumulative cost of recording L2 blocks on the DA chain as of the last recorded block
projected_total_da_cost: u64The predicted cost of recording L2 blocks on the DA chain as of the last L2 block
(This value is added on top of the latest_known_total_da_cost if the L2 height is higher)
da_p_component: i64The P component of the PID control for the DA gas price
da_d_component: i64The D component of the PID control for the DA gas price
profit_avg: i64The average profit over the last avg_window blocks
avg_window: u32The number of blocks to consider when calculating the average profit
latest_da_cost_per_byte: u64The latest known cost per byte for recording blocks on the DA chain
unrecorded_blocks: Vec<BlockBytes>The unrecorded blocks that are used to calculate the projected cost of recording blocks
Implementations§
source§impl AlgorithmUpdaterV1
impl AlgorithmUpdaterV1
pub fn update_da_record_data( &mut self, blocks: Vec<RecordedBlock>, ) -> Result<(), Error>
pub fn update_l2_block_data( &mut self, height: u32, used: u64, capacity: NonZeroU64, block_bytes: u64, gas_price: u64, ) -> Result<(), Error>
pub fn algorithm(&self) -> AlgorithmV1
Trait Implementations§
source§impl Clone for AlgorithmUpdaterV1
impl Clone for AlgorithmUpdaterV1
source§fn clone(&self) -> AlgorithmUpdaterV1
fn clone(&self) -> AlgorithmUpdaterV1
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Debug for AlgorithmUpdaterV1
impl Debug for AlgorithmUpdaterV1
source§impl<'de> Deserialize<'de> for AlgorithmUpdaterV1
impl<'de> Deserialize<'de> for AlgorithmUpdaterV1
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl PartialEq for AlgorithmUpdaterV1
impl PartialEq for AlgorithmUpdaterV1
source§impl Serialize for AlgorithmUpdaterV1
impl Serialize for AlgorithmUpdaterV1
impl StructuralPartialEq for AlgorithmUpdaterV1
Auto Trait Implementations§
impl Freeze for AlgorithmUpdaterV1
impl RefUnwindSafe for AlgorithmUpdaterV1
impl Send for AlgorithmUpdaterV1
impl Sync for AlgorithmUpdaterV1
impl Unpin for AlgorithmUpdaterV1
impl UnwindSafe for AlgorithmUpdaterV1
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit)