From 1c2cbe5adf0e95a225e1bc2edaedc2769fd4f7dd Mon Sep 17 00:00:00 2001 From: Alexander Sporn Date: Fri, 8 Mar 2024 12:32:18 +0100 Subject: [PATCH 1/3] add a stable sort to the committee api response --- pkg/requesthandler/accounts.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/requesthandler/accounts.go b/pkg/requesthandler/accounts.go index e82aa15ba..b21463b44 100644 --- a/pkg/requesthandler/accounts.go +++ b/pkg/requesthandler/accounts.go @@ -2,6 +2,7 @@ package requesthandler import ( "fmt" + "sort" "github.com/labstack/echo/v4" @@ -202,6 +203,14 @@ func (r *RequestHandler) SelectedCommittee(epoch iotago.EpochIndex) (*api.Commit return true }) + // sort committee by pool stake, then by address + sort.Slice(committee, func(i, j int) bool { + if committee[i].PoolStake == committee[j].PoolStake { + return committee[i].AddressBech32 < committee[j].AddressBech32 + } + return committee[i].PoolStake > committee[j].PoolStake + }) + return &api.CommitteeResponse{ Epoch: epoch, Committee: committee, From 688f982c704e50d70e69a9e7e397dd5dd6e37ddf Mon Sep 17 00:00:00 2001 From: Alexander Sporn Date: Fri, 8 Mar 2024 12:51:51 +0100 Subject: [PATCH 2/3] Fix error in validators endpoint --- components/restapi/core/accounts.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/restapi/core/accounts.go b/components/restapi/core/accounts.go index d94cef2ab..48f51361e 100644 --- a/components/restapi/core/accounts.go +++ b/components/restapi/core/accounts.go @@ -67,7 +67,7 @@ func validators(c echo.Context) (*api.ValidatorsResponse, error) { } slotRange := uint32(requestedSlot) / restapi.ParamsRestAPI.RequestsMemoryCacheGranularity - return deps.RequestHandler.Validators(slotRange, pageSize, cursorIndex) + return deps.RequestHandler.Validators(slotRange, cursorIndex, pageSize) } func validatorByAccountAddress(c echo.Context) (*api.ValidatorResponse, error) { From 05c4b432b743891d260403ed7501dcbf5d96aae7 Mon Sep 17 00:00:00 2001 From: Alexander Sporn Date: Fri, 8 Mar 2024 12:52:11 +0100 Subject: [PATCH 3/3] 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 })