-
-
Notifications
You must be signed in to change notification settings - Fork 313
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
feat: check gas limit in header received from builder #7336
base: unstable
Are you sure you want to change the base?
Conversation
587034f
to
c0308f9
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## unstable #7336 +/- ##
=========================================
Coverage 48.76% 48.76%
=========================================
Files 601 601
Lines 40243 40243
Branches 2067 2067
=========================================
Hits 19626 19626
Misses 20579 20579
Partials 38 38 |
Performance Report✔️ no performance regression detected 🚀🚀 Significant benchmark improvement detected
Full benchmark results
|
c0308f9
to
d317aef
Compare
gasLimit: number; | ||
}; | ||
|
||
export class ValidatorRegistrationCache { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
might be able to combine this with BeaconProposerCache
in the future but this requires apis to be consolidated first as proposed in ethereum/beacon-APIs#435
const parentGasLimit = (currentState as CachedBeaconStateBellatrix).latestExecutionPayloadHeader.gasLimit; | ||
const expectedGasLimit = getExpectedGasLimit(parentGasLimit, targetGasLimit); | ||
|
||
if (builderRes.header.gasLimit !== expectedGasLimit) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think many builders/relays might have bugs over here initially.
we should relax it and make sure its between [parent limit, exected limit] or [expected limit, parent limit] interval and then warn if its not equal to expected
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think many builders/relays might have bugs over here initially.
Running this branch on Holesky right now but it's hard to validate if gas target is not moving
we should relax it and make sure its between [parent limit, exected limit] or [expected limit, parent limit]
Right so in this case we should definitely reject as the block would be invalid, we can relax for now and observe this for a while on mainnet, eventually we can enforce the strict check
@@ -128,8 +132,17 @@ export class ExecutionBuilderHttp implements IExecutionBuilder { | |||
} | |||
} | |||
|
|||
async registerValidator(registrations: bellatrix.SignedValidatorRegistrationV1[]): Promise<void> { | |||
async registerValidator(epoch: Epoch, registrations: bellatrix.SignedValidatorRegistrationV1[]): Promise<void> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is adding epoch to api standard spec now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an internal method, the api call happens on L136 which does not need the epoch, we only need it to track registrations in our internal cache to be able to prune old records (similar to what we do for proposer cache).
I opted for supplying the epoch by the caller of registerValidator
but it could also just use clock.currentEpoch
export function getExpectedGasLimit(parentGasLimit: number, targetGasLimit: number): number { | ||
const maxGasLimitDifference = Math.max(Math.floor(parentGasLimit / gasLimitAdjustmentFactor) - 1, 0); | ||
|
||
if (targetGasLimit > parentGasLimit) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good to see upper/lower taken care of
Motivation
As per spec the builder must adhere to the preferred gas limit of the validator
but currently we are not validating this anywhere and rely on honest builder behavior which is not great considering there are only two builder that produce most of the blocks.
Description
This PR adds a check the to builder flow that compares the expected gas limit against the target gas limit (ie. preferred gas limit of validator) and rejects the builder block in case there is a mismatch which will trigger the fallback to local block.
The expected gas limit is calculated based on this spec
I haven't found where this is defined but it's based on what other clients implement (eg. prysmaticlabs/prysm#14707 and Consensys/teku#8909) and makes sense considering gas limit checks in EIP-1559.