Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
julienrbrt committed Mar 25, 2024
1 parent 3b3ef30 commit a9d390b
Show file tree
Hide file tree
Showing 14 changed files with 945 additions and 974 deletions.
122 changes: 62 additions & 60 deletions api/cosmos/staking/v1beta1/staking.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions x/staking/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* remove from `types`: `GetUnbondingTypeKey`.
* [#17063](https://github.com/cosmos/cosmos-sdk/pull/17063) Use collections for `HistoricalInfo`:
* remove `Keeper`: `GetHistoricalInfo`, `SetHistoricalInfo`
* [#17062](https://github.com/cosmos/cosmos-sdk/pull/17062) Use collections for `ValidatorUpdates`:
* remove `Keeper`: `SetValidatorUpdates`, `GetValidatorUpdates`
* [#17062](https://github.com/cosmos/cosmos-sdk/pull/17062), [#19788](https://github.com/cosmos/cosmos-sdk/pull/19788) Remove `GetValidatorUpdates` and `ValidatorUpdates` storage.
* [#17026](https://github.com/cosmos/cosmos-sdk/pull/17026) Use collections for `LastTotalPower`:
* remove `Keeper`: `SetLastTotalPower`, `GetLastTotalPower`
* [#17335](https://github.com/cosmos/cosmos-sdk/pull/17335) Remove usage of `"cosmossdk.io/x/staking/types".Infraction_*` in favour of `"cosmossdk.io/api/cosmos/staking/v1beta1".Infraction_` in order to remove dependency between modules on staking
Expand Down
8 changes: 0 additions & 8 deletions x/staking/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ network.
* [State](#state)
* [Pool](#pool)
* [LastTotalPower](#lasttotalpower)
* [ValidatorUpdates](#validatorupdates)
* [UnbondingID](#unbondingid)
* [Params](#params)
* [Validator](#validator)
Expand Down Expand Up @@ -75,13 +74,6 @@ Store entries prefixed with "Last" must remain unchanged until EndBlock.

* LastTotalPower: `0x12 -> ProtocolBuffer(math.Int)`

### ValidatorUpdates

ValidatorUpdates contains the validator updates returned to ABCI at the end of every block.
The values are overwritten in every block.

* ValidatorUpdates `0x61 -> []abci.ValidatorUpdate`

### UnbondingID

UnbondingID stores the ID of the latest unbonding operation. It enables creating unique IDs for unbonding operations, i.e., UnbondingID is incremented every time a new unbonding operation (validator unbonding, unbonding delegation, redelegation) is initiated.
Expand Down
47 changes: 0 additions & 47 deletions x/staking/keeper/keeper.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keeper

import (
"encoding/json"
"fmt"
"time"

Expand Down Expand Up @@ -42,49 +41,6 @@ func HistoricalInfoCodec(cdc codec.BinaryCodec) collcodec.ValueCodec[types.Histo
})
}

type moduleValidatorUpdatesCodec struct {
cdc codec.BinaryCodec
}

// Decode implements codec.ValueCodec.
func (m moduleValidatorUpdatesCodec) Decode(b []byte) (types.ModuleValidatorUpdates, error) {
var mvu types.ModuleValidatorUpdates
if err := json.Unmarshal(b, &mvu); err != nil {
return types.ModuleValidatorUpdates{}, err
}

return mvu, nil
}

// DecodeJSON implements codec.ValueCodec.
func (m moduleValidatorUpdatesCodec) DecodeJSON(b []byte) (types.ModuleValidatorUpdates, error) {
return m.Decode(b)
}

// Encode implements codec.ValueCodec.
func (m moduleValidatorUpdatesCodec) Encode(value types.ModuleValidatorUpdates) ([]byte, error) {
return json.Marshal(value)
}

// EncodeJSON implements codec.ValueCodec.
func (m moduleValidatorUpdatesCodec) EncodeJSON(value types.ModuleValidatorUpdates) ([]byte, error) {
return m.Encode(value)
}

// Stringify implements codec.ValueCodec.
func (m moduleValidatorUpdatesCodec) Stringify(value types.ModuleValidatorUpdates) string {
return fmt.Sprintf("%v", value)
}

// ValueType implements codec.ValueCodec.
func (m moduleValidatorUpdatesCodec) ValueType() string {
return "types.ModuleValidatorUpdates"
}

func ValidatorUpdateCodec(cdc codec.BinaryCodec) collcodec.ValueCodec[types.ModuleValidatorUpdates] {
return moduleValidatorUpdatesCodec{cdc}
}

type rotationHistoryIndexes struct {
Block *indexes.Multi[uint64, collections.Pair[[]byte, uint64], types.ConsPubKeyRotationHistory]
}
Expand Down Expand Up @@ -127,8 +83,6 @@ type Keeper struct {
HistoricalInfo collections.Map[uint64, types.HistoricalRecord]
// LastTotalPower value: LastTotalPower
LastTotalPower collections.Item[math.Int]
// ValidatorUpdates value: ValidatorUpdates
ValidatorUpdates collections.Item[types.ModuleValidatorUpdates]
// DelegationsByValidator key: valAddr+delAddr | value: none used (index key for delegations by validator index)
DelegationsByValidator collections.Map[collections.Pair[sdk.ValAddress, sdk.AccAddress], []byte]
UnbondingID collections.Sequence
Expand Down Expand Up @@ -215,7 +169,6 @@ func NewKeeper(
consensusAddressCodec: consensusAddressCodec,
LastTotalPower: collections.NewItem(sb, types.LastTotalPowerKey, "last_total_power", sdk.IntValue),
HistoricalInfo: collections.NewMap(sb, types.HistoricalInfoKey, "historical_info", collections.Uint64Key, HistoricalInfoCodec(cdc)),
ValidatorUpdates: collections.NewItem(sb, types.ValidatorUpdatesKey, "validator_updates", ValidatorUpdateCodec(cdc)),
Delegations: collections.NewMap(
sb, types.DelegationKey, "delegations",
collections.PairKeyCodec(
Expand Down
7 changes: 7 additions & 0 deletions x/staking/keeper/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"

v5 "cosmossdk.io/x/staking/migrations/v5"
v6 "cosmossdk.io/x/staking/migrations/v6"

"github.com/cosmos/cosmos-sdk/runtime"
)
Expand Down Expand Up @@ -40,3 +41,9 @@ func (m Migrator) Migrate4to5(ctx context.Context) error {
store := runtime.KVStoreAdapter(m.keeper.environment.KVStoreService.OpenKVStore(ctx))
return v5.MigrateStore(ctx, store, m.keeper.cdc, m.keeper.Logger())
}

// Migrate4to5 migrates x/staking state from consensus version 5 to 6.
func (m Migrator) Migrate5to6(ctx context.Context) error {
store := runtime.KVStoreAdapter(m.keeper.environment.KVStoreService.OpenKVStore(ctx))
return v6.MigrateStore(ctx, store, m.keeper.cdc)
}
9 changes: 0 additions & 9 deletions x/staking/keeper/val_state_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,6 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx context.Context) ([]appmod

for _, history := range historyObjects {
valAddr := history.OperatorAddress
if err != nil {
return nil, err
}

validator, err := k.GetValidator(ctx, valAddr)
if err != nil {
return nil, err
Expand Down Expand Up @@ -327,11 +323,6 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx context.Context) ([]appmod
}
}

// set the list of validator updates
if err = k.ValidatorUpdates.Set(ctx, updates); err != nil {
return nil, err
}

return updates, err
}

Expand Down
4 changes: 2 additions & 2 deletions x/staking/migrations/v5/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
)

func migrateDelegationsByValidatorIndex(ctx context.Context, store storetypes.KVStore, cdc codec.BinaryCodec) error {
func migrateDelegationsByValidatorIndex(store storetypes.KVStore) error {
iterator := storetypes.KVStorePrefixIterator(store, DelegationKey)

for ; iterator.Valid(); iterator.Next() {
Expand All @@ -31,7 +31,7 @@ func migrateDelegationsByValidatorIndex(ctx context.Context, store storetypes.KV

// MigrateStore performs in-place store migrations from v4 to v5.
func MigrateStore(ctx context.Context, store storetypes.KVStore, cdc codec.BinaryCodec, logger log.Logger) error {
if err := migrateDelegationsByValidatorIndex(ctx, store, cdc); err != nil {
if err := migrateDelegationsByValidatorIndex(store); err != nil {
return err
}
return migrateHistoricalInfoKeys(store, logger)
Expand Down
5 changes: 5 additions & 0 deletions x/staking/migrations/v6/keys.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package v6

import "cosmossdk.io/collections"

var ValidatorUpdatesKey = collections.NewPrefix(97)
16 changes: 16 additions & 0 deletions x/staking/migrations/v6/store.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package v6

import (
"context"

storetypes "cosmossdk.io/store/types"

"github.com/cosmos/cosmos-sdk/codec"
)

// MigrateStore performs in-place store migrations from v5 to v6.
// It deletes the ValidatorUpdatesKey from the store.
func MigrateStore(ctx context.Context, store storetypes.KVStore, cdc codec.BinaryCodec) error {
store.Delete(ValidatorUpdatesKey)
return nil
}
Loading

0 comments on commit a9d390b

Please sign in to comment.