From 679aa2a78c2f884017581a55aec8fa5ee5df90de Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Sat, 30 May 2026 17:14:46 +0100 Subject: [PATCH 1/6] fix: limit `shouldBuildOnFull` checks to the previous slot --- .../beacon-node/src/chain/prepareNextSlot.ts | 2 +- .../chain/produceBlock/produceBlockBody.ts | 2 +- .../fork-choice/src/forkChoice/forkChoice.ts | 4 ++-- .../fork-choice/src/forkChoice/interface.ts | 2 +- .../fork-choice/src/protoArray/protoArray.ts | 5 ++++- .../test/unit/protoArray/gloas.test.ts | 20 +++++++++++++------ 6 files changed, 23 insertions(+), 12 deletions(-) diff --git a/packages/beacon-node/src/chain/prepareNextSlot.ts b/packages/beacon-node/src/chain/prepareNextSlot.ts index 67fff1809e7e..ec6474c0d046 100644 --- a/packages/beacon-node/src/chain/prepareNextSlot.ts +++ b/packages/beacon-node/src/chain/prepareNextSlot.ts @@ -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) { diff --git a/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts b/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts index 8392c65829b0..08bb33922732 100644 --- a/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts +++ b/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts @@ -278,7 +278,7 @@ export async function produceBlockBody( // 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); if (isBuildingOnFull) { parentBlockHash = currentState.latestExecutionPayloadBid.blockHash; parentExecutionRequests = await this.getParentExecutionRequests(parentBlock.slot, parentBlock.blockRoot); diff --git a/packages/fork-choice/src/forkChoice/forkChoice.ts b/packages/fork-choice/src/forkChoice/forkChoice.ts index 4e06c8317e54..6d744ea2a0d6 100644 --- a/packages/fork-choice/src/forkChoice/forkChoice.ts +++ b/packages/fork-choice/src/forkChoice/forkChoice.ts @@ -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); } /** diff --git a/packages/fork-choice/src/forkChoice/interface.ts b/packages/fork-choice/src/forkChoice/interface.ts index fc4d7cdc28cd..f58afa03e2ae 100644 --- a/packages/fork-choice/src/forkChoice/interface.ts +++ b/packages/fork-choice/src/forkChoice/interface.ts @@ -256,7 +256,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; diff --git a/packages/fork-choice/src/protoArray/protoArray.ts b/packages/fork-choice/src/protoArray/protoArray.ts index 9619d743ed28..eb772ffdd2c9 100644 --- a/packages/fork-choice/src/protoArray/protoArray.ts +++ b/packages/fork-choice/src/protoArray/protoArray.ts @@ -760,11 +760,14 @@ export class ProtoArray { * The proposer is forced to build on the EMPTY variant (effectively reorging) * when the PTC majority voted that the blob data is not available. */ - 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; + // The PTC data availability view is 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; return !this.isPayloadDataNotAvailable(head.blockRoot); } diff --git a/packages/fork-choice/test/unit/protoArray/gloas.test.ts b/packages/fork-choice/test/unit/protoArray/gloas.test.ts index 06f7fb5a225a..1168ca90b25a 100644 --- a/packages/fork-choice/test/unit/protoArray/gloas.test.ts +++ b/packages/fork-choice/test/unit/protoArray/gloas.test.ts @@ -978,18 +978,18 @@ 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)", () => { @@ -997,7 +997,7 @@ describe("Gloas Fork Choice", () => { const overThreshold = Math.floor(PTC_SIZE / 2) + 1; const indices = Array.from({length: overThreshold}, (_, i) => i); protoArray.notifyPtcMessages("0x02", indices, true, false); - expect(protoArray.shouldBuildOnFull(head)).toBe(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 >=)", () => { @@ -1005,14 +1005,22 @@ describe("Gloas Fork Choice", () => { const atThreshold = Math.floor(PTC_SIZE / 2); const indices = Array.from({length: atThreshold}, (_, i) => i); protoArray.notifyPtcMessages("0x02", indices, true, false); - expect(protoArray.shouldBuildOnFull(head)).toBe(true); + 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", [0], true, false); - expect(protoArray.shouldBuildOnFull(head)).toBe(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", indices, true, false); + expect(protoArray.shouldBuildOnFull(head, head.slot + 2)).toBe(true); }); }); From e3790e33e943a9f408b05f46dd9a6945e001d386 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Sat, 30 May 2026 17:17:56 +0100 Subject: [PATCH 2/6] make both false --- packages/fork-choice/test/unit/protoArray/gloas.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/fork-choice/test/unit/protoArray/gloas.test.ts b/packages/fork-choice/test/unit/protoArray/gloas.test.ts index 1168ca90b25a..0c59a04ac739 100644 --- a/packages/fork-choice/test/unit/protoArray/gloas.test.ts +++ b/packages/fork-choice/test/unit/protoArray/gloas.test.ts @@ -1019,7 +1019,7 @@ describe("Gloas Fork Choice", () => { const head = makeHead(PayloadStatus.FULL); const overThreshold = Math.floor(PTC_SIZE / 2) + 1; const indices = Array.from({length: overThreshold}, (_, i) => i); - protoArray.notifyPtcMessages("0x02", indices, true, false); + protoArray.notifyPtcMessages("0x02", indices, false, false); expect(protoArray.shouldBuildOnFull(head, head.slot + 2)).toBe(true); }); }); From d9285cd45d30e3fbeba19a5482fe68f9ef72c64e Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Sat, 30 May 2026 17:42:53 +0100 Subject: [PATCH 3/6] add new lines --- packages/fork-choice/src/protoArray/protoArray.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/fork-choice/src/protoArray/protoArray.ts b/packages/fork-choice/src/protoArray/protoArray.ts index eb772ffdd2c9..adc5bf9393da 100644 --- a/packages/fork-choice/src/protoArray/protoArray.ts +++ b/packages/fork-choice/src/protoArray/protoArray.ts @@ -765,9 +765,11 @@ export class ProtoArray { throw new Error("shouldBuildOnFull called with PENDING head"); } if (head.payloadStatus === PayloadStatus.EMPTY) return false; + // The PTC data availability view is 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; + return !this.isPayloadDataNotAvailable(head.blockRoot); } From 165e6c222cfa26f2bbfc3f1e46053f645f8e10c7 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Sat, 30 May 2026 21:03:31 +0100 Subject: [PATCH 4/6] use head.slot --- .../fork-choice/test/unit/protoArray/gloas.test.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/fork-choice/test/unit/protoArray/gloas.test.ts b/packages/fork-choice/test/unit/protoArray/gloas.test.ts index 026b9d3d9218..677027b559b2 100644 --- a/packages/fork-choice/test/unit/protoArray/gloas.test.ts +++ b/packages/fork-choice/test/unit/protoArray/gloas.test.ts @@ -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(); }); }); @@ -1029,7 +1029,7 @@ describe("Gloas Fork Choice", () => { 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); + protoArray.notifyPtcMessages("0x02", head.slot, indices, true, false); expect(protoArray.shouldBuildOnFull(head, head.slot + 1)).toBe(false); }); @@ -1037,14 +1037,14 @@ describe("Gloas Fork Choice", () => { 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); + 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); + protoArray.notifyPtcMessages("0x02", head.slot, [0], true, false); expect(protoArray.shouldBuildOnFull(head, head.slot + 1)).toBe(true); }); @@ -1052,7 +1052,7 @@ describe("Gloas Fork Choice", () => { 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, false, false); + protoArray.notifyPtcMessages("0x02", head.slot, indices, false, false); expect(protoArray.shouldBuildOnFull(head, head.slot + 2)).toBe(true); }); }); From bbb6360ec256bbe527537f1078d6709b419daed9 Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Sun, 31 May 2026 11:59:52 +0100 Subject: [PATCH 5/6] feat: force the proposer to reorg late payloads --- .../fork-choice/src/protoArray/protoArray.ts | 12 ++++++++---- .../test/unit/protoArray/gloas.test.ts | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/fork-choice/src/protoArray/protoArray.ts b/packages/fork-choice/src/protoArray/protoArray.ts index c6908c92a856..c47e1a0b6d25 100644 --- a/packages/fork-choice/src/protoArray/protoArray.ts +++ b/packages/fork-choice/src/protoArray/protoArray.ts @@ -766,7 +766,8 @@ 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, slot: Slot): boolean { if (head.payloadStatus === PayloadStatus.PENDING) { @@ -774,11 +775,14 @@ export class ProtoArray { } if (head.payloadStatus === PayloadStatus.EMPTY) return false; - // The PTC data availability view is 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. + // 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; - return !this.isPayloadDataNotAvailable(head.blockRoot); + if (this.isPayloadDataNotAvailable(head.blockRoot)) return false; + + return !this.isPayloadNotTimely(head.blockRoot); } /** diff --git a/packages/fork-choice/test/unit/protoArray/gloas.test.ts b/packages/fork-choice/test/unit/protoArray/gloas.test.ts index 677027b559b2..9a737eddce77 100644 --- a/packages/fork-choice/test/unit/protoArray/gloas.test.ts +++ b/packages/fork-choice/test/unit/protoArray/gloas.test.ts @@ -1048,6 +1048,23 @@ describe("Gloas Fork Choice", () => { 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; From 7808e92412679498ba4e2a9bc3ca94ac2a2aecce Mon Sep 17 00:00:00 2001 From: Nico Flaig Date: Sun, 31 May 2026 12:28:04 +0100 Subject: [PATCH 6/6] update comment --- .../beacon-node/src/chain/produceBlock/produceBlockBody.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts b/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts index 08bb33922732..c9542d1519fb 100644 --- a/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts +++ b/packages/beacon-node/src/chain/produceBlock/produceBlockBody.ts @@ -276,8 +276,8 @@ export async function produceBlockBody( // Apply parent payload once here as it's reused by EL prep and voluntary exit filtering below let stateAfterParentPayload: IBeaconStateViewBellatrix = currentState; // 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). + // (set by chain.getProposerHead(slot)). Returns false when the PTC majority signalled + // the blob data is not available or the payload was not timely, forcing a build on EMPTY (reorg). const isBuildingOnFull = this.forkChoice.shouldBuildOnFull(parentBlock, blockSlot); if (isBuildingOnFull) { parentBlockHash = currentState.latestExecutionPayloadBid.blockHash;