Skip to content

fix(gossip): bind message ids to topics#2450

Open
niran wants to merge 1 commit intomainfrom
nb/bind-gossip-message-id-topic
Open

fix(gossip): bind message ids to topics#2450
niran wants to merge 1 commit intomainfrom
nb/bind-gossip-message-id-topic

Conversation

@niran
Copy link
Copy Markdown
Contributor

@niran niran commented Apr 29, 2026

Summary

  • bind gossipsub message IDs to the topic using the OP Stack preimage shape: domain || topic_len_le || topic || payload
  • preserve the existing Snappy decoded-size guard and valid/invalid Snappy domains
  • add a regression test that byte-identical payloads on V3 and V4 block topics produce different message IDs

Context

The relevant op-node implementation is op-node/p2p/gossip.go::BuildMsgIdFn, which includes the topic length and topic before hashing the payload. Without topic binding, libp2p-gossipsub duplicate-cache entries can collide across Base block-version topics.

Test Plan

  • cargo test --package base-consensus-gossip --lib
  • cargo clippy --package base-consensus-gossip --all-targets -- -D warnings

@cb-heimdall
Copy link
Copy Markdown
Collaborator

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 29, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
base Ignored Ignored Apr 29, 2026 9:57pm

Request Review

@github-actions
Copy link
Copy Markdown
Contributor

Review Summary

No blocking issues found. The change is correct and well-motivated.

What was reviewed

Single file change to crates/consensus/gossip/src/config.rs — binds gossipsub message IDs to the topic string, matching the upstream OP Stack BuildMsgIdFn implementation.

Key observations

  • Preimage layout is correct: domain (4B) || topic_len_le (8B) || topic || data. The fixed-width u64 length prefix before the topic eliminates any preimage ambiguity between topic and data fields.
  • Domain constants: Promoted from inline Vec allocations to const [u8; 4] — eliminates per-call heap allocation in a hot path. Good improvement.
  • Both snappy paths are consistent: Valid and invalid snappy paths both include the topic in the hash preimage via the shared message_id_hash helper.
  • Regression test (test_compute_message_id_includes_topic): Directly verifies the behavioral property — byte-identical payloads on /optimism/8453/2/blocks vs /optimism/8453/3/blocks produce different message IDs.

Note

The local spec (docs/specs/pages/protocol/consensus/p2p.md, lines 159–168) documents message ID computation without topic binding. If the spec is intended to track the actual implementation, it should be updated to reflect this change. This is non-blocking — the PR description makes clear this matches the upstream Go implementation.

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.

2 participants