Skip to content

Commit 38a8aec

Browse files
authored
feat: add mode-based configuration for seid init (#2456)
Add support for --mode flag in seid init command to configure nodes as: - removed SetTendermintConfigs() in sei-chain - The flow now reads default configs from Cosmos/Tendermint, then overrides them by mode. - validator: Secure configuration with minimal services - full: Query-enabled with API/gRPC/EVM services - seed: Optimized for peer discovery with high P2P connections - archive: Full node that keeps complete history ## Describe your changes and provide context ## Testing performed to validate your change
1 parent f61a2e7 commit 38a8aec

9 files changed

Lines changed: 503 additions & 86 deletions

File tree

app/params/config.go

Lines changed: 118 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package params
22

33
import (
4-
"time"
5-
4+
srvconfig "github.com/cosmos/cosmos-sdk/server/config"
65
"github.com/cosmos/cosmos-sdk/types/address"
6+
"github.com/sei-protocol/sei-chain/evmrpc"
77
tmcfg "github.com/tendermint/tendermint/config"
88

99
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -80,27 +80,120 @@ func SetAddressPrefixes() {
8080
})
8181
}
8282

83-
func SetTendermintConfigs(config *tmcfg.Config) {
84-
// P2P configs
85-
config.P2P.MaxConnections = 200
86-
config.P2P.SendRate = 20480000
87-
config.P2P.RecvRate = 20480000
88-
config.P2P.MaxPacketMsgPayloadSize = 1000000 // 1MB
89-
config.P2P.FlushThrottleTimeout = 10 * time.Millisecond
90-
// Mempool configs
91-
config.Mempool.Size = 1000
92-
config.Mempool.MaxTxsBytes = 10737418240
93-
config.Mempool.MaxTxBytes = 2048576
94-
config.Mempool.TTLDuration = 5 * time.Second
95-
config.Mempool.TTLNumBlocks = 10
96-
// Consensus Configs
97-
config.Consensus.GossipTransactionKeyOnly = true
98-
config.Consensus.UnsafeProposeTimeoutOverride = 300 * time.Millisecond
99-
config.Consensus.UnsafeProposeTimeoutDeltaOverride = 50 * time.Millisecond
100-
config.Consensus.UnsafeVoteTimeoutOverride = 50 * time.Millisecond
101-
config.Consensus.UnsafeVoteTimeoutDeltaOverride = 50 * time.Millisecond
102-
config.Consensus.UnsafeCommitTimeoutOverride = 200 * time.Millisecond
103-
config.Consensus.UnsafeBypassCommitTimeoutOverride = &UnsafeBypassCommitTimeoutOverride
104-
// Metrics
105-
config.Instrumentation.Prometheus = true
83+
// NodeMode represents the type of node being run
84+
// Extends Tendermint's Mode with additional archive mode
85+
type NodeMode string
86+
87+
const (
88+
// Reuse Tendermint's mode constants
89+
NodeModeValidator NodeMode = tmcfg.ModeValidator // "validator"
90+
NodeModeFull NodeMode = tmcfg.ModeFull // "full"
91+
NodeModeSeed NodeMode = tmcfg.ModeSeed // "seed"
92+
// Additional mode specific to Sei Chain
93+
NodeModeArchive NodeMode = "archive"
94+
)
95+
96+
// IsFullnodeType returns true if the node is a fullnode-like node (full or archive)
97+
func (m NodeMode) IsFullnodeType() bool {
98+
return m == NodeModeFull || m == NodeModeArchive
99+
}
100+
101+
// setValidatorTypeTendermintConfig sets common Tendermint config for validator-like nodes
102+
func setValidatorTypeTendermintConfig(config *tmcfg.Config) {
103+
config.TxIndex.Indexer = []string{"null"} // Validators don't need tx indexing
104+
config.P2P.AllowDuplicateIP = false
105+
}
106+
107+
// setFullnodeTypeTendermintConfig sets common Tendermint config for fullnode-like nodes
108+
func setFullnodeTypeTendermintConfig(config *tmcfg.Config) {
109+
config.TxIndex.Indexer = []string{"kv"} // Full nodes need tx indexing for queries
110+
}
111+
112+
// SetTendermintConfigByMode sets Tendermint config values based on node mode
113+
// Note: config.Mode should be set by the caller before calling this function
114+
// Archive nodes should have config.Mode = "full" since Tendermint doesn't recognize "archive"
115+
func SetTendermintConfigByMode(config *tmcfg.Config) {
116+
mode := NodeMode(config.Mode)
117+
118+
switch mode {
119+
case NodeModeValidator:
120+
setValidatorTypeTendermintConfig(config)
121+
122+
case NodeModeSeed:
123+
setValidatorTypeTendermintConfig(config)
124+
// Seed nodes need more connections to serve peers
125+
config.P2P.MaxConnections = 1000
126+
config.P2P.AllowDuplicateIP = true
127+
128+
case NodeModeFull:
129+
setFullnodeTypeTendermintConfig(config)
130+
131+
case NodeModeArchive:
132+
// Archive nodes use full node Tendermint config
133+
// The difference is in app config (keeping all history)
134+
setFullnodeTypeTendermintConfig(config)
135+
}
136+
}
137+
138+
// setValidatorTypeAppConfig sets common app config for validator-like nodes
139+
func setValidatorTypeAppConfig(config *srvconfig.Config) {
140+
// Services: validators should minimize exposed services for security
141+
config.API.Enable = false
142+
config.GRPC.Enable = false
143+
config.GRPCWeb.Enable = false
144+
config.Rosetta.Enable = false
145+
config.StateStore.Enable = false
146+
}
147+
148+
// setFullnodeTypeAppConfig sets common app config for fullnode-like nodes
149+
func setFullnodeTypeAppConfig(config *srvconfig.Config) {
150+
// Services: full nodes provide query services
151+
config.API.Enable = true
152+
config.GRPC.Enable = true
153+
config.GRPCWeb.Enable = true
154+
config.Rosetta.Enable = true
155+
config.StateStore.Enable = true
156+
157+
// StateStore: full nodes keep recent history for queries
158+
config.StateStore.KeepRecent = 100000
159+
160+
// MinRetainBlocks: keep 100k blocks for Tendermint pruning
161+
config.MinRetainBlocks = 100000
162+
}
163+
164+
// setArchiveTypeAppConfig configures archive node settings
165+
// Archive nodes are like full nodes but keep all history
166+
func setArchiveTypeAppConfig(config *srvconfig.Config) {
167+
// Start with full node configuration
168+
setFullnodeTypeAppConfig(config)
169+
170+
// Archive nodes keep all history
171+
config.StateStore.KeepRecent = 0 // 0 = keep all history
172+
}
173+
174+
// SetAppConfigByMode sets app config values based on node mode
175+
func SetAppConfigByMode(config *srvconfig.Config, mode NodeMode) {
176+
switch mode {
177+
case NodeModeValidator, NodeModeSeed:
178+
// Validator and Seed nodes share the same app config
179+
setValidatorTypeAppConfig(config)
180+
181+
case NodeModeFull:
182+
setFullnodeTypeAppConfig(config)
183+
184+
case NodeModeArchive:
185+
setArchiveTypeAppConfig(config)
186+
187+
default:
188+
// Default to full node settings
189+
SetAppConfigByMode(config, NodeModeFull)
190+
}
191+
}
192+
193+
// SetEVMConfigByMode sets EVM config based on node mode
194+
// Validators and seeds have EVM disabled, full nodes and archives have it enabled
195+
func SetEVMConfigByMode(config *evmrpc.Config, mode NodeMode) {
196+
evmEnabled := mode.IsFullnodeType()
197+
config.HTTPEnabled = evmEnabled
198+
config.WSEnabled = evmEnabled
106199
}

app/params/config_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package params
2+
3+
import (
4+
"testing"
5+
6+
"github.com/sei-protocol/sei-chain/evmrpc"
7+
"github.com/stretchr/testify/require"
8+
)
9+
10+
func TestSetEVMConfigByMode(t *testing.T) {
11+
tests := []struct {
12+
name string
13+
mode NodeMode
14+
expectedHTTP bool
15+
expectedWS bool
16+
}{
17+
{
18+
name: "validator mode - EVM disabled",
19+
mode: NodeModeValidator,
20+
expectedHTTP: false,
21+
expectedWS: false,
22+
},
23+
{
24+
name: "full mode - EVM enabled",
25+
mode: NodeModeFull,
26+
expectedHTTP: true,
27+
expectedWS: true,
28+
},
29+
{
30+
name: "seed mode - EVM disabled",
31+
mode: NodeModeSeed,
32+
expectedHTTP: false,
33+
expectedWS: false,
34+
},
35+
{
36+
name: "archive mode - EVM enabled",
37+
mode: NodeModeArchive,
38+
expectedHTTP: true,
39+
expectedWS: true,
40+
},
41+
}
42+
43+
for _, tt := range tests {
44+
t.Run(tt.name, func(t *testing.T) {
45+
// Create default EVM config
46+
evmConfig := evmrpc.DefaultConfig
47+
48+
// Set EVM config based on mode
49+
SetEVMConfigByMode(&evmConfig, tt.mode)
50+
51+
// Verify the config
52+
require.Equal(t, tt.expectedHTTP, evmConfig.HTTPEnabled, "EVM HTTP should match expected")
53+
require.Equal(t, tt.expectedWS, evmConfig.WSEnabled, "EVM WS should match expected")
54+
})
55+
}
56+
}

cmd/seid/cmd/app_config.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package cmd
2+
3+
import (
4+
srvconfig "github.com/cosmos/cosmos-sdk/server/config"
5+
seiapp "github.com/sei-protocol/sei-chain/app"
6+
"github.com/sei-protocol/sei-chain/evmrpc"
7+
"github.com/sei-protocol/sei-chain/x/evm/blocktest"
8+
"github.com/sei-protocol/sei-chain/x/evm/querier"
9+
"github.com/sei-protocol/sei-chain/x/evm/replay"
10+
)
11+
12+
// WASMConfig defines configuration for the wasm module.
13+
type WASMConfig struct {
14+
QueryGasLimit uint64 `mapstructure:"query_gas_limit"`
15+
LruSize uint64 `mapstructure:"lru_size"`
16+
}
17+
18+
// CustomAppConfig extends the Cosmos SDK's Config with custom fields
19+
// This structure is used for generating app.toml with custom sections
20+
type CustomAppConfig struct {
21+
srvconfig.Config
22+
23+
WASM WASMConfig `mapstructure:"wasm"`
24+
EVM evmrpc.Config `mapstructure:"evm"`
25+
ETHReplay replay.Config `mapstructure:"eth_replay"`
26+
ETHBlockTest blocktest.Config `mapstructure:"eth_block_test"`
27+
EvmQuery querier.Config `mapstructure:"evm_query"`
28+
LightInvariance seiapp.LightInvarianceConfig `mapstructure:"light_invariance"`
29+
}
30+
31+
// NewCustomAppConfig creates a CustomAppConfig with the given base config and EVM config
32+
func NewCustomAppConfig(baseConfig *srvconfig.Config, evmConfig evmrpc.Config) CustomAppConfig {
33+
return CustomAppConfig{
34+
Config: *baseConfig,
35+
WASM: WASMConfig{
36+
QueryGasLimit: 300000,
37+
LruSize: 1,
38+
},
39+
EVM: evmConfig,
40+
ETHReplay: replay.DefaultConfig,
41+
ETHBlockTest: blocktest.DefaultConfig,
42+
EvmQuery: querier.DefaultConfig,
43+
LightInvariance: seiapp.DefaultLightInvarianceConfig,
44+
}
45+
}

cmd/seid/cmd/compact.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"github.com/cosmos/cosmos-sdk/client"
1010
"github.com/cosmos/cosmos-sdk/server"
1111
sdk "github.com/cosmos/cosmos-sdk/types"
12-
"github.com/sei-protocol/sei-chain/app/params"
1312
"github.com/spf13/cobra"
1413
leveldbutils "github.com/syndtr/goleveldb/leveldb/util"
1514
"github.com/tendermint/tendermint/libs/cli"
@@ -26,7 +25,6 @@ func CompactCmd(defaultNodeHome string) *cobra.Command {
2625
clientCtx := client.GetClientContextFromCmd(cmd)
2726
serverCtx := server.GetServerContextFromCmd(cmd)
2827
config := serverCtx.Config
29-
params.SetTendermintConfigs(config)
3028
config.SetRoot(clientCtx.HomeDir)
3129
rootDir := config.RootDir
3230
dataDir := filepath.Join(rootDir, "data")

0 commit comments

Comments
 (0)