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 5 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,6 +4,7 @@ import { | |||||
| createSingleSignatureSetFromComponents, | ||||||
| getExecutionPayloadBidSigningRoot, | ||||||
| isActiveBuilder, | ||||||
| isGasLimitTargetCompatible, | ||||||
| isStatePostGloas, | ||||||
| } from "@lodestar/state-transition"; | ||||||
| import {gloas} from "@lodestar/types"; | ||||||
|
|
@@ -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, | ||||||
| }); | ||||||
| } | ||||||
|
|
||||||
| // [REJECT] `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) { | ||||||
| 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.REJECT, { | ||||||
|
Member
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. |
||||||
| 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), | ||||||
|
|
||||||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -764,40 +764,50 @@ export class ForkChoice implements IForkChoice { | |
| unrealizedFinalizedRoot: unrealizedFinalizedCheckpoint.rootHex, | ||
|
|
||
| ...(isGloasBeaconBlock(block) | ||
| ? { | ||
| executionPayloadBlockHash: toRootHex(block.body.signedExecutionPayloadBid.message.parentBlockHash), // post-gloas, we don't know payload hash until we import execution payload. Set to parent payload hash for now | ||
| executionPayloadNumber: (() => { | ||
| // Determine parent's execution payload number based on which variant the block extends | ||
| const parentBlockHashFromBid = toRootHex(block.body.signedExecutionPayloadBid.message.parentBlockHash); | ||
|
|
||
| // If parent is pre-merge, return 0 | ||
| ? (() => { | ||
| // post-gloas, we don't know payload hash until we import execution payload. Set to | ||
| // parent payload hash for now, along with the gas limit/number of that parent payload | ||
| // (which is what bids built on top of this block will reference until a payload arrives). | ||
| const parentBlockHashFromBid = toRootHex(block.body.signedExecutionPayloadBid.message.parentBlockHash); | ||
|
|
||
| // Inherit parent payload's (number, gasLimit) for the PENDING/EMPTY variants: | ||
| // - pre-merge parent: zero/no payload | ||
| // - pre-Gloas parent: single variant carries the values | ||
| // - Gloas parent: look up the variant matching parentBlockHashFromBid | ||
| const parentMeta = ((): {number: number; gasLimit: number} => { | ||
| if (parentBlock.executionPayloadBlockHash === null) { | ||
| return 0; | ||
| return {number: 0, gasLimit: 0}; | ||
| } | ||
|
|
||
| // If parent is pre-Gloas, it only has FULL variant | ||
| if (parentBlock.parentBlockHash === null) { | ||
| return parentBlock.executionPayloadNumber; | ||
| return {number: parentBlock.executionPayloadNumber, gasLimit: parentBlock.executionPayloadGasLimit}; | ||
| } | ||
|
|
||
| // Parent is Gloas: get the variant that matches the parentBlockHash from bid | ||
| const parentVariant = this.getBlockHexAndBlockHash(parentRootHex, parentBlockHashFromBid); | ||
|
Member
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. this is not necessary |
||
| if (parentVariant && parentVariant.executionPayloadBlockHash !== null) { | ||
| return parentVariant.executionPayloadNumber; | ||
| return { | ||
| number: parentVariant.executionPayloadNumber, | ||
| gasLimit: parentVariant.executionPayloadGasLimit, | ||
| }; | ||
| } | ||
| // Fallback to parent block's number (we know it's post-merge from check above) | ||
| return parentBlock.executionPayloadNumber; | ||
| })(), | ||
| executionStatus: this.getPostMergeExecStatus(executionStatus), | ||
| dataAvailabilityStatus, | ||
| } | ||
| // Fallback to parent block's values (we know it's post-merge from check above) | ||
| return {number: parentBlock.executionPayloadNumber, gasLimit: parentBlock.executionPayloadGasLimit}; | ||
| })(); | ||
|
|
||
| return { | ||
| executionPayloadBlockHash: parentBlockHashFromBid, | ||
| executionPayloadNumber: parentMeta.number, | ||
| executionPayloadGasLimit: parentMeta.gasLimit, | ||
| executionStatus: this.getPostMergeExecStatus(executionStatus), | ||
| dataAvailabilityStatus, | ||
| }; | ||
| })() | ||
| : isExecutionBlockBodyType(block.body) && | ||
| isStatePostBellatrix(state) && | ||
| state.isExecutionStateType && | ||
| state.isExecutionEnabled(block) | ||
| ? { | ||
| executionPayloadBlockHash: toRootHex(block.body.executionPayload.blockHash), | ||
| executionPayloadNumber: block.body.executionPayload.blockNumber, | ||
| executionPayloadGasLimit: block.body.executionPayload.gasLimit, | ||
| executionStatus: this.getPostMergeExecStatus(executionStatus), | ||
| dataAvailabilityStatus, | ||
| } | ||
|
|
@@ -947,6 +957,7 @@ export class ForkChoice implements IForkChoice { | |
| blockRoot: RootHex, | ||
| executionPayloadBlockHash: RootHex, | ||
| executionPayloadNumber: number, | ||
| executionPayloadGasLimit: number, | ||
| executionStatus: PayloadExecutionStatus, | ||
| dataAvailabilityStatus: DataAvailabilityStatus | ||
| ): void { | ||
|
|
@@ -955,6 +966,7 @@ export class ForkChoice implements IForkChoice { | |
| this.fcStore.currentSlot, | ||
| executionPayloadBlockHash, | ||
| executionPayloadNumber, | ||
| executionPayloadGasLimit, | ||
| this.proposerBoostRoot, | ||
| executionStatus, | ||
| dataAvailabilityStatus | ||
|
|
||
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?