Repository navigation
feat: check gas limit consistency with the target #9391
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
Changes from all commits
6151936
3b60b56
34ec0f9
873a4b6
eeb75ed
3b997a1
b3e038d
fbd98c9
852b4cf
bcb484f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,9 +4,10 @@ import { | |||||
| createSingleSignatureSetFromComponents, | ||||||
| getExecutionPayloadBidSigningRoot, | ||||||
| isActiveBuilder, | ||||||
| isGasLimitTargetCompatible, | ||||||
| isStatePostGloas, | ||||||
| } from "@lodestar/state-transition"; | ||||||
| import {gloas} from "@lodestar/types"; | ||||||
| import {ValidatorIndex, gloas} from "@lodestar/types"; | ||||||
| import {byteArrayEquals, toHex, toRootHex} from "@lodestar/utils"; | ||||||
| import {getShufflingDependentRoot} from "../../util/dependentRoot.js"; | ||||||
| import {ExecutionPayloadBidError, ExecutionPayloadBidErrorCode, GossipAction} from "../errors/index.js"; | ||||||
|
|
@@ -16,21 +17,21 @@ import {RegenCaller} from "../regen/index.js"; | |||||
| export async function validateApiExecutionPayloadBid( | ||||||
| chain: IBeaconChain, | ||||||
| signedExecutionPayloadBid: gloas.SignedExecutionPayloadBid | ||||||
| ): Promise<void> { | ||||||
| ): Promise<{proposerIndex: ValidatorIndex}> { | ||||||
| return validateExecutionPayloadBid(chain, signedExecutionPayloadBid); | ||||||
| } | ||||||
|
|
||||||
| export async function validateGossipExecutionPayloadBid( | ||||||
| chain: IBeaconChain, | ||||||
| signedExecutionPayloadBid: gloas.SignedExecutionPayloadBid | ||||||
| ): Promise<void> { | ||||||
| ): Promise<{proposerIndex: ValidatorIndex}> { | ||||||
| return validateExecutionPayloadBid(chain, signedExecutionPayloadBid); | ||||||
| } | ||||||
|
|
||||||
| async function validateExecutionPayloadBid( | ||||||
| chain: IBeaconChain, | ||||||
| signedExecutionPayloadBid: gloas.SignedExecutionPayloadBid | ||||||
| ): Promise<void> { | ||||||
| ): Promise<{proposerIndex: ValidatorIndex}> { | ||||||
| const bid = signedExecutionPayloadBid.message; | ||||||
| const parentBlockRootHex = toRootHex(bid.parentBlockRoot); | ||||||
| const parentBlockHashHex = toRootHex(bid.parentBlockHash); | ||||||
|
|
@@ -128,14 +129,33 @@ async function validateExecutionPayloadBid( | |||||
| }); | ||||||
| } | ||||||
|
|
||||||
| // [REJECT] `bid.gas_limit == proposer_preferences.target_gas_limit`. | ||||||
| // [IGNORE] `bid.parent_block_hash` is the block hash of a known execution payload in fork | ||||||
| // choice. Looks up the variant of `bid.parent_block_root` whose payload hash matches | ||||||
| // `bid.parent_block_hash` — works for both FULL parents (FULL variant carries the delivered | ||||||
| // payload's hash) and EMPTY parents (EMPTY/PENDING variants carry the inherited parent | ||||||
| // payload's hash, since the new block doesn't have its own payload). Variant carries the | ||||||
| // executed payload's gas_limit, which we use as `parent_gas_limit` below. | ||||||
| const parentPayloadVariant = chain.forkChoice.getBlockHexAndBlockHash(parentBlockRootHex, parentBlockHashHex); | ||||||
| if (parentPayloadVariant === null || parentPayloadVariant.executionPayloadBlockHash === null) { | ||||||
| throw new ExecutionPayloadBidError(GossipAction.IGNORE, { | ||||||
| code: ExecutionPayloadBidErrorCode.UNKNOWN_PARENT_BLOCK_HASH, | ||||||
| parentBlockHash: parentBlockHashHex, | ||||||
| }); | ||||||
| } | ||||||
|
|
||||||
| // [IGNORE] `is_gas_limit_target_compatible(parent_gas_limit, bid.gas_limit, target_gas_limit)`, | ||||||
| // where `parent_gas_limit` is the `gas_limit` of the parent execution payload and | ||||||
| // `target_gas_limit` is `proposer_preferences.target_gas_limit`. | ||||||
| const bidGasLimit = Number(bid.gasLimit); | ||||||
| if (bidGasLimit !== proposerPreferences.message.targetGasLimit) { | ||||||
| throw new ExecutionPayloadBidError(GossipAction.REJECT, { | ||||||
| const parentGasLimit = parentPayloadVariant.executionPayloadGasLimit; | ||||||
| const targetGasLimit = proposerPreferences.message.targetGasLimit; | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||
| if (!isGasLimitTargetCompatible(parentGasLimit, bidGasLimit, targetGasLimit)) { | ||||||
| throw new ExecutionPayloadBidError(GossipAction.IGNORE, { | ||||||
| code: ExecutionPayloadBidErrorCode.PROPOSER_PREFERENCES_GAS_LIMIT_MISMATCH, | ||||||
| builderIndex: bid.builderIndex, | ||||||
| bidGasLimit, | ||||||
| expectedGasLimit: proposerPreferences.message.targetGasLimit, | ||||||
| parentGasLimit, | ||||||
| targetGasLimit, | ||||||
| }); | ||||||
| } | ||||||
|
|
||||||
|
|
@@ -183,10 +203,6 @@ async function validateExecutionPayloadBid( | |||||
| }); | ||||||
| } | ||||||
|
|
||||||
| // [IGNORE] `bid.parent_block_hash` is the block hash of a known execution | ||||||
| // payload in fork choice. | ||||||
| // TODO GLOAS: implement this | ||||||
|
|
||||||
| // [REJECT] `signed_execution_payload_bid.signature` is valid with respect to the `bid.builder_index`. | ||||||
| const signatureSet = createSingleSignatureSetFromComponents( | ||||||
| PublicKey.fromBytes(builder.pubkey), | ||||||
|
|
@@ -204,4 +220,6 @@ async function validateExecutionPayloadBid( | |||||
|
|
||||||
| // Valid | ||||||
| chain.seenExecutionPayloadBids.add(bid.slot, bid.builderIndex); | ||||||
|
|
||||||
| return {proposerIndex: proposerPreferences.message.validatorIndex}; | ||||||
| } | ||||||
This file was deleted.
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 am bit confused by this comment, why is it not tracked in the state?
it's in
state.latestExecutionPayloadBid.gasLimit, or is there a reason this value is not viable to use?