diff --git a/cmd/harmony/config_migrations.go b/cmd/harmony/config_migrations.go index df8b50893..30ed261df 100644 --- a/cmd/harmony/config_migrations.go +++ b/cmd/harmony/config_migrations.go @@ -92,22 +92,6 @@ func init() { 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 { confTree.Set("RPCOpt.RateLimterEnabled", defaultConfig.RPCOpt.RateLimterEnabled) } @@ -254,4 +238,26 @@ func init() { confTree.Set("Version", "2.5.2") 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 + } + } diff --git a/cmd/harmony/config_migrations_test.go b/cmd/harmony/config_migrations_test.go index 031978448..075cfa8ec 100644 --- a/cmd/harmony/config_migrations_test.go +++ b/cmd/harmony/config_migrations_test.go @@ -67,7 +67,7 @@ Version = "1.0.2" EthRPCsEnabled = true StakingRPCsEnabled = true LegacyRPCsEnabled = true - RpcFilterFile = "" + RpcFilterFile = "./.hmy/rpc_filter.txt" [TxPool] BlacklistFile = "./.hmy/blacklist.txt" @@ -137,7 +137,7 @@ Version = "1.0.3" EthRPCsEnabled = true StakingRPCsEnabled = true LegacyRPCsEnabled = true - RpcFilterFile = "" + RpcFilterFile = "./.hmy/rpc_filter.txt" [TxPool] BlacklistFile = "./.hmy/blacklist.txt" @@ -207,7 +207,7 @@ Version = "1.0.4" EthRPCsEnabled = true StakingRPCsEnabled = true LegacyRPCsEnabled = true - RpcFilterFile = "" + RpcFilterFile = "./.hmy/rpc_filter.txt" [Sync] Concurrency = 6 @@ -289,7 +289,7 @@ Version = "1.0.4" EthRPCsEnabled = true StakingRPCsEnabled = true LegacyRPCsEnabled = true - RpcFilterFile = "" + RpcFilterFile = "./.hmy/rpc_filter.txt" [Sync] Concurrency = 6 diff --git a/cmd/harmony/default.go b/cmd/harmony/default.go index d6527f11f..c94fd4bdb 100644 --- a/cmd/harmony/default.go +++ b/cmd/harmony/default.go @@ -5,7 +5,7 @@ import ( 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 ( defNetworkType = nodeconfig.Mainnet @@ -51,7 +51,7 @@ var defaultConfig = harmonyconfig.HarmonyConfig{ EthRPCsEnabled: true, StakingRPCsEnabled: true, LegacyRPCsEnabled: true, - RpcFilterFile: "", + RpcFilterFile: "./.hmy/rpc_filter.txt", RateLimterEnabled: true, RequestsPerSecond: nodeconfig.DefaultRPCRateLimit, }, diff --git a/cmd/harmony/flags_test.go b/cmd/harmony/flags_test.go index a3c9a3dcc..ee4043895 100644 --- a/cmd/harmony/flags_test.go +++ b/cmd/harmony/flags_test.go @@ -78,7 +78,7 @@ func TestHarmonyFlags(t *testing.T) { EthRPCsEnabled: true, StakingRPCsEnabled: true, LegacyRPCsEnabled: true, - RpcFilterFile: "", + RpcFilterFile: "./.hmy/rpc_filter.txt", RateLimterEnabled: true, RequestsPerSecond: 1000, }, @@ -629,7 +629,7 @@ func TestRPCOptFlags(t *testing.T) { EthRPCsEnabled: true, StakingRPCsEnabled: true, LegacyRPCsEnabled: true, - RpcFilterFile: "", + RpcFilterFile: "./.hmy/rpc_filter.txt", RateLimterEnabled: true, RequestsPerSecond: 1000, }, @@ -642,7 +642,7 @@ func TestRPCOptFlags(t *testing.T) { EthRPCsEnabled: false, StakingRPCsEnabled: true, LegacyRPCsEnabled: true, - RpcFilterFile: "", + RpcFilterFile: "./.hmy/rpc_filter.txt", RateLimterEnabled: true, RequestsPerSecond: 1000, }, @@ -655,7 +655,7 @@ func TestRPCOptFlags(t *testing.T) { EthRPCsEnabled: true, StakingRPCsEnabled: false, LegacyRPCsEnabled: true, - RpcFilterFile: "", + RpcFilterFile: "./.hmy/rpc_filter.txt", RateLimterEnabled: true, RequestsPerSecond: 1000, }, @@ -668,7 +668,7 @@ func TestRPCOptFlags(t *testing.T) { EthRPCsEnabled: true, StakingRPCsEnabled: true, LegacyRPCsEnabled: false, - RpcFilterFile: "", + RpcFilterFile: "./.hmy/rpc_filter.txt", RateLimterEnabled: true, RequestsPerSecond: 1000, }, @@ -694,7 +694,7 @@ func TestRPCOptFlags(t *testing.T) { EthRPCsEnabled: true, StakingRPCsEnabled: true, LegacyRPCsEnabled: true, - RpcFilterFile: "", + RpcFilterFile: "./.hmy/rpc_filter.txt", RateLimterEnabled: true, RequestsPerSecond: 1000, }, @@ -707,7 +707,7 @@ func TestRPCOptFlags(t *testing.T) { EthRPCsEnabled: true, StakingRPCsEnabled: true, LegacyRPCsEnabled: true, - RpcFilterFile: "", + RpcFilterFile: "./.hmy/rpc_filter.txt", RateLimterEnabled: true, RequestsPerSecond: 2000, }, @@ -720,7 +720,7 @@ func TestRPCOptFlags(t *testing.T) { EthRPCsEnabled: true, StakingRPCsEnabled: true, LegacyRPCsEnabled: true, - RpcFilterFile: "", + RpcFilterFile: "./.hmy/rpc_filter.txt", RateLimterEnabled: false, RequestsPerSecond: 2000, }, diff --git a/eth/rpc/method_filter.go b/eth/rpc/method_filter.go index f47c39785..0cc8b3cdd 100644 --- a/eth/rpc/method_filter.go +++ b/eth/rpc/method_filter.go @@ -19,7 +19,7 @@ type RpcMethodFilter struct { // ExposeAll - init Allow and Deny array in a way to expose all APIs func (rmf *RpcMethodFilter) ExposeAll() error { rmf.Allow = rmf.Allow[:0] - rmf.Allow = rmf.Deny[:0] + rmf.Deny = rmf.Deny[:0] rmf.Allow = append(rmf.Allow, "*") return nil } @@ -39,7 +39,7 @@ func (rmf *RpcMethodFilter) LoadRpcMethodFiltersFromFile(file string) error { return rmf.LoadRpcMethodFilters(b) } else if errors.Is(err, os.ErrNotExist) { // file path does not exist - return fmt.Errorf("rpc filter file doesn't exist") + return rmf.ExposeAll() } else { // some other errors happened return fmt.Errorf("rpc filter file stat error - %s", err.Error()) diff --git a/rosetta/infra/harmony-mainnet.conf b/rosetta/infra/harmony-mainnet.conf index cca238ca0..f2b3903ae 100644 --- a/rosetta/infra/harmony-mainnet.conf +++ b/rosetta/infra/harmony-mainnet.conf @@ -1,4 +1,4 @@ -Version = "2.5.2" +Version = "2.5.3" [BLSKeys] KMSConfigFile = "" @@ -77,7 +77,7 @@ Version = "2.5.2" EthRPCsEnabled = true StakingRPCsEnabled = true LegacyRPCsEnabled = true - RpcFilterFile = "" + RpcFilterFile = "./.hmy/rpc_filter.txt" RateLimterEnabled = true RequestsPerSecond = 1000 diff --git a/rosetta/infra/harmony-pstn.conf b/rosetta/infra/harmony-pstn.conf index e61f36d9c..f6b3ef06d 100644 --- a/rosetta/infra/harmony-pstn.conf +++ b/rosetta/infra/harmony-pstn.conf @@ -1,4 +1,4 @@ -Version = "2.5.2" +Version = "2.5.3" [BLSKeys] KMSConfigFile = "" @@ -77,7 +77,7 @@ Version = "2.5.2" EthRPCsEnabled = true StakingRPCsEnabled = true LegacyRPCsEnabled = true - RpcFilterFile = "" + RpcFilterFile = "./.hmy/rpc_filter.txt" RateLimterEnabled = true RequestsPerSecond = 1000 diff --git a/rpc/rpc.go b/rpc/rpc.go index 7c1267a75..e06f87993 100644 --- a/rpc/rpc.go +++ b/rpc/rpc.go @@ -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)...) // load method filter from file (if exist) var rmf rpc.RpcMethodFilter - rpcFilterFilePath := strings.Trim(rpcOpt.RpcFilterFile, " ") + rpcFilterFilePath := strings.TrimSpace(rpcOpt.RpcFilterFile) if len(rpcFilterFilePath) > 0 { if err := rmf.LoadRpcMethodFiltersFromFile(rpcFilterFilePath); err != nil { return err