Skip to content

Commit

Permalink
Use backward-compatible V0 metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchTurner committed Dec 19, 2024
1 parent 15c26f0 commit 0dc2dc7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions crates/services/gas_price_service/src/v0/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ use fuel_gas_price_algorithm::v0::AlgorithmUpdaterV0;
pub struct V0Metadata {
/// The gas price to cover the execution of the next block
pub new_exec_price: u64,
// Execution
/// The lowest the algorithm allows the exec gas price to go
pub min_exec_gas_price: u64,
/// The Percentage the execution gas price will change in a single block, either increase or decrease
/// based on the fullness of the last L2 block
pub exec_gas_price_change_percent: u64,
/// The height for which the `new_exec_price` is calculated, which should be the _next_ block
pub l2_block_height: u32,
/// The 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
pub l2_block_fullness_threshold_percent: u64,
}

pub struct V0AlgorithmConfig {
Expand All @@ -19,7 +28,11 @@ impl From<AlgorithmUpdaterV0> for V0Metadata {
fn from(updater: AlgorithmUpdaterV0) -> Self {
Self {
new_exec_price: updater.new_exec_price,
min_exec_gas_price: updater.min_exec_gas_price,
exec_gas_price_change_percent: updater.exec_gas_price_change_percent,
l2_block_height: updater.l2_block_height,
l2_block_fullness_threshold_percent: updater
.l2_block_fullness_threshold_percent,
}
}
}
4 changes: 4 additions & 0 deletions crates/services/gas_price_service/src/v0/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ fn arbitrary_config() -> V0AlgorithmConfig {
fn arbitrary_metadata() -> V0Metadata {
V0Metadata {
new_exec_price: 100,
min_exec_gas_price: 0,
exec_gas_price_change_percent: 0,
l2_block_height: 0,
l2_block_fullness_threshold_percent: 0,
}
}

Expand Down Expand Up @@ -339,6 +342,7 @@ async fn uninitialized_task__new__if_exists_already_reload_old_values_with_overr
let V0Metadata {
new_exec_price,
l2_block_height,
..
} = original_metadata;
let UninitializedTask { algo_updater, .. } = service;
assert_eq!(algo_updater.new_exec_price, new_exec_price);
Expand Down

0 comments on commit 0dc2dc7

Please sign in to comment.