Skip to content

Commit df21a62

Browse files
committed
refactor: remove unused modes, consolidate ApplyOverrides, add overflow guards
- Remove ModeRPC and ModeIndexer (identical aliases for ModeFull/ModeArchive) - Export DefaultSnapshotInterval constant for controller use - Add SnapshotGenerationOverrides() helper for snapshot-producing nodes - Replace TOML round-trip in ApplyOverrides with direct Registry+reflection, unifying the string-to-typed-value path with ResolveEnv - Remove setNestedKey, coerceToType, splitDottedKey (no longer needed) - Add overflow guards in setReflectValue for narrower int/uint types - Add comprehensive ApplyOverrides tests for every type path and error case
1 parent 6bc1387 commit df21a62

8 files changed

Lines changed: 191 additions & 139 deletions

File tree

config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import "runtime"
1010
// CurrentVersion is the config schema version produced by this library.
1111
const CurrentVersion = 1
1212

13+
// DefaultSnapshotInterval is the default Tendermint state-sync snapshot
14+
// creation interval (in blocks) used when snapshot generation is enabled.
15+
const DefaultSnapshotInterval = 2000
16+
1317
// Pruning strategy constants.
1418
const (
1519
PruningDefault = "default"

config_test.go

Lines changed: 145 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
const testRPCAddr = "tcp://0.0.0.0:26657"
1111

1212
func TestDefaultForMode_AllModesValid(t *testing.T) {
13-
modes := []NodeMode{ModeValidator, ModeFull, ModeSeed, ModeArchive, ModeRPC, ModeIndexer}
13+
modes := []NodeMode{ModeValidator, ModeFull, ModeSeed, ModeArchive}
1414
for _, mode := range modes {
1515
cfg := DefaultForMode(mode)
1616
if cfg.Mode != mode {
@@ -200,7 +200,7 @@ func TestWriteReadRoundTrip(t *testing.T) {
200200
}
201201

202202
func TestWriteReadRoundTrip_AllModes(t *testing.T) {
203-
modes := []NodeMode{ModeValidator, ModeFull, ModeSeed, ModeArchive, ModeRPC, ModeIndexer}
203+
modes := []NodeMode{ModeValidator, ModeFull, ModeSeed, ModeArchive}
204204
for _, mode := range modes {
205205
t.Run(string(mode), func(t *testing.T) {
206206
dir := t.TempDir()
@@ -250,6 +250,146 @@ func TestApplyOverrides(t *testing.T) {
250250
}
251251
}
252252

253+
func TestApplyOverrides_Bool(t *testing.T) {
254+
cfg := Default()
255+
if err := ApplyOverrides(cfg, map[string]string{
256+
"network.p2p.allow_duplicate_ip": "true",
257+
}); err != nil {
258+
t.Fatalf("ApplyOverrides: %v", err)
259+
}
260+
if !cfg.Network.P2P.AllowDuplicateIP {
261+
t.Error("expected AllowDuplicateIP to be true")
262+
}
263+
264+
if err := ApplyOverrides(cfg, map[string]string{
265+
"network.p2p.allow_duplicate_ip": "false",
266+
}); err != nil {
267+
t.Fatalf("ApplyOverrides: %v", err)
268+
}
269+
if cfg.Network.P2P.AllowDuplicateIP {
270+
t.Error("expected AllowDuplicateIP to be false")
271+
}
272+
}
273+
274+
func TestApplyOverrides_Uint(t *testing.T) {
275+
cfg := Default()
276+
if err := ApplyOverrides(cfg, map[string]string{
277+
"chain.halt_height": "999999",
278+
}); err != nil {
279+
t.Fatalf("ApplyOverrides: %v", err)
280+
}
281+
if cfg.Chain.HaltHeight != 999999 {
282+
t.Errorf("halt_height: got %d, want 999999", cfg.Chain.HaltHeight)
283+
}
284+
}
285+
286+
func TestApplyOverrides_Float(t *testing.T) {
287+
cfg := Default()
288+
if err := ApplyOverrides(cfg, map[string]string{
289+
"mempool.drop_priority_threshold": "0.75",
290+
}); err != nil {
291+
t.Fatalf("ApplyOverrides: %v", err)
292+
}
293+
if cfg.Mempool.DropPriorityThreshold != 0.75 {
294+
t.Errorf("drop_priority_threshold: got %f, want 0.75", cfg.Mempool.DropPriorityThreshold)
295+
}
296+
}
297+
298+
func TestApplyOverrides_Duration(t *testing.T) {
299+
cfg := Default()
300+
if err := ApplyOverrides(cfg, map[string]string{
301+
"network.rpc.timeout_broadcast_tx_commit": "30s",
302+
}); err != nil {
303+
t.Fatalf("ApplyOverrides: %v", err)
304+
}
305+
if cfg.Network.RPC.TimeoutBroadcastTxCommit.Duration != 30*time.Second {
306+
t.Errorf("timeout_broadcast_tx_commit: got %v, want 30s",
307+
cfg.Network.RPC.TimeoutBroadcastTxCommit.Duration)
308+
}
309+
}
310+
311+
func TestApplyOverrides_Int64(t *testing.T) {
312+
cfg := Default()
313+
if err := ApplyOverrides(cfg, map[string]string{
314+
"state_sync.backfill_blocks": "500",
315+
}); err != nil {
316+
t.Fatalf("ApplyOverrides: %v", err)
317+
}
318+
if cfg.StateSync.BackfillBlocks != 500 {
319+
t.Errorf("backfill_blocks: got %d, want 500", cfg.StateSync.BackfillBlocks)
320+
}
321+
}
322+
323+
func TestApplyOverrides_UnknownKey(t *testing.T) {
324+
cfg := Default()
325+
err := ApplyOverrides(cfg, map[string]string{
326+
"totally.fake.key": "value",
327+
})
328+
if err == nil {
329+
t.Fatal("expected error for unknown key")
330+
}
331+
}
332+
333+
func TestApplyOverrides_InvalidBool(t *testing.T) {
334+
cfg := Default()
335+
err := ApplyOverrides(cfg, map[string]string{
336+
"network.p2p.allow_duplicate_ip": "maybe",
337+
})
338+
if err == nil {
339+
t.Fatal("expected error for invalid bool value")
340+
}
341+
}
342+
343+
func TestApplyOverrides_InvalidInt(t *testing.T) {
344+
cfg := Default()
345+
err := ApplyOverrides(cfg, map[string]string{
346+
"evm.http_port": "not_a_number",
347+
})
348+
if err == nil {
349+
t.Fatal("expected error for non-numeric int value")
350+
}
351+
}
352+
353+
func TestApplyOverrides_InvalidDuration(t *testing.T) {
354+
cfg := Default()
355+
err := ApplyOverrides(cfg, map[string]string{
356+
"network.rpc.timeout_broadcast_tx_commit": "not_a_duration",
357+
})
358+
if err == nil {
359+
t.Fatal("expected error for invalid duration value")
360+
}
361+
}
362+
363+
func TestApplyOverrides_Uint16Overflow(t *testing.T) {
364+
cfg := Default()
365+
err := ApplyOverrides(cfg, map[string]string{
366+
"network.p2p.max_connections": "70000",
367+
})
368+
if err == nil {
369+
t.Fatal("expected error for uint16 overflow (65535 max)")
370+
}
371+
}
372+
373+
func TestApplyOverrides_Int32Overflow(t *testing.T) {
374+
cfg := Default()
375+
err := ApplyOverrides(cfg, map[string]string{
376+
"state_sync.fetchers": "3000000000",
377+
})
378+
if err == nil {
379+
t.Fatal("expected error for int32 overflow")
380+
}
381+
}
382+
383+
func TestApplyOverrides_NegativeUint(t *testing.T) {
384+
cfg := Default()
385+
err := ApplyOverrides(cfg, map[string]string{
386+
"chain.halt_height": "-1",
387+
})
388+
if err == nil {
389+
t.Fatal("expected error for negative uint value")
390+
}
391+
}
392+
253393
func TestApplyOverrides_Empty(t *testing.T) {
254394
cfg := Default()
255395
original := cfg.EVM.HTTPPort
@@ -339,8 +479,8 @@ func TestNodeMode_Validity(t *testing.T) {
339479
{ModeFull, true},
340480
{ModeSeed, true},
341481
{ModeArchive, true},
342-
{ModeRPC, true},
343-
{ModeIndexer, true},
482+
{"rpc", false},
483+
{"indexer", false},
344484
{"bogus", false},
345485
{"", false},
346486
}
@@ -352,7 +492,7 @@ func TestNodeMode_Validity(t *testing.T) {
352492
}
353493

354494
func TestNodeMode_IsFullnodeType(t *testing.T) {
355-
fullnodeTypes := []NodeMode{ModeFull, ModeArchive, ModeRPC, ModeIndexer}
495+
fullnodeTypes := []NodeMode{ModeFull, ModeArchive}
356496
for _, m := range fullnodeTypes {
357497
if !m.IsFullnodeType() {
358498
t.Errorf("%s should be fullnode type", m)

defaults.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package seiconfig
22

33
import (
44
"os"
5+
"strconv"
56
"time"
67
)
78

@@ -240,10 +241,6 @@ func applyModeOverrides(cfg *SeiConfig, mode NodeMode) {
240241
applyFullOverrides(cfg)
241242
case ModeArchive:
242243
applyArchiveOverrides(cfg)
243-
case ModeRPC:
244-
applyRPCOverrides(cfg)
245-
case ModeIndexer:
246-
applyIndexerOverrides(cfg)
247244
}
248245
}
249246

@@ -300,12 +297,15 @@ func applyArchiveOverrides(cfg *SeiConfig) {
300297
cfg.EVM.MaxTraceLookbackBlocks = -1
301298
}
302299

303-
func applyRPCOverrides(cfg *SeiConfig) {
304-
applyFullOverrides(cfg)
305-
}
306-
307-
func applyIndexerOverrides(cfg *SeiConfig) {
308-
applyArchiveOverrides(cfg)
300+
// SnapshotGenerationOverrides returns the config overrides needed when a node
301+
// is configured to produce Tendermint state-sync snapshots. The controller
302+
// applies these as ConfigIntent.Overrides alongside the mode defaults.
303+
func SnapshotGenerationOverrides(keepRecent int32) map[string]string {
304+
return map[string]string{
305+
"storage.pruning": PruningNothing,
306+
"storage.snapshot_interval": strconv.FormatInt(DefaultSnapshotInterval, 10),
307+
"storage.snapshot_keep_recent": strconv.FormatInt(int64(keepRecent), 10),
308+
}
309309
}
310310

311311
func defaultMoniker() string {

intent_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
)
66

77
func TestValidateIntent_ValidModes(t *testing.T) {
8-
modes := []NodeMode{ModeValidator, ModeFull, ModeSeed, ModeArchive, ModeRPC, ModeIndexer}
8+
modes := []NodeMode{ModeValidator, ModeFull, ModeSeed, ModeArchive}
99
for _, mode := range modes {
1010
result := ValidateIntent(ConfigIntent{Mode: mode})
1111
if !result.Valid {
@@ -136,7 +136,7 @@ func TestValidateIntent_ValidOverrideKey(t *testing.T) {
136136
// ---------------------------------------------------------------------------
137137

138138
func TestResolveIntent_AllModes(t *testing.T) {
139-
modes := []NodeMode{ModeValidator, ModeFull, ModeSeed, ModeArchive, ModeRPC, ModeIndexer}
139+
modes := []NodeMode{ModeValidator, ModeFull, ModeSeed, ModeArchive}
140140
for _, mode := range modes {
141141
result, err := ResolveIntent(ConfigIntent{Mode: mode})
142142
if err != nil {
@@ -290,17 +290,17 @@ func TestResolveIncrementalIntent_PatchesExistingConfig(t *testing.T) {
290290
func TestResolveIncrementalIntent_ModeOverride(t *testing.T) {
291291
current := DefaultForMode(ModeFull)
292292
result, err := ResolveIncrementalIntent(
293-
ConfigIntent{Mode: ModeRPC},
293+
ConfigIntent{Mode: ModeArchive},
294294
current,
295295
)
296296
if err != nil {
297297
t.Fatalf("unexpected error: %v", err)
298298
}
299-
if result.Config.Mode != ModeRPC {
300-
t.Errorf("expected mode RPC, got %q", result.Config.Mode)
299+
if result.Config.Mode != ModeArchive {
300+
t.Errorf("expected mode archive, got %q", result.Config.Mode)
301301
}
302-
if result.Mode != ModeRPC {
303-
t.Errorf("expected result.Mode RPC, got %q", result.Mode)
302+
if result.Mode != ModeArchive {
303+
t.Errorf("expected result.Mode archive, got %q", result.Mode)
304304
}
305305
}
306306

@@ -334,7 +334,7 @@ func TestResolveIncrementalIntent_DoesNotMutateCaller(t *testing.T) {
334334

335335
_, err := ResolveIncrementalIntent(
336336
ConfigIntent{
337-
Mode: ModeRPC,
337+
Mode: ModeArchive,
338338
Overrides: map[string]string{
339339
"evm.http_port": "9999",
340340
},

0 commit comments

Comments
 (0)