Skip to content

Commit

Permalink
Merge v1.0.5 to main (#1038)
Browse files Browse the repository at this point in the history
* v1.2.0 (#965)

* Hotfix-logImprovements (#952)

* Set up blocknumber and epoch in logs

* updated blocknumber and epoch logger info in every command

* Hotfix-getDataFromAPI (#951)

* Changed numm of retry attempts

* removed redundant retry attempts

* corrected tests

* changed http timeout and logged time elapsed to fetch data (#954)

* Updated version (#960)

* Updated version

* updated version to v1.2.0

* version update (#972)

* Merged `v1.3.0-alpha` into `v1.0.5` (#973)

* Merged `v1` into `v1.3.0-aplha` with hotfixes (#966)

* Hotfix-proposed data (#913)

* Updated propose data global variables correctly

* Fixed tests

* Returned correct waitForBlockCompletion error

* coverage increase

* GetLocalData returns type types.ProposeFileData

* fixed benchmark

* Fetched Last proposed from contracts (#917)

* fetched getLastProposedEpoch from contracts and tests for it

* typo fix

* V1 propose hotfix (#918)

* Change propose.go to get sorted proposed block ids.
* Fix sorted proposed block issue.

Signed-off-by: Ashish Kumar Mishra <[email protected]>

* allow stakers to addStake < minSafeRazor (#928)

* Call claimStakerReward only if there reward to claim (#926)

* Make contract call only if there is commission to claim

* Add tests for claimCommission file

* update check

* Hotfix-giveSorted (#921)

* ResetDispute only done after FinalizeDispute

* Fixed tests

* Update README (#931)

* Update README

* Update logs path

* Fix home dir path

* Add logs to vote.go and commit.go

Signed-off-by: Ashish Kumar Mishra <[email protected]>

* Add logs for dispute and propose.

Signed-off-by: Ashish Kumar Mishra <[email protected]>

* Fix tests.

Signed-off-by: Ashish Kumar Mishra <[email protected]>

* Suppress unneccessary error logs. (#935)

Signed-off-by: Ashish Kumar Mishra <[email protected]>

* changed http timeout to 30 sec (#943)

* saving commit data only after successfull commit (#947)

* Added password flag (#946)

* added password flag

* README updated

* Hotfix-giveSorted (new implementation) (#953)

* GiveSorted linear recursion

* Added backupNode flag

* Compilation success for tests

* Fixed tests

* removed recusrsion, called giveSorted linearly

* fixed tests

* Added leafId to giveSortedLeafIds[] on successful giveSorted

* Hotfix-sortedProposedBlocks (#957)

* Shuffled copied slice instead of original slice

* returned error from giveSorted when len(sortedValues)=0

* Fixed dispute tests

* Changed pending nonce at to nonce at. (#948)

* Changed pending nonce at to nonce at.
* Update mockery

Signed-off-by: Ashish Kumar Mishra <[email protected]>

* Hotfix -RPCTimeout (#955)

* Added a generic function with timeout for contract calls

* Moved generic function to utils and implemented to all contract getter calls

* Implemented timeout for contract setter functions

* rpc timeout custom error

* type asserting structs from contract mappings

* Shifted timeout to constants

* passed timeout in int in constants.go

* Added rpcTimeout as config

* Removed errorIndex paramter from CheckIfAnyError()

* Function renamed

* Fixed tests

* Unrequired change

* Added backup node info in readme (#963)

* Passed a initialized varible instead of nil value as a parameter

Signed-off-by: Ashish Kumar Mishra <[email protected]>
Co-authored-by: Shekhar Gaur <[email protected]>
Co-authored-by: Ashish Kumar Mishra <[email protected]>
Co-authored-by: Shyam Patel <[email protected]>
Co-authored-by: Raj Kharvar <[email protected]>
Co-authored-by: Skanda Bhat <[email protected]>

* Updated `v1.3.0` branch to staging parameters for v1.3.0-alpha version (#967)

* Updated contract addresses and chainId to staging

* Updated razor-go version to v1.3.0-alpha

* Fixed `CheckIfAnyError()` on RPCTimeout. (#974)

* Added errorIndexInReturnedValues as a parameter in  function

* Fixed comparios of error data type from returned values

* Added a check if config key is present in yaml file before fetching value (#975)

* Added default values for config parameters

* Checked if config key is present in yaml file before fetching

* Fixed tests

* returned default values uniformly

Signed-off-by: Ashish Kumar Mishra <[email protected]>
Co-authored-by: Shekhar Gaur <[email protected]>
Co-authored-by: Ashish Kumar Mishra <[email protected]>
Co-authored-by: Shyam Patel <[email protected]>
Co-authored-by: Raj Kharvar <[email protected]>
Co-authored-by: Skanda Bhat <[email protected]>

* updated version to v1.0.5-alpha (#978)

* Changes Requested in v1.0.5 Review (#1006)

* updated logs and readMe for v1.0.5

* Canges string formater for errors to %v

* Inserted Logs in the entire codebase (#1018)

* Inserted Logs

* Corrected logs

* Modified lumberJack constants

* V1.0.5-alpha-patch1 Ready (#1022)

* Merge `v1.0.4` release to main branch  (#977)

* v1.2.0 (#965)

* Hotfix-logImprovements (#952)

* Set up blocknumber and epoch in logs

* updated blocknumber and epoch logger info in every command

* Hotfix-getDataFromAPI (#951)

* Changed numm of retry attempts

* removed redundant retry attempts

* corrected tests

* changed http timeout and logged time elapsed to fetch data (#954)

* Updated version (#960)

* Updated version

* updated version to v1.2.0

* version update (#972)

* Updated user in dockerfile (#1012)

* updating user in dockerfile

* updating readme for non-root user

* Log corrections

* updated release

* Revert "Updated user in dockerfile (#1012)" (#1021)

This reverts commit 7f95edb.

Co-authored-by: Shrikant upadhyay <[email protected]>

* Calculated blockNumber in a separate go-routine for logging (#1025)

* Cached block number in logger

* Revert "Cached block number in logger"

This reverts commit 760e3ad.

* Added block/block.go for calculating latestBlock in a seperate goroutine

* Fetched block number from block package

* log corrections

* Increased max size of file to 182MB (#1027)

* V1.0.5 beta ready (#1032)

* Production support

* Updated release version

* Updated maxSize of log file to 200MB

* Added mutex lock in blockNumber calculation (#1035)

* Merge `v1.0.4` release to main branch  (#977)

* v1.2.0 (#965)

* Hotfix-logImprovements (#952)

* Set up blocknumber and epoch in logs

* updated blocknumber and epoch logger info in every command

* Hotfix-getDataFromAPI (#951)

* Changed numm of retry attempts

* removed redundant retry attempts

* corrected tests

* changed http timeout and logged time elapsed to fetch data (#954)

* Updated version (#960)

* Updated version

* updated version to v1.2.0

* version update (#972)

* Updated user in dockerfile (#1012)

* updating user in dockerfile

* updating readme for non-root user

* Revert "Updated user in dockerfile (#1012)" (#1021)

This reverts commit 7f95edb.

* Added mutex lock in blockNumber calculation

* Added new staging addresses and chainId

* updated version

Co-authored-by: Shrikant upadhyay <[email protected]>

* v1.0.5-beta-patch1 (#1037)

* Updated depolyment paramters to prod

* updated version to v1.0.5-beta-patch1

* Updated version to v1.0.5 (#1033)

* Made v1.0.5 branch in sync with main branch (#1039)

* Merge `v1.0.4` release to main branch  (#977)

* v1.2.0 (#965)

* Hotfix-logImprovements (#952)

* Set up blocknumber and epoch in logs

* updated blocknumber and epoch logger info in every command

* Hotfix-getDataFromAPI (#951)

* Changed numm of retry attempts

* removed redundant retry attempts

* corrected tests

* changed http timeout and logged time elapsed to fetch data (#954)

* Updated version (#960)

* Updated version

* updated version to v1.2.0

* version update (#972)

* Updated user in dockerfile (#1012)

* updating user in dockerfile

* updating readme for non-root user

* Revert "Updated user in dockerfile (#1012)" (#1021)

This reverts commit 7f95edb.

Co-authored-by: Shrikant upadhyay <[email protected]>

* Deleted password file (#1040)

Signed-off-by: Ashish Kumar Mishra <[email protected]>
Co-authored-by: Shekhar Gaur <[email protected]>
Co-authored-by: Ashish Kumar Mishra <[email protected]>
Co-authored-by: Shyam Patel <[email protected]>
Co-authored-by: Raj Kharvar <[email protected]>
Co-authored-by: Skanda Bhat <[email protected]>
Co-authored-by: Shrikant upadhyay <[email protected]>
  • Loading branch information
7 people authored Dec 14, 2022
1 parent 694e704 commit 237ad2c
Show file tree
Hide file tree
Showing 87 changed files with 2,668 additions and 1,127 deletions.
181 changes: 144 additions & 37 deletions README.md

Large diffs are not rendered by default.

40 changes: 40 additions & 0 deletions block/block.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package block

import (
"context"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/sirupsen/logrus"
"razor/core"
"sync"
"time"
)

var latestBlock *types.Header
var mu = sync.Mutex{}

func GetLatestBlock() *types.Header {
mu.Lock()
defer mu.Unlock()
return latestBlock
}

func SetLatestBlock(block *types.Header) {
mu.Lock()
latestBlock = block
mu.Unlock()
}

func CalculateLatestBlock(client *ethclient.Client) {
for {
if client != nil {
latestHeader, err := client.HeaderByNumber(context.Background(), nil)
if err != nil {
logrus.Error("CalculateBlockNumber: Error in fetching block: ", err)
continue
}
SetLatestBlock(latestHeader)
}
time.Sleep(time.Second * time.Duration(core.BlockNumberInterval))
}
}
24 changes: 21 additions & 3 deletions cmd/addStake.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,43 @@ func initialiseStake(cmd *cobra.Command, args []string) {
func (*UtilsStruct) ExecuteStake(flagSet *pflag.FlagSet) {
config, err := cmdUtils.GetConfigData()
utils.CheckError("Error in getting config: ", err)
log.Debugf("ExecuteStake: config: %+v", config)

client := razorUtils.ConnectToClient(config.Provider)

address, err := flagSetUtils.GetStringAddress(flagSet)
utils.CheckError("Error in getting address: ", err)
log.Debug("ExecuteStake: Address: ", address)

logger.SetLoggerParameters(client, address)
log.Debug("Checking to assign log file...")
razorUtils.AssignLogFile(flagSet)

password := razorUtils.AssignPassword()
log.Debug("Getting password...")
password := razorUtils.AssignPassword(flagSet)

balance, err := razorUtils.FetchBalance(client, address)
utils.CheckError("Error in fetching razor balance for account: "+address, err)
log.Debug("Getting amount in wei...")
valueInWei, err := cmdUtils.AssignAmountInWei(flagSet)
utils.CheckError("Error in getting amount: ", err)
log.Debug("ExecuteStake: Amount in wei: ", valueInWei)

log.Debug("Checking for sufficient balance...")
razorUtils.CheckAmountAndBalance(valueInWei, balance)

log.Debug("Checking whether sFuel balance is not 0...")
razorUtils.CheckEthBalanceIsZero(client, address)

minSafeRazor, err := utils.UtilsInterface.GetMinSafeRazor(client)
utils.CheckError("Error in getting minimum safe razor amount: ", err)
log.Debug("ExecuteStake: Minimum razor that you can stake for first time: ", minSafeRazor)

if valueInWei.Cmp(minSafeRazor) < 0 {
stakerId, err := razorUtils.GetStakerId(client, address)
utils.CheckError("Error in getting stakerId: ", err)
log.Debug("ExecuteStake: Staker Id: ", stakerId)

if valueInWei.Cmp(minSafeRazor) < 0 && stakerId == 0 {
log.Fatal("The amount of razors entered is below min safe value.")
}

Expand All @@ -70,6 +83,7 @@ func (*UtilsStruct) ExecuteStake(flagSet *pflag.FlagSet) {
Config: config,
}

log.Debug("ExecuteStake: Calling Approve() for amount: ", txnArgs.Amount)
approveTxnHash, err := cmdUtils.Approve(txnArgs)
utils.CheckError("Approve error: ", err)

Expand All @@ -78,6 +92,7 @@ func (*UtilsStruct) ExecuteStake(flagSet *pflag.FlagSet) {
utils.CheckError("Error in WaitForBlockCompletion for approve: ", err)
}

log.Debug("ExecuteStake: Calling StakeCoins() for amount: ", txnArgs.Amount)
stakeTxnHash, err := cmdUtils.StakeCoins(txnArgs)
utils.CheckError("Stake error: ", err)

Expand All @@ -91,13 +106,14 @@ func (*UtilsStruct) StakeCoins(txnArgs types.TransactionOptions) (common.Hash, e
if err != nil {
return common.Hash{0x00}, err
}
log.Debug("StakeCoins: Epoch: ", epoch)

log.Info("Sending stake transactions...")
txnArgs.ContractAddress = core.StakeManagerAddress
txnArgs.MethodName = "stake"
txnArgs.Parameters = []interface{}{epoch, txnArgs.Amount}
txnArgs.ABI = bindings.StakeManagerABI
txnOpts := razorUtils.GetTxnOpts(txnArgs)
log.Debugf("Executing Stake transaction with epoch = %d, amount = %d", epoch, txnArgs.Amount)
tx, err := stakeManagerUtils.Stake(txnArgs.Client, txnOpts, epoch, txnArgs.Amount)
if err != nil {
return common.Hash{0x00}, err
Expand All @@ -111,11 +127,13 @@ func init() {
var (
Amount string
Address string
Password string
WeiRazor bool
)

stakeCmd.Flags().StringVarP(&Amount, "value", "v", "0", "amount of Razors to stake")
stakeCmd.Flags().StringVarP(&Address, "address", "a", "", "address of the staker")
stakeCmd.Flags().StringVarP(&Password, "password", "", "", "password path of staker to protect the keystore")
stakeCmd.Flags().BoolVarP(&WeiRazor, "weiRazor", "", false, "value can be passed in wei")

amountErr := stakeCmd.MarkFlagRequired("value")
Expand Down
29 changes: 27 additions & 2 deletions cmd/addStake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ func TestExecuteStake(t *testing.T) {
approveErr error
minSafeRazor *big.Int
minSafeRazorErr error
stakerId uint32
stakerIdErr error
stakeTxn common.Hash
stakeErr error
}
Expand All @@ -164,6 +166,7 @@ func TestExecuteStake(t *testing.T) {
amount: big.NewInt(2000),
balance: big.NewInt(10000),
minSafeRazor: big.NewInt(0),
stakerId: 1,
approveTxn: common.BigToHash(big.NewInt(1)),
stakeTxn: common.BigToHash(big.NewInt(2)),
},
Expand All @@ -179,6 +182,7 @@ func TestExecuteStake(t *testing.T) {
amount: big.NewInt(2000),
balance: big.NewInt(10000),
minSafeRazor: big.NewInt(0),
stakerId: 1,
approveTxn: common.BigToHash(big.NewInt(1)),
stakeTxn: common.BigToHash(big.NewInt(2)),
},
Expand All @@ -194,6 +198,7 @@ func TestExecuteStake(t *testing.T) {
amount: big.NewInt(2000),
balance: big.NewInt(10000),
minSafeRazor: big.NewInt(0),
stakerId: 1,
approveTxn: common.BigToHash(big.NewInt(1)),
stakeTxn: common.BigToHash(big.NewInt(2)),
},
Expand Down Expand Up @@ -222,6 +227,7 @@ func TestExecuteStake(t *testing.T) {
amount: big.NewInt(2000),
balance: big.NewInt(10000),
minSafeRazor: big.NewInt(0),
stakerId: 1,
approveTxn: core.NilHash,
approveErr: errors.New("approve error"),
stakeTxn: common.BigToHash(big.NewInt(2)),
Expand All @@ -237,6 +243,7 @@ func TestExecuteStake(t *testing.T) {
amount: big.NewInt(2000),
balance: big.NewInt(10000),
minSafeRazor: big.NewInt(0),
stakerId: 1,
approveTxn: common.BigToHash(big.NewInt(1)),
stakeTxn: core.NilHash,
stakeErr: errors.New("stake error"),
Expand All @@ -251,6 +258,7 @@ func TestExecuteStake(t *testing.T) {
address: "0x000000000000000000000000000000000000dead",
amount: big.NewInt(2000),
minSafeRazor: big.NewInt(0),
stakerId: 1,
balance: nil,
balanceErr: errors.New("balance error"),
approveTxn: common.BigToHash(big.NewInt(1)),
Expand All @@ -259,17 +267,33 @@ func TestExecuteStake(t *testing.T) {
expectedFatal: true,
},
{
name: "Test 8: When stake value is less than minSafeRazor",
name: "Test 8: When stake value is less than minSafeRazor and staker has never staked",
args: args{
config: config,
password: "test",
address: "0x000000000000000000000000000000000000dead",
amount: big.NewInt(20),
balance: big.NewInt(10000),
minSafeRazor: big.NewInt(100),
stakerId: 0,
},
expectedFatal: true,
},
{
name: "Test 9: When stake value is less than minSafeRazor and staker's stake is more than the minSafeRazor already",
args: args{
config: config,
password: "test",
address: "0x000000000000000000000000000000000000dead",
amount: big.NewInt(20),
balance: big.NewInt(10000),
minSafeRazor: big.NewInt(100),
stakerId: 1,
approveTxn: common.BigToHash(big.NewInt(1)),
stakeTxn: common.BigToHash(big.NewInt(2)),
},
expectedFatal: false,
},
}

defer func() { log.ExitFunc = nil }()
Expand All @@ -290,7 +314,7 @@ func TestExecuteStake(t *testing.T) {

utilsMock.On("AssignLogFile", mock.AnythingOfType("*pflag.FlagSet"))
cmdUtilsMock.On("GetConfigData").Return(tt.args.config, tt.args.configErr)
utilsMock.On("AssignPassword").Return(tt.args.password)
utilsMock.On("AssignPassword", mock.AnythingOfType("*pflag.FlagSet")).Return(tt.args.password)
flagSetUtilsMock.On("GetStringAddress", mock.AnythingOfType("*pflag.FlagSet")).Return(tt.args.address, tt.args.addressErr)
utilsMock.On("ConnectToClient", mock.AnythingOfType("string")).Return(client)
utilsMock.On("WaitForBlockCompletion", mock.AnythingOfType("*ethclient.Client"), mock.AnythingOfType("string")).Return(nil)
Expand All @@ -299,6 +323,7 @@ func TestExecuteStake(t *testing.T) {
utilsMock.On("CheckAmountAndBalance", mock.AnythingOfType("*big.Int"), mock.AnythingOfType("*big.Int")).Return(tt.args.amount)
utilsMock.On("CheckEthBalanceIsZero", mock.AnythingOfType("*ethclient.Client"), mock.AnythingOfType("string")).Return()
utilsPkgMock.On("GetMinSafeRazor", mock.AnythingOfType("*ethclient.Client")).Return(tt.args.minSafeRazor, tt.args.minSafeRazorErr)
utilsMock.On("GetStakerId", mock.Anything, mock.Anything).Return(tt.args.stakerId, tt.args.stakerIdErr)
cmdUtilsMock.On("Approve", mock.Anything).Return(tt.args.approveTxn, tt.args.approveErr)
cmdUtilsMock.On("StakeCoins", mock.Anything).Return(tt.args.stakeTxn, tt.args.stakeErr)

Expand Down
2 changes: 2 additions & 0 deletions cmd/approve.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func (*UtilsStruct) Approve(txnArgs types.TransactionOptions) (common.Hash, erro
if err != nil {
return common.Hash{0x00}, err
}
log.Debugf("Approve: Allowance amount: %d, Amount to get approved: %d", allowance, txnArgs.Amount)
if allowance.Cmp(txnArgs.Amount) >= 0 {
log.Debug("Sufficient allowance, no need to increase")
return common.Hash{0x00}, nil
Expand All @@ -25,6 +26,7 @@ func (*UtilsStruct) Approve(txnArgs types.TransactionOptions) (common.Hash, erro
txnArgs.ABI = bindings.RAZORABI
txnArgs.Parameters = []interface{}{common.HexToAddress(core.StakeManagerAddress), txnArgs.Amount}
txnOpts := razorUtils.GetTxnOpts(txnArgs)
log.Debug("Executing Approve transaction with amount: ", txnArgs.Amount)
txn, err := tokenManagerUtils.Approve(txnArgs.Client, txnOpts, common.HexToAddress(core.StakeManagerAddress), txnArgs.Amount)
if err != nil {
return common.Hash{0x00}, err
Expand Down
Loading

0 comments on commit 237ad2c

Please sign in to comment.