Skip to content

Commit

Permalink
Merge pull request #6151 from multiversx/merge_rc170_into_rc17next1_2…
Browse files Browse the repository at this point in the history
…024.05.08

Merge rc170 into rc17next1 2024.05.08
  • Loading branch information
sstanculeanu committed May 10, 2024
2 parents 13855e3 + 0ddca88 commit d8bc3fc
Show file tree
Hide file tree
Showing 53 changed files with 1,708 additions and 277 deletions.
9 changes: 9 additions & 0 deletions api/groups/addressGroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
urlParamBlockHash = "blockHash"
urlParamBlockRootHash = "blockRootHash"
urlParamHintEpoch = "hintEpoch"
urlParamWithKeys = "withKeys"
)

// addressFacadeHandler defines the methods to be implemented by a facade for handling address requests
Expand Down Expand Up @@ -185,6 +186,14 @@ func (ag *addressGroup) getAccount(c *gin.Context) {
return
}

withKeys, err := parseBoolUrlParam(c, urlParamWithKeys)
if err != nil {
shared.RespondWithValidationError(c, errors.ErrCouldNotGetAccount, err)
return
}

options.WithKeys = withKeys

accountResponse, blockInfo, err := ag.getFacade().GetAccount(addr, options)
if err != nil {
shared.RespondWithInternalError(c, errors.ErrCouldNotGetAccount, err)
Expand Down
1 change: 0 additions & 1 deletion common/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,6 @@ const (
StakingV4Step1Flag core.EnableEpochFlag = "StakingV4Step1Flag"
StakingV4Step2Flag core.EnableEpochFlag = "StakingV4Step2Flag"
StakingV4Step3Flag core.EnableEpochFlag = "StakingV4Step3Flag"
StakingQueueFlag core.EnableEpochFlag = "StakingQueueFlag"
StakingV4StartedFlag core.EnableEpochFlag = "StakingV4StartedFlag"
AlwaysMergeContextsInEEIFlag core.EnableEpochFlag = "AlwaysMergeContextsInEEIFlag"
DynamicESDTFlag core.EnableEpochFlag = "DynamicEsdtFlag"
Expand Down
6 changes: 0 additions & 6 deletions common/enablers/enableEpochsHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -713,12 +713,6 @@ func (handler *enableEpochsHandler) createAllFlagsMap() {
},
activationEpoch: handler.enableEpochsConfig.StakingV4Step3EnableEpoch,
},
common.StakingQueueFlag: {
isActiveInEpoch: func(epoch uint32) bool {
return epoch < handler.enableEpochsConfig.StakingV4Step1EnableEpoch
},
activationEpoch: handler.enableEpochsConfig.StakingV4Step1EnableEpoch,
},
common.StakingV4StartedFlag: {
isActiveInEpoch: func(epoch uint32) bool {
return epoch >= handler.enableEpochsConfig.StakingV4Step1EnableEpoch
Expand Down
9 changes: 0 additions & 9 deletions common/enablers/enableEpochsHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,6 @@ func TestEnableEpochsHandler_IsFlagEnabled(t *testing.T) {
handler.EpochConfirmed(cfg.SetGuardianEnableEpoch+1, 0)
require.True(t, handler.IsFlagEnabled(common.SetGuardianFlag))

handler.EpochConfirmed(cfg.StakingV4Step1EnableEpoch-1, 0)
require.True(t, handler.IsFlagEnabled(common.StakingQueueFlag))
handler.EpochConfirmed(cfg.StakingV4Step1EnableEpoch, 0)
require.False(t, handler.IsFlagEnabled(common.StakingQueueFlag))
handler.EpochConfirmed(cfg.StakingV4Step1EnableEpoch+1, 0)
require.False(t, handler.IsFlagEnabled(common.StakingQueueFlag))

handler.EpochConfirmed(cfg.StakingV4Step1EnableEpoch-1, 0)
require.False(t, handler.IsFlagEnabled(common.StakingV4StartedFlag))
handler.EpochConfirmed(cfg.StakingV4Step1EnableEpoch, 0)
Expand Down Expand Up @@ -321,7 +314,6 @@ func TestEnableEpochsHandler_IsFlagEnabled(t *testing.T) {
require.False(t, handler.IsFlagEnabled(common.StakingV4Step1Flag))
require.True(t, handler.IsFlagEnabled(common.StakingV4Step2Flag))
require.True(t, handler.IsFlagEnabled(common.StakingV4Step3Flag))
require.False(t, handler.IsFlagEnabled(common.StakingQueueFlag))
require.True(t, handler.IsFlagEnabled(common.StakingV4StartedFlag))
require.True(t, handler.IsFlagEnabled(common.AlwaysMergeContextsInEEIFlag))
require.True(t, handler.IsFlagEnabled(common.DynamicESDTFlag))
Expand Down Expand Up @@ -438,7 +430,6 @@ func TestEnableEpochsHandler_GetActivationEpoch(t *testing.T) {
require.Equal(t, cfg.StakingV4Step1EnableEpoch, handler.GetActivationEpoch(common.StakingV4Step1Flag))
require.Equal(t, cfg.StakingV4Step2EnableEpoch, handler.GetActivationEpoch(common.StakingV4Step2Flag))
require.Equal(t, cfg.StakingV4Step3EnableEpoch, handler.GetActivationEpoch(common.StakingV4Step3Flag))
require.Equal(t, cfg.StakingV4Step1EnableEpoch, handler.GetActivationEpoch(common.StakingQueueFlag))
require.Equal(t, cfg.StakingV4Step1EnableEpoch, handler.GetActivationEpoch(common.StakingV4StartedFlag))
require.Equal(t, cfg.AlwaysMergeContextsInEEIEnableEpoch, handler.GetActivationEpoch(common.AlwaysMergeContextsInEEIFlag))
require.Equal(t, cfg.DynamicESDTEnableEpoch, handler.GetActivationEpoch(common.DynamicESDTFlag))
Expand Down
7 changes: 7 additions & 0 deletions epochStart/dtos.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,10 @@ type OwnerData struct {
AuctionList []state.ValidatorInfoHandler
Qualified bool
}

// ValidatorStatsInEpoch holds validator stats in an epoch
type ValidatorStatsInEpoch struct {
Eligible map[uint32]int
Waiting map[uint32]int
Leaving map[uint32]int
}
1 change: 1 addition & 0 deletions epochStart/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ type StakingDataProvider interface {
ComputeUnQualifiedNodes(validatorInfos state.ShardValidatorsInfoMapHandler) ([][]byte, map[string][][]byte, error)
GetBlsKeyOwner(blsKey []byte) (string, error)
GetNumOfValidatorsInCurrentEpoch() uint32
GetCurrentEpochValidatorStats() ValidatorStatsInEpoch
GetOwnersData() map[string]*OwnerData
Clean()
IsInterfaceNil() bool
Expand Down
66 changes: 60 additions & 6 deletions epochStart/metachain/auctionListSelector.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (als *auctionListSelector) SelectNodesFromAuctionList(

currNodesConfig := als.nodesConfigProvider.GetCurrentNodesConfig()
currNumOfValidators := als.stakingDataProvider.GetNumOfValidatorsInCurrentEpoch()
numOfShuffledNodes := currNodesConfig.NodesToShufflePerShard * (als.shardCoordinator.NumberOfShards() + 1)
numOfShuffledNodes, numForcedToStay := als.computeNumShuffledNodes(currNodesConfig)
numOfValidatorsAfterShuffling, err := safeSub(currNumOfValidators, numOfShuffledNodes)
if err != nil {
log.Warn(fmt.Sprintf("auctionListSelector.SelectNodesFromAuctionList: %v when trying to compute numOfValidatorsAfterShuffling = %v - %v (currNumOfValidators - numOfShuffledNodes)",
Expand All @@ -210,12 +210,13 @@ func (als *auctionListSelector) SelectNodesFromAuctionList(
}

maxNumNodes := currNodesConfig.MaxNumNodes
availableSlots, err := safeSub(maxNumNodes, numOfValidatorsAfterShuffling)
numValidatorsAfterShufflingWithForcedToStay := numOfValidatorsAfterShuffling + numForcedToStay
availableSlots, err := safeSub(maxNumNodes, numValidatorsAfterShufflingWithForcedToStay)
if availableSlots == 0 || err != nil {
log.Info(fmt.Sprintf("auctionListSelector.SelectNodesFromAuctionList: %v or zero value when trying to compute availableSlots = %v - %v (maxNodes - numOfValidatorsAfterShuffling); skip selecting nodes from auction list",
log.Info(fmt.Sprintf("auctionListSelector.SelectNodesFromAuctionList: %v or zero value when trying to compute availableSlots = %v - %v (maxNodes - numOfValidatorsAfterShuffling+numForcedToStay); skip selecting nodes from auction list",
err,
maxNumNodes,
numOfValidatorsAfterShuffling,
numValidatorsAfterShufflingWithForcedToStay,
))
return nil
}
Expand All @@ -224,9 +225,10 @@ func (als *auctionListSelector) SelectNodesFromAuctionList(
"max nodes", maxNumNodes,
"current number of validators", currNumOfValidators,
"num of nodes which will be shuffled out", numOfShuffledNodes,
"num of validators after shuffling", numOfValidatorsAfterShuffling,
"num forced to stay", numForcedToStay,
"num of validators after shuffling with forced to stay", numValidatorsAfterShufflingWithForcedToStay,
"auction list size", auctionListSize,
fmt.Sprintf("available slots (%v - %v)", maxNumNodes, numOfValidatorsAfterShuffling), availableSlots,
fmt.Sprintf("available slots (%v - %v)", maxNumNodes, numValidatorsAfterShufflingWithForcedToStay), availableSlots,
)

als.auctionListDisplayer.DisplayOwnersData(ownersData)
Expand Down Expand Up @@ -272,6 +274,58 @@ func isInAuction(validator state.ValidatorInfoHandler) bool {
return validator.GetList() == string(common.AuctionList)
}

func (als *auctionListSelector) computeNumShuffledNodes(currNodesConfig config.MaxNodesChangeConfig) (uint32, uint32) {
numNodesToShufflePerShard := currNodesConfig.NodesToShufflePerShard
numTotalToShuffleOut := numNodesToShufflePerShard * (als.shardCoordinator.NumberOfShards() + 1)
epochStats := als.stakingDataProvider.GetCurrentEpochValidatorStats()

actuallyNumLeaving := uint32(0)
forcedToStay := uint32(0)

for shardID := uint32(0); shardID < als.shardCoordinator.NumberOfShards(); shardID++ {
leavingInShard, forcedToStayInShard := computeActuallyNumLeaving(shardID, epochStats, numNodesToShufflePerShard)
actuallyNumLeaving += leavingInShard
forcedToStay += forcedToStayInShard
}

leavingInMeta, forcedToStayInMeta := computeActuallyNumLeaving(core.MetachainShardId, epochStats, numNodesToShufflePerShard)
actuallyNumLeaving += leavingInMeta
forcedToStay += forcedToStayInMeta

finalShuffledOut, err := safeSub(numTotalToShuffleOut, actuallyNumLeaving)
if err != nil {
log.Error("auctionListSelector.computeNumShuffledNodes error computing finalShuffledOut, returning default values",
"error", err, "numTotalToShuffleOut", numTotalToShuffleOut, "actuallyNumLeaving", actuallyNumLeaving)
return numTotalToShuffleOut, 0
}

return finalShuffledOut, forcedToStay
}

func computeActuallyNumLeaving(shardID uint32, epochStats epochStart.ValidatorStatsInEpoch, numNodesToShuffledPerShard uint32) (uint32, uint32) {
numLeavingInShard := uint32(epochStats.Leaving[shardID])
numActiveInShard := uint32(epochStats.Waiting[shardID] + epochStats.Eligible[shardID])

log.Debug("auctionListSelector.computeActuallyNumLeaving computing",
"shardID", shardID, "numLeavingInShard", numLeavingInShard, "numActiveInShard", numActiveInShard)

actuallyLeaving := uint32(0)
forcedToStay := uint32(0)
if numLeavingInShard <= numNodesToShuffledPerShard && numActiveInShard > numLeavingInShard {
actuallyLeaving = numLeavingInShard
}

if numLeavingInShard > numNodesToShuffledPerShard {
actuallyLeaving = numNodesToShuffledPerShard
forcedToStay = numLeavingInShard - numNodesToShuffledPerShard
}

log.Debug("auctionListSelector.computeActuallyNumLeaving computed",
"actuallyLeaving", actuallyLeaving, "forcedToStay", forcedToStay)

return actuallyLeaving, forcedToStay
}

// TODO: Move this in elrond-go-core
func safeSub(a, b uint32) (uint32, error) {
if a < b {
Expand Down

0 comments on commit d8bc3fc

Please sign in to comment.