fix config migration issue for newly added rpc filter options (#4183)

Co-authored-by: “GheisMohammadi” <“Gheis.Mohammadi@gmail.com”>
pull/4185/head
Gheis 3 years ago committed by GitHub
parent 2367a0da23
commit 021c4db669
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 38
      cmd/harmony/config_migrations.go
  2. 8
      cmd/harmony/config_migrations_test.go
  3. 4
      cmd/harmony/default.go
  4. 16
      cmd/harmony/flags_test.go
  5. 4
      eth/rpc/method_filter.go
  6. 4
      rosetta/infra/harmony-mainnet.conf
  7. 4
      rosetta/infra/harmony-pstn.conf
  8. 2
      rpc/rpc.go

@ -92,22 +92,6 @@ func init() {
confTree.Set("HTTP.RosettaPort", defaultConfig.HTTP.RosettaPort) confTree.Set("HTTP.RosettaPort", defaultConfig.HTTP.RosettaPort)
} }
if confTree.Get("RPCOpt.EthRPCsEnabled") == nil {
confTree.Set("RPCOpt.EthRPCsEnabled", defaultConfig.RPCOpt.EthRPCsEnabled)
}
if confTree.Get("RPCOpt.StakingRPCsEnabled") == nil {
confTree.Set("RPCOpt.StakingRPCsEnabled", defaultConfig.RPCOpt.StakingRPCsEnabled)
}
if confTree.Get("RPCOpt.LegacyRPCsEnabled") == nil {
confTree.Set("RPCOpt.LegacyRPCsEnabled", defaultConfig.RPCOpt.LegacyRPCsEnabled)
}
if confTree.Get("RPCOpt.RpcFilterFile") == nil {
confTree.Set("RPCOpt.RpcFilterFile", defaultConfig.RPCOpt.RpcFilterFile)
}
if confTree.Get("RPCOpt.RateLimterEnabled") == nil { if confTree.Get("RPCOpt.RateLimterEnabled") == nil {
confTree.Set("RPCOpt.RateLimterEnabled", defaultConfig.RPCOpt.RateLimterEnabled) confTree.Set("RPCOpt.RateLimterEnabled", defaultConfig.RPCOpt.RateLimterEnabled)
} }
@ -254,4 +238,26 @@ func init() {
confTree.Set("Version", "2.5.2") confTree.Set("Version", "2.5.2")
return confTree return confTree
} }
migrations["2.5.2"] = func(confTree *toml.Tree) *toml.Tree {
if confTree.Get("RPCOpt.EthRPCsEnabled") == nil {
confTree.Set("RPCOpt.EthRPCsEnabled", defaultConfig.RPCOpt.EthRPCsEnabled)
}
if confTree.Get("RPCOpt.StakingRPCsEnabled") == nil {
confTree.Set("RPCOpt.StakingRPCsEnabled", defaultConfig.RPCOpt.StakingRPCsEnabled)
}
if confTree.Get("RPCOpt.LegacyRPCsEnabled") == nil {
confTree.Set("RPCOpt.LegacyRPCsEnabled", defaultConfig.RPCOpt.LegacyRPCsEnabled)
}
if confTree.Get("RPCOpt.RpcFilterFile") == nil {
confTree.Set("RPCOpt.RpcFilterFile", defaultConfig.RPCOpt.RpcFilterFile)
}
confTree.Set("Version", "2.5.3")
return confTree
}
} }

@ -67,7 +67,7 @@ Version = "1.0.2"
EthRPCsEnabled = true EthRPCsEnabled = true
StakingRPCsEnabled = true StakingRPCsEnabled = true
LegacyRPCsEnabled = true LegacyRPCsEnabled = true
RpcFilterFile = "" RpcFilterFile = "./.hmy/rpc_filter.txt"
[TxPool] [TxPool]
BlacklistFile = "./.hmy/blacklist.txt" BlacklistFile = "./.hmy/blacklist.txt"
@ -137,7 +137,7 @@ Version = "1.0.3"
EthRPCsEnabled = true EthRPCsEnabled = true
StakingRPCsEnabled = true StakingRPCsEnabled = true
LegacyRPCsEnabled = true LegacyRPCsEnabled = true
RpcFilterFile = "" RpcFilterFile = "./.hmy/rpc_filter.txt"
[TxPool] [TxPool]
BlacklistFile = "./.hmy/blacklist.txt" BlacklistFile = "./.hmy/blacklist.txt"
@ -207,7 +207,7 @@ Version = "1.0.4"
EthRPCsEnabled = true EthRPCsEnabled = true
StakingRPCsEnabled = true StakingRPCsEnabled = true
LegacyRPCsEnabled = true LegacyRPCsEnabled = true
RpcFilterFile = "" RpcFilterFile = "./.hmy/rpc_filter.txt"
[Sync] [Sync]
Concurrency = 6 Concurrency = 6
@ -289,7 +289,7 @@ Version = "1.0.4"
EthRPCsEnabled = true EthRPCsEnabled = true
StakingRPCsEnabled = true StakingRPCsEnabled = true
LegacyRPCsEnabled = true LegacyRPCsEnabled = true
RpcFilterFile = "" RpcFilterFile = "./.hmy/rpc_filter.txt"
[Sync] [Sync]
Concurrency = 6 Concurrency = 6

@ -5,7 +5,7 @@ import (
nodeconfig "github.com/harmony-one/harmony/internal/configs/node" nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
) )
const tomlConfigVersion = "2.5.2" // bump from 2.5.1 for DisablePrivateIPScan const tomlConfigVersion = "2.5.3" // bump from 2.5.2 for rpc filters
const ( const (
defNetworkType = nodeconfig.Mainnet defNetworkType = nodeconfig.Mainnet
@ -51,7 +51,7 @@ var defaultConfig = harmonyconfig.HarmonyConfig{
EthRPCsEnabled: true, EthRPCsEnabled: true,
StakingRPCsEnabled: true, StakingRPCsEnabled: true,
LegacyRPCsEnabled: true, LegacyRPCsEnabled: true,
RpcFilterFile: "", RpcFilterFile: "./.hmy/rpc_filter.txt",
RateLimterEnabled: true, RateLimterEnabled: true,
RequestsPerSecond: nodeconfig.DefaultRPCRateLimit, RequestsPerSecond: nodeconfig.DefaultRPCRateLimit,
}, },

@ -78,7 +78,7 @@ func TestHarmonyFlags(t *testing.T) {
EthRPCsEnabled: true, EthRPCsEnabled: true,
StakingRPCsEnabled: true, StakingRPCsEnabled: true,
LegacyRPCsEnabled: true, LegacyRPCsEnabled: true,
RpcFilterFile: "", RpcFilterFile: "./.hmy/rpc_filter.txt",
RateLimterEnabled: true, RateLimterEnabled: true,
RequestsPerSecond: 1000, RequestsPerSecond: 1000,
}, },
@ -629,7 +629,7 @@ func TestRPCOptFlags(t *testing.T) {
EthRPCsEnabled: true, EthRPCsEnabled: true,
StakingRPCsEnabled: true, StakingRPCsEnabled: true,
LegacyRPCsEnabled: true, LegacyRPCsEnabled: true,
RpcFilterFile: "", RpcFilterFile: "./.hmy/rpc_filter.txt",
RateLimterEnabled: true, RateLimterEnabled: true,
RequestsPerSecond: 1000, RequestsPerSecond: 1000,
}, },
@ -642,7 +642,7 @@ func TestRPCOptFlags(t *testing.T) {
EthRPCsEnabled: false, EthRPCsEnabled: false,
StakingRPCsEnabled: true, StakingRPCsEnabled: true,
LegacyRPCsEnabled: true, LegacyRPCsEnabled: true,
RpcFilterFile: "", RpcFilterFile: "./.hmy/rpc_filter.txt",
RateLimterEnabled: true, RateLimterEnabled: true,
RequestsPerSecond: 1000, RequestsPerSecond: 1000,
}, },
@ -655,7 +655,7 @@ func TestRPCOptFlags(t *testing.T) {
EthRPCsEnabled: true, EthRPCsEnabled: true,
StakingRPCsEnabled: false, StakingRPCsEnabled: false,
LegacyRPCsEnabled: true, LegacyRPCsEnabled: true,
RpcFilterFile: "", RpcFilterFile: "./.hmy/rpc_filter.txt",
RateLimterEnabled: true, RateLimterEnabled: true,
RequestsPerSecond: 1000, RequestsPerSecond: 1000,
}, },
@ -668,7 +668,7 @@ func TestRPCOptFlags(t *testing.T) {
EthRPCsEnabled: true, EthRPCsEnabled: true,
StakingRPCsEnabled: true, StakingRPCsEnabled: true,
LegacyRPCsEnabled: false, LegacyRPCsEnabled: false,
RpcFilterFile: "", RpcFilterFile: "./.hmy/rpc_filter.txt",
RateLimterEnabled: true, RateLimterEnabled: true,
RequestsPerSecond: 1000, RequestsPerSecond: 1000,
}, },
@ -694,7 +694,7 @@ func TestRPCOptFlags(t *testing.T) {
EthRPCsEnabled: true, EthRPCsEnabled: true,
StakingRPCsEnabled: true, StakingRPCsEnabled: true,
LegacyRPCsEnabled: true, LegacyRPCsEnabled: true,
RpcFilterFile: "", RpcFilterFile: "./.hmy/rpc_filter.txt",
RateLimterEnabled: true, RateLimterEnabled: true,
RequestsPerSecond: 1000, RequestsPerSecond: 1000,
}, },
@ -707,7 +707,7 @@ func TestRPCOptFlags(t *testing.T) {
EthRPCsEnabled: true, EthRPCsEnabled: true,
StakingRPCsEnabled: true, StakingRPCsEnabled: true,
LegacyRPCsEnabled: true, LegacyRPCsEnabled: true,
RpcFilterFile: "", RpcFilterFile: "./.hmy/rpc_filter.txt",
RateLimterEnabled: true, RateLimterEnabled: true,
RequestsPerSecond: 2000, RequestsPerSecond: 2000,
}, },
@ -720,7 +720,7 @@ func TestRPCOptFlags(t *testing.T) {
EthRPCsEnabled: true, EthRPCsEnabled: true,
StakingRPCsEnabled: true, StakingRPCsEnabled: true,
LegacyRPCsEnabled: true, LegacyRPCsEnabled: true,
RpcFilterFile: "", RpcFilterFile: "./.hmy/rpc_filter.txt",
RateLimterEnabled: false, RateLimterEnabled: false,
RequestsPerSecond: 2000, RequestsPerSecond: 2000,
}, },

@ -19,7 +19,7 @@ type RpcMethodFilter struct {
// ExposeAll - init Allow and Deny array in a way to expose all APIs // ExposeAll - init Allow and Deny array in a way to expose all APIs
func (rmf *RpcMethodFilter) ExposeAll() error { func (rmf *RpcMethodFilter) ExposeAll() error {
rmf.Allow = rmf.Allow[:0] rmf.Allow = rmf.Allow[:0]
rmf.Allow = rmf.Deny[:0] rmf.Deny = rmf.Deny[:0]
rmf.Allow = append(rmf.Allow, "*") rmf.Allow = append(rmf.Allow, "*")
return nil return nil
} }
@ -39,7 +39,7 @@ func (rmf *RpcMethodFilter) LoadRpcMethodFiltersFromFile(file string) error {
return rmf.LoadRpcMethodFilters(b) return rmf.LoadRpcMethodFilters(b)
} else if errors.Is(err, os.ErrNotExist) { } else if errors.Is(err, os.ErrNotExist) {
// file path does not exist // file path does not exist
return fmt.Errorf("rpc filter file doesn't exist") return rmf.ExposeAll()
} else { } else {
// some other errors happened // some other errors happened
return fmt.Errorf("rpc filter file stat error - %s", err.Error()) return fmt.Errorf("rpc filter file stat error - %s", err.Error())

@ -1,4 +1,4 @@
Version = "2.5.2" Version = "2.5.3"
[BLSKeys] [BLSKeys]
KMSConfigFile = "" KMSConfigFile = ""
@ -77,7 +77,7 @@ Version = "2.5.2"
EthRPCsEnabled = true EthRPCsEnabled = true
StakingRPCsEnabled = true StakingRPCsEnabled = true
LegacyRPCsEnabled = true LegacyRPCsEnabled = true
RpcFilterFile = "" RpcFilterFile = "./.hmy/rpc_filter.txt"
RateLimterEnabled = true RateLimterEnabled = true
RequestsPerSecond = 1000 RequestsPerSecond = 1000

@ -1,4 +1,4 @@
Version = "2.5.2" Version = "2.5.3"
[BLSKeys] [BLSKeys]
KMSConfigFile = "" KMSConfigFile = ""
@ -77,7 +77,7 @@ Version = "2.5.2"
EthRPCsEnabled = true EthRPCsEnabled = true
StakingRPCsEnabled = true StakingRPCsEnabled = true
LegacyRPCsEnabled = true LegacyRPCsEnabled = true
RpcFilterFile = "" RpcFilterFile = "./.hmy/rpc_filter.txt"
RateLimterEnabled = true RateLimterEnabled = true
RequestsPerSecond = 1000 RequestsPerSecond = 1000

@ -77,7 +77,7 @@ func StartServers(hmy *hmy.Harmony, apis []rpc.API, config nodeconfig.RPCServerC
authApis := append(apis, getAuthAPIs(hmy, config.DebugEnabled, config.RateLimiterEnabled, config.RequestsPerSecond)...) authApis := append(apis, getAuthAPIs(hmy, config.DebugEnabled, config.RateLimiterEnabled, config.RequestsPerSecond)...)
// load method filter from file (if exist) // load method filter from file (if exist)
var rmf rpc.RpcMethodFilter var rmf rpc.RpcMethodFilter
rpcFilterFilePath := strings.Trim(rpcOpt.RpcFilterFile, " ") rpcFilterFilePath := strings.TrimSpace(rpcOpt.RpcFilterFile)
if len(rpcFilterFilePath) > 0 { if len(rpcFilterFilePath) > 0 {
if err := rmf.LoadRpcMethodFiltersFromFile(rpcFilterFilePath); err != nil { if err := rmf.LoadRpcMethodFiltersFromFile(rpcFilterFilePath); err != nil {
return err return err

Loading…
Cancel
Save