Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion bin/fuel-core/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,9 @@ impl Command {
heavy_work: pool_heavy_work_config,
service_channel_limits,
pending_pool_tx_ttl: tx_pending_pool_ttl.into(),
max_pending_pool_size_percentage: tx_pending_pool_size_percentage,
max_pending_pool_size_percentage: fuel_core_types::ClampedPercentage::new(
tx_pending_pool_size_percentage.min(100) as u8,
),
metrics: metrics.is_enabled(Module::TxPool),
},
block_producer: ProducerConfig {
Expand Down
7 changes: 5 additions & 2 deletions crates/fuel-core/src/service/adapters/gas_price_adapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use fuel_core_storage::{
transactional::HistoricalView,
};
use fuel_core_types::{
ClampedPercentage,
blockchain::{
block::Block,
header::ConsensusParametersVersion,
Expand Down Expand Up @@ -91,7 +92,9 @@ impl From<Config> for V1AlgorithmConfig {
new_exec_gas_price: starting_exec_gas_price.max(min_exec_gas_price),
min_exec_gas_price,
exec_gas_price_change_percent,
l2_block_fullness_threshold_percent: exec_gas_price_threshold_percent,
l2_block_fullness_threshold_percent: ClampedPercentage::new(
exec_gas_price_threshold_percent,
),
min_da_gas_price,
max_da_gas_price,
max_da_gas_price_change_percent,
Expand All @@ -100,7 +103,7 @@ impl From<Config> for V1AlgorithmConfig {
normal_range_size: activity_normal_range_size,
capped_range_size: activity_capped_range_size,
decrease_range_size: activity_decrease_range_size,
block_activity_threshold,
block_activity_threshold: ClampedPercentage::new(block_activity_threshold),
da_poll_interval,
gas_price_factor: da_gas_price_factor,
starting_recorded_height: starting_recorded_height.map(BlockHeight::from),
Expand Down
1 change: 1 addition & 0 deletions crates/fuel-gas-price-algorithm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ name = "fuel_gas_price_algorithm"
path = "src/lib.rs"

[dependencies]
fuel-core-types = { path = "../types", features = ["serde"] }
serde = { workspace = true, features = ["derive"] }
thiserror = { workspace = true }
tracing = { workspace = true }
Expand Down
31 changes: 1 addition & 30 deletions crates/fuel-gas-price-algorithm/src/v1.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::utils::cumulative_percentage_change;
use fuel_core_types::ClampedPercentage;
use std::{
cmp::{
max,
Expand Down Expand Up @@ -321,36 +322,6 @@ impl L2ActivityTracker {
}
}

/// A value that represents a value between 0 and 100. Higher values are clamped to 100
#[derive(
serde::Serialize, serde::Deserialize, Debug, Copy, Clone, PartialEq, PartialOrd,
)]
pub struct ClampedPercentage {
value: u8,
}

impl ClampedPercentage {
pub fn new(maybe_value: u8) -> Self {
Self {
value: maybe_value.min(100),
}
}
}

impl From<u8> for ClampedPercentage {
fn from(value: u8) -> Self {
Self::new(value)
}
}

impl core::ops::Deref for ClampedPercentage {
type Target = u8;

fn deref(&self) -> &Self::Target {
&self.value
}
}

impl AlgorithmUpdaterV1 {
pub fn update_da_record_data<U: UnrecordedBlocks>(
&mut self,
Expand Down
21 changes: 10 additions & 11 deletions crates/services/gas_price_service/src/v1/metadata.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use crate::v0::metadata::V0Metadata;
use fuel_core_types::fuel_types::BlockHeight;
use fuel_core_types::{
ClampedPercentage,
fuel_types::BlockHeight,
};
use fuel_gas_price_algorithm::v1::{
AlgorithmUpdaterV1,
L2ActivityTracker,
Expand Down Expand Up @@ -78,7 +81,7 @@ pub struct V1AlgorithmConfig {
pub new_exec_gas_price: u64,
pub min_exec_gas_price: u64,
pub exec_gas_price_change_percent: u16,
pub l2_block_fullness_threshold_percent: u8,
pub l2_block_fullness_threshold_percent: ClampedPercentage,
// TODO:We don't need this after we implement
// https://github.com/FuelLabs/fuel-core/issues/2481
pub gas_price_factor: NonZeroU64,
Expand All @@ -90,7 +93,7 @@ pub struct V1AlgorithmConfig {
pub normal_range_size: u16,
pub capped_range_size: u16,
pub decrease_range_size: u16,
pub block_activity_threshold: u8,
pub block_activity_threshold: ClampedPercentage,
/// The interval at which the `DaSourceService` polls for new data
pub da_poll_interval: Option<Duration>,
pub starting_recorded_height: Option<BlockHeight>,
Expand All @@ -105,7 +108,7 @@ pub fn updater_from_config(
value.normal_range_size,
value.capped_range_size,
value.decrease_range_size,
value.block_activity_threshold.into(),
value.block_activity_threshold,
);
let unrecorded_blocks_bytes = 0;
AlgorithmUpdaterV1 {
Expand All @@ -126,9 +129,7 @@ pub fn updater_from_config(
l2_activity,
min_exec_gas_price: value.min_exec_gas_price,
exec_gas_price_change_percent: value.exec_gas_price_change_percent,
l2_block_fullness_threshold_percent: value
.l2_block_fullness_threshold_percent
.into(),
l2_block_fullness_threshold_percent: value.l2_block_fullness_threshold_percent,
min_da_gas_price: value.min_da_gas_price,
max_da_gas_price: value.max_da_gas_price,
max_da_gas_price_change_percent: value.max_da_gas_price_change_percent,
Expand Down Expand Up @@ -163,7 +164,7 @@ pub fn v1_algorithm_from_metadata(
config.normal_range_size,
config.capped_range_size,
config.decrease_range_size,
config.block_activity_threshold.into(),
config.block_activity_threshold,
);
let unrecorded_blocks_bytes: u128 = metadata.unrecorded_block_bytes;
let projected_portion =
Expand All @@ -185,9 +186,7 @@ pub fn v1_algorithm_from_metadata(
l2_activity,
min_exec_gas_price: config.min_exec_gas_price,
exec_gas_price_change_percent: config.exec_gas_price_change_percent,
l2_block_fullness_threshold_percent: config
.l2_block_fullness_threshold_percent
.into(),
l2_block_fullness_threshold_percent: config.l2_block_fullness_threshold_percent,
min_da_gas_price: config.min_da_gas_price,
max_da_gas_price: config.max_da_gas_price,
max_da_gas_price_change_percent: config.max_da_gas_price_change_percent,
Expand Down
24 changes: 16 additions & 8 deletions crates/services/gas_price_service/src/v1/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,9 @@ mod tests {
new_exec_gas_price: 100,
min_exec_gas_price: 50,
exec_gas_price_change_percent: 20,
l2_block_fullness_threshold_percent: 20,
l2_block_fullness_threshold_percent: fuel_core_types::ClampedPercentage::new(
20,
),
gas_price_factor: NonZeroU64::new(10).unwrap(),
min_da_gas_price: 10,
max_da_gas_price: 11,
Expand All @@ -723,7 +725,7 @@ mod tests {
normal_range_size: 10,
capped_range_size: 100,
decrease_range_size: 4,
block_activity_threshold: 20,
block_activity_threshold: fuel_core_types::ClampedPercentage::new(20),
da_poll_interval: None,
starting_recorded_height: None,
record_metrics: false,
Expand Down Expand Up @@ -807,7 +809,9 @@ mod tests {
new_exec_gas_price: 100,
min_exec_gas_price: 50,
exec_gas_price_change_percent: 0,
l2_block_fullness_threshold_percent: 20,
l2_block_fullness_threshold_percent: fuel_core_types::ClampedPercentage::new(
20,
),
gas_price_factor: NonZeroU64::new(10).unwrap(),
min_da_gas_price: 0,
max_da_gas_price: 1,
Expand All @@ -817,7 +821,7 @@ mod tests {
normal_range_size: 10,
capped_range_size: 100,
decrease_range_size: 4,
block_activity_threshold: 20,
block_activity_threshold: fuel_core_types::ClampedPercentage::new(20),
da_poll_interval: None,
starting_recorded_height: None,
record_metrics: false,
Expand Down Expand Up @@ -896,7 +900,9 @@ mod tests {
new_exec_gas_price: 100,
min_exec_gas_price: 50,
exec_gas_price_change_percent: 0,
l2_block_fullness_threshold_percent: 20,
l2_block_fullness_threshold_percent: fuel_core_types::ClampedPercentage::new(
20,
),
gas_price_factor: NonZeroU64::new(10).unwrap(),
min_da_gas_price: 0,
max_da_gas_price: 1,
Expand All @@ -906,7 +912,7 @@ mod tests {
normal_range_size: 10,
capped_range_size: 100,
decrease_range_size: 4,
block_activity_threshold: 20,
block_activity_threshold: fuel_core_types::ClampedPercentage::new(20),
da_poll_interval: None,
starting_recorded_height: None,
record_metrics: false,
Expand Down Expand Up @@ -1108,7 +1114,9 @@ mod tests {
new_exec_gas_price: 100,
min_exec_gas_price: 50,
exec_gas_price_change_percent: 20,
l2_block_fullness_threshold_percent: 20,
l2_block_fullness_threshold_percent: fuel_core_types::ClampedPercentage::new(
20,
),
gas_price_factor: NonZeroU64::new(10).unwrap(),
min_da_gas_price: 10,
max_da_gas_price: 11,
Expand All @@ -1118,7 +1126,7 @@ mod tests {
normal_range_size: 10,
capped_range_size: 100,
decrease_range_size: 4,
block_activity_threshold: 20,
block_activity_threshold: fuel_core_types::ClampedPercentage::new(20),
da_poll_interval: None,
starting_recorded_height: None,
record_metrics: false,
Expand Down
11 changes: 6 additions & 5 deletions crates/services/gas_price_service/src/v1/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ use fuel_core_storage::{
},
};
use fuel_core_types::{
ClampedPercentage,
blockchain::{
block::Block,
header::ConsensusParametersVersion,
Expand Down Expand Up @@ -290,7 +291,7 @@ fn zero_threshold_arbitrary_config() -> V1AlgorithmConfig {
new_exec_gas_price: 100,
min_exec_gas_price: 0,
exec_gas_price_change_percent: 10,
l2_block_fullness_threshold_percent: 0,
l2_block_fullness_threshold_percent: ClampedPercentage::new(0),
gas_price_factor: NonZeroU64::new(100).unwrap(),
min_da_gas_price: 0,
max_da_gas_price: 1,
Expand All @@ -300,7 +301,7 @@ fn zero_threshold_arbitrary_config() -> V1AlgorithmConfig {
normal_range_size: 0,
capped_range_size: 0,
decrease_range_size: 0,
block_activity_threshold: 0,
block_activity_threshold: ClampedPercentage::new(0),
da_poll_interval: None,
starting_recorded_height: None,
record_metrics: false,
Expand All @@ -327,7 +328,7 @@ fn different_arb_config() -> V1AlgorithmConfig {
new_exec_gas_price: 200,
min_exec_gas_price: 0,
exec_gas_price_change_percent: 20,
l2_block_fullness_threshold_percent: 0,
l2_block_fullness_threshold_percent: ClampedPercentage::new(0),
gas_price_factor: NonZeroU64::new(100).unwrap(),
min_da_gas_price: 0,
max_da_gas_price: 1,
Expand All @@ -337,7 +338,7 @@ fn different_arb_config() -> V1AlgorithmConfig {
normal_range_size: 0,
capped_range_size: 0,
decrease_range_size: 0,
block_activity_threshold: 0,
block_activity_threshold: ClampedPercentage::new(0),
da_poll_interval: None,
starting_recorded_height: None,
record_metrics: false,
Expand Down Expand Up @@ -816,7 +817,7 @@ fn algo_updater_override_values_match(
);
assert_eq!(
algo_updater.l2_block_fullness_threshold_percent,
config.l2_block_fullness_threshold_percent.into()
config.l2_block_fullness_threshold_percent
);
assert_eq!(algo_updater.gas_price_factor, config.gas_price_factor);
assert_eq!(algo_updater.min_da_gas_price, config.min_da_gas_price);
Expand Down
5 changes: 3 additions & 2 deletions crates/services/txpool_v2/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::{
};

use fuel_core_types::{
ClampedPercentage,
fuel_tx::{
Address,
ContractId,
Expand Down Expand Up @@ -143,7 +144,7 @@ pub struct Config {
/// TTL for transactions inside the pending pool.
pub pending_pool_tx_ttl: Duration,
/// Maximum percentage of the pool size to be used for the pending pool.
pub max_pending_pool_size_percentage: u16,
pub max_pending_pool_size_percentage: ClampedPercentage,
/// Enable metrics when set to true
pub metrics: bool,
}
Expand Down Expand Up @@ -206,7 +207,7 @@ impl Default for Config {
max_pending_read_pool_requests: 1000,
},
pending_pool_tx_ttl: Duration::from_secs(3),
max_pending_pool_size_percentage: 50,
max_pending_pool_size_percentage: ClampedPercentage::new(50),
metrics: false,
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/services/txpool_v2/src/pool_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,21 +624,21 @@ where
.config
.pool_limits
.max_gas
.saturating_mul(self.pool.config.max_pending_pool_size_percentage as u64)
.saturating_mul(*self.pool.config.max_pending_pool_size_percentage as u64)
.saturating_div(100);
let max_bytes = self
.pool
.config
.pool_limits
.max_bytes_size
.saturating_mul(self.pool.config.max_pending_pool_size_percentage as usize)
.saturating_mul(*self.pool.config.max_pending_pool_size_percentage as usize)
.saturating_div(100);
let max_txs = self
.pool
.config
.pool_limits
.max_txs
.saturating_mul(self.pool.config.max_pending_pool_size_percentage as usize)
.saturating_mul(*self.pool.config.max_pending_pool_size_percentage as usize)
.saturating_div(100);

if gas_used > max_gas || bytes_used > max_bytes || txs_used > max_txs {
Expand Down
3 changes: 2 additions & 1 deletion crates/services/txpool_v2/src/tests/tests_pending_pool.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use fuel_core_services::Service;
use fuel_core_types::{
ClampedPercentage,
fuel_tx::{
UniqueIdentifier,
UtxoId,
Expand Down Expand Up @@ -94,7 +95,7 @@ async fn test_tx__return_error_expired() {
async fn test_tx__directly_removed_not_enough_space() {
let mut universe = TestPoolUniverse::default();
universe.config.utxo_validation = true;
universe.config.max_pending_pool_size_percentage = 1;
universe.config.max_pending_pool_size_percentage = ClampedPercentage::new(1);
universe.config.pool_limits.max_txs = 1;

let (_, unset_input) = universe.create_output_and_input();
Expand Down
3 changes: 3 additions & 0 deletions crates/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,12 @@ pub use tai64;

pub mod blockchain;
pub mod entities;
pub mod primitives;
pub mod services;
pub mod signer;

pub use primitives::ClampedPercentage;

/// Re-export of some fuel-vm types
pub mod fuel_vm {
#[doc(no_inline)]
Expand Down
Loading