Skip to content

Commit

Permalink
Integrate with V1 algo for tests (FuelLabs#2469)
Browse files Browse the repository at this point in the history
## Linked Issues/PRs

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

In this PR we:
- upgrade the node to use the V1 algorithm for block production and
TxPool
- modify the graphql service to use the latest block for gas price
estimation
- add some CLI args for the V1 configuration with defaults
- add support for querying block committer API
- improve syncing logic for startup

## Checklist
- [ ] Breaking changes are clearly marked as such in the PR description
and changelog
- [ ] New behavior is reflected in tests
- [ ] [The specification](https://github.com/FuelLabs/fuel-specs/)
matches the implemented behavior (link update PR if changes are needed)

### Before requesting review
- [ ] I have reviewed the code myself
- [ ] I have created follow-up issues caused by this PR and linked them
here

### After merging, notify other teams

[Add or remove entries as needed]

- [ ] [Rust SDK](https://github.com/FuelLabs/fuels-rs/)
- [ ] [Sway compiler](https://github.com/FuelLabs/sway/)
- [ ] [Platform
documentation](https://github.com/FuelLabs/devrel-requests/issues/new?assignees=&labels=new+request&projects=&template=NEW-REQUEST.yml&title=%5BRequest%5D%3A+)
(for out-of-organization contributors, the person merging the PR will do
this)
- [ ] Someone else?

---------

Co-authored-by: Rafał Chabowski <[email protected]>
Co-authored-by: Green Baneling <[email protected]>
Co-authored-by: Mårten Blankfors <[email protected]>
Co-authored-by: Aaryamann Challani <[email protected]>
Co-authored-by: Brandon Kite <[email protected]>
  • Loading branch information
6 people authored Jan 14, 2025
1 parent a955708 commit be1bc51
Show file tree
Hide file tree
Showing 53 changed files with 2,465 additions and 834 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ node_modules/
package-lock.json
package.json
bin/fuel-core/chainspec/local-testnet/state_transition_bytecode.wasm

.DS_Store
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [2535](https://github.com/FuelLabs/fuel-core/pull/2535): Expose `backup` and `restore` APIs on the `CombinedDatabase` struct to create portable backups and restore from them.

### Fixed
- [2469](https://github.com/FuelLabs/fuel-core/pull/2469): Improved the logic for syncing the gas price database with on_chain database
- [2365](https://github.com/FuelLabs/fuel-core/pull/2365): Fixed the error during dry run in the case of race condition.
- [2366](https://github.com/FuelLabs/fuel-core/pull/2366): The `importer_gas_price_for_block` metric is properly collected.
- [2369](https://github.com/FuelLabs/fuel-core/pull/2369): The `transaction_insertion_time_in_thread_pool_milliseconds` metric is properly collected.
Expand All @@ -50,6 +51,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [2511](https://github.com/FuelLabs/fuel-core/pull/2511): Fix backward compatibility of V0Metadata in gas price db.

### Changed
- [2469](https://github.com/FuelLabs/fuel-core/pull/2469): Updated adapter for querying costs from DA Block committer API
- [2469](https://github.com/FuelLabs/fuel-core/pull/2469): Use the gas price from the latest block to estimate future gas prices
- [2501](https://github.com/FuelLabs/fuel-core/pull/2501): Use gas price from block for estimating future gas prices
- [2468](https://github.com/FuelLabs/fuel-core/pull/2468): Abstract unrecorded blocks concept for V1 algorithm, create new storage impl. Introduce `TransactionableStorage` trait to allow atomic changes to the storage.
- [2295](https://github.com/FuelLabs/fuel-core/pull/2295): `CombinedDb::from_config` now respects `state_rewind_policy` with tmp RocksDB.
Expand All @@ -62,6 +65,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- [2463](https://github.com/FuelLabs/fuel-core/pull/2463): The `coinsToSpend` GraphQL query handler now uses index to provide the response in a more performant way. As the index is not created retroactively, the client must be initialized with an empty database and synced from the genesis block to utilize it. Otherwise, the legacy way of retrieving data will be used.

#### Breaking
- [2469](https://github.com/FuelLabs/fuel-core/pull/2469): Move from `GasPriceServicev0` to `GasPriceServiceV1`. Include new config values.
- [2438](https://github.com/FuelLabs/fuel-core/pull/2438): The `fuel-core-client` can only work with new version of the `fuel-core`. The `0.40` and all older versions are not supported.
- [2438](https://github.com/FuelLabs/fuel-core/pull/2438): Updated `fuel-vm` to `0.59.1` release. Check [release notes](https://github.com/FuelLabs/fuel-vm/releases/tag/v0.59.0) for more details.
- [2389](https://github.com/FuelLabs/fuel-core/pull/2258): Updated the `messageProof` GraphQL schema to return a non-nullable `MessageProof`.
Expand Down
50 changes: 50 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,4 @@ itertools = { version = "0.12", default-features = false }
insta = "1.8"
tempfile = "3.4"
tikv-jemallocator = "0.5"
url = "2.2"
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
2 changes: 1 addition & 1 deletion bin/fuel-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ tracing-subscriber = { workspace = true, features = [
"env-filter",
"json",
] }
url = { version = "2.2", optional = true }
url = { workspace = true, optional = true }

[dev-dependencies]
fuel-core = { workspace = true, features = ["test-helpers"] }
Expand Down
100 changes: 91 additions & 9 deletions bin/fuel-core/src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ use tracing::{
trace,
warn,
};
use url::Url;

#[cfg(feature = "rocksdb")]
use fuel_core::state::historical_rocksdb::StateRewindPolicy;
Expand Down Expand Up @@ -192,21 +193,78 @@ pub struct Command {
#[arg(long = "native-executor-version", env)]
pub native_executor_version: Option<StateTransitionBytecodeVersion>,

/// The starting gas price for the network
#[arg(long = "starting-gas-price", default_value = "0", env)]
/// 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
#[arg(long = "gas-price-change-percent", default_value = "0", env)]
pub gas_price_change_percent: u64,
#[cfg_attr(
feature = "production",
arg(long = "gas-price-change-percent", default_value = "10", 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: u64,
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 signing key used when producing blocks.
/// Setting via the `CONSENSUS_KEY_SECRET` ENV var is preferred.
Expand Down Expand Up @@ -310,6 +368,12 @@ impl Command {
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,
consensus_key,
#[cfg(feature = "aws-kms")]
consensus_aws_kms,
Expand Down Expand Up @@ -344,6 +408,12 @@ impl Command {
info!("All metrics are disabled");
}

if max_da_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"
);
}

let addr = net::SocketAddr::new(graphql.ip, graphql.port);

let snapshot_reader = match snapshot.as_ref() {
Expand Down Expand Up @@ -604,10 +674,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 @@ -624,6 +694,18 @@ 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,
max_da_gas_price_change_percent: gas_price_change_percent,
da_gas_price_p_component,
da_gas_price_d_component,
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
2 changes: 1 addition & 1 deletion ci_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ cargo make check --all-features --locked &&
cargo make check --locked &&
OVERRIDE_CHAIN_CONFIGS=true cargo test --test integration_tests local_node &&
cargo nextest run --workspace &&
FUEL_ALWAYS_USE_WASM=true cargo nextest run --all-features --workspace &&
FUEL_ALWAYS_USE_WASM=true cargo test run --all-features --workspace &&
cargo nextest run -p fuel-core --no-default-features &&
cargo nextest run -p fuel-core-client --no-default-features &&
cargo nextest run -p fuel-core-chain-config --no-default-features &&
Expand Down
1 change: 1 addition & 0 deletions crates/fuel-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ tokio-util = { workspace = true }
tower = { version = "0.4", features = ["limit"] }
tower-http = { version = "0.4", features = ["set-header", "trace", "timeout"] }
tracing = { workspace = true }
url = { workspace = true }
uuid = { version = "1.1", features = ["v4"] }

[dev-dependencies]
Expand Down
1 change: 1 addition & 0 deletions crates/fuel-core/src/combined_database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ impl CombinedDatabase {
self.on_chain.check_version()?;
self.off_chain.check_version()?;
self.relayer.check_version()?;
self.gas_price.check_version()?;
Ok(())
}

Expand Down
Loading

0 comments on commit be1bc51

Please sign in to comment.