Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
42 changes: 27 additions & 15 deletions packages/beacon-node/src/api/impl/beacon/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,24 +208,29 @@ export function getBeaconBlockApi({
const blockLocallyProduced = chain.blockProductionCache.has(blockRoot);
const valLogMeta = {slot, blockRoot, bodyRoot, broadcastValidation, blockLocallyProduced};

// For a REPEAT_PROPOSAL (equivocating) block we still import it into fork choice but must not
// re-publish it (or its sidecars) to the network; this flag gates the publish thunks below.
let skipPublish = false;

switch (broadcastValidation) {
case routes.beacon.BroadcastValidation.gossip: {
if (!blockLocallyProduced) {
try {
await validateGossipBlock(config, chain, signedBlock, fork);
} catch (error) {
if (error instanceof BlockGossipError) {
switch (error.type.code) {
case BlockErrorCode.ALREADY_KNOWN:
// Block has already been seen, e.g. via gossip racing the publish API. Benign.
chain.logger.debug("Ignoring already-known block during publishing", valLogMeta);
return;
case BlockErrorCode.REPEAT_PROPOSAL:
// The proposer already produced a block for this slot. For a solo setup this is a
// notable signal (duplicate-proposal attempt). For fallback / DVT setups it is
// expected on every block where another node published first.
chain.logger.warn("Ignoring repeat-proposal block during publishing", valLogMeta);
return;
Comment thread
twoeths marked this conversation as resolved.
Resolved
if (error.type.code === BlockErrorCode.ALREADY_KNOWN) {
// Block has already been seen, e.g. via gossip racing the publish API. Benign.
chain.logger.debug("Ignoring already-known block during publishing", valLogMeta);
return;
}
if (error.type.code === BlockErrorCode.REPEAT_PROPOSAL) {
// the proposer already produced a block for this slot
// Spec: do NOT re-publish it, but we should still import because each node may receive different block
// and this block may become canonical
chain.logger.warn("Importing repeat-proposal block without publishing", valLogMeta);
skipPublish = true;
break;
}
}

Expand Down Expand Up @@ -371,9 +376,15 @@ export function getBeaconBlockApi({
// b) getting block first allows nodes to use getBlobs from local ELs and save
// import latency and hopefully bandwidth
//
() => network.publishBeaconBlock(signedBlock),
...dataColumnSidecars.map((dataColumnSidecar) => () => network.publishDataColumnSidecar(dataColumnSidecar)),
...blobSidecars.map((blobSidecar) => () => network.publishBlobSidecar(blobSidecar)),
// For a REPEAT_PROPOSAL (equivocating) block we still import it (below) but do not re-publish
// it or its sidecars to the network.
...(skipPublish
Comment thread
twoeths marked this conversation as resolved.
Resolved
? []

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep Fulu publish results aligned when skipping gossip

When skipPublish is true for a Fulu repeat proposal with blobs, this branch removes the beacon-block and data-column publish thunks, so sentPeersArr only contains the processBlock result. The Fulu metrics loop below still reads sentPeersArr[i + 1] for each data column and destructures it, which turns a successfully imported repeat-proposal publish into a TypeError instead of returning normally.

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.

fixed in 4ac0456

: [
() => network.publishBeaconBlock(signedBlock),
...dataColumnSidecars.map((dataColumnSidecar) => () => network.publishDataColumnSidecar(dataColumnSidecar)),
...blobSidecars.map((blobSidecar) => () => network.publishBlobSidecar(blobSidecar)),
]),
() =>
// there is no rush to persist block since we published it to gossip anyway
chain
Expand All @@ -397,7 +408,8 @@ export function getBeaconBlockApi({
publishPromises
);

if (isForkPostGloas(fork)) {
if (skipPublish || isForkPostGloas(fork)) {
// For a REPEAT_PROPOSAL block we published nothing, so there are no sent-peers metrics to record.
// After gloas, data columns are not published with the block but when publishing the execution payload envelope
} else if (isForkPostFulu(fork)) {
let columnsPublishedWithZeroPeers = 0;
Expand Down
2 changes: 1 addition & 1 deletion packages/beacon-node/src/chain/errors/blockError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export type BlockErrorType =
| {code: BlockErrorCode.GENESIS_BLOCK}
| {code: BlockErrorCode.WOULD_REVERT_FINALIZED_SLOT; blockSlot: Slot; finalizedSlot: Slot}
| {code: BlockErrorCode.ALREADY_KNOWN; root: RootHex}
| {code: BlockErrorCode.REPEAT_PROPOSAL; proposerIndex: ValidatorIndex}
| {code: BlockErrorCode.REPEAT_PROPOSAL; proposerIndex: ValidatorIndex; root: RootHex}
| {code: BlockErrorCode.BLOCK_SLOT_LIMIT_REACHED}
| {code: BlockErrorCode.INCORRECT_PROPOSER; proposerIndex: ValidatorIndex}
| {code: BlockErrorCode.PROPOSAL_SIGNATURE_INVALID; blockSlot: Slot}
Expand Down
12 changes: 10 additions & 2 deletions packages/beacon-node/src/chain/validation/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ export async function validateGossipBlock(
await verifyBlockProposerSignature(chain, signedBlock, blockRoot, {verifyOnMainThread: false});
chain.seenBlockProposers.observeBlockRoot(blockSlot, proposerIndex, blockRoot, signedBlockHeader);
}
throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.REPEAT_PROPOSAL, proposerIndex});
throw new BlockGossipError(GossipAction.IGNORE, {
code: BlockErrorCode.REPEAT_PROPOSAL,
proposerIndex,
root: blockRoot,
});
}

// [REJECT] The current finalized_checkpoint is an ancestor of block -- i.e.
Expand Down Expand Up @@ -301,7 +305,11 @@ export async function validateGossipBlock(

// Check again after all async validation and the early-block delay so concurrent proposals cannot both pass
if (chain.seenBlockProposers.isKnown(blockSlot, proposerIndex)) {
throw new BlockGossipError(GossipAction.IGNORE, {code: BlockErrorCode.REPEAT_PROPOSAL, proposerIndex});
throw new BlockGossipError(GossipAction.IGNORE, {
code: BlockErrorCode.REPEAT_PROPOSAL,
proposerIndex,
root: blockRoot,
});
}

chain.seenBlockProposers.add(blockSlot, proposerIndex);
Expand Down
27 changes: 24 additions & 3 deletions packages/beacon-node/src/network/processor/gossipHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,9 +713,30 @@ function getSequentialHandlers(modules: ValidatorFnsModules, options: GossipHand
const {serializedData} = gossipData;

const signedBlock = sszDeserialize(topic, serializedData);
const blockInput = await validateBeaconBlock(signedBlock, topic.boundary.fork, peerIdStr, seenTimestampSec);
chain.serializedCache.set(signedBlock, serializedData);
handleValidBeaconBlock(blockInput, peerIdStr, seenTimestampSec);
try {
const blockInput = await validateBeaconBlock(signedBlock, topic.boundary.fork, peerIdStr, seenTimestampSec);
chain.serializedCache.set(signedBlock, serializedData);
handleValidBeaconBlock(blockInput, peerIdStr, seenTimestampSec);
} catch (e) {
// Spec: IGNORE the block, ie not to re-publish to peers
// but we should still import an equivocating (REPEAT_PROPOSAL) block into fork choice because we don't
// know if this block (or the 1st known block with same slot) will become canonical yet
if (
e instanceof BlockGossipError &&
e.type.code === BlockErrorCode.REPEAT_PROPOSAL &&
// this is make sure the block's proposer signature was verified, it should be true anyway
chain.seenBlockProposers.hasBlockRoot(signedBlock.message.slot, e.type.proposerIndex, e.type.root)
) {
// blockInput was optimistically seeded in validateBeaconBlock and retained on IGNORE
const blockInput = chain.seenBlockInputCache.get(e.type.root);
if (blockInput) {
chain.serializedCache.set(signedBlock, serializedData);
handleValidBeaconBlock(blockInput, peerIdStr, seenTimestampSec);

@nflaig nflaig Aug 12, 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.

I think we need to revisit the ordering in validateGossipBlock, so right now, if we throw a REPEAT_PROPOSAL that happens quite early, so the beacon block isn't fully validated here?

also it's before this check

 if (blockState.getBeaconProposer(blockSlot) !== proposerIndex) {
    throw new BlockGossipError(GossipAction.REJECT, {code: BlockErrorCode.INCORRECT_PROPOSER, proposerIndex});
  }

which seems questionable?

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.

I think the p2p rules are just quick checks to forward the gossip block without having to run state transition
if the block is really invalid, it should be caught inside the state transition itself
in this case it's

it's worth to mention this in the code

@nflaig nflaig Aug 13, 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.

yeah that is probably fine was thinking the same way, but we should be more explicit about it, so adding a comment as suggested makes sense.

there was one worry that we could receive many invalid blocks and fill our cache but due to how gossip re-propagation works this should be unlikely unless a peer sends them directly to us, but I think we still wanna make sure that we at least validate the proposer signature in any case, although my worry here is that we run blockState.getBeaconProposer(blockSlot) !== proposerIndex later, so technically any validator can produce a valid signature (of course they would get slashed too if they do more >=2 so the incentives for doing so are low) and we downscore them, so it's likely fine

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.

but I think we still wanna make sure that we at least validate the proposer signature in any case

it's already checked at line 718 above

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.

ah yeah that looks fine

}
}
// rethrow so gossipValidatorFn maps IGNORE -> TopicValidatorResult.Ignore (message not forwarded)
throw e;
}
},

[GossipType.blob_sidecar]: async ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ import {toRootHex} from "@lodestar/utils";
import {getBeaconBlockApi} from "../../../../../../src/api/impl/beacon/blocks/index.js";
import {BlockInputPreData, BlockInputSource} from "../../../../../../src/chain/blocks/blockInput/index.js";
import {verifyBlocksInEpoch} from "../../../../../../src/chain/blocks/verifyBlock.js";
import {BlockErrorCode, BlockGossipError, GossipAction} from "../../../../../../src/chain/errors/index.js";
import {SeenBlockProposers} from "../../../../../../src/chain/seenCache/seenBlockProposers.js";
import {validateGossipBlock} from "../../../../../../src/chain/validation/block.js";
import {ApiTestModules, getApiTestModules} from "../../../../../utils/api.js";
import {generateProtoBlock} from "../../../../../utils/typeGenerator.js";

vi.mock("../../../../../../src/chain/blocks/verifyBlock.js");
// Partial mock: keep verifyBlockProposerSignature (used by the consensus paths), override validateGossipBlock
vi.mock("../../../../../../src/chain/validation/block.js", async (importOriginal) => ({
...(await importOriginal<typeof import("../../../../../../src/chain/validation/block.js")>()),
validateGossipBlock: vi.fn(),
}));

describe("api - beacon - publishBlockV2", () => {
const config = createBeaconConfig(configDef, Buffer.alloc(32, 1));
Expand Down Expand Up @@ -68,6 +75,42 @@ describe("api - beacon - publishBlockV2", () => {
});
});

describe("broadcast_validation=gossip", () => {
it("imports a REPEAT_PROPOSAL (equivocating) block into fork choice but does not re-publish it", async () => {
const signedBlock = ssz.phase0.SignedBeaconBlock.defaultValue();
signedBlock.message.slot = 1;
signedBlock.message.proposerIndex = 2;
const blockRoot = toRootHex(
modules.config.getForkTypes(signedBlock.message.slot).BeaconBlock.hashTreeRoot(signedBlock.message)
);
const blockInput = BlockInputPreData.createFromBlock({
forkName: ForkName.phase0,
block: signedBlock,
blockRootHex: blockRoot,
source: BlockInputSource.api,
seenTimestampSec: 0,
daOutOfRange: false,
});
modules.chain.seenBlockInputCache.getByBlock.mockReturnValue(blockInput);
// Default (gossip) broadcast validation runs validateGossipBlock; simulate an equivocating proposal
vi.mocked(validateGossipBlock).mockRejectedValue(
new BlockGossipError(GossipAction.IGNORE, {
code: BlockErrorCode.REPEAT_PROPOSAL,
proposerIndex: signedBlock.message.proposerIndex,
root: blockRoot,
})
);

const api = getBeaconBlockApi(modules);
await api.publishBlockV2({signedBlockContents: {signedBlock}});

// Imported into fork choice so LMD-GHOST can weigh it ...
expect(modules.chain.processBlock).toHaveBeenCalledWith(blockInput, {});
// ... but not re-published to the network
expect(modules.network.publishBeaconBlock).not.toHaveBeenCalled();
});
});

describe("consensus validation strategies", () => {
it.each([routes.beacon.BroadcastValidation.consensus, routes.beacon.BroadcastValidation.consensusAndEquivocation])(
"verifies the proposer signature and records the root before publishing a local block with broadcast_validation=%s",
Expand Down
26 changes: 26 additions & 0 deletions packages/beacon-node/test/unit/chain/validation/block.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,32 @@ describe("gossip block validation", () => {
).toEqual([blockRoot, conflictingBlockRoot]);
});

it("attaches the conflicting block root to the REPEAT_PROPOSAL error", async () => {
const forkTypes = gloasConfig.getForkTypes(clockSlot);
const signedBlock = forkTypes.SignedBeaconBlock.defaultValue();
signedBlock.message.slot = clockSlot;
signedBlock.message.proposerIndex = proposerIndex;
const blockRoot = toRootHex(forkTypes.BeaconBlock.hashTreeRoot(signedBlock.message));
chain.seenBlockProposers.observeBlockRoot(
clockSlot,
proposerIndex,
blockRoot,
signedBlockToSignedHeader(gloasConfig, signedBlock)
);
chain.seenBlockProposers.add(clockSlot, proposerIndex);

const conflictingBlock = forkTypes.SignedBeaconBlock.clone(signedBlock);
conflictingBlock.message.stateRoot = Buffer.alloc(32, 1);
const conflictingBlockRoot = toRootHex(forkTypes.BeaconBlock.hashTreeRoot(conflictingBlock.message));

const error = (await validateGossipBlock(gloasConfig, chain, conflictingBlock, ForkName.gloas).catch(
(e) => e
)) as {type: {code: BlockErrorCode; root?: string}};
expect(error.type.code).toBe(BlockErrorCode.REPEAT_PROPOSAL);
// The root lets the gossip/API handlers fetch the seeded blockInput and import the equivocating block
expect(error.type.root).toBe(conflictingBlockRoot);
});

it("does not record a conflicting block root when the proposer signature is invalid", async () => {
const forkTypes = gloasConfig.getForkTypes(clockSlot);
const signedBlock = forkTypes.SignedBeaconBlock.defaultValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {toRootHex} from "@lodestar/utils";
import {BlockInputBlobs} from "../../../../src/chain/blocks/blockInput/blockInput.js";
import {BlockInputSource} from "../../../../src/chain/blocks/blockInput/types.js";
import {BlockError, BlockErrorCode} from "../../../../src/chain/errors/blockError.js";
import {BlockGossipError, GossipAction} from "../../../../src/chain/errors/index.js";
import {ChainEventEmitter, IBeaconChain} from "../../../../src/chain/index.js";
import {SeenBlockProposers} from "../../../../src/chain/seenCache/seenBlockProposers.js";
import {SeenBlockInput} from "../../../../src/chain/seenCache/seenGossipBlockInput.js";
Expand Down Expand Up @@ -62,6 +63,22 @@ describe("getGossipHandlers", () => {
expect(core.reportPeer).toHaveBeenCalledOnce();
expect(core.reportPeer).toHaveBeenCalledWith(peerIdStr, PeerAction.LowToleranceError, "ExecutionEngineInvalid");
});

it("imports a signature-verified REPEAT_PROPOSAL (equivocating) block into fork choice but keeps IGNORE", async () => {
const {processBlock, threw} = await runBeaconBlockRepeatProposal(denebConfig, {recorded: true});

// imported so LMD-GHOST can weigh it ...
expect(processBlock).toHaveBeenCalledOnce();
// ... but the gossip result stays IGNORE (handler re-throws), so the message is not forwarded
expect(threw).toBe(true);
});

it("does not import a REPEAT_PROPOSAL block whose root was not recorded (unverified 3rd+ proposal)", async () => {
const {processBlock, threw} = await runBeaconBlockRepeatProposal(denebConfig, {recorded: false});

expect(processBlock).not.toHaveBeenCalled();
expect(threw).toBe(true);
});
});

async function runBeaconBlockProcessingError(
Expand Down Expand Up @@ -138,6 +155,103 @@ async function runBeaconBlockProcessingError(
return {core, peerIdStr};
}

async function runBeaconBlockRepeatProposal(
config: BeaconConfig,
{recorded}: {recorded: boolean}
): Promise<{processBlock: ReturnType<typeof vi.fn>; threw: boolean}> {
const logger = testLogger();
const peerIdStr = "16Uiu2HAmTestGossipPeer" as PeerIdStr;
const signedBlock = ssz.deneb.SignedBeaconBlock.defaultValue();
signedBlock.message.slot = 1;
signedBlock.message.proposerIndex = 3;
const blockRootHex = toRootHex(ssz.deneb.BeaconBlock.hashTreeRoot(signedBlock.message));
const blockInput = BlockInputBlobs.createFromBlock({
block: signedBlock,
blockRootHex,
forkName: ForkName.deneb,
daOutOfRange: false,
source: BlockInputSource.gossip,
seenTimestampSec: 0,
peerIdStr,
});

// gossip validation rejects the 2nd distinct block for this (proposer, slot) with REPEAT_PROPOSAL
vi.mocked(validateGossipBlock).mockRejectedValue(
new BlockGossipError(GossipAction.IGNORE, {
code: BlockErrorCode.REPEAT_PROPOSAL,
proposerIndex: signedBlock.message.proposerIndex,
root: blockRootHex,
})
);

const seenBlockProposers = new SeenBlockProposers();
if (recorded) {
// observeBlockRoot runs only after the proposer signature is verified, so hasBlockRoot(root)
// being true is the handler's proof the signature was checked (the 2nd distinct block)
seenBlockProposers.observeBlockRoot(
signedBlock.message.slot,
signedBlock.message.proposerIndex,
blockRootHex,
ssz.phase0.SignedBeaconBlockHeader.defaultValue()
);
}

const processBlock = vi.fn().mockResolvedValue(undefined);
const chain = {
clock: new ClockStopped(1),
custodyConfig: {sampledColumns: [], custodyColumns: []} as unknown as CustodyConfig,
emitter: new ChainEventEmitter(),
getBlobsTracker: {triggerGetBlobs: vi.fn()},
logger,
processBlock,
processProposerEquivocation: vi.fn(),
seenBlockProposers,
seenBlockInputCache: {
getByBlock: vi.fn().mockReturnValue(blockInput),
get: vi.fn().mockReturnValue(blockInput),
prune: vi.fn(),
} as unknown as SeenBlockInput,
seenPayloadEnvelopeInputCache: {
add: vi.fn(),
get: vi.fn().mockReturnValue(undefined),
prune: vi.fn(),
} as unknown as IBeaconChain["seenPayloadEnvelopeInputCache"],
serializedCache: {set: vi.fn()},
} as unknown as IBeaconChain;

const handlers = getGossipHandlers(
{
aggregatorTracker: {} as AggregatorTracker,
chain,
config,
core: {reportPeer: vi.fn()} as unknown as INetworkCore,
events: new NetworkEventBus(),
logger,
metrics: null,
},
{}
);
const beaconBlockHandler = handlers[GossipType.beacon_block] as SequentialGossipHandler<GossipType.beacon_block>;

let threw = false;
try {
await beaconBlockHandler({
gossipData: {serializedData: ssz.deneb.SignedBeaconBlock.serialize(signedBlock)},
peerIdStr,
seenTimestampSec: 0,
topic: {
boundary: {fork: ForkName.deneb, epoch: 0},
type: GossipType.beacon_block,
},
});
} catch {
threw = true;
}
await new Promise((resolve) => setTimeout(resolve, 0));

return {processBlock, threw};
}

function getExecutionBlockError(
signedBlock: SignedBeaconBlock<typeof ForkName.deneb>,
code: BlockErrorCode.EXECUTION_ENGINE_ERROR | BlockErrorCode.EXECUTION_ENGINE_INVALID
Expand Down
Loading