-
Notifications
You must be signed in to change notification settings - Fork 387
refactor: replace full-node flag with explicit node-mode config #5431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
martinconic
wants to merge
4
commits into
master
Choose a base branch
from
refactor/node-mode-config
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e386677
refactor: replace full-node flag with explicit node-mode config
martinconic b58c43a
fix: restore legacy mode detection in resolveNodeMode
martinconic 9d736a0
test: add table-driven tests for resolveNodeMode
martinconic 7e68799
fix: tighten node-mode validation to prevent silent upgrade regressions
martinconic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,203 @@ | ||
| // Copyright 2026 The Swarm Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style | ||
| // license that can be found in the LICENSE file. | ||
|
|
||
| package cmd | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/ethersphere/bee/v2/pkg/log" | ||
| "github.com/ethersphere/bee/v2/pkg/node" | ||
| "github.com/spf13/viper" | ||
| ) | ||
|
|
||
| func TestResolveNodeMode(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| config map[string]any | ||
| wantMode node.NodeMode | ||
| wantErr string | ||
| }{ | ||
| // ── Explicit node-mode: strict validation ──────────────────────────────── | ||
| { | ||
| name: "full mode with rpc, swap, chequebook and incentives succeeds", | ||
| config: map[string]any{ | ||
| optionNameNodeMode: "full", | ||
| configKeyBlockchainRpcEndpoint: "http://localhost:8545", | ||
| optionNameSwapEnable: true, | ||
| optionNameChequebookEnable: true, | ||
| optionNameStorageIncentivesEnable: true, | ||
| }, | ||
| wantMode: node.FullMode, | ||
| }, | ||
| { | ||
| name: "full mode without rpc fails", | ||
| config: map[string]any{ | ||
| optionNameNodeMode: "full", | ||
| optionNameSwapEnable: true, | ||
| }, | ||
| wantErr: "full node requires blockchain-rpc-endpoint", | ||
| }, | ||
| { | ||
| name: "full mode without swap fails", | ||
| config: map[string]any{ | ||
| optionNameNodeMode: "full", | ||
| configKeyBlockchainRpcEndpoint: "http://localhost:8545", | ||
| }, | ||
| wantErr: "full node requires swap-enable", | ||
| }, | ||
| { | ||
| name: "full mode without chequebook fails", | ||
| config: map[string]any{ | ||
| optionNameNodeMode: "full", | ||
| configKeyBlockchainRpcEndpoint: "http://localhost:8545", | ||
| optionNameSwapEnable: true, | ||
| optionNameStorageIncentivesEnable: true, | ||
| }, | ||
| wantErr: "full node requires chequebook-enable", | ||
| }, | ||
| { | ||
| name: "full mode without storage-incentives fails", | ||
| config: map[string]any{ | ||
| optionNameNodeMode: "full", | ||
| configKeyBlockchainRpcEndpoint: "http://localhost:8545", | ||
| optionNameSwapEnable: true, | ||
| optionNameChequebookEnable: true, | ||
| }, | ||
| wantErr: "storage-incentives-enable", | ||
| }, | ||
| { | ||
| name: "chequebook-enable without swap-enable fails (light mode)", | ||
| config: map[string]any{ | ||
| optionNameNodeMode: "light", | ||
| configKeyBlockchainRpcEndpoint: "http://localhost:8545", | ||
| optionNameChequebookEnable: true, | ||
| }, | ||
| wantErr: "chequebook-enable requires swap-enable", | ||
| }, | ||
| { | ||
| name: "light mode with rpc succeeds", | ||
| config: map[string]any{ | ||
| optionNameNodeMode: "light", | ||
| configKeyBlockchainRpcEndpoint: "http://localhost:8545", | ||
| }, | ||
| wantMode: node.LightMode, | ||
| }, | ||
| { | ||
| name: "light mode without rpc fails", | ||
| config: map[string]any{ | ||
| optionNameNodeMode: "light", | ||
| }, | ||
| wantErr: "light node requires blockchain-rpc-endpoint", | ||
| }, | ||
| { | ||
| name: "ultra-light mode succeeds", | ||
| config: map[string]any{ | ||
| optionNameNodeMode: "ultra-light", | ||
| }, | ||
| wantMode: node.UltraLightMode, | ||
| }, | ||
| { | ||
| name: "ultra-light mode rejects swap-enable", | ||
| config: map[string]any{ | ||
| optionNameNodeMode: "ultra-light", | ||
| optionNameSwapEnable: true, | ||
| }, | ||
| wantErr: "ultra-light node cannot have swap-enable", | ||
| }, | ||
| { | ||
| name: "invalid node-mode value fails", | ||
| config: map[string]any{ | ||
| optionNameNodeMode: "superlight", | ||
| }, | ||
| wantErr: "invalid node-mode", | ||
| }, | ||
|
|
||
| // ── Legacy path: no node-mode set ──────────────────────────────────────── | ||
| { | ||
| name: "legacy full-node true with all required flags maps to full mode", | ||
| config: map[string]any{ | ||
| optionNameFullNode: true, | ||
| configKeyBlockchainRpcEndpoint: "http://localhost:8545", | ||
| optionNameSwapEnable: true, | ||
| optionNameChequebookEnable: true, | ||
| optionNameStorageIncentivesEnable: true, | ||
| }, | ||
| wantMode: node.FullMode, | ||
| }, | ||
| { | ||
| // Upgraders relying on the old chequebook-enable=true default must | ||
| // now fail loudly instead of silently degrading to pseudo-settle. | ||
| name: "legacy full-node true without chequebook fails", | ||
| config: map[string]any{ | ||
| optionNameFullNode: true, | ||
| configKeyBlockchainRpcEndpoint: "http://localhost:8545", | ||
| optionNameSwapEnable: true, | ||
| optionNameStorageIncentivesEnable: true, | ||
| }, | ||
| wantErr: "full node requires chequebook-enable", | ||
| }, | ||
| { | ||
| name: "legacy with rpc endpoint infers light mode", | ||
| config: map[string]any{ | ||
| configKeyBlockchainRpcEndpoint: "http://localhost:8545", | ||
| }, | ||
| wantMode: node.LightMode, | ||
| }, | ||
| { | ||
| name: "legacy without rpc endpoint infers ultra-light mode", | ||
| config: map[string]any{}, | ||
| wantMode: node.UltraLightMode, | ||
| }, | ||
| { | ||
| // Beekeeper's inherited-config scenario: rpc + swap-enable without node-mode. | ||
| // Legacy path must NOT apply strict swap validation; this was the CI regression. | ||
| name: "legacy with rpc and swap-enable infers light without error", | ||
| config: map[string]any{ | ||
| configKeyBlockchainRpcEndpoint: "http://localhost:8545", | ||
| optionNameSwapEnable: true, | ||
| }, | ||
| wantMode: node.LightMode, | ||
| }, | ||
| { | ||
| // Same scenario but for ultra-light: no rpc, swap-enable inherited from base. | ||
| name: "legacy without rpc but with swap-enable infers ultra-light without error", | ||
| config: map[string]any{ | ||
| optionNameSwapEnable: true, | ||
| }, | ||
| wantMode: node.UltraLightMode, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| c := &command{ | ||
| config: viper.New(), | ||
| logger: log.Noop, | ||
| } | ||
| for k, v := range tt.config { | ||
| c.config.Set(k, v) | ||
| } | ||
|
|
||
| gotMode, err := c.resolveNodeMode(c.logger) | ||
|
|
||
| if tt.wantErr != "" { | ||
| if err == nil { | ||
| t.Fatalf("expected error containing %q, got nil (mode=%q)", tt.wantErr, gotMode) | ||
| } | ||
| if !strings.Contains(err.Error(), tt.wantErr) { | ||
| t.Fatalf("expected error containing %q, got %q", tt.wantErr, err.Error()) | ||
| } | ||
| return | ||
| } | ||
| if err != nil { | ||
| t.Fatalf("unexpected error: %v", err) | ||
| } | ||
| if gotMode != tt.wantMode { | ||
| t.Errorf("got mode %q, want %q", gotMode, tt.wantMode) | ||
| } | ||
| }) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.