fix(beacon-node): apply tsgo cast + add slot to merged-in #9479 test emit#9492
Conversation
test emit The merge of unstable into the PR branch brought in ChainSafe#9479's new test "defers envelope validation until the block is in fork choice when payload input is seeded from the block body". That test reproduces the same `let emitter!: ChainEventEmitter` + destructuring-assignment + sibling closure capture pattern that ChainSafe#9491 already mitigated in the sibling test below, so the same tsgo TS2769 fires at the new test's emit site: test/unit/sync/unknownBlock.test.ts(1027,20): error TS2769: No overload matches this call. Argument of type 'ChainEvent.unknownEnvelopeBlockRoot' is not assignable to parameter of type 'unique symbol'. Also, ChainSafe#9479's emit predates this PR's addition of `slot: Slot` to the `ChainEvent.unknownEnvelopeBlockRoot` event signature, so the emit data is missing the required `slot` field after the merge. Apply the same minimal fix: - Cast emitter at the failing site: `(emitter as ChainEventEmitter).emit(...)`. - Add `slot: 0` to the emit data. 🤖 Generated with AI assistance
There was a problem hiding this comment.
Code Review
This pull request updates a unit test in unknownBlock.test.ts by casting emitter to ChainEventEmitter to resolve a TypeScript overload-resolution issue and adding a slot property to the emitted event payload. The reviewer suggested fixing a typo in the added comment (tsgo to tsc) and replacing the hardcoded slot: 0 with block.message.slot for better accuracy and robustness.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| // tsgo overload-resolution miss when emit is reached through a closure that captures emitter | ||
| // first; cast re-anchors the StrictEventEmitter overload for ChainEvent keys (see #9491). | ||
| (emitter as ChainEventEmitter).emit(ChainEvent.unknownEnvelopeBlockRoot, { | ||
| rootHex: blockRootHex, | ||
| slot: 0, | ||
| peer, | ||
| source: BlockInputSource.gossip, | ||
| }); |
There was a problem hiding this comment.
There is a typo in the comment (tsgo instead of tsc). Additionally, instead of hardcoding slot: 0, it is more accurate and robust to use block.message.slot to match the slot of the block and envelope created in the test fixture.
| // tsgo overload-resolution miss when emit is reached through a closure that captures emitter | |
| // first; cast re-anchors the StrictEventEmitter overload for ChainEvent keys (see #9491). | |
| (emitter as ChainEventEmitter).emit(ChainEvent.unknownEnvelopeBlockRoot, { | |
| rootHex: blockRootHex, | |
| slot: 0, | |
| peer, | |
| source: BlockInputSource.gossip, | |
| }); | |
| // tsc overload-resolution miss when emit is reached through a closure that captures emitter | |
| // first; cast re-anchors the StrictEventEmitter overload for ChainEvent keys (see #9491). | |
| (emitter as ChainEventEmitter).emit(ChainEvent.unknownEnvelopeBlockRoot, { | |
| rootHex: blockRootHex, | |
| slot: block.message.slot, | |
| peer, | |
| source: BlockInputSource.gossip, | |
| }); |
There was a problem hiding this comment.
Declining both suggestions, but flagging the reasoning:
-
tsgovstsc—tsgois correct, not a typo. This repo uses@typescript/native-previewvia"check-types": "tsgo"inpackages/beacon-node/package.json:94, with@typescript/native-preview: 7.0.0-dev.20260303.1pinned in the rootpackage.json. The overload-resolution behavior that motivates this cast is specificallytsgo's —tscdoesn't reject this site. -
slot: 0vsblock.message.slot— keptslot: 0for consistency with every otheremitter.emit(ChainEvent.unknownEnvelopeBlockRoot, ...)site in this file (unknownBlock.test.ts:762,:836,:926,:1131). The field is a logging/prune hint per the emitter.ts comment (// slot is the message slot, not necessarily the envelope's slot, but useful as a logging/prune hint), not a correctness-load-bearing value in these tests, and switching just this one site would diverge from the established pattern. Happy to update all sites toblock.message.slotin a follow-up if you'd rather have semantic accuracy across the board.
|
Re Gemini's two suggestions on the inline thread: declined both with reasoning in |
fec0c36
into
ChainSafe:te/fix_block_input_sync_metrics_logs
Summary
The base-branch update brought in #9479's new test ("defers envelope validation until the block is in fork choice when payload input is seeded from the block body") which uses the same
let emitter!: ChainEventEmitter+ destructuring-assignment + sibling closure capture pattern that #9491 already mitigated in the original failing test below. SameTS2769fires at the new test's emit site:Also, #9479's emit predates this PR's addition of
slot: Slotto theChainEvent.unknownEnvelopeBlockRootevent signature, so the emit data is missing the requiredslotfield after the merge.Fix
Same minimal cast workaround as #9491 plus the required
slot: 0field:Single-site change. The 5 other
emitter.emit(ChainEvent.unknownEnvelopeBlockRoot, ...)sites in the file remain unchanged because they aren't reached through a sibling closure capture; the cast at the sibling test's emit (introduced in #9491, currently at line 1126) also remains as-is and continues to typecheck cleanly with the expandedEventTypeunion from #9439.Test plan
Type Checks (24)passes (no TS2769 onunknownBlock.test.ts).defers envelope validation until the block is in fork choice when payload input is seeded from the block bodytest still passes — emit semantics unchanged.🤖 Generated with Claude Code