Skip to content

builder gas limit & some refactoring #6583

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

Merged
merged 5 commits into from
Dec 16, 2024
Merged

Conversation

ethDreamer
Copy link
Member

I had forgotten to finish this one when I got distracted by other stuff but I think it's good to go now.

Lighthouse now enforces validator sovereignty over the gas limit. The overwhelming majority of builders already respect this and I've notified the relays for the few that didn't and they told me they've fixed the bug. I also did some refactoring for clarity and convenience.

@michaelsproul michaelsproul added the v7.0.0-beta.0 New release c. Q1 2025 label Dec 2, 2024
Copy link
Member

@michaelsproul michaelsproul left a comment

Choose a reason for hiding this comment

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

Looks good. Will merge to unstable shortly.

@@ -1423,6 +1442,10 @@ const fn default_max_per_epoch_activation_churn_limit() -> u64 {
8
}

const fn default_gas_limit_adjustment_factor() -> u64 {
1024
Copy link
Member

Choose a reason for hiding this comment

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

@@ -1296,6 +1311,10 @@ pub struct Config {
#[serde(with = "serde_utils::address_hex")]
deposit_contract_address: Address,

#[serde(default = "default_gas_limit_adjustment_factor")]
#[serde(with = "serde_utils::quoted_u64")]
gas_limit_adjustment_factor: u64,
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we should leave this out of Config so that users can't set it? It's not defined as part of the upstream config.yaml that the EF uses, so might make sense not to add it here as a non-standard config.

Then again, for most configs it just won't be present so this doesn't pose an issue.

Comment on lines +343 to +345
// Update `gas_limit` if `updated.gas_limit` is `Some` and:
// - `self.gas_limit` is `None`, or
// - both are `Some` but the values differ.
Copy link
Member

Choose a reason for hiding this comment

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

Just to confirm, the idea here is to make any previous gas limit "sticky"? So if we receive a validator registration that has a gas limit, followed by a duplicate registration without a gas limit, we remember the gas limit after processing the 2nd registration rather than overwriting it with None?

Comment on lines +2016 to +2029
let max_gas_limit_difference = parent_gas_limit
.checked_div(spec.gas_limit_adjustment_factor)
.and_then(|result| result.checked_sub(1))
.unwrap_or(0);

// Adjust the gas limit safely
if target_gas_limit > parent_gas_limit {
let gas_diff = target_gas_limit.saturating_sub(parent_gas_limit);
parent_gas_limit.checked_add(std::cmp::min(gas_diff, max_gas_limit_difference))
} else {
let gas_diff = parent_gas_limit.saturating_sub(target_gas_limit);
parent_gas_limit.checked_sub(std::cmp::min(gas_diff, max_gas_limit_difference))
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I've checked this against the spec for check_gas_limit and I am convinced this is correct.

https://ethereum.github.io/execution-specs/src/ethereum/cancun/fork.py.html#ethereum.cancun.fork.check_gas_limit:0

It's unfortunate that the spec uses max_adjustment_delta for an inclusive (>=) check, meaning that the actual max is 1 less than the "max adjustment delta". Oh well.

@michaelsproul michaelsproul added the ready-for-merge This PR is ready to merge. label Dec 11, 2024
@jimmygchen
Copy link
Member

@mergify queue

Copy link

mergify bot commented Dec 16, 2024

queue

🛑 The pull request has been removed from the queue default

Pull request #6583 has been dequeued by a dequeue command.

You can take a look at Queue: Embarked in merge queue check runs for more details.

In case of a failure due to a flaky test, you should first retrigger the CI.
Then, re-embark the pull request into the merge queue by posting the comment
@mergifyio refresh on the pull request.

@jimmygchen
Copy link
Member

@mergify dequeue

Copy link

mergify bot commented Dec 16, 2024

This pull request has been removed from the queue for the following reason: pull request dequeued.

Pull request #6583 has been dequeued by a dequeue command.

You should look at the reason for the failure and decide if the pull request needs to be fixed or if you want to requeue it.

If you want to requeue this pull request, you need to post a comment with the text: @mergifyio requeue

Copy link

mergify bot commented Dec 16, 2024

dequeue

✅ The pull request has been removed from the queue default

@jimmygchen
Copy link
Member

@mergify requeue

Copy link

mergify bot commented Dec 16, 2024

requeue

✅ This pull request will be re-embarked automatically

The followup queue command will be automatically executed to re-embark the pull request

Copy link

mergify bot commented Dec 16, 2024

queue

✅ The pull request has been merged automatically

The pull request has been merged automatically at 86891e6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
builder API ready-for-merge This PR is ready to merge. v7.0.0-beta.0 New release c. Q1 2025
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants