Skip to content

Skip mainnet RPC probe when mainnet is explicitly disabled#23

Open
MysticRyuujin wants to merge 2 commits into
TrueBlocks:mainfrom
MysticRyuujin:fix/issue-22-headless-mainnet
Open

Skip mainnet RPC probe when mainnet is explicitly disabled#23
MysticRyuujin wants to merge 2 commits into
TrueBlocks:mainfrom
MysticRyuujin:fix/issue-22-headless-mainnet

Conversation

@MysticRyuujin

@MysticRyuujin MysticRyuujin commented May 20, 2026

Copy link
Copy Markdown

Summary

Closes #22.

Adds a skipMainnetProbe: false field to the [general] section of config.yaml. When true, install.Configured() skips the mainnet RPC reachability probe and the wizard no longer rejects mainnet.enabled: false. This unblocks headless / air-gapped / container / CI deployments — specifically, the kurtosis ethereum-package integration that runs khedra against an isolated devnet with no public network access.

Default is false, so existing installs are completely unaffected.

Design (revised per maintainer feedback)

The first version of this PR detected the headless case with a second-pass YAML unmarshal into a *bool. As @tjayrush pointed out, that created a hidden three-state boolean — two identical Chain structs could exhibit different runtime behavior depending on whether enabled was omitted or explicitly false. Fragile and surprising.

This revision replaces that with a plain bool in the [general] section, exactly as suggested. No YAML sniffing, no ambiguity, no helper functions.

How it works

pkg/types/general.go

  • New field SkipMainnetProbe bool with koanf / yaml / json tags. No validate tag needed for a plain bool.

pkg/types/config.go

  • Template emits skipMainnetProbe: {{ .General.SkipMainnetProbe }} under the general: block.

pkg/types/apply_env.go

  • New env key KeyGeneralSkipMainnetProbe = "TB_KHEDRA_GENERAL_SKIPMAINNETPROBE" with a strconv.ParseBool handler.

pkg/install/validity.go

  • Configured() calls checkMainnetAccessible() unless cfg.General.SkipMainnetProbe is true.
  • Structural checks (RPC non-empty, chainId != 0) still run unconditionally, so downstream code that reads main.RPCs[0] (env wiring in action_daemon.go) stays safe.

pkg/install/validation.go

  • ValidateChains continues to emit require_mainnet when mainnet.enabled: false unless general.skipMainnetProbe: true. Error message updated to mention the escape hatch.

Docs

  • config.yaml.example — field added with explanatory note.
  • book/src/user_manual/getting_started.md — reference config + note 7 (with kurtosis link and env-var override).

Test plan

  • go build ./... clean
  • go test ./pkg/install/... ./pkg/types/... passes — includes:
    • TestConfigured_SkipMainnetProbe_SkipsReachabilityProbe
    • TestConfigured_SkipMainnetProbeOmitted_RequiresReachableProbe
    • TestConfigured_SkipMainnetProbeFalse_RequiresReachableProbe
    • TestConfigured_SkipMainnetProbe_StillRequiresRPC
    • TestConfigured_SkipMainnetProbe_StillRequiresChainID
    • TestValidateChains_MainnetDisabled_RequireMainnetByDefault
    • TestValidateChains_MainnetDisabled_SkipProbeAllowed
    • TestValidateChains_MainnetDisabled_SkipProbe_RequiresRPC
    • TestGetEnvironmentKeys updated for the new env key
  • Smoke test: `khedra daemon` with `general.skipMainnetProbe: true` + unreachable mainnet RPC → no wizard.
  • Smoke test: `khedra daemon` with `skipMainnetProbe: false` (or omitted) + unreachable mainnet RPC → wizard appears.

Closes TrueBlocks#22.

When chains.mainnet.enabled is explicitly false in the config YAML,
skip the install.Configured() reachability check and the ValidateChains
"mainnet must be enabled" guard. This unblocks headless / air-gapped /
container / CI deployments (kurtosis devnets, isolated environments)
where no real mainnet node is available.

Behavior preserved when mainnet is enabled or when the enabled field is
omitted (legacy configs): RPC must be reachable and return chainId == 1.

Structural checks (non-empty RPC, non-zero chainId) still apply on the
disabled branch so downstream code reading main.RPCs[0] remains safe.
@tjayrush

Copy link
Copy Markdown
Member

Hey Chase — thanks for this. Appreciate you digging in.

I can't merge it though. The *bool YAML re-parse creates a hidden three-state boolean — two identical Chain structs with different runtime behavior. It's fragile and surprising.

Simpler approach: add skipMainnetProbe: false to the [general] section. This defaults to false (plain bool, omitted = false), so existing installs are unaffected. Users like you can set it to true. No YAML sniffing, no ambiguity.

Also, new config fields need documentation — book and config.yaml.example.

Happy to discuss further. Hopefully, your AI can do this easily.

Per maintainer feedback on PR TrueBlocks#23: a plain bool in the [general] section
is clearer than a second-pass *bool unmarshal that creates a hidden
three-state boolean. Default false preserves existing behavior; set true
to skip the mainnet RPC reachability probe in headless / air-gapped /
container / CI deployments. Documented in config.yaml.example and the
user manual.
@MysticRyuujin

Copy link
Copy Markdown
Author

Thanks for the review @tjayrush — that critique was on point. Pushed a revised version that drops the *bool re-parse entirely and uses a plain skipMainnetProbe: false field in [general], exactly as you suggested.

  • Default false, so existing installs are completely unaffected.
  • No YAML sniffing, no three-state ambiguity. Configured() and ValidateChains consult cfg.General.SkipMainnetProbe directly.
  • mainnet.enabled: false is still rejected by the wizard unless skipMainnetProbe: true is set, and the error message points to the new field.
  • Structural checks (mainnet block present, non-empty rpcs, chainId != 0) still apply unconditionally — action_daemon.go reads main.RPCs[0], so we don't want to weaken those.
  • Docs added to both config.yaml.example (new note 7) and book/src/user_manual/getting_started.md (note 7 with kurtosis link + env-var override TB_KHEDRA_GENERAL_SKIPMAINNETPROBE).

Test list and details are in the updated PR description.

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.

khedra daemon requires reachable mainnet RPC, blocks headless / container / CI deployments

2 participants