refactor(x/staking): migrate ValidatorUpdates to collections (#17062)
This commit is contained in:
parent
c6926b6193
commit
535d711e7f
@ -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`:
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user