Skip to content

Commit 5666553

Browse files
authored
renamed flags (#298)
* renamed flags * rename admin api flags * add deprecation
1 parent e7645fa commit 5666553

File tree

3 files changed

+55
-15
lines changed

3 files changed

+55
-15
lines changed

plugin/evm/config.go

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ type Duration struct {
7878
type Config struct {
7979
// Coreth APIs
8080
SnowmanAPIEnabled bool `json:"snowman-api-enabled"`
81-
CorethAdminAPIEnabled bool `json:"coreth-admin-api-enabled"`
82-
CorethAdminAPIDir string `json:"coreth-admin-api-dir"`
81+
AdminAPIEnabled bool `json:"admin-api-enabled"`
82+
AdminAPIDir string `json:"admin-api-dir"`
83+
CorethAdminAPIEnabled bool `json:"coreth-admin-api-enabled"` // Deprecated: use AdminAPIEnabled instead
84+
CorethAdminAPIDir string `json:"coreth-admin-api-dir"` // Deprecated: use AdminAPIDir instead
8385

8486
// EnabledEthAPIs is a list of Ethereum services that should be enabled
8587
// If none is specified, then we use the default list [defaultEnabledAPIs]
@@ -144,9 +146,12 @@ type Config struct {
144146
KeystoreInsecureUnlockAllowed bool `json:"keystore-insecure-unlock-allowed"`
145147

146148
// Gossip Settings
147-
RemoteTxGossipOnlyEnabled bool `json:"remote-tx-gossip-only-enabled"`
148-
TxRegossipFrequency Duration `json:"tx-regossip-frequency"`
149-
TxRegossipMaxSize int `json:"tx-regossip-max-size"`
149+
RemoteGossipOnlyEnabled bool `json:"remote-gossip-only-enabled"`
150+
RegossipFrequency Duration `json:"regossip-frequency"`
151+
RegossipMaxTxs int `json:"regossip-max-txs"`
152+
RemoteTxGossipOnlyEnabled bool `json:"remote-tx-gossip-only-enabled"` // Deprecated: use RemoteGossipOnlyEnabled instead
153+
TxRegossipFrequency Duration `json:"tx-regossip-frequency"` // Deprecated: use RegossipFrequency instead
154+
TxRegossipMaxSize int `json:"tx-regossip-max-size"` // Deprecated: use RegossipMaxTxs instead
150155

151156
// Log
152157
LogLevel string `json:"log-level"`
@@ -230,8 +235,8 @@ func (c *Config) SetDefaults() {
230235
c.SnapshotCache = defaultSnapshotCache
231236
c.AcceptorQueueLimit = defaultAcceptorQueueLimit
232237
c.SnapshotWait = defaultSnapshotWait
233-
c.TxRegossipFrequency.Duration = defaultTxRegossipFrequency
234-
c.TxRegossipMaxSize = defaultTxRegossipMaxSize
238+
c.RegossipFrequency.Duration = defaultTxRegossipFrequency
239+
c.RegossipMaxTxs = defaultTxRegossipMaxSize
235240
c.OfflinePruningBloomFilterSize = defaultOfflinePruningBloomFilterSize
236241
c.LogLevel = defaultLogLevel
237242
c.PopulateMissingTriesParallelism = defaultPopulateMissingTriesParallelism
@@ -285,3 +290,30 @@ func (c *Config) Validate() error {
285290

286291
return nil
287292
}
293+
294+
func (c *Config) Deprecate() string {
295+
msg := ""
296+
// Deprecate the old config options and set the new ones.
297+
if c.CorethAdminAPIEnabled {
298+
msg += "coreth-admin-api-enabled is deprecated, use admin-api-enabled instead. "
299+
c.AdminAPIEnabled = c.CorethAdminAPIEnabled
300+
}
301+
if c.CorethAdminAPIDir != "" {
302+
msg += "coreth-admin-api-dir is deprecated, use admin-api-dir instead. "
303+
c.AdminAPIDir = c.CorethAdminAPIDir
304+
}
305+
if c.RemoteTxGossipOnlyEnabled {
306+
msg += "remote-tx-gossip-only-enabled is deprecated, use tx-gossip-enabled instead. "
307+
c.RemoteGossipOnlyEnabled = c.RemoteTxGossipOnlyEnabled
308+
}
309+
if c.TxRegossipFrequency != (Duration{}) {
310+
msg += "tx-regossip-frequency is deprecated, use regossip-frequency instead. "
311+
c.RegossipFrequency = c.TxRegossipFrequency
312+
}
313+
if c.TxRegossipMaxSize != 0 {
314+
msg += "tx-regossip-max-size is deprecated, use regossip-max-txs instead. "
315+
c.RegossipMaxTxs = c.TxRegossipMaxSize
316+
}
317+
318+
return msg
319+
}

plugin/evm/gossiper.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func (n *pushGossiper) queueExecutableTxs(state *state.StateDB, baseFee *big.Int
140140
}
141141

142142
// Don't try to regossip a transaction too frequently
143-
if time.Since(tx.FirstSeen()) < n.config.TxRegossipFrequency.Duration {
143+
if time.Since(tx.FirstSeen()) < n.config.RegossipFrequency.Duration {
144144
continue
145145
}
146146

@@ -197,14 +197,14 @@ func (n *pushGossiper) queueRegossipTxs() types.Transactions {
197197
)
198198
return nil
199199
}
200-
localQueued := n.queueExecutableTxs(state, tip.BaseFee, localTxs, n.config.TxRegossipMaxSize)
200+
localQueued := n.queueExecutableTxs(state, tip.BaseFee, localTxs, n.config.RegossipMaxTxs)
201201
localCount := len(localQueued)
202202
n.stats.IncEthTxsRegossipQueuedLocal(localCount)
203-
if localCount >= n.config.TxRegossipMaxSize {
203+
if localCount >= n.config.RegossipMaxTxs {
204204
n.stats.IncEthTxsRegossipQueued()
205205
return localQueued
206206
}
207-
remoteQueued := n.queueExecutableTxs(state, tip.BaseFee, remoteTxs, n.config.TxRegossipMaxSize-localCount)
207+
remoteQueued := n.queueExecutableTxs(state, tip.BaseFee, remoteTxs, n.config.RegossipMaxTxs-localCount)
208208
n.stats.IncEthTxsRegossipQueuedRemote(len(remoteQueued))
209209
if localCount+len(remoteQueued) > 0 {
210210
// only increment the regossip stat when there are any txs queued
@@ -220,7 +220,7 @@ func (n *pushGossiper) awaitEthTxGossip() {
220220
go n.ctx.Log.RecoverAndPanic(func() {
221221
var (
222222
gossipTicker = time.NewTicker(ethTxsGossipInterval)
223-
regossipTicker = time.NewTicker(n.config.TxRegossipFrequency.Duration)
223+
regossipTicker = time.NewTicker(n.config.RegossipFrequency.Duration)
224224
)
225225
defer func() {
226226
gossipTicker.Stop()
@@ -349,7 +349,7 @@ func (n *pushGossiper) gossipEthTxs(force bool) (int, error) {
349349
continue
350350
}
351351

352-
if n.config.RemoteTxGossipOnlyEnabled && n.txPool.HasLocal(txHash) {
352+
if n.config.RemoteGossipOnlyEnabled && n.txPool.HasLocal(txHash) {
353353
continue
354354
}
355355

plugin/evm/vm.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,10 @@ func (vm *VM) Initialize(
333333
if err := vm.config.Validate(); err != nil {
334334
return err
335335
}
336+
// We should deprecate config flags as the first thing, before we do anything else
337+
// because this can set old flags to new flags. log the message after we have
338+
// initialized the logger.
339+
deprecateMsg := vm.config.Deprecate()
336340

337341
vm.ctx = chainCtx
338342

@@ -355,6 +359,10 @@ func (vm *VM) Initialize(
355359

356360
log.Info("Initializing Coreth VM", "Version", Version, "Config", vm.config)
357361

362+
if deprecateMsg != "" {
363+
log.Warn("Deprecation Warning", "msg", deprecateMsg)
364+
}
365+
358366
if len(fxs) > 0 {
359367
return errUnsupportedFXs
360368
}
@@ -1156,8 +1164,8 @@ func (vm *VM) CreateHandlers(context.Context) (map[string]*commonEng.HTTPHandler
11561164
enabledAPIs = append(enabledAPIs, "avax")
11571165
apis[avaxEndpoint] = avaxAPI
11581166

1159-
if vm.config.CorethAdminAPIEnabled {
1160-
adminAPI, err := newHandler("admin", NewAdminService(vm, os.ExpandEnv(fmt.Sprintf("%s_coreth_performance_%s", vm.config.CorethAdminAPIDir, primaryAlias))))
1167+
if vm.config.AdminAPIEnabled {
1168+
adminAPI, err := newHandler("admin", NewAdminService(vm, os.ExpandEnv(fmt.Sprintf("%s_coreth_performance_%s", vm.config.AdminAPIDir, primaryAlias))))
11611169
if err != nil {
11621170
return nil, fmt.Errorf("failed to register service for admin API due to %w", err)
11631171
}

0 commit comments

Comments
 (0)