|
1 | 1 | package params |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "time" |
5 | | - |
| 4 | + srvconfig "github.com/cosmos/cosmos-sdk/server/config" |
6 | 5 | "github.com/cosmos/cosmos-sdk/types/address" |
| 6 | + "github.com/sei-protocol/sei-chain/evmrpc" |
7 | 7 | tmcfg "github.com/tendermint/tendermint/config" |
8 | 8 |
|
9 | 9 | sdk "github.com/cosmos/cosmos-sdk/types" |
@@ -80,27 +80,120 @@ func SetAddressPrefixes() { |
80 | 80 | }) |
81 | 81 | } |
82 | 82 |
|
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 |
106 | 199 | } |
0 commit comments