Skip to content

Commit

Permalink
WIP add new config values
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchTurner committed Dec 2, 2024
1 parent f7f60cd commit 1598c2d
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 87 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_gas_price = 1;
config.starting_exec_gas_price = 1;
config.block_producer.coinbase_recipient = Some(
ContractId::from_str(
"0x7777777777777777777777777777777777777777777777777777777777777777",
Expand Down
38 changes: 29 additions & 9 deletions bin/fuel-core/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,28 @@ pub struct Command {
pub native_executor_version: Option<StateTransitionBytecodeVersion>,

/// The starting gas price for the network
#[arg(long = "starting-gas-price", default_value = "0", env)]
pub starting_gas_price: u64,
#[arg(long = "starting-exec-gas-price", default_value = "0", env)]
pub starting_exec_gas_price: u64,

/// The percentage change in gas price per block
#[arg(long = "gas-price-change-percent", default_value = "0", env)]
pub gas_price_change_percent: u64,
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: u64,
pub gas_price_threshold_percent: u8,

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

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

/// The signing key used when producing blocks.
/// Setting via the `CONSENSUS_KEY_SECRET` ENV var is preferred.
Expand Down Expand Up @@ -299,10 +307,12 @@ impl Command {
debug,
utxo_validation,
native_executor_version,
starting_gas_price,
starting_exec_gas_price: starting_gas_price,
gas_price_change_percent,
min_gas_price,
gas_price_threshold_percent,
min_da_gas_price,
da_committer_url,
consensus_key,
#[cfg(feature = "aws-kms")]
consensus_aws_kms,
Expand Down Expand Up @@ -588,10 +598,10 @@ impl Command {
coinbase_recipient,
metrics: disabled_metrics.is_enabled(Module::Producer),
},
starting_gas_price,
gas_price_change_percent,
min_gas_price,
gas_price_threshold_percent,
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,
block_importer,
da_compression,
#[cfg(feature = "relayer")]
Expand All @@ -606,6 +616,16 @@ 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"),
min_da_gas_price,
max_da_gas_price_change_percent: 0,
da_p_component: 0,
da_d_component: 0,
activity_normal_range_size: 100,
activity_capped_range_size: 0,
activity_decrease_range_size: 0,
da_committer_url,
block_activity_threshold: 0,
};
Ok(config)
}
Expand Down
19 changes: 14 additions & 5 deletions crates/fuel-core/src/service/adapters/gas_price_adapters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,20 @@ impl GasPriceData for Database<GasPriceDatabase> {

impl From<Config> for GasPriceServiceConfig {
fn from(value: Config) -> Self {
GasPriceServiceConfig::new_v0(
value.starting_gas_price,
value.min_gas_price,
value.gas_price_change_percent,
value.gas_price_threshold_percent,
GasPriceServiceConfig::new_v1(
value.starting_exec_gas_price,
value.min_exec_gas_price,
value.exec_gas_price_change_percent,
value.exec_gas_price_threshold_percent,
value.da_gas_price_factor,
value.min_da_gas_price,
value.max_da_gas_price_change_percent,
value.da_p_component,
value.da_d_component,
value.activity_normal_range_size,
value.activity_capped_range_size,
value.activity_decrease_range_size,
value.block_activity_threshold,
)
}
}
Expand Down
55 changes: 39 additions & 16 deletions crates/fuel-core/src/service/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use clap::ValueEnum;
use fuel_core_poa::signer::SignMode;
use std::{
num::NonZeroU64,
path::PathBuf,
time::Duration,
};

use clap::ValueEnum;
use fuel_core_poa::signer::SignMode;
use strum_macros::{
Display,
EnumString,
Expand Down Expand Up @@ -57,10 +57,11 @@ pub struct Config {
pub vm: VMConfig,
pub txpool: TxPoolConfig,
pub block_producer: fuel_core_producer::Config,
pub starting_gas_price: u64,
pub gas_price_change_percent: u64,
pub min_gas_price: u64,
pub gas_price_threshold_percent: u64,
pub starting_exec_gas_price: u64,
pub exec_gas_price_change_percent: u16,
pub min_exec_gas_price: u64,
pub exec_gas_price_threshold_percent: u8,
pub da_committer_url: Option<String>,
pub da_compression: DaCompressionConfig,
pub block_importer: fuel_core_importer::Config,
#[cfg(feature = "relayer")]
Expand All @@ -78,6 +79,15 @@ pub struct Config {
pub time_until_synced: Duration,
/// The size of the memory pool in number of `MemoryInstance`s.
pub memory_pool_size: usize,
pub da_gas_price_factor: NonZeroU64,
pub min_da_gas_price: u64,
pub max_da_gas_price_change_percent: u16,
pub da_p_component: i64,
pub da_d_component: i64,
pub activity_normal_range_size: u16,
pub activity_capped_range_size: u16,
pub activity_decrease_range_size: u16,
pub block_activity_threshold: u8,
}

impl Config {
Expand All @@ -96,14 +106,17 @@ impl Config {
chain_config: ChainConfig,
state_config: StateConfig,
) -> Self {
Self::local_node_with_reader(SnapshotReader::new_in_memory(
chain_config,
state_config,
))
Self::local_node_with_reader(
SnapshotReader::new_in_memory(chain_config, state_config),
None,
)
}

#[cfg(feature = "test-helpers")]
pub fn local_node_with_reader(snapshot_reader: SnapshotReader) -> Self {
pub fn local_node_with_reader(
snapshot_reader: SnapshotReader,
da_committer_url: Option<String>,
) -> Self {
let block_importer = fuel_core_importer::Config::new(false);
let latest_block = snapshot_reader.last_block_config();
// In tests, we always want to use the native executor as a default configuration.
Expand Down Expand Up @@ -171,10 +184,10 @@ impl Config {
..Default::default()
},
da_compression: DaCompressionConfig::Disabled,
starting_gas_price,
gas_price_change_percent,
min_gas_price,
gas_price_threshold_percent,
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,
block_importer,
#[cfg(feature = "relayer")]
relayer: None,
Expand All @@ -190,6 +203,16 @@ impl Config {
min_connected_reserved_peers: 0,
time_until_synced: Duration::ZERO,
memory_pool_size: 4,
da_gas_price_factor: NonZeroU64::new(100).expect("100 is not zero"),
min_da_gas_price: 0,
max_da_gas_price_change_percent: 0,
da_p_component: 0,
da_d_component: 0,
activity_normal_range_size: 0,
activity_capped_range_size: 0,
activity_decrease_range_size: 0,
da_committer_url,
block_activity_threshold: 0,
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/fuel-core/src/service/sub_services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ pub fn init_sub_services(
let block_stream = importer_adapter.events_shared_result();
let metadata = StructuredStorage::new(database.gas_price().clone());

let committer = BlockCommitterHttpApi::new("lolz".to_string());
let committer = BlockCommitterHttpApi::new(config.da_committer_url.clone());
let da_source = BlockCommitterDaBlockCosts::new(committer, None);
let on_chain_db = database.on_chain().clone();

Expand Down
33 changes: 31 additions & 2 deletions crates/services/gas_price_service/src/ports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use fuel_core_types::{
fuel_tx::Transaction,
fuel_types::BlockHeight,
};
use std::num::NonZeroU64;

pub trait L2Data: Send + Sync {
fn latest_height(&self) -> StorageResult<BlockHeight>;
Expand Down Expand Up @@ -54,8 +55,36 @@ impl GasPriceServiceConfig {
})
}

pub fn new_v1(metadata: V1AlgorithmConfig) -> Self {
Self::V1(metadata)
pub fn new_v1(
new_exec_gas_price: u64,
min_exec_gas_price: u64,
exec_gas_price_change_percent: u16,
l2_block_fullness_threshold_percent: u8,
gas_price_factor: NonZeroU64,
min_da_gas_price: u64,
max_da_gas_price_change_percent: u16,
da_p_component: i64,
da_d_component: i64,
normal_range_size: u16,
capped_range_size: u16,
decrease_range_size: u16,
block_activity_threshold: u8,
) -> Self {
Self::V1(V1AlgorithmConfig {
new_exec_gas_price,
min_exec_gas_price,
exec_gas_price_change_percent,
l2_block_fullness_threshold_percent,
gas_price_factor,
min_da_gas_price,
max_da_gas_price_change_percent,
da_p_component,
da_d_component,
normal_range_size,
capped_range_size,
decrease_range_size,
block_activity_threshold,
})
}

/// Extract V0AlgorithmConfig if it is of V0 version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,11 @@ where

pub struct BlockCommitterHttpApi {
client: reqwest::Client,
url: String,
url: Option<String>,
}

impl BlockCommitterHttpApi {
pub fn new(url: String) -> Self {
pub fn new(url: Option<String>) -> Self {
Self {
client: reqwest::Client::new(),
url,
Expand All @@ -135,37 +135,49 @@ impl BlockCommitterHttpApi {
#[async_trait::async_trait]
impl BlockCommitterApi for BlockCommitterHttpApi {
async fn get_latest_costs(&self) -> DaBlockCostsResult<Option<RawDaBlockCosts>> {
let val = self.client.get(&self.url).send().await?;
let response = val.json::<RawDaBlockCosts>().await?;
Ok(Some(response))
if let Some(url) = &self.url {
let val = self.client.get(url).send().await?;
let response = val.json::<RawDaBlockCosts>().await?;
Ok(Some(response))
} else {
Ok(None)
}
}

async fn get_costs_by_seqno(
&self,
number: u32,
) -> DaBlockCostsResult<Option<RawDaBlockCosts>> {
let response = self
.client
.get(&format!("{}/{}", self.url, number))
.send()
.await?
.json::<RawDaBlockCosts>()
.await?;
Ok(Some(response))
if let Some(url) = &self.url {
let response = self
.client
.get(&format!("{}/{}", url, number))
.send()
.await?
.json::<RawDaBlockCosts>()
.await?;
Ok(Some(response))
} else {
Ok(None)
}
}

async fn get_cost_bundles_by_range(
&self,
range: core::ops::Range<u32>,
) -> DaBlockCostsResult<Vec<Option<RawDaBlockCosts>>> {
let response = self
.client
.get(&format!("{}/{}-{}", self.url, range.start, range.end))
.send()
.await?
.json::<Vec<RawDaBlockCosts>>()
.await?;
Ok(response.into_iter().map(Some).collect())
if let Some(url) = &self.url {
let response = self
.client
.get(&format!("{}/{}-{}", url, range.start, range.end))
.send()
.await?
.json::<Vec<RawDaBlockCosts>>()
.await?;
Ok(response.into_iter().map(Some).collect())
} else {
Ok(vec![])
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion crates/services/gas_price_service/src/v1/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,9 @@ pub fn updater_from_config<U>(
.new_exec_gas_price
.saturating_mul(value.gas_price_factor.get()),
l2_block_height: 0,
new_scaled_da_gas_price: value.min_da_gas_price,
new_scaled_da_gas_price: value
.min_da_gas_price
.saturating_mul(value.gas_price_factor.get()),
gas_price_factor: value.gas_price_factor,
total_da_rewards_excess: 0,
latest_known_total_da_cost_excess: 0,
Expand Down
2 changes: 1 addition & 1 deletion tests/test-helpers/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl TestSetupBuilder {
utxo_validation: self.utxo_validation,
txpool: fuel_core_txpool::config::Config::default(),
block_production: self.trigger,
starting_gas_price: self.starting_gas_price,
starting_exec_gas_price: self.starting_gas_price,
..Config::local_node_with_configs(chain_conf, state)
};
assert_eq!(config.combined_db_config.database_type, DbType::RocksDb);
Expand Down
4 changes: 2 additions & 2 deletions tests/test-helpers/src/fuel_core_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl FuelCoreDriver {

pub async fn spawn_feeless(extra_args: &[&str]) -> anyhow::Result<Self> {
let mut args = vec![
"--starting-gas-price",
"--starting-exec-gas-price",
"0",
"--gas-price-change-percent",
"0",
Expand All @@ -36,7 +36,7 @@ impl FuelCoreDriver {
extra_args: &[&str],
) -> anyhow::Result<Self> {
let mut args = vec![
"--starting-gas-price",
"--starting-exec-gas-price",
"0",
"--gas-price-change-percent",
"0",
Expand Down
Loading

0 comments on commit 1598c2d

Please sign in to comment.