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

Check if gas limit is in line with the value registered by the proposer #18

Merged
merged 9 commits into from
Nov 18, 2023

Conversation

ckoopmann
Copy link
Collaborator

@ckoopmann ckoopmann commented Nov 17, 2023

Note: This introduces some inefficiency because we are getting the parent block and doing some gas check on it twice.
See here

@ckoopmann ckoopmann requested a review from alextes November 17, 2023 10:32
Copy link
Member

@alextes alextes 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.

src/rpc/utils.rs Show resolved Hide resolved
src/rpc/utils.rs Outdated
// Compute the gas limit of the next block after parent. It aims
// to keep the baseline gas close to the provided target, and increase it towards
// the target if the baseline gas is lower.
// Reference: https://github.com/flashbots/builder/blob/03ee71cf0a344397204f65ff6d3a917ee8e06724/core/utils/gas_limit.go#L8
Copy link
Member

Choose a reason for hiding this comment

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

Same here. Flashbots doesn't really have any authority here. It'd be good to link the 1559 spec where this calculation is defined.

I'm a bit surprised at the - 1 now that I read the spec. Do you happen to grok where it comes from? No big deal if not, just curious if this is cancelling out a minor bug somewhere else. Spec doesn't seem to say anything about it.

... oooh I might know. Where the spec says >= they probably have a >, sloppy but acceptable. Or a spec bug. Or a way to deal with builders which are off-by-one actually, probably with the same root cause. Hm :-/ would've been good to have a comment there. Can we add a comment: // Not in the spec, presumably added to allow an off-by-one error on the builder side. Which imo, totally not okay, builders should just implement the spec correctly, but let's start by understanding where we are.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The reference here wasn't exactly meant as "authoritative source of truth" but rather the reference implementation that I just ported to rust tbh. Good point thought to invest the time to really understand how the specs map to this implementation and what differences where introduced / for what reasons. I will add the comment and then also added an issue to review / understand this in more depth.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Your understanding of the "-1" is correct I think. I removed that and used ">=" instead to be closer to the specification.

Could this have been a performance optimization though ?🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Actually I think the logic is actually different from just using >=
In the case where: desired_limit == parent_gas_limit + parent_gas_limit / GAS_LIMIT_BOUND_DIVISOR the max_acceptable_limit (as defined below) will be one less and therefore also the result.

I will keep the logic consistent with the flashbots implementation for now and create an issue to review / understand this apparent difference to the eip reference implementation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I also included references both to the flashbots code as well as the eip.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Created issue for further investigation here: #19

src/rpc/utils.rs Outdated Show resolved Hide resolved
src/rpc/mod.rs Outdated Show resolved Hide resolved
@ckoopmann ckoopmann requested a review from alextes November 17, 2023 13:13
Copy link
Member

@alextes alextes left a comment

Choose a reason for hiding this comment

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

One small change request still.

src/rpc/mod.rs Outdated
// limit as calculated with a desired limit of 0, and builders which fall
// back to calculating with the default 30_000_000.
// TODO: Review if we still need this
if registered_gas_limit != 0
Copy link
Member

Choose a reason for hiding this comment

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

How about we have two early return OK cases and err becomes the default last return with Err?

For context: here we still nest an if which feels more complex to me. Second, the first if is looking for a positive match but written as a negative.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense.
Adjusted accordingly in: 76a7f23

src/rpc/utils.rs Show resolved Hide resolved
@ckoopmann ckoopmann merged commit 58c5c6a into main Nov 18, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants