diff --git a/CHANGELOG.md b/CHANGELOG.md index 19752e8d335f..7ce8834c9be9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes +* (x/staking) [17062](https://github.com/cosmos/cosmos-sdk/pull/17062) Use collections for `ValidatorUpdates`: + * remove `Keeper`: `SetValidatorUpdates`, `GetValidatorUpdates` * (x/slashing) [17023](https://github.com/cosmos/cosmos-sdk/pull/17023) Use collections for `ValidatorSigningInfo`: * remove `Keeper`: `SetValidatorSigningInfo`, `GetValidatorSigningInfo`, `IterateValidatorSigningInfos` * (x/staking) [#17026](https://github.com/cosmos/cosmos-sdk/pull/17026) Use collections for `LastTotalPower`: diff --git a/x/staking/keeper/keeper.go b/x/staking/keeper/keeper.go index 8d4d85a786fb..35b04a8deb90 100644 --- a/x/staking/keeper/keeper.go +++ b/x/staking/keeper/keeper.go @@ -4,8 +4,6 @@ import ( "context" "fmt" - abci "github.com/cometbft/cometbft/abci/types" - "cosmossdk.io/collections" addresscodec "cosmossdk.io/core/address" storetypes "cosmossdk.io/core/store" @@ -34,8 +32,9 @@ type Keeper struct { validatorAddressCodec addresscodec.Codec consensusAddressCodec addresscodec.Codec - Schema collections.Schema - LastTotalPower collections.Item[math.Int] + Schema collections.Schema + LastTotalPower collections.Item[math.Int] + ValidatorUpdates collections.Item[types.ValidatorUpdates] } // NewKeeper creates a new staking Keeper instance @@ -77,6 +76,7 @@ func NewKeeper( validatorAddressCodec: validatorAddressCodec, consensusAddressCodec: consensusAddressCodec, LastTotalPower: collections.NewItem(sb, types.LastTotalPowerKey, "last_total_power", sdk.IntValue), + ValidatorUpdates: collections.NewItem(sb, types.ValidatorUpdatesKey, "validator_updates", codec.CollValue[types.ValidatorUpdates](cdc)), } schema, err := sb.Build() @@ -127,30 +127,3 @@ func (k Keeper) ValidatorAddressCodec() addresscodec.Codec { func (k Keeper) ConsensusAddressCodec() addresscodec.Codec { return k.consensusAddressCodec } - -// SetValidatorUpdates sets the ABCI validator power updates for the current block. -func (k Keeper) SetValidatorUpdates(ctx context.Context, valUpdates []abci.ValidatorUpdate) error { - store := k.storeService.OpenKVStore(ctx) - bz, err := k.cdc.Marshal(&types.ValidatorUpdates{Updates: valUpdates}) - if err != nil { - return err - } - return store.Set(types.ValidatorUpdatesKey, bz) -} - -// GetValidatorUpdates returns the ABCI validator power updates within the current block. -func (k Keeper) GetValidatorUpdates(ctx context.Context) ([]abci.ValidatorUpdate, error) { - store := k.storeService.OpenKVStore(ctx) - bz, err := store.Get(types.ValidatorUpdatesKey) - if err != nil { - return nil, err - } - - var valUpdates types.ValidatorUpdates - err = k.cdc.Unmarshal(bz, &valUpdates) - if err != nil { - return nil, err - } - - return valUpdates.Updates, nil -} diff --git a/x/staking/keeper/val_state_change.go b/x/staking/keeper/val_state_change.go index c59328554b7c..43f1f463353d 100644 --- a/x/staking/keeper/val_state_change.go +++ b/x/staking/keeper/val_state_change.go @@ -256,8 +256,9 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx context.Context) (updates } } + valUpdates := types.ValidatorUpdates{Updates: updates} // set the list of validator updates - if err = k.SetValidatorUpdates(ctx, updates); err != nil { + if err = k.ValidatorUpdates.Set(ctx, valUpdates); err != nil { return nil, err } diff --git a/x/staking/types/keys.go b/x/staking/types/keys.go index 9b1c7e63ec06..57689058c9ec 100644 --- a/x/staking/types/keys.go +++ b/x/staking/types/keys.go @@ -53,8 +53,8 @@ var ( RedelegationQueueKey = []byte{0x42} // prefix for the timestamps in redelegations queue ValidatorQueueKey = []byte{0x43} // prefix for the timestamps in validator queue - HistoricalInfoKey = []byte{0x50} // prefix for the historical info - ValidatorUpdatesKey = []byte{0x61} // prefix for the end block validator updates key + HistoricalInfoKey = []byte{0x50} // prefix for the historical info + ValidatorUpdatesKey = collections.NewPrefix(97) // prefix for the end block validator updates key ParamsKey = []byte{0x51} // prefix for parameters for module x/staking