Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: incorrect state error for shorter epoch length #1192

Merged
14 changes: 7 additions & 7 deletions cmd/config-utils.go
Original file line number Diff line number Diff line change
@@ -209,8 +209,8 @@ func (*UtilsStruct) GetMultiplier() (float32, error) {
//This function returns the buffer percent
func (*UtilsStruct) GetBufferPercent() (int32, error) {
const (
MinBufferPercent = 10
MaxBufferPercent = 30
MinBufferPercent = 0
MaxBufferPercent = 5
)

bufferPercent, err := getConfigValue("buffer", "int32", core.DefaultBufferPercent, "buffer")
@@ -228,7 +228,7 @@ func (*UtilsStruct) GetBufferPercent() (int32, error) {

// If bufferPercent is 0, use the default value.
if bufferPercentInt32 == 0 {
log.Debugf("BufferPercent is unset, using default value %d", core.DefaultBufferPercent)
log.Debugf("BufferPercent is unset or set to 0, using its default %d value", core.DefaultBufferPercent)
return core.DefaultBufferPercent, nil
}

@@ -238,8 +238,8 @@ func (*UtilsStruct) GetBufferPercent() (int32, error) {
//This function returns the wait time
func (*UtilsStruct) GetWaitTime() (int32, error) {
const (
MinWaitTime = 1 // Minimum wait time in seconds
MaxWaitTime = 30 // Maximum wait time in seconds
MinWaitTime = 1 // Minimum wait time in seconds
MaxWaitTime = 5 // Maximum wait time in seconds
ashish10677 marked this conversation as resolved.
Show resolved Hide resolved
)

waitTime, err := getConfigValue("wait", "int32", core.DefaultWaitTime, "wait")
@@ -335,7 +335,7 @@ func (*UtilsStruct) GetGasLimitOverride() (uint64, error) {
func (*UtilsStruct) GetRPCTimeout() (int64, error) {
const (
MinRPCTimeout = 10 // Minimum RPC timeout in seconds
MaxRPCTimeout = 60 // Maximum RPC timeout in seconds
MaxRPCTimeout = 20 // Maximum RPC timeout in seconds
)

rpcTimeout, err := getConfigValue("rpcTimeout", "int64", core.DefaultRPCTimeout, "rpcTimeout")
@@ -357,7 +357,7 @@ func (*UtilsStruct) GetRPCTimeout() (int64, error) {
func (*UtilsStruct) GetHTTPTimeout() (int64, error) {
const (
MinHTTPTimeout = 10 // Minimum HTTP timeout in seconds
MaxHTTPTimeout = 60 // Maximum HTTP timeout in seconds
MaxHTTPTimeout = 20 // Maximum HTTP timeout in seconds
)

httpTimeout, err := getConfigValue("httpTimeout", "int64", core.DefaultHTTPTimeout, "httpTimeout")
16 changes: 8 additions & 8 deletions cmd/config-utils_test.go
Original file line number Diff line number Diff line change
@@ -260,9 +260,9 @@ func TestGetBufferPercent(t *testing.T) {
name: "Test 1: When buffer percent is fetched from root flag",
args: args{
isFlagSet: true,
bufferPercent: 15,
bufferPercent: 5,
},
want: 15,
want: 5,
wantErr: nil,
},
{
@@ -278,9 +278,9 @@ func TestGetBufferPercent(t *testing.T) {
name: "Test 3: When buffer value is fetched from config",
useDummyConfigFile: true,
args: args{
bufferInTestConfig: 30,
bufferInTestConfig: 1,
},
want: 30,
want: 1,
wantErr: nil,
},
{
@@ -1130,9 +1130,9 @@ func TestGetWaitTime(t *testing.T) {
name: "Test 1: When wait time is fetched from root flag",
args: args{
isFlagSet: true,
waitTime: 10,
waitTime: 2,
},
want: 10,
want: 2,
wantErr: nil,
},
{
@@ -1148,9 +1148,9 @@ func TestGetWaitTime(t *testing.T) {
name: "Test 3: When wait time value is fetched from config",
useDummyConfigFile: true,
args: args{
waitInTestConfig: 20,
waitInTestConfig: 3,
},
want: 20,
want: 3,
wantErr: nil,
},
{
24 changes: 13 additions & 11 deletions cmd/vote.go
Original file line number Diff line number Diff line change
@@ -127,19 +127,21 @@ func (*UtilsStruct) HandleExit() {
//This function handles all the states of voting
func (*UtilsStruct) Vote(ctx context.Context, config types.Configurations, client *ethclient.Client, rogueData types.Rogue, account types.Account, backupNodeActionsToIgnore []string) error {
assetCacheTicker := time.NewTicker(time.Second * time.Duration(core.AssetCacheExpiry))
errChan := make(chan error, 1)

header, err := clientUtils.GetLatestBlockWithRetry(client)
utils.CheckError("Error in getting block: ", err)
for {
select {
case <-assetCacheTicker.C:
log.Info("ASSET CACHE EXPIRED!")
log.Info("INITIALIZING JOBS AND COLLECTIONS CACHE AGAIN...")
if err := utils.InitJobsCache(client); err != nil {
log.Error("Error in initializing jobs cache: ", err)
continue
}
if err := utils.InitCollectionsCache(client); err != nil {
log.Error("Error in initializing collections cache: ", err)
log.Info("ASSET CACHE EXPIRED! INITIALIZING JOBS AND COLLECTIONS CACHE AGAIN...")
go func() {
err := utils.ResetAssetCache(client, config.BufferPercent)
errChan <- err
}()
case err := <-errChan: // Handling the error from ResetAssetCache
if err != nil {
log.Errorf("Error resetting asset cache: %v", err)
continue
}
case <-ctx.Done():
@@ -319,8 +321,8 @@ func (*UtilsStruct) HandleBlock(client *ethclient.Client, account types.Account,
}
}
case -1:
if config.WaitTime > 5 {
timeUtils.Sleep(5 * time.Second)
if config.WaitTime >= core.BufferStateSleepTime {
timeUtils.Sleep(time.Second * time.Duration(core.BufferStateSleepTime))
return
}
}
@@ -529,7 +531,7 @@ func (*UtilsStruct) InitiateReveal(client *ethclient.Client, config types.Config
if revealTxn != core.NilHash {
waitForBlockCompletionErr := razorUtils.WaitForBlockCompletion(client, revealTxn.Hex())
if waitForBlockCompletionErr != nil {
log.Error("Error in WaitForBlockCompletionErr for reveal: ", err)
log.Error("Error in WaitForBlockCompletionErr for reveal: ", waitForBlockCompletionErr)
return err
}
}
8 changes: 4 additions & 4 deletions config.sh
Original file line number Diff line number Diff line change
@@ -19,20 +19,20 @@ then
GAS_MULTIPLIER=1.0
fi

read -rp "Buffer Percent: (20) " BUFFER
read -rp "Buffer Percent: (0) " BUFFER
if [ -z "$BUFFER" ];
then
BUFFER=20
BUFFER=0
fi

read -rp "Wait Time: (1) " WAIT_TIME
if [ -z "$WAIT_TIME" ]; then
WAIT_TIME=1
fi

read -rp "Gas Price: (1) " GAS_PRICE
read -rp "Gas Price: (0) " GAS_PRICE
if [ -z "$GAS_PRICE" ]; then
GAS_PRICE=1
GAS_PRICE=0
fi

read -rp "Gas Limit Increment : (2) " GAS_LIMIT
5 changes: 4 additions & 1 deletion core/constants.go
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ var BlockCompletionTimeout = 30
//Following are the default config values for all the config parameters

var DefaultGasMultiplier float32 = 1.0
var DefaultBufferPercent int32 = 20
var DefaultBufferPercent int32 = 0
var DefaultGasPrice int32 = 0
var DefaultWaitTime int32 = 1
var DefaultGasLimit float32 = 2
@@ -30,6 +30,9 @@ var DefaultRPCTimeout int64 = 10
var DefaultHTTPTimeout int64 = 10
var DefaultLogLevel = ""

//BufferStateSleepTime is the sleeping time whenever buffer state hits
var BufferStateSleepTime int32 = 2

//Following are the default logFile parameters in config

var DefaultLogFileMaxSize = 200
30 changes: 30 additions & 0 deletions utils/asset.go
Original file line number Diff line number Diff line change
@@ -531,6 +531,36 @@ func (*UtilsStruct) HandleOfficialJobsFromJSONFile(client *ethclient.Client, col
return overrideJobs, overriddenJobIds
}

func ResetAssetCache(client *ethclient.Client, bufferPercent int32) error {
state, err := UtilsInterface.GetBufferedState(client, bufferPercent)
if err != nil {
log.Error("Error in getting buffered state: ", err)
return err
}
// Avoiding resetting jobs/collections cache in commit state
if state == 0 {
log.Info("ResetAssetCache: Cannot reset Jobs/Collections cache in commit state!")
stateRemainingTime, err := UtilsInterface.GetRemainingTimeOfCurrentState(client, bufferPercent)
if err != nil {
log.Error("Error in getting remaining time of current state: ", err)
return err
}
log.Infof("ResetAssetCache: Waiting for commit state to complete, sleeping for %v seconds...", stateRemainingTime)
time.Sleep(time.Second * time.Duration(stateRemainingTime))
log.Infof("ResetAssetCache: INITIALIZING JOBS AND COLLECTIONS CACHE NOW!")
}

if err := InitJobsCache(client); err != nil {
log.Error("Error in initializing jobs cache: ", err)
return err
}
if err := InitCollectionsCache(client); err != nil {
log.Error("Error in initializing collections cache: ", err)
return err
}
return nil
}

func InitJobsCache(client *ethclient.Client) error {
cache.JobsCache.Mu.Lock()
defer cache.JobsCache.Mu.Unlock()
Loading