Skip to content

Commit

Permalink
Merge branch 'rc/v1.7.0' into integration-tests-calling-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
iulianpascalau authored Mar 20, 2024
2 parents 790e71d + 5c3ca8c commit d2b1804
Show file tree
Hide file tree
Showing 13 changed files with 367 additions and 63 deletions.
3 changes: 2 additions & 1 deletion cmd/node/config/enableEpochs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@
CurrentRandomnessOnSortingEnableEpoch = 4

# StakeLimitsEnableEpoch represents the epoch when stake limits on validators are enabled
StakeLimitsEnableEpoch = 5
# Should have the same value as StakingV4Step1EnableEpoch that triggers the automatic unstake operations for the queue nodes
StakeLimitsEnableEpoch = 4

# StakingV4Step1EnableEpoch represents the epoch when staking v4 is initialized. This is the epoch in which
# all nodes from staking queue are moved in the auction list
Expand Down
24 changes: 22 additions & 2 deletions epochStart/metachain/systemSCs.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package metachain

import (
"fmt"
"math"
"math/big"

"github.com/multiversx/mx-chain-core-go/core"
Expand Down Expand Up @@ -139,7 +138,7 @@ func (s *systemSCProcessor) processWithNewFlags(
}

if s.enableEpochsHandler.IsFlagEnabled(common.StakingV4Step1Flag) {
err := s.stakeNodesFromQueue(validatorsInfoMap, math.MaxUint32, header.GetNonce(), common.AuctionList)
err := s.unStakeAllNodesFromQueue()
if err != nil {
return err
}
Expand Down Expand Up @@ -170,6 +169,27 @@ func (s *systemSCProcessor) processWithNewFlags(
return nil
}

func (s *systemSCProcessor) unStakeAllNodesFromQueue() error {
vmInput := &vmcommon.ContractCallInput{
VMInput: vmcommon.VMInput{
CallerAddr: vm.EndOfEpochAddress,
CallValue: big.NewInt(0),
Arguments: [][]byte{},
},
RecipientAddr: vm.StakingSCAddress,
Function: "unStakeAllNodesFromQueue",
}
vmOutput, errRun := s.systemVM.RunSmartContractCall(vmInput)
if errRun != nil {
return fmt.Errorf("%w when unStaking all nodes from staking queue", errRun)
}
if vmOutput.ReturnCode != vmcommon.Ok {
return fmt.Errorf("got return code %s when unStaking all nodes from staking queue", vmOutput.ReturnCode)
}

return s.processSCOutputAccounts(vmOutput)
}

func (s *systemSCProcessor) unStakeNodesWithNotEnoughFundsWithStakingV4(
validatorsInfoMap state.ShardValidatorsInfoMapHandler,
epoch uint32,
Expand Down
8 changes: 0 additions & 8 deletions epochStart/metachain/systemSCs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2053,14 +2053,6 @@ func TestSystemSCProcessor_ProcessSystemSmartContractStakingV4Init(t *testing.T)
0: {
createValidatorInfo(owner1ListPubKeysStaked[0], common.EligibleList, "", 0, owner1),
createValidatorInfo(owner1ListPubKeysStaked[1], common.WaitingList, "", 0, owner1),
createValidatorInfo(owner1ListPubKeysWaiting[0], common.AuctionList, "", 0, owner1),
createValidatorInfo(owner1ListPubKeysWaiting[1], common.AuctionList, "", 0, owner1),
createValidatorInfo(owner1ListPubKeysWaiting[2], common.AuctionList, "", 0, owner1),

createValidatorInfo(owner2ListPubKeysWaiting[0], common.AuctionList, "", 0, owner2),

createValidatorInfo(owner3ListPubKeysWaiting[0], common.AuctionList, "", 0, owner3),
createValidatorInfo(owner3ListPubKeysWaiting[1], common.AuctionList, "", 0, owner3),
},
1: {
createValidatorInfo(owner2ListPubKeysStaked[0], common.EligibleList, "", 1, owner2),
Expand Down
16 changes: 15 additions & 1 deletion integrationTests/chainSimulator/staking/delegation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ func testChainSimulatorMakeNewContractFromValidatorDataWith2StakingContracts(t *
// 9. Unbond the 2 nodes (that were un staked)

// Internal test scenario #85
func TestWIP(t *testing.T) {
func TestChainSimulatorMakeNewContractFromValidatorDataWith1StakingContractUnstakeAndUnbond(t *testing.T) {
if testing.Short() {
t.Skip("this is not a short test")
}
Expand All @@ -675,6 +675,7 @@ func TestWIP(t *testing.T) {
NumNodesWaitingListMeta: 3,
NumNodesWaitingListShard: 3,
AlterConfigsFunction: func(cfg *config.Configs) {
cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 100
cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100
cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101
cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 102
Expand Down Expand Up @@ -705,12 +706,14 @@ func TestWIP(t *testing.T) {
NumNodesWaitingListMeta: 3,
NumNodesWaitingListShard: 3,
AlterConfigsFunction: func(cfg *config.Configs) {
cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2
cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2
cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3
cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4
cfg.EpochConfig.EnableEpochs.AlwaysMergeContextsInEEIEnableEpoch = 1

cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4
cfg.SystemSCConfig.StakingSystemSCConfig.NodeLimitPercentage = 1
},
})
require.Nil(t, err)
Expand All @@ -735,12 +738,14 @@ func TestWIP(t *testing.T) {
NumNodesWaitingListMeta: 3,
NumNodesWaitingListShard: 3,
AlterConfigsFunction: func(cfg *config.Configs) {
cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2
cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2
cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3
cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4
cfg.EpochConfig.EnableEpochs.AlwaysMergeContextsInEEIEnableEpoch = 1

cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4
cfg.SystemSCConfig.StakingSystemSCConfig.NodeLimitPercentage = 1
},
})
require.Nil(t, err)
Expand All @@ -765,12 +770,14 @@ func TestWIP(t *testing.T) {
NumNodesWaitingListMeta: 3,
NumNodesWaitingListShard: 3,
AlterConfigsFunction: func(cfg *config.Configs) {
cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2
cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2
cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3
cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4
cfg.EpochConfig.EnableEpochs.AlwaysMergeContextsInEEIEnableEpoch = 1

cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4
cfg.SystemSCConfig.StakingSystemSCConfig.NodeLimitPercentage = 1
},
})
require.Nil(t, err)
Expand Down Expand Up @@ -1500,6 +1507,7 @@ func TestChainSimulator_MergeDelegation(t *testing.T) {
NumNodesWaitingListMeta: 3,
NumNodesWaitingListShard: 3,
AlterConfigsFunction: func(cfg *config.Configs) {
cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 100
cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 100
cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 101
cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 102
Expand Down Expand Up @@ -1530,11 +1538,13 @@ func TestChainSimulator_MergeDelegation(t *testing.T) {
NumNodesWaitingListMeta: 3,
NumNodesWaitingListShard: 3,
AlterConfigsFunction: func(cfg *config.Configs) {
cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2
cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2
cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3
cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4

cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4
cfg.SystemSCConfig.StakingSystemSCConfig.NodeLimitPercentage = 1
},
})
require.Nil(t, err)
Expand All @@ -1560,11 +1570,13 @@ func TestChainSimulator_MergeDelegation(t *testing.T) {
NumNodesWaitingListMeta: 3,
NumNodesWaitingListShard: 3,
AlterConfigsFunction: func(cfg *config.Configs) {
cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2
cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2
cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3
cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4

cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4
cfg.SystemSCConfig.StakingSystemSCConfig.NodeLimitPercentage = 1
},
})
require.Nil(t, err)
Expand All @@ -1590,11 +1602,13 @@ func TestChainSimulator_MergeDelegation(t *testing.T) {
NumNodesWaitingListMeta: 3,
NumNodesWaitingListShard: 3,
AlterConfigsFunction: func(cfg *config.Configs) {
cfg.EpochConfig.EnableEpochs.StakeLimitsEnableEpoch = 2
cfg.EpochConfig.EnableEpochs.StakingV4Step1EnableEpoch = 2
cfg.EpochConfig.EnableEpochs.StakingV4Step2EnableEpoch = 3
cfg.EpochConfig.EnableEpochs.StakingV4Step3EnableEpoch = 4

cfg.EpochConfig.EnableEpochs.MaxNodesChangeEnableEpoch[2].EpochEnable = 4
cfg.SystemSCConfig.StakingSystemSCConfig.NodeLimitPercentage = 1
},
})
require.Nil(t, err)
Expand Down
7 changes: 4 additions & 3 deletions integrationTests/chainSimulator/staking/jail_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/data/transaction"
"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/config"
chainSimulatorIntegrationTests "github.com/multiversx/mx-chain-go/integrationTests/chainSimulator"
"github.com/multiversx/mx-chain-go/node/chainSimulator"
Expand Down Expand Up @@ -145,7 +146,7 @@ func testChainSimulatorJailAndUnJail(t *testing.T, targetEpoch int32, nodeStatus
// Add a new node and wait until the node get jailed
// Add a second node to take the place of the jailed node
// UnJail the first node --> should go in queue
// Activate staking v4 step 1 --> node should be moved from queue to auction list
// Activate staking v4 step 1 --> node should be unstaked as the queue is cleaned up

// Internal test scenario #2
func TestChainSimulator_FromQueueToAuctionList(t *testing.T) {
Expand Down Expand Up @@ -241,9 +242,9 @@ func TestChainSimulator_FromQueueToAuctionList(t *testing.T) {
require.Nil(t, err)

status = getBLSKeyStatus(t, metachainNode, decodedBLSKey0)
require.Equal(t, "staked", status)
require.Equal(t, unStakedStatus, status)

checkValidatorStatus(t, cs, blsKeys[0], "auction")
checkValidatorStatus(t, cs, blsKeys[0], string(common.InactiveList))
}

func checkValidatorStatus(t *testing.T, cs chainSimulatorIntegrationTests.ChainSimulator, blsKey string, expectedStatus string) {
Expand Down
22 changes: 20 additions & 2 deletions integrationTests/chainSimulator/staking/simpleStake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ func testChainSimulatorSimpleStake(t *testing.T, targetEpoch int32, nodesStatus
// - 2 nodes to shuffle per shard
// - max num nodes config for stakingV4 step3 = 24 (being downsized from previously 32 nodes)
// Steps:
// 1. Stake 1 node and check that in stakingV4 step1 it is found in auction
// 2. From stakingV4 step2 onwards, check that api returns 8 qualified + 1 unqualified nodes
// 1. Stake 1 node and check that in stakingV4 step1 it is unstaked
// 2. Re-stake the node to enter the auction list
// 3. From stakingV4 step2 onwards, check that api returns 8 qualified + 1 unqualified nodes
func TestChainSimulator_StakingV4Step2APICalls(t *testing.T) {
if testing.Short() {
t.Skip("this is not a short test")
Expand Down Expand Up @@ -215,6 +216,23 @@ func TestChainSimulator_StakingV4Step2APICalls(t *testing.T) {
require.Nil(t, err)
auctionList, err := metachainNode.GetProcessComponents().ValidatorsProvider().GetAuctionList()
require.Nil(t, err)
require.Empty(t, auctionList)

// re-stake the node
txDataField = fmt.Sprintf("reStakeUnStakedNodes@%s", blsKeys[0])
txReStake := generateTransaction(validatorOwner.Bytes, 1, vm.ValidatorSCAddress, big.NewInt(0), txDataField, gasLimitForStakeOperation)
reStakeTx, err := cs.SendTxAndGenerateBlockTilTxIsExecuted(txReStake, maxNumOfBlockToGenerateWhenExecutingTx)
require.Nil(t, err)
require.NotNil(t, reStakeTx)

err = cs.GenerateBlocks(2)
require.Nil(t, err)

// after the re-stake process, the node should be in auction list
err = metachainNode.GetProcessComponents().ValidatorsProvider().ForceUpdate()
require.Nil(t, err)
auctionList, err = metachainNode.GetProcessComponents().ValidatorsProvider().GetAuctionList()
require.Nil(t, err)
require.Equal(t, []*common.AuctionListValidatorAPIResponse{
{
Owner: validatorOwner.Bech32,
Expand Down
Loading

0 comments on commit d2b1804

Please sign in to comment.