@@ -17,107 +17,110 @@ import (
17
17
)
18
18
19
19
const (
20
+ FlagPrefixRollkit = "rollkit."
21
+ FlagPrefixEvnode = "evnode."
22
+
20
23
// Base configuration flags
21
24
22
25
// FlagRootDir is a flag for specifying the root directory
23
26
FlagRootDir = "home"
24
27
// FlagDBPath is a flag for specifying the database path
25
- FlagDBPath = "rollkit. db_path"
28
+ FlagDBPath = FlagPrefixEvnode + " db_path"
26
29
27
30
// Node configuration flags
28
31
29
32
// FlagAggregator is a flag for running node in aggregator mode
30
- FlagAggregator = "rollkit. node.aggregator"
33
+ FlagAggregator = FlagPrefixEvnode + " node.aggregator"
31
34
// FlagLight is a flag for running the node in light mode
32
- FlagLight = "rollkit. node.light"
35
+ FlagLight = FlagPrefixEvnode + " node.light"
33
36
// FlagBlockTime is a flag for specifying the block time
34
- FlagBlockTime = "rollkit. node.block_time"
37
+ FlagBlockTime = FlagPrefixEvnode + " node.block_time"
35
38
// FlagTrustedHash is a flag for specifying the trusted hash
36
- FlagTrustedHash = "rollkit. node.trusted_hash"
39
+ FlagTrustedHash = FlagPrefixEvnode + " node.trusted_hash"
37
40
// FlagLazyAggregator is a flag for enabling lazy aggregation mode that only produces blocks when transactions are available
38
- FlagLazyAggregator = "rollkit. node.lazy_mode"
41
+ FlagLazyAggregator = FlagPrefixEvnode + " node.lazy_mode"
39
42
// FlagMaxPendingHeadersAndData is a flag to limit and pause block production when too many headers or data are waiting for DA confirmation
40
- FlagMaxPendingHeadersAndData = "rollkit. node.max_pending_headers_and_data"
43
+ FlagMaxPendingHeadersAndData = FlagPrefixEvnode + " node.max_pending_headers_and_data"
41
44
// FlagLazyBlockTime is a flag for specifying the maximum interval between blocks in lazy aggregation mode
42
- FlagLazyBlockTime = "rollkit. node.lazy_block_interval"
45
+ FlagLazyBlockTime = FlagPrefixEvnode + " node.lazy_block_interval"
43
46
44
47
// Data Availability configuration flags
45
48
46
49
// FlagDAAddress is a flag for specifying the data availability layer address
47
- FlagDAAddress = "rollkit. da.address"
50
+ FlagDAAddress = FlagPrefixEvnode + " da.address"
48
51
// FlagDAAuthToken is a flag for specifying the data availability layer auth token
49
- FlagDAAuthToken = "rollkit. da.auth_token" // #nosec G101
52
+ FlagDAAuthToken = FlagPrefixEvnode + " da.auth_token" // #nosec G101
50
53
// FlagDABlockTime is a flag for specifying the data availability layer block time
51
- FlagDABlockTime = "rollkit. da.block_time"
54
+ FlagDABlockTime = FlagPrefixEvnode + " da.block_time"
52
55
// FlagDAGasPrice is a flag for specifying the data availability layer gas price
53
- FlagDAGasPrice = "rollkit. da.gas_price"
56
+ FlagDAGasPrice = FlagPrefixEvnode + " da.gas_price"
54
57
// FlagDAGasMultiplier is a flag for specifying the data availability layer gas price retry multiplier
55
- FlagDAGasMultiplier = "rollkit. da.gas_multiplier"
58
+ FlagDAGasMultiplier = FlagPrefixEvnode + " da.gas_multiplier"
56
59
// FlagDAStartHeight is a flag for specifying the data availability layer start height
57
- FlagDAStartHeight = "rollkit. da.start_height"
60
+ FlagDAStartHeight = FlagPrefixEvnode + " da.start_height"
58
61
// FlagDANamespace is a flag for specifying the DA namespace ID
59
- FlagDANamespace = "rollkit. da.namespace"
62
+ FlagDANamespace = FlagPrefixEvnode + " da.namespace"
60
63
// FlagDAHeaderNamespace is a flag for specifying the DA header namespace ID
61
- FlagDAHeaderNamespace = "rollkit. da.header_namespace"
64
+ FlagDAHeaderNamespace = FlagPrefixEvnode + " da.header_namespace"
62
65
// FlagDADataNamespace is a flag for specifying the DA data namespace ID
63
- FlagDADataNamespace = "rollkit. da.data_namespace"
66
+ FlagDADataNamespace = FlagPrefixEvnode + " da.data_namespace"
64
67
// FlagDASubmitOptions is a flag for data availability submit options
65
- FlagDASubmitOptions = "rollkit. da.submit_options"
68
+ FlagDASubmitOptions = FlagPrefixEvnode + " da.submit_options"
66
69
// FlagDAMempoolTTL is a flag for specifying the DA mempool TTL
67
- FlagDAMempoolTTL = "rollkit. da.mempool_ttl"
70
+ FlagDAMempoolTTL = FlagPrefixEvnode + " da.mempool_ttl"
68
71
// FlagDAMaxSubmitAttempts is a flag for specifying the maximum DA submit attempts
69
- FlagDAMaxSubmitAttempts = "rollkit. da.max_submit_attempts"
72
+ FlagDAMaxSubmitAttempts = FlagPrefixEvnode + " da.max_submit_attempts"
70
73
71
74
// P2P configuration flags
72
75
73
76
// FlagP2PListenAddress is a flag for specifying the P2P listen address
74
- FlagP2PListenAddress = "rollkit. p2p.listen_address"
77
+ FlagP2PListenAddress = FlagPrefixEvnode + " p2p.listen_address"
75
78
// FlagP2PPeers is a flag for specifying the P2P peers
76
- FlagP2PPeers = "rollkit. p2p.peers"
79
+ FlagP2PPeers = FlagPrefixEvnode + " p2p.peers"
77
80
// FlagP2PBlockedPeers is a flag for specifying the P2P blocked peers
78
- FlagP2PBlockedPeers = "rollkit. p2p.blocked_peers"
81
+ FlagP2PBlockedPeers = FlagPrefixEvnode + " p2p.blocked_peers"
79
82
// FlagP2PAllowedPeers is a flag for specifying the P2P allowed peers
80
- FlagP2PAllowedPeers = "rollkit. p2p.allowed_peers"
83
+ FlagP2PAllowedPeers = FlagPrefixEvnode + " p2p.allowed_peers"
81
84
82
85
// Instrumentation configuration flags
83
86
84
87
// FlagPrometheus is a flag for enabling Prometheus metrics
85
- FlagPrometheus = "rollkit. instrumentation.prometheus"
88
+ FlagPrometheus = FlagPrefixEvnode + " instrumentation.prometheus"
86
89
// FlagPrometheusListenAddr is a flag for specifying the Prometheus listen address
87
- FlagPrometheusListenAddr = "rollkit. instrumentation.prometheus_listen_addr"
90
+ FlagPrometheusListenAddr = FlagPrefixEvnode + " instrumentation.prometheus_listen_addr"
88
91
// FlagMaxOpenConnections is a flag for specifying the maximum number of open connections
89
- FlagMaxOpenConnections = "rollkit. instrumentation.max_open_connections"
92
+ FlagMaxOpenConnections = FlagPrefixEvnode + " instrumentation.max_open_connections"
90
93
// FlagPprof is a flag for enabling pprof profiling endpoints for runtime debugging
91
- FlagPprof = "rollkit. instrumentation.pprof"
94
+ FlagPprof = FlagPrefixEvnode + " instrumentation.pprof"
92
95
// FlagPprofListenAddr is a flag for specifying the pprof listen address
93
- FlagPprofListenAddr = "rollkit. instrumentation.pprof_listen_addr"
96
+ FlagPprofListenAddr = FlagPrefixEvnode + " instrumentation.pprof_listen_addr"
94
97
95
98
// Logging configuration flags
96
99
97
100
// FlagLogLevel is a flag for specifying the log level
98
- FlagLogLevel = "rollkit. log.level"
101
+ FlagLogLevel = FlagPrefixEvnode + " log.level"
99
102
// FlagLogFormat is a flag for specifying the log format
100
- FlagLogFormat = "rollkit. log.format"
103
+ FlagLogFormat = FlagPrefixEvnode + " log.format"
101
104
// FlagLogTrace is a flag for enabling stack traces in error logs
102
- FlagLogTrace = "rollkit. log.trace"
105
+ FlagLogTrace = FlagPrefixEvnode + " log.trace"
103
106
104
107
// Signer configuration flags
105
108
106
109
// FlagSignerType is a flag for specifying the signer type
107
- FlagSignerType = "rollkit. signer.type"
110
+ FlagSignerType = FlagPrefixEvnode + " signer.type"
108
111
// FlagSignerPath is a flag for specifying the signer path
109
- FlagSignerPath = "rollkit. signer.path"
112
+ FlagSignerPath = FlagPrefixEvnode + " signer.path"
110
113
111
114
// FlagSignerPassphrase is a flag for specifying the signer passphrase
112
115
//nolint:gosec
113
- FlagSignerPassphrase = "rollkit. signer.passphrase"
116
+ FlagSignerPassphrase = FlagPrefixEvnode + " signer.passphrase"
114
117
115
118
// RPC configuration flags
116
119
117
120
// FlagRPCAddress is a flag for specifying the RPC server address
118
- FlagRPCAddress = "rollkit. rpc.address"
121
+ FlagRPCAddress = FlagPrefixEvnode + " rpc.address"
119
122
// FlagRPCEnableDAVisualization is a flag for enabling DA visualization endpoints
120
- FlagRPCEnableDAVisualization = "rollkit. rpc.enable_da_visualization"
123
+ FlagRPCEnableDAVisualization = FlagPrefixEvnode + " rpc.enable_da_visualization"
121
124
)
122
125
123
126
// Config stores Rollkit configuration.
@@ -262,6 +265,15 @@ func AddGlobalFlags(cmd *cobra.Command, defaultHome string) {
262
265
func AddFlags (cmd * cobra.Command ) {
263
266
def := DefaultConfig
264
267
268
+ // Set normalization function to support both flag prefixes
269
+ cmd .Flags ().SetNormalizeFunc (func (f * pflag.FlagSet , name string ) pflag.NormalizedName {
270
+ if strings .HasPrefix (name , FlagPrefixRollkit ) {
271
+ return pflag .NormalizedName (strings .Replace (name , FlagPrefixRollkit , FlagPrefixEvnode , 1 ))
272
+ }
273
+
274
+ return pflag .NormalizedName (name )
275
+ })
276
+
265
277
// Add base flags
266
278
cmd .Flags ().String (FlagDBPath , def .DBPath , "path for the node database" )
267
279
@@ -400,7 +412,11 @@ func LoadFromViper(inputViper *viper.Viper) (Config, error) {
400
412
// then override with settings from input viper (higher precedence)
401
413
for _ , key := range inputViper .AllKeys () {
402
414
// Handle special case for prefixed keys
403
- if after , ok := strings .CutPrefix (key , "rollkit." ); ok {
415
+ if after , ok := strings .CutPrefix (key , FlagPrefixEvnode ); ok {
416
+ // Strip the prefix for the merged viper
417
+ strippedKey := after
418
+ mergedViper .Set (strippedKey , inputViper .Get (key ))
419
+ } else if after , ok := strings .CutPrefix (key , FlagPrefixRollkit ); ok {
404
420
// Strip the prefix for the merged viper
405
421
strippedKey := after
406
422
mergedViper .Set (strippedKey , inputViper .Get (key ))
@@ -457,7 +473,9 @@ func bindFlags(basename string, cmd *cobra.Command, v *viper.Viper) (err error)
457
473
}()
458
474
459
475
cmd .Flags ().VisitAll (func (f * pflag.Flag ) {
460
- flagName := strings .TrimPrefix (f .Name , "rollkit." ) // trimm the prefix from the flag name
476
+ // trimm possible prefixes from the flag name
477
+ flagName := strings .TrimPrefix (f .Name , FlagPrefixEvnode )
478
+ flagName = strings .TrimPrefix (flagName , FlagPrefixRollkit )
461
479
462
480
// Environment variables can't have dashes in them, so bind them to their equivalent
463
481
// keys with underscores, e.g. --favorite-color to STING_FAVORITE_COLOR
0 commit comments