Skip to content

Use fork digest in gossipsub topic strings#297

Open
MegaRedHand wants to merge 4 commits intomainfrom
fork-digest-gossipsub-topics
Open

Use fork digest in gossipsub topic strings#297
MegaRedHand wants to merge 4 commits intomainfrom
fork-digest-gossipsub-topics

Conversation

@MegaRedHand
Copy link
Copy Markdown
Collaborator

@MegaRedHand MegaRedHand commented Apr 16, 2026

Summary

  • Match the leanSpec gossipsub topic format /leanconsensus/{fork_digest}/{name}/ssz_snappy instead of the custom /leanconsensus/devnet0/... we had hard-coded.

Closes #292.

Match the leanSpec topic format `/leanconsensus/{fork_digest}/{name}/ssz_snappy`
(leanEthereum/leanSpec#622) instead of the custom `/leanconsensus/devnet0/...`.

Introduce a `ForkDigest` newtype displayed as lowercase hex without `0x`
prefix, plus `block_topic` / `aggregation_topic` / `attestation_subnet_topic`
helpers. The digest is plumbed through `SwarmConfig` / `BuiltSwarm` /
`P2PServer` so it becomes configurable once the spec defines real fork
identification. For now every client agrees on the dummy `12345678` value,
exposed as `ForkDigest::DUMMY`.

Closes #292
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 16, 2026

Greptile Summary

This PR replaces the hardcoded devnet0 string in gossipsub topic strings with a proper ForkDigest([u8; 4]) newtype, matching the leanSpec format /leanconsensus/{fork_digest}/{name}/ssz_snappy. The digest is plumbed through SwarmConfigBuiltSwarmP2PServer, with ForkDigest::DUMMY (12345678) as the agreed-upon placeholder until the spec defines real fork identification. The implementation is clean, well-tested, and all existing call sites are correctly updated.

Confidence Score: 5/5

Safe to merge — clean refactor with no logic errors, full test coverage for the new type, and consistent plumbing throughout the stack.

All changes are mechanical substitutions of a hardcoded string with a properly typed value. The ForkDigest Display impl is verified by unit tests, all three topic builders are tested end-to-end, and the runtime message parsing (split("/").nth(3)) is unaffected by the change in position 2 of the topic path. No P0 or P1 findings.

No files require special attention.

Important Files Changed

Filename Overview
crates/net/p2p/src/gossipsub/messages.rs Introduces ForkDigest newtype with Display (lowercase hex, no 0x prefix), DUMMY constant, and three topic builder functions; covered by unit tests for all cases.
crates/net/p2p/src/lib.rs Adds fork_digest field to SwarmConfig, BuiltSwarm, and P2PServer; replaces all inline topic string construction with builder function calls consistently.
crates/net/p2p/src/gossipsub/handler.rs Updates attestation_subnet_topic fallback call to pass &server.fork_digest; topic parsing via split("/").nth(3) is unaffected and correct for the new format.
bin/ethlambda/src/main.rs Adds ForkDigest::DUMMY to SwarmConfig with a clear TODO comment explaining when to replace it with a real computed digest.
crates/net/p2p/src/gossipsub/mod.rs Re-exports updated to expose ForkDigest and topic builder functions instead of the old NETWORK_NAME/BLOCK_TOPIC_KIND/AGGREGATION_TOPIC_KIND constants.
CLAUDE.md Documentation updated to reflect the new topic format with fork_digest and the 12345678 placeholder, matching the implementation.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["main.rs\nForkDigest::DUMMY"] -->|fork_digest field| B["SwarmConfig"]
    B -->|build_swarm| C["BuiltSwarm\n+ fork_digest"]
    C -->|P2P::spawn| D["P2PServer\n+ fork_digest"]
    B -->|block_topic| E["IdentTopic\nblock"]
    B -->|aggregation_topic| F["IdentTopic\naggregation"]
    B -->|attestation_subnet_topic| G["IdentTopic\nattestation_N"]
    E --> C
    F --> C
    G -->|cached in attestation_topics| C
    D -->|fallback publish| H["attestation_subnet_topic\nfork_digest + subnet_id"]
Loading

Reviews (1): Last reviewed commit: "Use fork digest in gossipsub topics" | Re-trigger Greptile

Drop the `ForkDigest` newtype, `SwarmConfig` / `BuiltSwarm` / `P2PServer`
plumbing, and `pub` re-export. The fork digest is the dummy `12345678`
placeholder every Lean client currently agrees on; a `FORK_DIGEST` `&str`
constant with a TODO captures that cleanly until the spec defines real
fork identification, and leaves the topic builder functions taking only
the pieces that actually vary (subnet id).
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.

Use fork digest in gossipsub message topic

2 participants