diff --git a/README.md b/README.md index 1ff370397..4722902e1 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ $ ./razor setConfig --provider --gasmultiplier docker ``` -docker exec -it razor-go razor setConfig --provider --alternateProvider --gasmultiplier --buffer --wait --gasprice --logLevel --gasLimit --rpcTimeout --httpTimeout --logFileMaxSize --logFileMaxBackups --logFileMaxAge +docker exec -it razor-go razor setConfig --provider --gasmultiplier --buffer --wait --gasprice --logLevel --gasLimit --rpcTimeout --httpTimeout --logFileMaxSize --logFileMaxBackups --logFileMaxAge ``` Example: diff --git a/client/alternateClient.go b/client/alternateClient.go deleted file mode 100644 index 7d2394ff0..000000000 --- a/client/alternateClient.go +++ /dev/null @@ -1,63 +0,0 @@ -package client - -import ( - "github.com/ethereum/go-ethereum/ethclient" - "razor/logger" - "reflect" - "time" -) - -var ( - log = logger.NewLogger() - alternateClientStruct AlternateClientStruct -) - -type AlternateClientStruct struct { - switchToAlternateClient bool - alternateProvider string -} - -func StartTimerForAlternateClient(switchClientAfterTime uint64) { - log.Infof("StartTimerForAlternateClient: Alternate client will be switched back to primary client in %v seconds!", switchClientAfterTime) - time.Sleep(time.Duration(switchClientAfterTime) * time.Second) - log.Info("Switching back to primary RPC..") - SetSwitchToAlternateClientStatus(false) -} - -//ReplaceClientWithAlternateClient will replace the primary client(client from primary RPC) with secondary client which would be created using alternate RPC -func ReplaceClientWithAlternateClient(arguments []reflect.Value) []reflect.Value { - clientDataType := reflect.TypeOf((*ethclient.Client)(nil)).Elem() - for i := range arguments { - argument := arguments[i] - argumentDataType := reflect.TypeOf(argument.Interface()).Elem() - if argumentDataType != nil { - if argumentDataType == clientDataType { - alternateProvider := GetAlternateProvider() - alternateClient, dialErr := ethclient.Dial(alternateProvider) - if dialErr != nil { - log.Errorf("Error in connecting using alternate RPC %v: %v", alternateProvider, dialErr) - return arguments - } - arguments[i] = reflect.ValueOf(alternateClient) - return arguments - } - } - } - return arguments -} - -func GetSwitchToAlternateClientStatus() bool { - return alternateClientStruct.switchToAlternateClient -} - -func SetSwitchToAlternateClientStatus(status bool) { - alternateClientStruct.switchToAlternateClient = status -} - -func GetAlternateProvider() string { - return alternateClientStruct.alternateProvider -} - -func SetAlternateProvider(alternateProvider string) { - alternateClientStruct.alternateProvider = alternateProvider -} diff --git a/cmd/config-utils.go b/cmd/config-utils.go index 634301ab1..95e89e343 100644 --- a/cmd/config-utils.go +++ b/cmd/config-utils.go @@ -4,7 +4,6 @@ package cmd import ( "errors" "razor/RPC" - "razor/client" "razor/core" "razor/core/types" "razor/utils" @@ -19,7 +18,6 @@ import ( func (*UtilsStruct) GetConfigData() (types.Configurations, error) { config := types.Configurations{ Provider: "", - AlternateProvider: "", GasMultiplier: 0, BufferPercent: 0, WaitTime: 0, @@ -36,10 +34,6 @@ func (*UtilsStruct) GetConfigData() (types.Configurations, error) { if err != nil { return config, err } - alternateProvider, err := cmdUtils.GetAlternateProvider() - if err != nil { - return config, err - } gasMultiplier, err := cmdUtils.GetMultiplier() if err != nil { return config, err @@ -89,8 +83,6 @@ func (*UtilsStruct) GetConfigData() (types.Configurations, error) { return config, err } config.Provider = provider - config.AlternateProvider = alternateProvider - client.SetAlternateProvider(alternateProvider) config.GasMultiplier = gasMultiplier config.BufferPercent = bufferPercent config.WaitTime = waitTime @@ -171,19 +163,6 @@ func (*UtilsStruct) GetProvider() (string, error) { return providerString, nil } -//This function returns the alternate provider -func (*UtilsStruct) GetAlternateProvider() (string, error) { - alternateProvider, err := getConfigValue("alternateProvider", "string", "", "alternateProvider") - if err != nil { - return "", err - } - alternateProviderString := alternateProvider.(string) - if !strings.HasPrefix(alternateProviderString, "https") { - log.Warn("You are not using a secure RPC URL. Switch to an https URL instead to be safe.") - } - return alternateProviderString, nil -} - //This function returns the multiplier func (*UtilsStruct) GetMultiplier() (float32, error) { const ( diff --git a/cmd/config-utils_test.go b/cmd/config-utils_test.go index 81be93197..92f8a70b5 100644 --- a/cmd/config-utils_test.go +++ b/cmd/config-utils_test.go @@ -37,7 +37,6 @@ func removeTestConfig(path string) { func TestGetConfigData(t *testing.T) { nilConfig := types.Configurations{ Provider: "", - AlternateProvider: "", GasMultiplier: 0, BufferPercent: 0, WaitTime: 0, @@ -52,7 +51,6 @@ func TestGetConfigData(t *testing.T) { configData := types.Configurations{ Provider: "", - AlternateProvider: "", GasMultiplier: 1, BufferPercent: 20, WaitTime: 1, @@ -69,8 +67,6 @@ func TestGetConfigData(t *testing.T) { type args struct { provider string providerErr error - alternateProvider string - alternateProviderErr error gasMultiplier float32 gasMultiplierErr error bufferPercent int32 @@ -106,7 +102,6 @@ func TestGetConfigData(t *testing.T) { name: "Test 1: When GetConfigData function executes successfully", args: args{ provider: "", - alternateProvider: "", gasMultiplier: 1, bufferPercent: 20, waitTime: 1, @@ -194,21 +189,12 @@ func TestGetConfigData(t *testing.T) { want: nilConfig, wantErr: errors.New("httpTimeout error"), }, - { - name: "Test 11: When there is an error in getting alternate provider", - args: args{ - alternateProviderErr: errors.New("alternate provider error"), - }, - want: nilConfig, - wantErr: errors.New("alternate provider error"), - }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { SetUpMockInterfaces() cmdUtilsMock.On("GetProvider").Return(tt.args.provider, tt.args.providerErr) - cmdUtilsMock.On("GetAlternateProvider").Return(tt.args.alternateProvider, tt.args.alternateProviderErr) cmdUtilsMock.On("GetMultiplier").Return(tt.args.gasMultiplier, tt.args.gasMultiplierErr) cmdUtilsMock.On("GetWaitTime").Return(tt.args.waitTime, tt.args.waitTimeErr) cmdUtilsMock.On("GetGasPrice").Return(tt.args.gasPrice, tt.args.gasPriceErr) @@ -848,94 +834,6 @@ func TestGetProvider(t *testing.T) { } } -func TestGetAlternateProvider(t *testing.T) { - type args struct { - isFlagSet bool - alternateProvider string - alternateProviderErr error - alternateProviderInConfig string - } - tests := []struct { - name string - useDummyConfigFile bool - args args - want string - wantErr error - }{ - { - name: "Test 1: When alternateProvider is fetched from root flag", - args: args{ - isFlagSet: true, - alternateProvider: "https://polygon-mumbai.g.alchemy.com/v2/-Re1lE3oDIVTWchuKMfRIECn0I", - }, - want: "https://polygon-mumbai.g.alchemy.com/v2/-Re1lE3oDIVTWchuKMfRIECn0I", - wantErr: nil, - }, - { - name: "Test 2: When alternateProvider from root flag has prefix https", - args: args{ - isFlagSet: true, - alternateProvider: "127.0.0.1:8545", - }, - want: "127.0.0.1:8545", - wantErr: nil, - }, - { - name: "Test 3: When there is an error in fetching alternateProvider from root flag", - args: args{ - isFlagSet: true, - alternateProviderErr: errors.New("alternateProvider error"), - }, - want: "", - wantErr: errors.New("alternateProvider error"), - }, - { - name: "Test 4: When alternateProvider value is fetched from config", - useDummyConfigFile: true, - args: args{ - alternateProviderInConfig: "https://some-config-provider.com", - }, - want: "https://some-config-provider.com", - wantErr: nil, - }, - { - name: "Test 5: When alternateProvider is not passed in root nor set in config", - want: "", - wantErr: nil, - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - viper.Reset() // Reset viper state - - if tt.useDummyConfigFile { - createTestConfig(t, "alternateProvider", tt.args.alternateProviderInConfig) - defer removeTestConfig(tempConfigPath) - } - - SetUpMockInterfaces() - - flagSetMock.On("FetchRootFlagInput", mock.Anything, mock.Anything).Return(tt.args.alternateProvider, tt.args.alternateProviderErr) - flagSetMock.On("Changed", mock.Anything, mock.Anything).Return(tt.args.isFlagSet) - - utils := &UtilsStruct{} - got, err := utils.GetAlternateProvider() - if got != tt.want { - t.Errorf("getAlternateProvider() got = %v, want %v", got, tt.want) - } - if err == nil || tt.wantErr == nil { - if err != tt.wantErr { - t.Errorf("Error for getAlternateProvider function, got = %v, want = %v", err, tt.wantErr) - } - } else { - if err.Error() != tt.wantErr.Error() { - t.Errorf("Error for getAlternateProvider function, got = %v, want = %v", err, tt.wantErr) - } - } - }) - } -} - func TestGetRPCTimeout(t *testing.T) { type args struct { isFlagSet bool diff --git a/cmd/interface.go b/cmd/interface.go index 7bbb44ee6..239ccf2a0 100644 --- a/cmd/interface.go +++ b/cmd/interface.go @@ -140,7 +140,6 @@ type FlagSetInterface interface { type UtilsCmdInterface interface { SetConfig(flagSet *pflag.FlagSet) error GetProvider() (string, error) - GetAlternateProvider() (string, error) GetMultiplier() (float32, error) GetWaitTime() (int32, error) GetGasPrice() (int32, error) diff --git a/cmd/mocks/utils_cmd_interface.go b/cmd/mocks/utils_cmd_interface.go index 520036bae..7e7b642f3 100644 --- a/cmd/mocks/utils_cmd_interface.go +++ b/cmd/mocks/utils_cmd_interface.go @@ -552,30 +552,6 @@ func (_m *UtilsCmdInterface) GenerateTreeRevealData(merkleTree [][][]byte, commi return r0 } -// GetAlternateProvider provides a mock function with given fields: -func (_m *UtilsCmdInterface) GetAlternateProvider() (string, error) { - ret := _m.Called() - - var r0 string - var r1 error - if rf, ok := ret.Get(0).(func() (string, error)); ok { - return rf() - } - if rf, ok := ret.Get(0).(func() string); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(string) - } - - if rf, ok := ret.Get(1).(func() error); ok { - r1 = rf() - } else { - r1 = ret.Error(1) - } - - return r0, r1 -} - // GetBiggestStakeAndId provides a mock function with given fields: rpcParameters, epoch func (_m *UtilsCmdInterface) GetBiggestStakeAndId(rpcParameters RPC.RPCParameters, epoch uint32) (*big.Int, uint32, error) { ret := _m.Called(rpcParameters, epoch) diff --git a/cmd/root.go b/cmd/root.go index 56eca6b7b..9c3ecd9d2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -14,7 +14,6 @@ import ( var ( Provider string - AlternateProvider string GasMultiplier float32 BufferPercent int32 WaitTime int32 @@ -61,7 +60,6 @@ func init() { cobra.OnInitialize(initConfig) rootCmd.PersistentFlags().StringVarP(&Provider, "provider", "p", "", "provider name") - rootCmd.PersistentFlags().StringVarP(&AlternateProvider, "alternateProvider", "", "", "alternate provider name") rootCmd.PersistentFlags().Float32VarP(&GasMultiplier, "gasmultiplier", "g", -1, "gas multiplier value") rootCmd.PersistentFlags().Int32VarP(&BufferPercent, "buffer", "b", 0, "buffer percent") rootCmd.PersistentFlags().Int32VarP(&WaitTime, "wait", "w", -1, "wait time") diff --git a/cmd/setConfig.go b/cmd/setConfig.go index 7f0ad8746..4008bbcd6 100644 --- a/cmd/setConfig.go +++ b/cmd/setConfig.go @@ -34,7 +34,6 @@ func (*UtilsStruct) SetConfig(flagSet *pflag.FlagSet) error { flagDetails := []types.FlagDetail{ {Name: "provider", Type: "string"}, - {Name: "alternateProvider", Type: "string"}, {Name: "gasmultiplier", Type: "float32"}, {Name: "buffer", Type: "int32"}, {Name: "wait", Type: "int32"}, @@ -62,7 +61,6 @@ func (*UtilsStruct) SetConfig(flagSet *pflag.FlagSet) error { configDetails := []types.ConfigDetail{ {FlagName: "provider", Key: "provider", DefaultValue: ""}, - {FlagName: "alternateProvider", Key: "alternateProvider", DefaultValue: ""}, {FlagName: "gasmultiplier", Key: "gasmultiplier", DefaultValue: core.DefaultGasMultiplier}, {FlagName: "buffer", Key: "buffer", DefaultValue: core.DefaultBufferPercent}, {FlagName: "wait", Key: "wait", DefaultValue: core.DefaultWaitTime}, @@ -152,7 +150,6 @@ func init() { var ( Provider string - AlternateProvider string GasMultiplier float32 BufferPercent int32 WaitTime int32 @@ -170,7 +167,6 @@ func init() { LogFileMaxAge int ) setConfig.Flags().StringVarP(&Provider, "provider", "p", "", "provider name") - setConfig.Flags().StringVarP(&AlternateProvider, "alternateProvider", "", "", "alternate provider name") setConfig.Flags().Float32VarP(&GasMultiplier, "gasmultiplier", "g", -1, "gas multiplier value") setConfig.Flags().Int32VarP(&BufferPercent, "buffer", "b", 0, "buffer percent") setConfig.Flags().Int32VarP(&WaitTime, "wait", "w", 0, "wait time (in secs)") diff --git a/config.sh b/config.sh index 89ca8532e..96af7366b 100644 --- a/config.sh +++ b/config.sh @@ -11,8 +11,6 @@ then PROVIDER="http://127.0.0.1:8545" fi -read -rp "Alternate Provider: " ALTERNATE_PROVIDER - read -rp "Gas Multiplier: (1.0) " GAS_MULTIPLIER if [ -z "$GAS_MULTIPLIER" ]; then @@ -55,9 +53,4 @@ if [ -z "$MAX_AGE" ]; then MAX_AGE=60 fi -ALT_PROVIDER_OPTION="" -if [ -n "$ALTERNATE_PROVIDER" ]; then - ALT_PROVIDER_OPTION="--alternateProvider $ALTERNATE_PROVIDER" -fi - -$RAZOR setConfig -p $PROVIDER $ALT_PROVIDER_OPTION -b $BUFFER -g $GAS_MULTIPLIER -w $WAIT_TIME --gasprice $GAS_PRICE --gasLimit $GAS_LIMIT --rpcTimeout 5 --httpTimeout 5 --logFileMaxSize $MAX_SIZE --logFileMaxBackups $MAX_BACKUPS --logFileMaxAge $MAX_AGE \ No newline at end of file +$RAZOR setConfig -p $PROVIDER -b $BUFFER -g $GAS_MULTIPLIER -w $WAIT_TIME --gasprice $GAS_PRICE --gasLimit $GAS_LIMIT --rpcTimeout 5 --httpTimeout 5 --logFileMaxSize $MAX_SIZE --logFileMaxBackups $MAX_BACKUPS --logFileMaxAge $MAX_AGE \ No newline at end of file diff --git a/core/types/configurations.go b/core/types/configurations.go index da42176f9..2fded1d0b 100644 --- a/core/types/configurations.go +++ b/core/types/configurations.go @@ -2,7 +2,6 @@ package types type Configurations struct { Provider string - AlternateProvider string GasMultiplier float32 BufferPercent int32 WaitTime int32