From 05c4b432b743891d260403ed7501dcbf5d96aae7 Mon Sep 17 00:00:00 2001 From: Alexander Sporn Date: Fri, 8 Mar 2024 12:52:11 +0100 Subject: [PATCH] Sort validators by pool stake and then by address --- .../sybilprotection/sybilprotectionv1/sybilprotection.go | 9 +++++++-- pkg/requesthandler/accounts.go | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go b/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go index 4abf4db90..ca6531202 100644 --- a/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go +++ b/pkg/protocol/sybilprotection/sybilprotectionv1/sybilprotection.go @@ -371,9 +371,14 @@ func (o *SybilProtection) OrderedRegisteredCandidateValidatorsList(epoch iotago. }); err != nil { return nil, ierrors.Wrapf(err, "failed to iterate over eligible validator candidates") } - // sort candidates by stake + + // sort validators by pool stake, then by address sort.Slice(validatorResp, func(i int, j int) bool { - return validatorResp[i].ValidatorStake > validatorResp[j].ValidatorStake + if validatorResp[i].PoolStake == validatorResp[j].PoolStake { + return validatorResp[i].AddressBech32 < validatorResp[j].AddressBech32 + } + + return validatorResp[i].PoolStake > validatorResp[j].PoolStake }) return validatorResp, nil diff --git a/pkg/requesthandler/accounts.go b/pkg/requesthandler/accounts.go index b21463b44..1d463cf15 100644 --- a/pkg/requesthandler/accounts.go +++ b/pkg/requesthandler/accounts.go @@ -208,6 +208,7 @@ func (r *RequestHandler) SelectedCommittee(epoch iotago.EpochIndex) (*api.Commit if committee[i].PoolStake == committee[j].PoolStake { return committee[i].AddressBech32 < committee[j].AddressBech32 } + return committee[i].PoolStake > committee[j].PoolStake })