Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create uninitialized task for v1 gas price service #2442

Merged
merged 54 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
448d8c2
Remove height parameter, change tests
MitchTurner Oct 30, 2024
c5866a3
Modify to take vec instead of range
MitchTurner Oct 30, 2024
c54f098
Add tests to make sure it is sane
MitchTurner Oct 30, 2024
fcf4477
Rename variable
MitchTurner Oct 30, 2024
159d5b4
Fix analyzer
MitchTurner Oct 30, 2024
ba080ff
Rename some params
MitchTurner Oct 30, 2024
d2b3c28
Use slice instead of vec
MitchTurner Oct 30, 2024
128a9ba
Merge branch 'master' into feature/allow-DA-blocks-to-be-received-out…
MitchTurner Oct 30, 2024
5f19932
Cleanup code a bit
MitchTurner Oct 31, 2024
922f3e0
Update crates/fuel-gas-price-algorithm/src/v1/tests/update_da_record_…
MitchTurner Oct 31, 2024
d7e9bdd
Pick nit
MitchTurner Oct 31, 2024
12c517e
Merge branch 'master' into feature/allow-DA-blocks-to-be-received-out…
MitchTurner Oct 31, 2024
f8dca06
Merge branch 'master' into feature/allow-DA-blocks-to-be-received-out…
MitchTurner Oct 31, 2024
2bb86fe
Optimize projected calc by caching running total
MitchTurner Nov 1, 2024
60771e9
Merge branch 'master' into feature/allow-DA-blocks-to-be-received-out…
MitchTurner Nov 1, 2024
03da963
Fix analyzer
MitchTurner Nov 1, 2024
ea14e6f
Simplify metadata
MitchTurner Nov 1, 2024
b615b33
Merge branch 'master' into feature/allow-DA-blocks-to-be-received-out…
MitchTurner Nov 14, 2024
cfd1a71
Merge remote-tracking branch 'origin' into feature/allow-DA-blocks-to…
MitchTurner Nov 17, 2024
d983891
Resolve logical conflicts from merge
MitchTurner Nov 17, 2024
4c2b844
Merge branch 'master' into feature/allow-DA-blocks-to-be-received-out…
MitchTurner Nov 17, 2024
1836656
WIP
MitchTurner Nov 18, 2024
48fe978
Merge branch 'master' into feature/allow-DA-blocks-to-be-received-out…
MitchTurner Nov 18, 2024
18fefb7
Merge branch 'feature/allow-DA-blocks-to-be-received-out-of-order' in…
MitchTurner Nov 19, 2024
b15a93f
Get compiling
MitchTurner Nov 19, 2024
279191c
Start adding tests
MitchTurner Nov 19, 2024
63b0266
Get existing tests passing
MitchTurner Nov 19, 2024
477c731
WIP
MitchTurner Nov 19, 2024
b578a8e
Merge branch 'master' into feature/allow-DA-blocks-to-be-received-out…
MitchTurner Nov 19, 2024
7ca55c7
Ignore entire batches with blocks not in the unrecorded_blocks
MitchTurner Nov 19, 2024
6ac41de
Add comments to explain unexpected behavior
MitchTurner Nov 19, 2024
f2af4aa
Merge branch 'master' into feature/allow-DA-blocks-to-be-received-out…
MitchTurner Nov 20, 2024
4e07415
Merge branch 'feature/allow-DA-blocks-to-be-received-out-of-order' in…
MitchTurner Nov 20, 2024
cc90cbd
Fix tracing messages to be emitted at the right time
MitchTurner Nov 20, 2024
11df7ae
Merge branch 'feature/allow-DA-blocks-to-be-received-out-of-order' in…
MitchTurner Nov 20, 2024
7ac01aa
Fix logic to always remove recorded blocks, use predicted cost as bes…
MitchTurner Nov 20, 2024
ca6e1e5
Merge branch 'feature/allow-DA-blocks-to-be-received-out-of-order' in…
MitchTurner Nov 20, 2024
2592ad0
Update CHANGELOG
MitchTurner Nov 20, 2024
eb233ab
Remove some TODOs
MitchTurner Nov 20, 2024
d32b347
Remove other todo
MitchTurner Nov 20, 2024
9f78fa6
Add tests, fix bad bug
MitchTurner Nov 20, 2024
6b9969c
Merge branch 'feature/allow-DA-blocks-to-be-received-out-of-order' in…
MitchTurner Nov 20, 2024
fc8c427
Fix copy-paste errors
MitchTurner Nov 20, 2024
87dc547
Fix broken tests
MitchTurner Nov 20, 2024
008f5fb
Correct test, use trace instead of debug
MitchTurner Nov 27, 2024
a409e6e
Merge remote-tracking branch 'origin' into feature/init-task-for-v1-g…
MitchTurner Nov 29, 2024
2a06ec0
Merge branch 'master' into feature/init-task-for-v1-gas-price-service
MitchTurner Nov 30, 2024
b9d6571
Update crates/services/gas_price_service/src/v0/service.rs
MitchTurner Dec 3, 2024
0c4640e
Simplify generic constraints
MitchTurner Dec 3, 2024
f443289
Merge branch 'master' into feature/init-task-for-v1-gas-price-service
MitchTurner Dec 4, 2024
f43f00d
Merge branch 'master' into feature/init-task-for-v1-gas-price-service
MitchTurner Dec 6, 2024
51d41c7
Correct typo
MitchTurner Dec 6, 2024
a642cb7
Use relevant config for v1 constructor
MitchTurner Dec 6, 2024
0b6b1d9
Add todo
MitchTurner Dec 6, 2024
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased]

### Added
- [2442](https://github.com/FuelLabs/fuel-core/pull/2442): Add uninitialized task for V1 gas price service
- [2154](https://github.com/FuelLabs/fuel-core/pull/2154): Added `Unknown` variant to `ConsensusParameters` graphql queries
- [2154](https://github.com/FuelLabs/fuel-core/pull/2154): Added `Unknown` variant to `Block` graphql queries
- [2154](https://github.com/FuelLabs/fuel-core/pull/2154): Added `TransactionType` type in `fuel-client`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ pub fn get_block_info(
Ok(info)
}

fn mint_values(block: &Block<Transaction>) -> GasPriceResult<(u64, u64)> {
pub(crate) fn mint_values(block: &Block<Transaction>) -> GasPriceResult<(u64, u64)> {
let mint = block
.transactions()
.last()
Expand All @@ -121,6 +121,13 @@ fn mint_values(block: &Block<Transaction>) -> GasPriceResult<(u64, u64)> {
})?;
Ok((*mint.mint_amount(), *mint.gas_price()))
}

// TODO: Don't take a direct dependency on `Postcard` as it's not guaranteed to be the encoding format
// https://github.com/FuelLabs/fuel-core/issues/2443
pub(crate) fn block_bytes(block: &Block<Transaction>) -> u64 {
Postcard::encode(block).len() as u64
}

fn block_used_gas(
fee: u64,
gas_price: u64,
Expand Down
2 changes: 2 additions & 0 deletions crates/services/gas_price_service/src/v0/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,15 @@ where
Metadata: MetadataStorage,
{
async fn run(&mut self, watcher: &mut StateWatcher) -> TaskNextAction {
tracing::trace!("Starting gas price service");
MitchTurner marked this conversation as resolved.
Show resolved Hide resolved
tokio::select! {
biased;
_ = watcher.while_started() => {
tracing::debug!("Stopping gas price service");
TaskNextAction::Stop
}
l2_block_res = self.l2_block_source.get_l2_block() => {
tracing::debug!("Received L2 block");
let res = self.process_l2_block_res(l2_block_res).await;
TaskNextAction::always_continue(res)
}
Expand Down
22 changes: 11 additions & 11 deletions crates/services/gas_price_service/src/v0/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,14 +167,16 @@ async fn next_gas_price__affected_by_new_l2_block() {
algo_updater,
);

tracing::debug!("service created");

let read_algo = service.next_block_algorithm();
let initial = read_algo.next_gas_price();
let mut watcher = StateWatcher::default();
let mut watcher = StateWatcher::started();
tokio::spawn(async move { service.run(&mut watcher).await });

// when
service.run(&mut watcher).await;
l2_block_sender.send(l2_block).await.unwrap();
service.shutdown().await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(10)).await;

// then
let new = read_algo.next_gas_price();
Expand Down Expand Up @@ -212,18 +214,16 @@ async fn next__new_l2_block_saves_old_metadata() {
algo_updater,
);

// when
let read_algo = service.next_block_algorithm();
let mut watcher = StateWatcher::default();
let start = read_algo.next_gas_price();
let mut watcher = StateWatcher::started();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason this isn't StateWatcher::default()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were some places that process_l2_block_res wasn't getting called because of get_l2_block yielding a result, but because the service was shutting down (and we always check if there is an l2 block available before shutting down).

I added the started in a few places that it was shutting down early.

That being said, this isn't doing what the test says it's doing next__new_l2_block_saves_old_metadata. It's checking the gas price:

    // then
    let new = read_algo.next_gas_price();
    assert_ne!(start, new);

So I'll fix that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

tokio::spawn(async move { service.run(&mut watcher).await });

service.run(&mut watcher).await;
// when
l2_block_sender.send(l2_block).await.unwrap();
service.shutdown().await.unwrap();
tokio::time::sleep(std::time::Duration::from_millis(10)).await;

// then
let new = read_algo.next_gas_price();
assert_ne!(start, new);
let metadata_has_been_updated = metadata_inner.lock().unwrap().is_some();
assert!(metadata_has_been_updated);
}

#[derive(Clone)]
Expand Down
4 changes: 4 additions & 0 deletions crates/services/gas_price_service/src/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ pub mod algorithm;
pub mod da_source_service;
pub mod metadata;
pub mod service;

#[cfg(test)]
mod tests;
pub mod uninitialized_task;
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 @@ -92,7 +92,9 @@ impl From<&V1AlgorithmConfig> for AlgorithmUpdaterV1 {
.map(|size| u128::from(*size))
.sum();
Self {
new_scaled_exec_price: value.new_exec_gas_price,
new_scaled_exec_price: value
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we multiple by the gas_price_factor here? And what is gas_price_factor? I don't see where this value comes from and it is not clear what is the purpose of it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gas_price_factor is just a scaling factor to make sure we can track the change between small values. Like we do for gas costs. If the gas price is 1, it is stored as 100 as the scaled value, then we can increase it by 10% or 5% under the hood but it will still be returned as 1 until it crosses 150 or whatever.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The gas price factor can be different on different heights. Do we take it into account?

I though we work with Wei and because of that we don't need to scale gas price.

Copy link
Member Author

@MitchTurner MitchTurner Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the price is 1 Wei, which it often is? Possibly less so in the future, but still.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a TODO to remove this with this issue:
#2481

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better if you added todo for the field of the config instead of here=)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll move it in my next pr. Gonna merge.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved here:
abf0cca

.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,
gas_price_factor: value.gas_price_factor,
Expand Down
2 changes: 1 addition & 1 deletion crates/services/gas_price_service/src/v1/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ where
async fn shutdown(mut self) -> anyhow::Result<()> {
// handle all the remaining l2 blocks
while let Some(Ok(block)) = self.l2_block_source.get_l2_block().now_or_never() {
tracing::debug!("Updating gas price algorithm");
tracing::debug!("Updating gas price algorithm before shutdown");
self.apply_block_info_to_gas_algorithm(block).await?;
}

Expand Down
Loading
Loading