From 879f1d0aaa6160a53f1b13d0bfbb4ca26214fb28 Mon Sep 17 00:00:00 2001 From: Philip Offtermatt Date: Thu, 16 May 2024 13:05:21 +0200 Subject: [PATCH] Start implementing unbonded validators for consumer chains --- x/ccv/provider/keeper/relay.go | 26 ++++++++++++++++++++++++-- x/ccv/types/expected_keepers.go | 1 + 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/x/ccv/provider/keeper/relay.go b/x/ccv/provider/keeper/relay.go index 230ed0a96a..15dcfcbcb7 100644 --- a/x/ccv/provider/keeper/relay.go +++ b/x/ccv/provider/keeper/relay.go @@ -217,8 +217,30 @@ func (k Keeper) SendVSCPacketsToChain(ctx sdk.Context, chainID, channelID string func (k Keeper) QueueVSCPackets(ctx sdk.Context) { valUpdateID := k.GetValidatorSetUpdateId(ctx) // current valset update ID - // get the bonded validators from the staking module - bondedValidators := k.stakingKeeper.GetLastValidators(ctx) + // get all validators from the staking module + validatorIterator := k.stakingKeeper.ValidatorsPowerStoreIterator(ctx) + + // get the first N validators + // TODO make this a param + maxTotalValidators := 500 + + validators := make([]stakingtypes.Validator, 0, maxTotalValidators) + defer validatorIterator.Close() + + i := 0 + for ; validatorIterator.Valid() && i < int(maxTotalValidators); validatorIterator.Next() { + address := validatorIterator.Value() + validator, found := k.stakingKeeper.GetValidatorByConsAddr(ctx, address) + if !found { + k.Logger(ctx).Error("validator not found", "address", address.String()) + continue + } + + if validator.IsBonded() { + validators[i] = validator + i++ + } + } for _, chain := range k.GetAllConsumerChains(ctx) { currentValidators := k.GetConsumerValSet(ctx, chain.ChainId) diff --git a/x/ccv/types/expected_keepers.go b/x/ccv/types/expected_keepers.go index b3815b6d65..d6219d9fc8 100644 --- a/x/ccv/types/expected_keepers.go +++ b/x/ccv/types/expected_keepers.go @@ -58,6 +58,7 @@ type StakingKeeper interface { GetRedelegationsFromSrcValidator(ctx sdk.Context, valAddr sdk.ValAddress) (reds []stakingtypes.Redelegation) GetUnbondingType(ctx sdk.Context, id uint64) (unbondingType stakingtypes.UnbondingType, found bool) MinCommissionRate(ctx sdk.Context) math.LegacyDec + ValidatorsPowerStoreIterator(ctx sdk.Context) sdk.Iterator } // SlashingKeeper defines the contract expected to perform ccv slashing