Skip to content

cmd/utils: allow --networkid to override other config options#32999

Merged
fjl merged 4 commits intoethereum:masterfrom
lightclient:cmd-utils-allow-networkid-override
Nov 28, 2025
Merged

cmd/utils: allow --networkid to override other config options#32999
fjl merged 4 commits intoethereum:masterfrom
lightclient:cmd-utils-allow-networkid-override

Conversation

@lightclient
Copy link
Copy Markdown
Member

Recently in #31630 we removed support for overriding the network id in preset networks. While this feature is niche, it is useful for shadow forks. This PR proposes we add the functionality back, but in a simpler way.

Instead of checking whether the flag is set in each branch of the network switch statement, simply apply the network flag after the switch statement is complete. This retains the following behavior:

  1. Auto network id based on chain id still works, because IsSet only returns true if the flag is actually set. Not if it just has a default set.
  2. The preset networks will set their network id directly and only if the network id flag is set is it overridden. This, combined with the override genesis flag is what allows the shadow forks.
  3. Setting the network id to the same network id that the preset would have set causes no issues and simply emits the WARN that the flag is being set explicitly. I don't think people explicitly set the network id flag often.
WARN [10-22|09:36:15.052] Setting network id with flag             id=10

Copy link
Copy Markdown
Member

@barnabasbusa barnabasbusa left a comment

Choose a reason for hiding this comment

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

LGTM

@fjl fjl changed the title cmd: allow --networkid to override other config options cmd/utils: allow --networkid to override other config options Nov 26, 2025
@fjl fjl added this to the 1.16.8 milestone Nov 28, 2025
@fjl fjl removed the status:triage label Nov 28, 2025
fjl
fjl previously approved these changes Nov 28, 2025
fjl
fjl previously approved these changes Nov 28, 2025
@fjl fjl force-pushed the cmd-utils-allow-networkid-override branch from 34b21d6 to 7fb54af Compare November 28, 2025 14:11
@fjl fjl merged commit f12f0ec into ethereum:master Nov 28, 2025
5 of 6 checks passed
weiihann pushed a commit to weiihann/go-ethereum that referenced this pull request Jan 14, 2026
…um#32999)

Recently in ethereum#31630 we removed support for overriding the network id in
preset networks. While this feature is niche, it is useful for shadow
forks. This PR proposes we add the functionality back, but in a simpler
way.

Instead of checking whether the flag is set in each branch of the
network switch statement, simply apply the network flag after the switch
statement is complete. This retains the following behavior:

1. Auto network id based on chain id still works, because `IsSet` only
returns true if the flag is _actually_ set. Not if it just has a default
set.
2. The preset networks will set their network id directly and only if
the network id flag is set is it overridden. This, combined with the
override genesis flag is what allows the shadow forks.
3. Setting the network id to the same network id that the preset _would
have_ set causes no issues and simply emits the `WARN` that the flag is
being set explicitly. I don't think people explicitly set the network id
flag often.

```
WARN [10-22|09:36:15.052] Setting network id with flag             id=10
```

---------

Co-authored-by: Felix Lange <fjl@twurst.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.

3 participants