Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import "runtime"
// CurrentVersion is the config schema version produced by this library.
const CurrentVersion = 1

// DefaultSnapshotInterval is the default Tendermint state-sync snapshot
// creation interval (in blocks) used when snapshot generation is enabled.
const DefaultSnapshotInterval = 2000

// Pruning strategy constants.
const (
PruningDefault = "default"
Expand Down
150 changes: 145 additions & 5 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
const testRPCAddr = "tcp://0.0.0.0:26657"

func TestDefaultForMode_AllModesValid(t *testing.T) {
modes := []NodeMode{ModeValidator, ModeFull, ModeSeed, ModeArchive, ModeRPC, ModeIndexer}
modes := []NodeMode{ModeValidator, ModeFull, ModeSeed, ModeArchive}
for _, mode := range modes {
cfg := DefaultForMode(mode)
if cfg.Mode != mode {
Expand Down Expand Up @@ -200,7 +200,7 @@ func TestWriteReadRoundTrip(t *testing.T) {
}

func TestWriteReadRoundTrip_AllModes(t *testing.T) {
modes := []NodeMode{ModeValidator, ModeFull, ModeSeed, ModeArchive, ModeRPC, ModeIndexer}
modes := []NodeMode{ModeValidator, ModeFull, ModeSeed, ModeArchive}
for _, mode := range modes {
t.Run(string(mode), func(t *testing.T) {
dir := t.TempDir()
Expand Down Expand Up @@ -250,6 +250,146 @@ func TestApplyOverrides(t *testing.T) {
}
}

func TestApplyOverrides_Bool(t *testing.T) {
cfg := Default()
if err := ApplyOverrides(cfg, map[string]string{
"network.p2p.allow_duplicate_ip": "true",
}); err != nil {
t.Fatalf("ApplyOverrides: %v", err)
}
if !cfg.Network.P2P.AllowDuplicateIP {
t.Error("expected AllowDuplicateIP to be true")
}

if err := ApplyOverrides(cfg, map[string]string{
"network.p2p.allow_duplicate_ip": "false",
}); err != nil {
t.Fatalf("ApplyOverrides: %v", err)
}
if cfg.Network.P2P.AllowDuplicateIP {
t.Error("expected AllowDuplicateIP to be false")
}
}

func TestApplyOverrides_Uint(t *testing.T) {
cfg := Default()
if err := ApplyOverrides(cfg, map[string]string{
"chain.halt_height": "999999",
}); err != nil {
t.Fatalf("ApplyOverrides: %v", err)
}
if cfg.Chain.HaltHeight != 999999 {
t.Errorf("halt_height: got %d, want 999999", cfg.Chain.HaltHeight)
}
}

func TestApplyOverrides_Float(t *testing.T) {
cfg := Default()
if err := ApplyOverrides(cfg, map[string]string{
"mempool.drop_priority_threshold": "0.75",
}); err != nil {
t.Fatalf("ApplyOverrides: %v", err)
}
if cfg.Mempool.DropPriorityThreshold != 0.75 {
t.Errorf("drop_priority_threshold: got %f, want 0.75", cfg.Mempool.DropPriorityThreshold)
}
}

func TestApplyOverrides_Duration(t *testing.T) {
cfg := Default()
if err := ApplyOverrides(cfg, map[string]string{
"network.rpc.timeout_broadcast_tx_commit": "30s",
}); err != nil {
t.Fatalf("ApplyOverrides: %v", err)
}
if cfg.Network.RPC.TimeoutBroadcastTxCommit.Duration != 30*time.Second {
t.Errorf("timeout_broadcast_tx_commit: got %v, want 30s",
cfg.Network.RPC.TimeoutBroadcastTxCommit.Duration)
}
}

func TestApplyOverrides_Int64(t *testing.T) {
cfg := Default()
if err := ApplyOverrides(cfg, map[string]string{
"state_sync.backfill_blocks": "500",
}); err != nil {
t.Fatalf("ApplyOverrides: %v", err)
}
if cfg.StateSync.BackfillBlocks != 500 {
t.Errorf("backfill_blocks: got %d, want 500", cfg.StateSync.BackfillBlocks)
}
}

func TestApplyOverrides_UnknownKey(t *testing.T) {
cfg := Default()
err := ApplyOverrides(cfg, map[string]string{
"totally.fake.key": "value",
})
if err == nil {
t.Fatal("expected error for unknown key")
}
}

func TestApplyOverrides_InvalidBool(t *testing.T) {
cfg := Default()
err := ApplyOverrides(cfg, map[string]string{
"network.p2p.allow_duplicate_ip": "maybe",
})
if err == nil {
t.Fatal("expected error for invalid bool value")
}
}

func TestApplyOverrides_InvalidInt(t *testing.T) {
cfg := Default()
err := ApplyOverrides(cfg, map[string]string{
"evm.http_port": "not_a_number",
})
if err == nil {
t.Fatal("expected error for non-numeric int value")
}
}

func TestApplyOverrides_InvalidDuration(t *testing.T) {
cfg := Default()
err := ApplyOverrides(cfg, map[string]string{
"network.rpc.timeout_broadcast_tx_commit": "not_a_duration",
})
if err == nil {
t.Fatal("expected error for invalid duration value")
}
}

func TestApplyOverrides_Uint16Overflow(t *testing.T) {
cfg := Default()
err := ApplyOverrides(cfg, map[string]string{
"network.p2p.max_connections": "70000",
})
if err == nil {
t.Fatal("expected error for uint16 overflow (65535 max)")
}
}

func TestApplyOverrides_Int32Overflow(t *testing.T) {
cfg := Default()
err := ApplyOverrides(cfg, map[string]string{
"state_sync.fetchers": "3000000000",
})
if err == nil {
t.Fatal("expected error for int32 overflow")
}
}

func TestApplyOverrides_NegativeUint(t *testing.T) {
cfg := Default()
err := ApplyOverrides(cfg, map[string]string{
"chain.halt_height": "-1",
})
if err == nil {
t.Fatal("expected error for negative uint value")
}
}

func TestApplyOverrides_Empty(t *testing.T) {
cfg := Default()
original := cfg.EVM.HTTPPort
Expand Down Expand Up @@ -339,8 +479,8 @@ func TestNodeMode_Validity(t *testing.T) {
{ModeFull, true},
{ModeSeed, true},
{ModeArchive, true},
{ModeRPC, true},
{ModeIndexer, true},
{"rpc", false},
{"indexer", false},
{"bogus", false},
{"", false},
}
Expand All @@ -352,7 +492,7 @@ func TestNodeMode_Validity(t *testing.T) {
}

func TestNodeMode_IsFullnodeType(t *testing.T) {
fullnodeTypes := []NodeMode{ModeFull, ModeArchive, ModeRPC, ModeIndexer}
fullnodeTypes := []NodeMode{ModeFull, ModeArchive}
for _, m := range fullnodeTypes {
if !m.IsFullnodeType() {
t.Errorf("%s should be fullnode type", m)
Expand Down
20 changes: 10 additions & 10 deletions defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package seiconfig

import (
"os"
"strconv"
"time"
)

Expand Down Expand Up @@ -240,10 +241,6 @@ func applyModeOverrides(cfg *SeiConfig, mode NodeMode) {
applyFullOverrides(cfg)
case ModeArchive:
applyArchiveOverrides(cfg)
case ModeRPC:
applyRPCOverrides(cfg)
case ModeIndexer:
applyIndexerOverrides(cfg)
}
}

Expand Down Expand Up @@ -300,12 +297,15 @@ func applyArchiveOverrides(cfg *SeiConfig) {
cfg.EVM.MaxTraceLookbackBlocks = -1
}

func applyRPCOverrides(cfg *SeiConfig) {
applyFullOverrides(cfg)
}

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

func defaultMoniker() string {
Expand Down
16 changes: 8 additions & 8 deletions intent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

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

func TestResolveIntent_AllModes(t *testing.T) {
modes := []NodeMode{ModeValidator, ModeFull, ModeSeed, ModeArchive, ModeRPC, ModeIndexer}
modes := []NodeMode{ModeValidator, ModeFull, ModeSeed, ModeArchive}
for _, mode := range modes {
result, err := ResolveIntent(ConfigIntent{Mode: mode})
if err != nil {
Expand Down Expand Up @@ -290,17 +290,17 @@ func TestResolveIncrementalIntent_PatchesExistingConfig(t *testing.T) {
func TestResolveIncrementalIntent_ModeOverride(t *testing.T) {
current := DefaultForMode(ModeFull)
result, err := ResolveIncrementalIntent(
ConfigIntent{Mode: ModeRPC},
ConfigIntent{Mode: ModeArchive},
current,
)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if result.Config.Mode != ModeRPC {
t.Errorf("expected mode RPC, got %q", result.Config.Mode)
if result.Config.Mode != ModeArchive {
t.Errorf("expected mode archive, got %q", result.Config.Mode)
}
if result.Mode != ModeRPC {
t.Errorf("expected result.Mode RPC, got %q", result.Mode)
if result.Mode != ModeArchive {
t.Errorf("expected result.Mode archive, got %q", result.Mode)
}
}

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

_, err := ResolveIncrementalIntent(
ConfigIntent{
Mode: ModeRPC,
Mode: ModeArchive,
Overrides: map[string]string{
"evm.http_port": "9999",
},
Expand Down
Loading
Loading