Skip to content

fix: make addPayloadEnvelope idempotent on API path#9504

Draft
markolazic01 wants to merge 11 commits into
ChainSafe:unstablefrom
markolazic01:feat/idempotent-add-payload-envelope
Draft

fix: make addPayloadEnvelope idempotent on API path#9504
markolazic01 wants to merge 11 commits into
ChainSafe:unstablefrom
markolazic01:feat/idempotent-add-payload-envelope

Conversation

@markolazic01

Copy link
Copy Markdown
Contributor

Motivation

addPayloadEnvelope throws if called when an envelope is already set. This is reachable from the API handler when the envelope has already been set by another source before the call reaches addPayloadEnvelope, causing a 500 to the VC.

Description

All call sites of addPayloadEnvelope were audited before applying the fix:

gossipHandlers.ts — unguarded, but all handler throws are caught by gossipValidatorFn and converted to TopicValidatorResult.Ignore, so safe
sync/unknownBlock.ts — guarded with !payloadInput.hasPayloadEnvelope() before calling
sync/utils/downloadByRange.ts — same guard, safe
api/impl/beacon/blocks/index.ts — unguarded, the only path where the throw caused a user-visible error

Adds the same hasPayloadEnvelope() guard to the API handler, matching the existing sync path pattern. A debug log is emitted when the envelope is already set to aid debugging.

Closes #9071

@markolazic01
markolazic01 requested a review from a team as a code owner June 10, 2026 22:15
@markolazic01 markolazic01 changed the title fix: make addPayloadEnvelope idempotent on API path fix: make addPayloadEnvelope idempotent on API path Jun 10, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

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.

Code Review

This pull request adds a check to prevent overwriting an existing execution payload envelope, logging a debug message when skipping a duplicate. The reviewer recommends verifying whether the incoming envelope matches the existing one by comparing their block hashes, and logging a warning instead of a debug message if they differ, as this could indicate a potential equivocation or software bug.

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.

Comment thread packages/beacon-node/src/api/impl/beacon/blocks/index.ts

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b7ba49abf0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

seenTimestampSec,
peerIdStr: undefined,
});
if (!payloadInput.hasPayloadEnvelope()) {

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 Handle known envelopes before validation

When the duplicate envelope is already in seenPayloadEnvelopeInputCache before this API call starts validation, the earlier validateApiExecutionPayloadEnvelope() call still throws ENVELOPE_ALREADY_KNOWN, so execution never reaches this new idempotency guard. This only fixes the narrow race where another path sets the envelope after validation but before addPayloadEnvelope(); VC retries or gossip-first arrivals still get an error instead of an idempotent success. Consider checking/returning success for the already-known case before validation, or mapping that validation result to the intended duplicate behavior.

Useful? React with 👍 / 👎.

@markolazic01
markolazic01 marked this pull request as draft June 10, 2026 22:33
@markolazic01

Copy link
Copy Markdown
Contributor Author

needs more work

@markolazic01
markolazic01 marked this pull request as ready for review June 18, 2026 11:45

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d40231371e

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread packages/beacon-node/src/api/impl/beacon/blocks/index.ts
@markolazic01

Copy link
Copy Markdown
Contributor Author

fixed the typing in the test, the failing type check should now pass

@nflaig nflaig left a comment

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.

let's revisit this after #9595, converting to draft for now


await validateApiExecutionPayloadEnvelope(chain, signedExecutionPayloadEnvelope);
try {
await validateApiExecutionPayloadEnvelope(chain, signedExecutionPayloadEnvelope);

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.

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.

will follow up after it lands 👍

@nflaig
nflaig marked this pull request as draft July 5, 2026 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

addPayloadEnvelope should be idempotent for API/gossip race

4 participants