Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions packages/api/src/beacon/routes/events.ts
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,
Expand Down Expand Up @@ -69,6 +69,24 @@ const headV2 = new ContainerType(
},
{typeName: "HeadV2", jsonCase: "eth2"}
);
const blockBase = new ContainerType(

@nflaig nflaig Oct 1, 2026 •

Copy link
Copy Markdown
Member

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 blockPhase0 and blockGloas

I guess if we wanna follow the data column naming, should be phase0Block and gloasBlock

{
slot: ssz.Slot,
block: stringType,
executionOptimistic: ssz.Boolean,
Comment on lines +72 to +76

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would like these fields after block and before executionOptimistic

executionOptimistic: ssz.Boolean,
},
{typeName: "BlockGloas", jsonCase: "eth2"}
);
type FuluDataColumnSidecarSSE = ValueOf<typeof fuluDataColumnSidecarSSE>;
type GloasDataColumnSidecarSSE = ValueOf<typeof gloasDataColumnSidecarSSE>;
type DataColumnSidecarSSE = FuluDataColumnSidecarSSE | GloasDataColumnSidecarSSE;
Expand Down Expand Up @@ -185,6 +203,8 @@ export type EventData = {
[EventType.block]: {
slot: Slot;
block: RootHex;
blockHash?: RootHex;
builderIndex?: BuilderIndex;
executionOptimistic: boolean;
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we type this similar to data column event?

[EventType.blockGossip]: {
Expand Down Expand Up @@ -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(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kinda warrants the question if we should also update block_gossip event

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, we should probably do it

@nflaig nflaig Oct 1, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 block event

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got it

{
slot: ssz.Slot,
Expand Down
3 changes: 3 additions & 0 deletions packages/api/test/unit/beacon/oapiSpec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ const ignoredTopics: string[] = [
// TODO: unskip once the spec release adds `current_slot` to the fast_confirmation event
// (tracked in https://github.com/ethereum/beacon-APIs/pull/598)
"fast_confirmation",
// TODO: unskip once the spec release adds `builder_index` and `block_hash` to the block event
// (tracked in https://github.com/ethereum/beacon-APIs/issues/599)
"block",
];

// eventstream types are defined as comments in the description of "examples".
Expand Down
2 changes: 2 additions & 0 deletions packages/api/test/unit/beacon/testData/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export const eventTestData: EventData = {
[EventType.block]: {
slot: 10,
block: "0x9a2fefd2fdb57f74993c7780ea5b9030d2897b615b89f808011ca5aebed54eaf",
blockHash: "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
builderIndex: 1,
executionOptimistic: false,
},
[EventType.blockGossip]: {
Expand Down
24 changes: 23 additions & 1 deletion packages/beacon-node/src/chain/blocks/importBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getSafeExecutionBlockHash,
} from "@lodestar/fork-choice";
import {
BUILDER_INDEX_SELF_BUILD,
ForkPostAltair,
ForkPostElectra,
ForkSeq,
Expand All @@ -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";
Expand Down Expand Up @@ -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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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)) {
Expand Down