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

chore(gas_price_service_v1): strictly ensure last_recorded_height is set, to avoid initial poll of da source #2523

Conversation

rymnc
Copy link
Member

@rymnc rymnc commented Dec 30, 2024

Warning

Needs to be merged into master after #2469 is merged

Linked Issues/PRs

Description

When starting a node, we request the da source service for the latest costs. This results in large negative profit / loss influencing the da gas price. We want to avoid this behaviour, and therefore, we ensure that the last_recorded_height is set in the block committer.

Checklist

  • Breaking changes are clearly marked as such in the PR description and changelog
  • New behavior is reflected in tests
  • The specification 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]

@rymnc rymnc added the no changelog Skip the CI check of the changelog modification label Dec 30, 2024
@rymnc rymnc force-pushed the chore/gas-price-service-v1-poll-da-source-with-specific-height branch from 0b912e1 to 1f5fc22 Compare December 30, 2024 18:36
Copy link
Member

@MitchTurner MitchTurner left a comment

Choose a reason for hiding this comment

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

When starting a node, we request the da source service for the latest costs. This results in large negative profit / loss influencing the da gas price. We want to avoid this behaviour, and therefore, we ensure that the last_recorded_height is set in the block committer.

Yeah. Nice catch. This isn't how it worked before, as we only added costs for blocks that were included in our unrecorded_blocks, but looks like we just add it all blindly now:

        let new_da_block_cost = self
            .latest_known_total_da_cost_excess
            .saturating_add(recording_cost);
        self.latest_known_total_da_cost_excess = new_da_block_cost;

I've also considered adding a config value to specify which block we want to start from. That would avoid the Error entirely.

@rymnc rymnc force-pushed the chore/gas-price-service-v1-poll-da-source-with-specific-height branch from 1f5fc22 to cbc6dee Compare December 30, 2024 19:30
@rymnc rymnc force-pushed the chore/gas-price-service-v1-poll-da-source-with-specific-height branch from 50e0299 to 3b60422 Compare December 30, 2024 22:11
@rymnc rymnc marked this pull request as ready for review December 30, 2024 22:50
@rymnc rymnc requested a review from MitchTurner December 30, 2024 22:50
@MitchTurner
Copy link
Member

MitchTurner commented Dec 31, 2024

If we set the latest_recorded_height to be the same as the l2 block height on startup, then we still have the same problem (if less extreme) of paying for old blocks. i.e. if the committer is working on a bundle of 200..300, and we start on 250, then we will still add the costs of 200..249, although they weren't the V1 service's responsibility.
Unfortunately, I don't know how to avoid this. The problem is that we don't know what proportion of the DA bundle any specific "unrecorded block" would represent. That's why we just take the entire bundle's cost blindly.

@rymnc
Copy link
Member Author

rymnc commented Dec 31, 2024

If we set the latest_recorded_height to be the same as the l2 block height on startup, then we still have the same problem (if less extreme) of paying for old blocks. i.e. if the committer is working on a bundle of 200..300, and we start on 250, then we will still add the costs of 200..249, although they weren't the V1 service's responsibility.
Unfortunately, I don't know how to avoid this. The problem is that we don't know what proportion of the DA bundle any specific "unrecorded block" would represent. That's why we just take the entire bundle's cost blindly.

there's no way for us to know the next bundle height deterministically so yeah, no way to avoid fully

@rymnc rymnc requested a review from a team January 6, 2025 06:04
@rymnc
Copy link
Member Author

rymnc commented Jan 7, 2025

moving back to draft as there are some things needing discussion

@rymnc rymnc marked this pull request as draft January 7, 2025 18:10
let mut service = DaSourceService::new_with_sender(
da_block_costs_source,
Some(Duration::from_millis(1)),
latest_l2_height,
None,
expected_height,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand this test.
You start and run DaSourceService with a block_height ofexpected_height, but then after running the service the recorded_height is still the same? This seems to be the opposite of what the test name suggests.

Should it be

Suggested change
expected_height,
BlockHeight::new(2),

instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

perhaps.. theres a bunch of things that are wrong in this pr now after #2512 was merged.

Copy link
Contributor

Choose a reason for hiding this comment

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

cool, I didn't see it was back in draft. Will stop reviewing until it's ready for review again

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed in 73cf35b

Comment on lines 192 to 195
let recorded_height = match self.gas_price_db.get_recorded_height()? {
Some(height) => height,
None => BlockHeight::from(latest_block_height),
};
Copy link
Contributor

Choose a reason for hiding this comment

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

nit (see https://www.lurklurk.org/effective-rust/transform.html)

Suggested change
let recorded_height = match self.gas_price_db.get_recorded_height()? {
Some(height) => height,
None => BlockHeight::from(latest_block_height),
};
let recorded_height = self
.gas_price_db
.get_recorded_height()?
.unwrap_or(BlockHeight::from(latest_block_height));

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed in 4ca7a94

@rymnc rymnc marked this pull request as ready for review January 8, 2025 14:37
@rymnc rymnc requested a review from acerone85 January 8, 2025 14:37
@rymnc rymnc requested a review from MitchTurner January 8, 2025 14:37
@@ -178,10 +184,11 @@ mod tests {

// given
let l2_height = 10;
let recorded_height = 9;
let starting_recorded_height = 2;
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't the starting_recorded_height be 2 - 1? We call succ on the recorded_height to query the DA heights.

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed in 53a96cf

@@ -178,10 +184,11 @@ mod tests {

// given
let l2_height = 10;
let recorded_height = 9;
let starting_recorded_height = 2;
let expected_recorded_height = 9;
let unexpected_costs = DaBlockCosts {
Copy link
Member

Choose a reason for hiding this comment

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

nit: I think this is probably misnamed but that would be my fault.

Suggested change
let unexpected_costs = DaBlockCosts {
let costs = DaBlockCosts {

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed in 53a96cf

MitchTurner
MitchTurner previously approved these changes Jan 8, 2025
@rymnc
Copy link
Member Author

rymnc commented Jan 8, 2025

@acerone85 this is ready for another review :)

rymnc added 2 commits January 9, 2025 12:13
…e-service-v1-poll-da-source-with-specific-height
…e-service-v1-poll-da-source-with-specific-height
@rymnc rymnc added the release label Jan 9, 2025
@rymnc rymnc requested a review from rafal-ch January 10, 2025 10:42
…e-service-v1-poll-da-source-with-specific-height
xgreenx
xgreenx previously approved these changes Jan 14, 2025
Base automatically changed from chore/add-tests-for-v1-gas-service to master January 14, 2025 05:33
@MitchTurner MitchTurner dismissed stale reviews from xgreenx and themself January 14, 2025 05:33

The base branch was changed.

@rymnc rymnc changed the base branch from master to chore/add-tests-for-v1-gas-service January 14, 2025 05:36
@rymnc
Copy link
Member Author

rymnc commented Jan 14, 2025

github is being weird with the base branch being different. i'm going to merge this into the previous base and reopen the PR with that: https://github.com/orgs/community/discussions/39031

@rymnc rymnc merged commit 4ac8593 into chore/add-tests-for-v1-gas-service Jan 14, 2025
31 checks passed
@rymnc rymnc deleted the chore/gas-price-service-v1-poll-da-source-with-specific-height branch January 14, 2025 05:39
rymnc added a commit that referenced this pull request Jan 14, 2025
…set, to avoid initial poll of da source (#2556)

## Linked Issues/PRs
<!-- List of related issues/PRs -->
- #2523

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

prev pr didn't have a clean history because the prev base branch was
squashed and merged instead of a regular merge commit. same changes as
before.

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

### Before requesting review
- [x] I have reviewed the code myself
- [x] 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?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no changelog Skip the CI check of the changelog modification release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants