Repository navigation
feat: add block_hash and builder_index to block event
#9854
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 9 commits
00d4c99
06e3d59
623073b
d6f4a2a
b4c4c04
60aae61
49c5cbc
b723bc4
eafa3ad
1c564df
2dd4540
cce9a54
84e6f00
e70a9c3
9753cd5
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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| import {ContainerType, ListBasicType, ValueOf} from "@chainsafe/ssz"; | ||
| import {ChainForkConfig} from "@lodestar/config"; | ||
| import {ForkName, MAX_BLOB_COMMITMENTS_PER_BLOCK, isForkPostGloas} from "@lodestar/params"; | ||
| import {ForkName, ForkSeq, MAX_BLOB_COMMITMENTS_PER_BLOCK, isForkPostGloas} from "@lodestar/params"; | ||
| import { | ||
| Attestation, | ||
| AttesterSlashing, | ||
|
|
@@ -69,6 +69,24 @@ const headV2 = new ContainerType( | |
| }, | ||
| {typeName: "HeadV2", jsonCase: "eth2"} | ||
| ); | ||
| const blockBase = new ContainerType( | ||
| { | ||
| slot: ssz.Slot, | ||
| block: stringType, | ||
| executionOptimistic: ssz.Boolean, | ||
|
Comment on lines
+72
to
+76
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. I guess calling this phase0, but it having a execution optimistic field isn't ideal either, but I think it's fine |
||
| }, | ||
| {typeName: "Block", jsonCase: "eth2"} | ||
| ); | ||
| const blockGloas = new ContainerType( | ||
| { | ||
| slot: ssz.Slot, | ||
| block: stringType, | ||
| blockHash: stringType, | ||
| builderIndex: ssz.BuilderIndex, | ||
|
Comment on lines
+84
to
+85
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. nit: I would like these fields after |
||
| executionOptimistic: ssz.Boolean, | ||
| }, | ||
| {typeName: "BlockGloas", jsonCase: "eth2"} | ||
| ); | ||
| type FuluDataColumnSidecarSSE = ValueOf<typeof fuluDataColumnSidecarSSE>; | ||
| type GloasDataColumnSidecarSSE = ValueOf<typeof gloasDataColumnSidecarSSE>; | ||
| type DataColumnSidecarSSE = FuluDataColumnSidecarSSE | GloasDataColumnSidecarSSE; | ||
|
|
@@ -185,6 +203,8 @@ export type EventData = { | |
| [EventType.block]: { | ||
| slot: Slot; | ||
| block: RootHex; | ||
| blockHash?: RootHex; | ||
| builderIndex?: BuilderIndex; | ||
| executionOptimistic: boolean; | ||
| }; | ||
|
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. can we type this similar to data column event? |
||
| [EventType.blockGossip]: { | ||
|
|
@@ -330,14 +350,17 @@ export function getTypeByEvent(config: ChainForkConfig): {[K in EventType]: Type | |
| ), | ||
| [EventType.headV2]: WithVersion(() => headV2), | ||
|
|
||
| [EventType.block]: new ContainerType( | ||
| { | ||
| slot: ssz.Slot, | ||
| block: stringType, | ||
| executionOptimistic: ssz.Boolean, | ||
| [EventType.block]: { | ||
| toJson: (val) => { | ||
| if (config.getForkSeq(val.slot) < ForkSeq.gloas) return blockBase.toJson(val); | ||
| if (val.blockHash === undefined || val.builderIndex === undefined) { | ||
| throw Error(`Missing block hash or builder index for block at ${val.slot}`); | ||
| } | ||
| return blockGloas.toJson({...val, blockHash: val.blockHash, builderIndex: val.builderIndex}); | ||
| }, | ||
| {jsonCase: "eth2"} | ||
| ), | ||
| fromJson: (json) => | ||
| (config.getForkSeq((json as {slot: Slot}).slot) >= ForkSeq.gloas ? blockGloas : blockBase).fromJson(json), | ||
| }, | ||
| [EventType.blockGossip]: new ContainerType( | ||
|
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. kinda warrants the question if we should also update
Contributor
Author
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. makes sense, we should probably do it
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 doesn't make sense btw, bad idea. the additional fields are targeted for builders to use and they should only use the
Contributor
Author
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. got it |
||
| { | ||
| slot: ssz.Slot, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ import { | |
| getSafeExecutionBlockHash, | ||
| } from "@lodestar/fork-choice"; | ||
| import { | ||
| BUILDER_INDEX_SELF_BUILD, | ||
| ForkPostAltair, | ||
| ForkPostElectra, | ||
| ForkSeq, | ||
|
|
@@ -25,7 +26,17 @@ import { | |
| isStatePostAltair, | ||
| isStatePostBellatrix, | ||
| } from "@lodestar/state-transition"; | ||
| import {Attestation, BeaconBlock, altair, capella, electra, isGloasBeaconBlock, phase0, ssz} from "@lodestar/types"; | ||
| import { | ||
| Attestation, | ||
| BeaconBlock, | ||
| BuilderIndex, | ||
| altair, | ||
| capella, | ||
| electra, | ||
| isGloasBeaconBlock, | ||
| phase0, | ||
| ssz, | ||
| } from "@lodestar/types"; | ||
| import {isErrorAborted, toRootHex} from "@lodestar/utils"; | ||
| import {GENESIS_SLOT, ZERO_HASH_HEX} from "../../constants/index.js"; | ||
| import {callInNextEventLoop} from "../../util/eventLoop.js"; | ||
|
|
@@ -529,10 +540,21 @@ export async function importBlock( | |
| callInNextEventLoop(() => { | ||
| // NOTE: Skip emitting if there are no listeners from the API | ||
| if (this.emitter.listenerCount(routes.events.EventType.block)) { | ||
| let gloasFields: undefined | {blockHash: string; builderIndex: BuilderIndex}; | ||
| if (isGloasBeaconBlock(block.message)) { | ||
| const builderIndex = block.message.body.signedExecutionPayloadBid.message.builderIndex; | ||
| if (builderIndex !== BUILDER_INDEX_SELF_BUILD) { | ||
|
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. While comparing this PoC, I found that self-built Gloas blocks omit both new fields here, but the Gloas serializer requires them and throws. If we keep this variant, could we emit the block hash and SELF_BUILD index too, with a self-build round-trip test?
Contributor
Author
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. ah, nice catch, thanks if we choose this version the check should get fixed at minimum, think the easiest fix here really is to emit self built as well, but initially we decided not to emit on such scenario so we should discuss it first
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. Thanks, I checked the latest version. Self-builds now include both fields and the round-trip test covers them, so that addresses the issue I raised. |
||
| gloasFields = { | ||
| blockHash: toRootHex(block.message.body.signedExecutionPayloadBid.message.blockHash), | ||
| builderIndex, | ||
| }; | ||
| } | ||
| } | ||
| this.emitter.emit(routes.events.EventType.block, { | ||
| block: blockRootHex, | ||
| slot: blockSlot, | ||
| executionOptimistic: blockSummary != null && isOptimisticBlock(blockSummary), | ||
| ...gloasFields, | ||
| }); | ||
| } | ||
| if (this.emitter.listenerCount(routes.events.EventType.voluntaryExit)) { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
nit: the term "base" isn't ideal, it's not used as a base for anything
could do
blockPhase0andblockGloasI guess if we wanna follow the data column naming, should be
phase0BlockandgloasBlock