Skip to content

Commit

Permalink
Refactor all the gas price cli args, fix downstream problems (#2670)
Browse files Browse the repository at this point in the history
## Linked Issues/PRs
<!-- List of related issues/PRs -->
#2555

## Description
<!-- List of detailed changes -->

There are a lot of gas price args. Now they are all in their own place
:) Doesn't change API.
  • Loading branch information
MitchTurner authored Feb 7, 2025
1 parent e41d936 commit 8224289
Show file tree
Hide file tree
Showing 10 changed files with 286 additions and 205 deletions.
2 changes: 1 addition & 1 deletion bin/e2e-test-client/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ fn dev_config() -> Config {
let reader = reader.with_chain_config(chain_config);

let mut config = Config::local_node_with_reader(reader);
config.starting_exec_gas_price = 1;
config.gas_price_config.starting_exec_gas_price = 1;
config.block_producer.coinbase_recipient = Some(
ContractId::from_str(
"0x7777777777777777777777777777777777777777777777777777777777777777",
Expand Down
155 changes: 45 additions & 110 deletions bin/fuel-core/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ use crate::{
};
use anyhow::Context;
use clap::Parser;
#[cfg(feature = "production")]
use fuel_core::service::sub_services::DEFAULT_GAS_PRICE_CHANGE_PERCENT;
use fuel_core::{
chain_config::default_consensus_dev_key,
combined_database::{
Expand Down Expand Up @@ -90,11 +88,12 @@ use tracing::{
trace,
warn,
};
use url::Url;

#[cfg(feature = "rocksdb")]
use fuel_core::state::historical_rocksdb::StateRewindPolicy;

use crate::cli::run::gas_price::GasPriceArgs;
use fuel_core::service::config::GasPriceConfig;
#[cfg(feature = "parallel-executor")]
use std::num::NonZeroUsize;

Expand All @@ -111,6 +110,8 @@ mod profiling;
mod relayer;
mod tx_pool;

mod gas_price;

/// Run the Fuel client node locally.
#[derive(Debug, Clone, Parser)]
pub struct Command {
Expand Down Expand Up @@ -204,83 +205,9 @@ pub struct Command {
#[arg(long = "executor-number-of-cores", env, default_value = "1")]
pub executor_number_of_cores: NonZeroUsize,

/// The starting execution gas price for the network
#[cfg_attr(
feature = "production",
arg(long = "starting-gas-price", default_value = "1000", env)
)]
#[cfg_attr(
not(feature = "production"),
arg(long = "starting-gas-price", default_value = "0", env)
)]
pub starting_gas_price: u64,

/// The percentage change in gas price per block
#[cfg_attr(
feature = "production",
arg(long = "gas-price-change-percent", default_value_t = DEFAULT_GAS_PRICE_CHANGE_PERCENT, env)
)]
#[cfg_attr(
not(feature = "production"),
arg(long = "gas-price-change-percent", default_value = "0", env)
)]
pub gas_price_change_percent: u16,

/// The minimum allowed gas price
#[arg(long = "min-gas-price", default_value = "0", env)]
pub min_gas_price: u64,

/// The percentage threshold for gas price increase
#[arg(long = "gas-price-threshold-percent", default_value = "50", env)]
pub gas_price_threshold_percent: u8,

/// Minimum DA gas price
#[cfg_attr(
feature = "production",
arg(long = "min-da-gas-price", default_value = "1000", env)
)]
#[cfg_attr(
not(feature = "production"),
arg(long = "min-da-gas-price", default_value = "0", env)
)]
pub min_da_gas_price: u64,

/// Maximum allowed gas price for DA.
#[arg(long = "max-da-gas-price", default_value = "100000", env)]
pub max_da_gas_price: u64,

/// P component of DA gas price calculation
/// **NOTE**: This is the **inverse** gain of a typical P controller.
/// Increasing this value will reduce gas price fluctuations.
#[arg(
long = "da-gas-price-p-component",
default_value = "799999999999993",
env
)]
pub da_gas_price_p_component: i64,

/// D component of DA gas price calculation
/// **NOTE**: This is the **inverse** anticipatory control factor of a typical PD controller.
/// Increasing this value will reduce the dampening effect of quick algorithm changes.
#[arg(
long = "da-gas-price-d-component",
default_value = "10000000000000000",
env
)]
pub da_gas_price_d_component: i64,

/// The URL for the DA Block Committer info
#[arg(long = "da-committer-url", env)]
pub da_committer_url: Option<Url>,

/// The interval at which the `DaSourceService` polls for new data
#[arg(long = "da-poll-interval", env)]
pub da_poll_interval: Option<humantime::Duration>,

/// The L2 height the Gas Price Service will assume is already recorded on DA
/// i.e. If you want the Gas Price Service to look for the costs of block 1000, set to 999
#[arg(long = "da-starting-recorded-height", env)]
da_starting_recorded_height: Option<u32>,
/// All the configurations for the gas price service.
#[clap(flatten)]
pub gas_price: gas_price::GasPriceArgs,

/// The signing key used when producing blocks.
/// Setting via the `CONSENSUS_KEY_SECRET` ENV var is preferred.
Expand Down Expand Up @@ -382,17 +309,7 @@ impl Command {
native_executor_version,
#[cfg(feature = "parallel-executor")]
executor_number_of_cores,
starting_gas_price,
gas_price_change_percent,
min_gas_price,
gas_price_threshold_percent,
min_da_gas_price,
max_da_gas_price,
da_gas_price_p_component,
da_gas_price_d_component,
da_committer_url,
da_poll_interval,
da_starting_recorded_height: starting_recorded_height,
gas_price,
consensus_key,
#[cfg(feature = "aws-kms")]
consensus_aws_kms,
Expand All @@ -419,6 +336,20 @@ impl Command {
profiling: _,
} = self;

let GasPriceArgs {
starting_gas_price,
gas_price_change_percent,
min_gas_price,
gas_price_threshold_percent,
min_da_gas_price,
max_da_gas_price,
da_gas_price_p_component,
da_gas_price_d_component,
da_committer_url,
da_poll_interval,
da_starting_recorded_height,
} = gas_price;

let enabled_metrics = disabled_metrics.list_of_enabled();

if !enabled_metrics.is_empty() {
Expand All @@ -427,7 +358,7 @@ impl Command {
info!("All metrics are disabled");
}

if max_da_gas_price < min_da_gas_price {
if gas_price.max_da_gas_price < gas_price.min_da_gas_price {
anyhow::bail!(
"The maximum DA gas price must be greater than or equal to the minimum DA gas price"
);
Expand Down Expand Up @@ -629,6 +560,27 @@ impl Command {
max_pending_write_pool_requests: tx_max_pending_write_requests,
};

let gas_price_config = GasPriceConfig {
starting_exec_gas_price: gas_price.starting_gas_price,
exec_gas_price_change_percent: gas_price.gas_price_change_percent,
min_exec_gas_price: gas_price.min_gas_price,
exec_gas_price_threshold_percent: gas_price.gas_price_threshold_percent,
da_gas_price_factor: NonZeroU64::new(100).expect("100 is not zero"),
starting_recorded_height: da_starting_recorded_height,
min_da_gas_price,
max_da_gas_price,
max_da_gas_price_change_percent: gas_price.gas_price_change_percent,
da_gas_price_p_component,
da_gas_price_d_component,
gas_price_metrics,
activity_normal_range_size: 100,
activity_capped_range_size: 0,
activity_decrease_range_size: 0,
da_committer_url,
block_activity_threshold: 0,
da_poll_interval: gas_price.da_poll_interval.map(Into::into),
};

let config = Config {
graphql_config: GraphQLConfig {
addr,
Expand Down Expand Up @@ -697,10 +649,7 @@ impl Command {
coinbase_recipient,
metrics: disabled_metrics.is_enabled(Module::Producer),
},
starting_exec_gas_price: starting_gas_price,
exec_gas_price_change_percent: gas_price_change_percent,
min_exec_gas_price: min_gas_price,
exec_gas_price_threshold_percent: gas_price_threshold_percent,
gas_price_config,
block_importer,
da_compression,
#[cfg(feature = "relayer")]
Expand All @@ -717,20 +666,6 @@ impl Command {
min_connected_reserved_peers,
time_until_synced: time_until_synced.into(),
memory_pool_size,
da_gas_price_factor: NonZeroU64::new(100).expect("100 is not zero"),
starting_recorded_height,
min_da_gas_price,
max_da_gas_price,
max_da_gas_price_change_percent: gas_price_change_percent,
da_gas_price_p_component,
da_gas_price_d_component,
gas_price_metrics,
activity_normal_range_size: 100,
activity_capped_range_size: 0,
activity_decrease_range_size: 0,
da_committer_url,
block_activity_threshold: 0,
da_poll_interval: da_poll_interval.map(Into::into),
};
Ok(config)
}
Expand Down
85 changes: 85 additions & 0 deletions bin/fuel-core/src/cli/run/gas_price.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
use clap::Args;
#[cfg(feature = "production")]
use fuel_core::service::sub_services::DEFAULT_GAS_PRICE_CHANGE_PERCENT;
use url::Url;

#[derive(Debug, Clone, Args)]
pub struct GasPriceArgs {
/// The starting execution gas price for the network
#[cfg_attr(
feature = "production",
arg(long = "starting-gas-price", default_value = "1000", env)
)]
#[cfg_attr(
not(feature = "production"),
arg(long = "starting-gas-price", default_value = "0", env)
)]
pub starting_gas_price: u64,

/// The percentage change in gas price per block
#[cfg_attr(
feature = "production",
arg(long = "gas-price-change-percent", default_value_t = DEFAULT_GAS_PRICE_CHANGE_PERCENT, env)
)]
#[cfg_attr(
not(feature = "production"),
arg(long = "gas-price-change-percent", default_value = "0", env)
)]
pub gas_price_change_percent: u16,

/// The minimum allowed gas price
#[arg(long = "min-gas-price", default_value = "0", env)]
pub min_gas_price: u64,

/// The percentage threshold for gas price increase
#[arg(long = "gas-price-threshold-percent", default_value = "50", env)]
pub gas_price_threshold_percent: u8,

/// Minimum DA gas price
#[cfg_attr(
feature = "production",
arg(long = "min-da-gas-price", default_value = "1000", env)
)]
#[cfg_attr(
not(feature = "production"),
arg(long = "min-da-gas-price", default_value = "0", env)
)]
pub min_da_gas_price: u64,

/// Maximum allowed gas price for DA.
#[arg(long = "max-da-gas-price", default_value = "100000", env)]
pub max_da_gas_price: u64,

/// P component of DA gas price calculation
/// **NOTE**: This is the **inverse** gain of a typical P controller.
/// Increasing this value will reduce gas price fluctuations.
#[arg(
long = "da-gas-price-p-component",
default_value = "799999999999993",
env
)]
pub da_gas_price_p_component: i64,

/// D component of DA gas price calculation
/// **NOTE**: This is the **inverse** anticipatory control factor of a typical PD controller.
/// Increasing this value will reduce the dampening effect of quick algorithm changes.
#[arg(
long = "da-gas-price-d-component",
default_value = "10000000000000000",
env
)]
pub da_gas_price_d_component: i64,

/// The URL for the DA Block Committer info
#[arg(long = "da-committer-url", env)]
pub da_committer_url: Option<Url>,

/// The interval at which the `DaSourceService` polls for new data
#[arg(long = "da-poll-interval", env)]
pub da_poll_interval: Option<humantime::Duration>,

/// The L2 height the Gas Price Service will assume is already recorded on DA
/// i.e. If you want the Gas Price Service to look for the costs of block 1000, set to 999
#[arg(long = "da-starting-recorded-height", env)]
pub da_starting_recorded_height: Option<u32>,
}
2 changes: 1 addition & 1 deletion crates/fuel-core/src/p2p_test_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ pub fn make_config(
node_config.utxo_validation = true;
node_config.name = name;
if let Some(min_gas_price) = config_overrides.min_exec_gas_price {
node_config.min_exec_gas_price = min_gas_price;
node_config.gas_price_config.min_exec_gas_price = min_gas_price;
}
node_config
}
Expand Down
Loading

0 comments on commit 8224289

Please sign in to comment.