Skip to content

feat(p2p): [proxy] magic overrides the devnet's wire magic - #29

Open
cafebedouin wants to merge 2 commits into
mwaddip:mainfrom
cafebedouin:devnet-magic-override
Open

cafebedouin wants to merge 2 commits into
mwaddip:mainfrom
cafebedouin:devnet-magic-override

Conversation

@cafebedouin

Copy link
Copy Markdown

Prepared with Claude (Anthropic, Claude Fable 5.1) for cafebedouin; the tests and the mixed-implementation run below were executed on this branch head. Stacked on #28 (the devnet-network pull request): this branch carries that commit too, and only its last commit, the magic override, is under review here.

[proxy] magic: let the devnet's wire magic be overridden

Observed: with the devnet network the magic [7,7,7,7] is compiled in (p2p/src/types.rs), so two private networks on one host, or a devnet that must join a private network with another magic, cannot be configured.

Change: an optional magic = [b0, b1, b2, b3] under [proxy], accepted only when the network is devnet and never a public network's magic, both rejected at config load (p2p/src/config.rs). HandshakeConfig gains a required magic field, the magic in force, and the session feature, the peer check (validate_peer_magic; validate_peer stays as a wrapper) and the frame reader and writer read it. Documented in the example config, the manpage, the p2p-node facts contract and the changelog (which names the crate API change).

Invariant kept: mainnet and testnet keep their compiled-in magic; the override cannot be set for them, and the magic in force is network.magic() whenever the key is absent. Falsifier: a public-network config with magic that loads, or a devnet config without the key whose session feature or frames carry anything but [7,7,7,7].

Recommended: merge after #28.

Executed: cargo test -p enr-p2p (library, including acceptance, fallback, both rejections and the session-body test, and every enr-p2p integration test binary, updated for the new field); the root crate's one integration test that builds a HandshakeConfig, also updated, compiled with --no-run. Not run: the workspace suite, clippy, other platforms.

Evidence: ERGO-NODE-RUST-FOLLOW: PASS (A=6.0.6 B=0.8.2 followed=yes maxlag=13 SAME@41 SAME@41 topology=ok): this node, built at this commit (sha256 4a0ee25f9230d9e1be7b08737b6265c23f9a727a99b3d10996183c61e1627176) with magic = [102, 111, 114, 107], followed an ergo v6.0.6 node on that magic to the same chain and state root.

To reproduce without the bench that ran it

The devnet-network pull request's recipe with two changes: the Scala node runs scorex.network.magicBytes = [102, 111, 114, 107], and this node's [proxy] has magic = [102, 111, 114, 107]. Same checks. By reading, not executed here: with the key removed on either side the two nodes should never connect (the peer check rejects a magic mismatch); with network = "testnet" and the key, this node refuses at config load (executed as a unit test).

cafebedouin and others added 2 commits September 23, 2026 11:45
…t"`)

A third `Network` variant for isolated multi-node testing: magic [7,7,7,7],
protocol v4 from genesis with the sub-blocks parameter, testnet genesis
boxes and digest, difficulty pinned at 1 by an unreachable difficulty and
voting epoch (1 << 25 blocks), a 20 s block interval, the v2 activation
height and re-emission rules of testnet (neither reachable), and the
testnet address prefix. The profile is a Scala `networkType = "devnet60"`
node with those overrides (the mixed Scala/Rust devnet of arkadianet/ergo,
`scripts/devnet-mixed/genesis.conf`, runs the same one), so a Scala node,
an arkadianet node and this node share one wire.

Mainnet and testnet behaviour is unchanged: every touched match adds a
`Devnet` arm and the existing arms keep their values. Tests cover the
magic and its TOML name, the chain, voting and re-emission parameters, the
launch parameters, and that the devnet genesis boxes reproduce the testnet
state digest. The example config, the manpage, the operator guide, the
facts contracts (config, journal events, p2p node, p2p routing, mining),
the changelog and the wire-format magic table name the new network.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
An optional `magic = [b0, b1, b2, b3]` under `[proxy]`, accepted only when
the network is devnet and never a public network's magic (rejected at
config load otherwise), so several private networks can run side by side
or a devnet can join another private network's magic. `HandshakeConfig`
gains a required `magic` field, the magic in force, and the session
feature, the peer check (`validate_peer_magic`; `validate_peer` stays as a
wrapper) and the frame codec read it. Mainnet and testnet keep their
compiled-in magic: the override cannot be set for them.

Tests cover acceptance on devnet, the fallback, both rejections, and that
the handshake session body carries the configured magic; the crate's
integration tests are updated for the new field. Documented in the
example config, the manpage, the p2p-node facts contract and the changelog.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.

1 participant