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

highlight nodes shuffled out to auction list #6166

Merged
merged 10 commits into from
May 17, 2024
5 changes: 5 additions & 0 deletions epochStart/bootstrap/disabled/disabledNodesCoordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ func (n *nodesCoordinator) GetAllShuffledOutValidatorsPublicKeys(_ uint32) (map[
return nil, nil
}

// GetShuffledOutToAuctionValidatorsPublicKeys -
func (n *nodesCoordinator) GetShuffledOutToAuctionValidatorsPublicKeys(_ uint32) (map[uint32][][]byte, error) {
return nil, nil
}

// GetConsensusValidatorsPublicKeys -
func (n *nodesCoordinator) GetConsensusValidatorsPublicKeys(_ []byte, _ uint64, _ uint32, _ uint32) ([]string, error) {
return nil, nil
Expand Down
5 changes: 3 additions & 2 deletions process/peer/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import (
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/block"
"github.com/multiversx/mx-chain-core-go/marshal"
logger "github.com/multiversx/mx-chain-logger-go"

"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/common/errChan"
"github.com/multiversx/mx-chain-go/common/validatorInfo"
Expand All @@ -23,7 +25,6 @@ import (
"github.com/multiversx/mx-chain-go/state"
"github.com/multiversx/mx-chain-go/state/accounts"
"github.com/multiversx/mx-chain-go/state/parsers"
logger "github.com/multiversx/mx-chain-logger-go"
)

var log = logger.GetOrCreate("process/peer")
Expand Down Expand Up @@ -197,7 +198,7 @@ func (vs *validatorStatistics) saveNodesCoordinatorUpdates(epoch uint32) (bool,
nodeForcedToRemain = nodeForcedToRemain || tmpNodeForcedToRemain

if vs.enableEpochsHandler.IsFlagEnabled(common.StakingV4Step2Flag) {
nodesMap, err = vs.nodesCoordinator.GetAllShuffledOutValidatorsPublicKeys(epoch)
nodesMap, err = vs.nodesCoordinator.GetShuffledOutToAuctionValidatorsPublicKeys(epoch)
if err != nil {
return false, err
}
Expand Down
14 changes: 11 additions & 3 deletions process/peer/process_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
"github.com/multiversx/mx-chain-core-go/core/keyValStorage"
"github.com/multiversx/mx-chain-core-go/data"
"github.com/multiversx/mx-chain-core-go/data/block"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/dataRetriever"
Expand All @@ -33,9 +37,6 @@ import (
"github.com/multiversx/mx-chain-go/testscommon/shardingMocks"
stateMock "github.com/multiversx/mx-chain-go/testscommon/state"
storageStubs "github.com/multiversx/mx-chain-go/testscommon/storage"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

const (
Expand Down Expand Up @@ -2719,6 +2720,13 @@ func TestValidatorStatisticsProcessor_SaveNodesCoordinatorUpdatesWithStakingV4(t
}
return mapNodes, nil
},
GetShuffledOutToAuctionValidatorsPublicKeysCalled: func(epoch uint32) (map[uint32][][]byte, error) {
mapNodes := map[uint32][][]byte{
0: {pk1},
core.MetachainShardId: {pk2},
}
return mapNodes, nil
},
}
stakingV4Step2EnableEpochCalledCt := 0
arguments.EnableEpochsHandler = &enableEpochsHandlerMock.EnableEpochsHandlerStub{
Expand Down
1 change: 1 addition & 0 deletions sharding/nodesCoordinator/dtos.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ type ResUpdateNodes struct {
ShuffledOut map[uint32][]Validator
Leaving []Validator
StillRemaining []Validator
LowWaitingList bool
}
2 changes: 2 additions & 0 deletions sharding/nodesCoordinator/hashValidatorShuffler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/multiversx/mx-chain-core-go/core/atomic"
"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-core-go/hashing/sha256"

"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/config"
"github.com/multiversx/mx-chain-go/epochStart"
Expand Down Expand Up @@ -350,6 +351,7 @@ func shuffleNodes(arg shuffleNodesArg) (*ResUpdateNodes, error) {
ShuffledOut: shuffledOutMap,
Leaving: actualLeaving,
StillRemaining: stillRemainingInLeaving,
LowWaitingList: lowWaitingList,
}, nil
}

Expand Down
25 changes: 24 additions & 1 deletion sharding/nodesCoordinator/indexHashedNodesCoordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ import (
"github.com/multiversx/mx-chain-core-go/data/endProcess"
"github.com/multiversx/mx-chain-core-go/hashing"
"github.com/multiversx/mx-chain-core-go/marshal"
logger "github.com/multiversx/mx-chain-logger-go"

"github.com/multiversx/mx-chain-go/common"
"github.com/multiversx/mx-chain-go/epochStart"
"github.com/multiversx/mx-chain-go/state"
"github.com/multiversx/mx-chain-go/storage"
logger "github.com/multiversx/mx-chain-logger-go"
)

var _ NodesCoordinator = (*indexHashedNodesCoordinator)(nil)
Expand Down Expand Up @@ -68,6 +69,7 @@ type epochNodesConfig struct {
newList []Validator
auctionList []Validator
mutNodesMaps sync.RWMutex
lowWaitingList bool
}

type indexHashedNodesCoordinator struct {
Expand Down Expand Up @@ -122,6 +124,7 @@ func NewIndexHashedNodesCoordinator(arguments ArgNodesCoordinator) (*indexHashed
shuffledOutMap: make(map[uint32][]Validator),
newList: make([]Validator, 0),
auctionList: make([]Validator, 0),
lowWaitingList: false,
}

// todo: if not genesis, use previous randomness from start of epoch meta block
Expand Down Expand Up @@ -546,6 +549,26 @@ func (ihnc *indexHashedNodesCoordinator) GetAllShuffledOutValidatorsPublicKeys(e
return validatorsPubKeys, nil
}

// GetShuffledOutToAuctionValidatorsPublicKeys will return shuffled out to auction validators public keys
func (ihnc *indexHashedNodesCoordinator) GetShuffledOutToAuctionValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error) {
validatorsPubKeys := make(map[uint32][][]byte)

ihnc.mutNodesConfig.RLock()
nodesConfig, ok := ihnc.nodesConfig[epoch]
ihnc.mutNodesConfig.RUnlock()

if !ok {
return nil, fmt.Errorf("%w epoch=%v", ErrEpochNodesConfigDoesNotExist, epoch)
}

if nodesConfig.lowWaitingList {
// in case of low waiting list the nodes do not go through auction but directly to waiting
return validatorsPubKeys, nil
}

return ihnc.GetAllShuffledOutValidatorsPublicKeys(epoch)
}

// GetValidatorsIndexes will return validators indexes for a block
func (ihnc *indexHashedNodesCoordinator) GetValidatorsIndexes(
publicKeys []string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ func (ihnc *indexHashedNodesCoordinator) nodesCoordinatorToRegistryWithAuction()

func epochNodesConfigToEpochValidatorsWithAuction(config *epochNodesConfig) *EpochValidatorsWithAuction {
result := &EpochValidatorsWithAuction{
Eligible: make(map[string]Validators, len(config.eligibleMap)),
Waiting: make(map[string]Validators, len(config.waitingMap)),
Leaving: make(map[string]Validators, len(config.leavingMap)),
ShuffledOut: make(map[string]Validators, len(config.shuffledOutMap)),
Eligible: make(map[string]Validators, len(config.eligibleMap)),
Waiting: make(map[string]Validators, len(config.waitingMap)),
Leaving: make(map[string]Validators, len(config.leavingMap)),
ShuffledOut: make(map[string]Validators, len(config.shuffledOutMap)),
LowWaitingList: config.lowWaitingList,
}

for k, v := range config.eligibleMap {
Expand Down
8 changes: 5 additions & 3 deletions sharding/nodesCoordinator/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package nodesCoordinator
import (
"github.com/multiversx/mx-chain-core-go/core"
"github.com/multiversx/mx-chain-core-go/data"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"

"github.com/multiversx/mx-chain-go/epochStart"
"github.com/multiversx/mx-chain-go/state"
vmcommon "github.com/multiversx/mx-chain-vm-common-go"
)

// Validator defines a node that can be allocated to a shard for participation in a consensus group as validator
Expand Down Expand Up @@ -48,6 +49,7 @@ type PublicKeysSelector interface {
GetAllWaitingValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error)
GetAllLeavingValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error)
GetAllShuffledOutValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error)
GetShuffledOutToAuctionValidatorsPublicKeys(epoch uint32) (map[uint32][][]byte, error)
GetConsensusValidatorsPublicKeys(randomness []byte, round uint64, shardId uint32, epoch uint32) ([]string, error)
GetOwnPublicKey() []byte
}
Expand All @@ -68,9 +70,9 @@ type NodesCoordinatorHelper interface {

// ChanceComputer provides chance computation capabilities based on a rating
type ChanceComputer interface {
//GetChance returns the chances for the rating
// GetChance returns the chances for the rating
GetChance(uint32) uint32
//IsInterfaceNil verifies if the interface is nil
// IsInterfaceNil verifies if the interface is nil
IsInterfaceNil() bool
}

Expand Down
Loading
Loading