Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion packages/beacon-node/src/chain/prepareNextSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class PrepareNextSlotScheduler {
let stateAfterParentPayload: IBeaconStateViewBellatrix = updatedPrepareState;
if (isStatePostGloas(updatedPrepareState)) {
// Spec: should_build_on_full(store, head) — see produceBlockBody.ts for context.
if (this.chain.forkChoice.shouldBuildOnFull(updatedHead)) {
if (this.chain.forkChoice.shouldBuildOnFull(updatedHead, prepareSlot)) {
parentBlockHash = updatedPrepareState.latestExecutionPayloadBid.blockHash;
// Skip applying parent payload unless we're proposing the next slot or have to emit payload_attributes events
if (feeRecipient !== undefined || this.chain.opts.emitPayloadAttributes === true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export async function produceBlockBody<T extends BlockType>(
// Spec: should_build_on_full(store, head). `parentBlock` is the proposer's head
// (set by chain.getProposerHead(slot)). Returns false when the PTC majority
// signalled the blob data is not available, forcing a build on EMPTY (reorg).
const isBuildingOnFull = this.forkChoice.shouldBuildOnFull(parentBlock);
const isBuildingOnFull = this.forkChoice.shouldBuildOnFull(parentBlock, blockSlot);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Reject builder bids when forced onto EMPTY

When a Gloas proposer has a builder bid for the FULL head and PTC timeliness NO votes exceed the threshold, this new shouldBuildOnFull check only affects the local execution-payload branch. The earlier builderBid !== undefined branch never calls it, and produceBlockV4 fetches a bid for parentBlock.executionPayloadBlockHash then prefers any fulfilled builder result, so the validator can still publish a builder block extending the late FULL payload instead of reorging to EMPTY. The builder path needs to be gated or look up/build only bids for the EMPTY parent when shouldBuildOnFull(parentBlock, slot) is false.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this new shouldBuildOnFull check only affects the local execution-payload branch

this seems like a bug if that's the case, but kinda unrelated to this PR

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

cc @ensi321 since you worked on this, I haven't reviewed your PR in detail yet but this seems like a valid finding, meaning we would not reorg late payloads if we use a bid instead of local build

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.

It's a valid concern. We need to call shouldBuildOnFull in our builder bid flow

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

if (isBuildingOnFull) {
parentBlockHash = currentState.latestExecutionPayloadBid.blockHash;
parentExecutionRequests = await this.getParentExecutionRequests(parentBlock.slot, parentBlock.blockRoot);
Expand Down
4 changes: 2 additions & 2 deletions packages/fork-choice/src/forkChoice/forkChoice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ export class ForkChoice implements IForkChoice {
}

/** Spec: should_build_on_full(store, head) */
shouldBuildOnFull(head: ProtoBlock): boolean {
return this.protoArray.shouldBuildOnFull(head);
shouldBuildOnFull(head: ProtoBlock, slot: Slot): boolean {
return this.protoArray.shouldBuildOnFull(head, slot);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/fork-choice/src/forkChoice/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ export interface IForkChoice {
getBlockHexAndBlockHash(blockRoot: RootHex, blockHash: RootHex): ProtoBlock | null;
shouldExtendPayload(blockRoot: RootHex): boolean;
/** Spec: should_build_on_full(store, head) */
shouldBuildOnFull(head: ProtoBlock): boolean;
shouldBuildOnFull(head: ProtoBlock, slot: Slot): boolean;
getFinalizedBlock(): ProtoBlock;
getJustifiedBlock(): ProtoBlock;
getFinalizedCheckpointSlot(): Slot;
Expand Down
15 changes: 12 additions & 3 deletions packages/fork-choice/src/protoArray/protoArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,14 +766,23 @@ export class ProtoArray {
* Spec: should_build_on_full(store, head)
*
* The proposer is forced to build on the EMPTY variant (effectively reorging)
* when the PTC majority voted that the blob data is not available.
* when the PTC majority voted that the blob data is not available or that the
* payload was not timely.
*/
shouldBuildOnFull(head: ProtoBlock): boolean {
shouldBuildOnFull(head: ProtoBlock, slot: Slot): boolean {
if (head.payloadStatus === PayloadStatus.PENDING) {
throw new Error("shouldBuildOnFull called with PENDING head");
}
if (head.payloadStatus === PayloadStatus.EMPTY) return false;
Comment thread
twoeths marked this conversation as resolved.
Resolved
return !this.isPayloadDataNotAvailable(head.blockRoot);

// The PTC data availability and timeliness views are only consulted for a head from the
// previous slot. For an earlier head the empty/full variant has already been resolved by
// weight in getHead.
if (head.slot + 1 !== slot) return true;

if (this.isPayloadDataNotAvailable(head.blockRoot)) return false;

return !this.isPayloadNotTimely(head.blockRoot);
}

/**
Expand Down
45 changes: 35 additions & 10 deletions packages/fork-choice/test/unit/protoArray/gloas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ describe("Gloas Fork Choice", () => {
expect(protoArray.isPayloadTimely("0x02")).toBe(false);

// notifyPtcMessages should be no-op
expect(() => protoArray.notifyPtcMessages("0x02", gloasForkSlot, [0], true, true)).not.toThrow();
expect(() => protoArray.notifyPtcMessages("0x02", gloasForkSlot - 1, [0], true, true)).not.toThrow();
});
});

Expand Down Expand Up @@ -1011,41 +1011,66 @@ describe("Gloas Fork Choice", () => {

it("throws when head is PENDING", () => {
const head = makeHead(PayloadStatus.PENDING);
expect(() => protoArray.shouldBuildOnFull(head)).toThrow(/PENDING/);
expect(() => protoArray.shouldBuildOnFull(head, head.slot + 1)).toThrow(/PENDING/);
});

it("returns false when head is EMPTY", () => {
const head = makeHead(PayloadStatus.EMPTY);
expect(protoArray.shouldBuildOnFull(head)).toBe(false);
expect(protoArray.shouldBuildOnFull(head, head.slot + 1)).toBe(false);
});

it("returns true when head is FULL and no DA NO votes", () => {
const head = makeHead(PayloadStatus.FULL);
// No votes at all — isPayloadDataNotAvailable returns false → build on full
expect(protoArray.shouldBuildOnFull(head)).toBe(true);
expect(protoArray.shouldBuildOnFull(head, head.slot + 1)).toBe(true);
});

it("returns false when head is FULL and DA NO votes exceed threshold (reorg trigger)", () => {
const head = makeHead(PayloadStatus.FULL);
const overThreshold = Math.floor(PTC_SIZE / 2) + 1;
const indices = Array.from({length: overThreshold}, (_, i) => i);
protoArray.notifyPtcMessages("0x02", gloasForkSlot, indices, true, false);
expect(protoArray.shouldBuildOnFull(head)).toBe(false);
protoArray.notifyPtcMessages("0x02", head.slot, indices, true, false);
expect(protoArray.shouldBuildOnFull(head, head.slot + 1)).toBe(false);
});

it("returns true when head is FULL and DA NO votes exactly at threshold (>, not >=)", () => {
const head = makeHead(PayloadStatus.FULL);
const atThreshold = Math.floor(PTC_SIZE / 2);
const indices = Array.from({length: atThreshold}, (_, i) => i);
protoArray.notifyPtcMessages("0x02", gloasForkSlot, indices, true, false);
expect(protoArray.shouldBuildOnFull(head)).toBe(true);
protoArray.notifyPtcMessages("0x02", head.slot, indices, true, false);
expect(protoArray.shouldBuildOnFull(head, head.slot + 1)).toBe(true);
});

it("returns true when many PTC members did not vote and few NO votes are below threshold", () => {
// Guards against None being miscounted as NO — would force a spurious reorg.
const head = makeHead(PayloadStatus.FULL);
protoArray.notifyPtcMessages("0x02", gloasForkSlot, [0], true, false);
expect(protoArray.shouldBuildOnFull(head)).toBe(true);
protoArray.notifyPtcMessages("0x02", head.slot, [0], true, false);
expect(protoArray.shouldBuildOnFull(head, head.slot + 1)).toBe(true);
});

it("returns false when head is FULL, data available but timeliness NO votes exceed threshold (late payload reorg)", () => {
const head = makeHead(PayloadStatus.FULL);
const overThreshold = Math.floor(PTC_SIZE / 2) + 1;
const indices = Array.from({length: overThreshold}, (_, i) => i);
// payloadPresent=false (untimely), blobDataAvailable=true (data available)
protoArray.notifyPtcMessages("0x02", head.slot, indices, false, true);
expect(protoArray.shouldBuildOnFull(head, head.slot + 1)).toBe(false);
});

it("returns true when head is FULL and timeliness NO votes exactly at threshold (>, not >=)", () => {
const head = makeHead(PayloadStatus.FULL);
const atThreshold = Math.floor(PTC_SIZE / 2);
const indices = Array.from({length: atThreshold}, (_, i) => i);
protoArray.notifyPtcMessages("0x02", head.slot, indices, false, true);
expect(protoArray.shouldBuildOnFull(head, head.slot + 1)).toBe(true);
});

it("returns true for a FULL head that is not from the previous slot, even with PTC voting against it", () => {
const head = makeHead(PayloadStatus.FULL);
const overThreshold = Math.floor(PTC_SIZE / 2) + 1;
const indices = Array.from({length: overThreshold}, (_, i) => i);
protoArray.notifyPtcMessages("0x02", head.slot, indices, false, false);
expect(protoArray.shouldBuildOnFull(head, head.slot + 2)).toBe(true);
});
});

Expand Down
Loading