-
-
Notifications
You must be signed in to change notification settings - Fork 479
feat: add payload envelope reqresp #9050
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
677f8a3
init
ensi321 2e20f2b
typo
ensi321 ed1c68f
Add getSerializedExecutionPayloadEnvelope
ensi321 ba70076
Apply suggestion from @gemini-code-assist[bot]
ensi321 9f82f73
update todo
ensi321 7b5f809
remove slot param
ensi321 8ab9114
Merge branch 'unstable' into nc/epbs-reqresp
ensi321 6835906
Merge branch 'unstable' into nc/epbs-reqresp
ensi321 95f7a9b
Merge branch 'unstable' into nc/epbs-reqresp
ensi321 3f3409e
Merge branch 'unstable' into nc/epbs-reqresp
ensi321 583a07b
fix: resolve TODOs in getSerializedExecutionPayloadEnvelope
ensi321 d65eac2
Merge branch 'unstable' into nc/epbs-reqresp
ensi321 88dd816
feat: add client-side reqresp methods for execution payload envelopes
ensi321 bc89a38
Merge branch 'unstable' into nc/epbs-reqresp
nflaig 22149ba
address comments
ensi321 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
packages/beacon-node/src/network/reqresp/handlers/executionPayloadEnvelopesByRange.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import {ChainConfig} from "@lodestar/config"; | ||
| import {PayloadStatus} from "@lodestar/fork-choice"; | ||
| import {GENESIS_SLOT} from "@lodestar/params"; | ||
| import {RespStatus, ResponseError, ResponseOutgoing} from "@lodestar/reqresp"; | ||
| import {computeEpochAtSlot} from "@lodestar/state-transition"; | ||
| import {gloas} from "@lodestar/types"; | ||
| import {IBeaconChain} from "../../../chain/index.js"; | ||
| import {IBeaconDb} from "../../../db/index.js"; | ||
|
|
||
| export async function* onExecutionPayloadEnvelopesByRange( | ||
| request: gloas.ExecutionPayloadEnvelopesByRangeRequest, | ||
| chain: IBeaconChain, | ||
| db: IBeaconDb | ||
| ): AsyncIterable<ResponseOutgoing> { | ||
| const {startSlot, count} = validateExecutionPayloadEnvelopesByRangeRequest(chain.config, request); | ||
|
ensi321 marked this conversation as resolved.
|
||
| const endSlot = startSlot + count; | ||
|
|
||
|
wemeetagain marked this conversation as resolved.
|
||
| if (startSlot < chain.earliestAvailableSlot) { | ||
| return; | ||
| } | ||
|
|
||
| const finalized = db.executionPayloadEnvelopeArchive; | ||
| const finalizedSlot = chain.forkChoice.getFinalizedCheckpointSlot(); | ||
|
|
||
| // Finalized range of envelopes | ||
| if (startSlot <= finalizedSlot) { | ||
| for await (const {key, value: envelopeBytes} of finalized.binaryEntriesStream({ | ||
| gte: startSlot, | ||
| lt: endSlot, | ||
| })) { | ||
| const slot = finalized.decodeKey(key); | ||
| yield { | ||
| data: envelopeBytes, | ||
| boundary: chain.config.getForkBoundaryAtEpoch(computeEpochAtSlot(slot)), | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| // Non-finalized range of envelopes | ||
| if (endSlot > finalizedSlot) { | ||
| const headBlock = chain.forkChoice.getHead(); | ||
| const headRoot = headBlock.blockRoot; | ||
| const headChain = chain.forkChoice.getAllAncestorBlocks(headRoot, headBlock.payloadStatus); | ||
|
|
||
| // Iterate head chain with ascending block numbers | ||
| for (let i = headChain.length - 1; i >= 0; i--) { | ||
| const block = headChain[i]; | ||
|
|
||
| if (block.slot >= startSlot && block.slot < endSlot) { | ||
| // Skip EMPTY blocks | ||
| if (block.payloadStatus !== PayloadStatus.FULL) { | ||
| continue; | ||
| } | ||
|
|
||
| const envelopeBytes = await chain.getSerializedExecutionPayloadEnvelope(block.slot, block.blockRoot); | ||
|
ensi321 marked this conversation as resolved.
|
||
| if (!envelopeBytes) { | ||
| throw new ResponseError( | ||
| RespStatus.SERVER_ERROR, | ||
| `No envelope for root ${block.blockRoot} slot ${block.slot}, startSlot=${startSlot} endSlot=${endSlot} finalizedSlot=${finalizedSlot}` | ||
| ); | ||
| } | ||
|
|
||
| yield { | ||
| data: envelopeBytes, | ||
| boundary: chain.config.getForkBoundaryAtEpoch(computeEpochAtSlot(block.slot)), | ||
| }; | ||
| } else if (block.slot >= endSlot) { | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export function validateExecutionPayloadEnvelopesByRangeRequest( | ||
| config: ChainConfig, | ||
| request: gloas.ExecutionPayloadEnvelopesByRangeRequest | ||
| ): gloas.ExecutionPayloadEnvelopesByRangeRequest { | ||
| const {startSlot} = request; | ||
| let {count} = request; | ||
|
|
||
| if (count < 1) { | ||
| throw new ResponseError(RespStatus.INVALID_REQUEST, "count < 1"); | ||
| } | ||
| // TODO: validate against MIN_EPOCHS_FOR_BLOCK_REQUESTS | ||
| if (startSlot < GENESIS_SLOT) { | ||
| throw new ResponseError(RespStatus.INVALID_REQUEST, "startSlot < genesis"); | ||
| } | ||
|
|
||
| if (count > config.MAX_REQUEST_BLOCKS_DENEB) { | ||
| count = config.MAX_REQUEST_BLOCKS_DENEB; | ||
|
twoeths marked this conversation as resolved.
|
||
| } | ||
|
|
||
| return {startSlot, count}; | ||
| } | ||
43 changes: 43 additions & 0 deletions
43
packages/beacon-node/src/network/reqresp/handlers/executionPayloadEnvelopesByRoot.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import {ResponseOutgoing} from "@lodestar/reqresp"; | ||
| import {computeEpochAtSlot} from "@lodestar/state-transition"; | ||
| import {toRootHex} from "@lodestar/utils"; | ||
| import {IBeaconChain} from "../../../chain/index.js"; | ||
| import {IBeaconDb} from "../../../db/index.js"; | ||
| import {ExecutionPayloadEnvelopesByRootRequest} from "../../../util/types.js"; | ||
|
|
||
| export async function* onExecutionPayloadEnvelopesByRoot( | ||
| requestBody: ExecutionPayloadEnvelopesByRootRequest, | ||
| chain: IBeaconChain, | ||
| db: IBeaconDb | ||
| ): AsyncIterable<ResponseOutgoing> { | ||
| // Spec: [max(GLOAS_FORK_EPOCH, current_epoch - MIN_EPOCHS_FOR_BLOCK_REQUESTS), current_epoch] | ||
| const currentEpoch = chain.clock.currentEpoch; | ||
| const minimumRequestEpoch = Math.max( | ||
| currentEpoch - chain.config.MIN_EPOCHS_FOR_BLOCK_REQUESTS, | ||
| chain.config.GLOAS_FORK_EPOCH | ||
| ); | ||
|
|
||
| for (const root of requestBody) { | ||
| const rootHex = toRootHex(root); | ||
| const block = chain.forkChoice.getBlockHexDefaultStatus(rootHex); | ||
| // If the block is not in fork choice, it may be finalized. Attempt to find its slot in block archive | ||
| const slot = block ? block.slot : await db.blockArchive.getSlotByRoot(root); | ||
|
|
||
| if (slot === null) { | ||
| continue; | ||
| } | ||
|
|
||
| const requestedEpoch = computeEpochAtSlot(slot); | ||
| if (requestedEpoch < minimumRequestEpoch) { | ||
| continue; | ||
| } | ||
|
|
||
| const envelopeBytes = await chain.getSerializedExecutionPayloadEnvelope(slot, rootHex); | ||
|
ensi321 marked this conversation as resolved.
|
||
| if (envelopeBytes) { | ||
| yield { | ||
| data: envelopeBytes, | ||
| boundary: chain.config.getForkBoundaryAtEpoch(requestedEpoch), | ||
| }; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.