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: changed keyword to const for defining constants #1206

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 57 additions & 45 deletions core/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,77 +7,89 @@ import (
"math/big"
)

var EpochLength uint64 = 300
var NumberOfStates uint64 = 5
var StateLength = EpochLength / NumberOfStates
const (
EpochLength uint64 = 300
NumberOfStates uint64 = 5
StateLength = EpochLength / NumberOfStates
)

// ChainId corresponds to the SKALE chain
var ChainId = big.NewInt(0x561bf78b)

var MaxRetries uint = 8
const MaxRetries uint = 8

var NilHash = common.Hash{0x00}
var BlockCompletionTimeout = 30

//Following are the default config values for all the config parameters
const BlockCompletionTimeout = 30

var DefaultGasMultiplier float32 = 1.0
var DefaultBufferPercent int32 = 0
var DefaultGasPrice int32 = 0
var DefaultWaitTime int32 = 1
var DefaultGasLimit float32 = 2
var DefaultGasLimitOverride uint64 = 30000000
var DefaultRPCTimeout int64 = 10
var DefaultHTTPTimeout int64 = 10
var DefaultLogLevel = ""
//Following are the default config values for all the config parameters
const (
DefaultGasMultiplier float32 = 1.0
DefaultBufferPercent int32 = 0
DefaultGasPrice int32 = 0
DefaultWaitTime int32 = 1
DefaultGasLimit float32 = 2
DefaultGasLimitOverride uint64 = 30000000
DefaultRPCTimeout int64 = 10
DefaultHTTPTimeout int64 = 10
DefaultLogLevel = ""
)

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

//Following are the default logFile parameters in config

var DefaultLogFileMaxSize = 200
var DefaultLogFileMaxBackups = 52
var DefaultLogFileMaxAge = 365
const (
DefaultLogFileMaxSize = 200
DefaultLogFileMaxBackups = 52
DefaultLogFileMaxAge = 365
)

//DisputeGasMultiplier is a constant gasLimitMultiplier to increase gas Limit for function `disputeCollectionIdShouldBeAbsent` and `disputeCollectionIdShouldBePresent`
var DisputeGasMultiplier float32 = 5.5
const DisputeGasMultiplier float32 = 5.5

// Following are the constants which will be used to derive different file paths

var DataFileDirectory = "data_files"
var CommitDataFile = "_commitData.json"
var ProposeDataFile = "_proposeData.json"
var DisputeDataFile = "_disputeData.json"
var AssetsDataFile = "assets.json"
var ConfigFile = "razor.yaml"
var LogFileDirectory = "logs"
var DefaultPathName = ".razor"
const (
DataFileDirectory = "data_files"
CommitDataFile = "_commitData.json"
ProposeDataFile = "_proposeData.json"
DisputeDataFile = "_disputeData.json"
AssetsDataFile = "assets.json"
ConfigFile = "razor.yaml"
LogFileDirectory = "logs"
DefaultPathName = ".razor"
)

//BlockNumberInterval is the interval in seconds after which blockNumber needs to be calculated again
var BlockNumberInterval = 5
const BlockNumberInterval = 5

//APIKeyRegex will be used as a regular expression to be matched in job Urls
var APIKeyRegex = `\$\{(.+?)\}`
const APIKeyRegex = `\$\{(.+?)\}`

// Following are the constants which defines retry attempts and retry delay if there is an error in processing request

var ProcessRequestRetryAttempts uint = 2
var ProcessRequestRetryDelay = 2
const (
ProcessRequestRetryAttempts uint = 2
ProcessRequestRetryDelay int64 = 2
)

//SwitchClientDuration is the time after which alternate client from secondary RPC will be switched back to client from primary RPC
var SwitchClientDuration = 5 * EpochLength
const SwitchClientDuration = 5 * EpochLength

// HexReturnType is the ReturnType for a job if that job returns a hex value
var HexReturnType = "hex"
const (
// HexReturnType is the ReturnType for a job if that job returns a hex value
HexReturnType = "hex"

// HexArrayReturnType is the ReturnType for a job if that job returns a hex array value
var HexArrayReturnType = "^hexArray\\[\\d+\\]$"
// HexArrayReturnType is the ReturnType for a job if that job returns a hex array value
HexArrayReturnType = "^hexArray\\[\\d+\\]$"

// HexArrayExtractIndexRegex will be used as a regular expression to extract index from hexArray return type
var HexArrayExtractIndexRegex = `^hexArray\[(\d+)\]$`
// HexArrayExtractIndexRegex will be used as a regular expression to extract index from hexArray return type
HexArrayExtractIndexRegex = `^hexArray\[(\d+)\]$`
)

// Following are the constants which helps in calculating iteration for a staker

var BatchSize = 1000
var NumRoutines = 10
var MaxIterations = 10000000
const (
BatchSize = 1000
NumRoutines = 10
MaxIterations = 10000000
)
6 changes: 3 additions & 3 deletions utils/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func getAPIByteArray(index int) []byte {

func TestGetDataFromAPI(t *testing.T) {
//postRequestInput := `{"type": "POST","url": "https://rpc.ankr.com/polygon_mumbai","body": {"jsonrpc": "2.0","method": "eth_chainId","params": [],"id": 0},"header": {"content-type": "application/json"}}`
sampleChainId, _ := hex.DecodeString("7b226a736f6e727063223a22322e30222c226964223a302c22726573756c74223a2230783133383831227d")
sampleChainId, _ := hex.DecodeString("7b226a736f6e727063223a22322e30222c22726573756c74223a223078616133376463222c226964223a307d0a")

type args struct {
urlStruct types.DataSourceURL
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestGetDataFromAPI(t *testing.T) {
args: args{
urlStruct: types.DataSourceURL{
Type: "POST",
URL: "https://rpc.ankr.com/polygon_mumbai",
URL: "https://sepolia.optimism.io",
Body: map[string]interface{}{"jsonrpc": "2.0", "method": "eth_chainId", "params": nil, "id": 0},
Header: map[string]string{"content-type": "application/json"},
},
Expand All @@ -120,7 +120,7 @@ func TestGetDataFromAPI(t *testing.T) {
args: args{
urlStruct: types.DataSourceURL{
Type: "POST",
URL: "https://rpc.ankr.com/polygon_mumbai",
URL: "https://sepolia.optimism.io",
Body: map[string]interface{}{"jsonrpc": "2.0", "method": "eth_chainId", "params": nil, "id": 0},
Header: map[string]string{"auth": "${API_KEY}", "content-type": "application/json"},
},
Expand Down
Loading