Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(staking)!: remove historical info #20845

Merged
merged 15 commits into from
Jul 5, 2024
10 changes: 2 additions & 8 deletions x/staking/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Bug Fixes

* [#20688](https://github.com/cosmos/cosmos-sdk/pull/20688) Avoid overslashing unbonding delegations after a redelegation.
* [#19226](https://github.com/cosmos/cosmos-sdk/pull/19226) Ensure `GetLastValidators` in `x/staking` does not return an error when `MaxValidators` exceeds total number of bonded validators.

### Features

Expand All @@ -42,9 +43,6 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#18636](https://github.com/cosmos/cosmos-sdk/pull/18636) `IterateBondedValidatorsByPower`, `GetDelegatorBonded`, `Delegate`, `Unbond`, `Slash`, `Jail`, `SlashRedelegation`, `ApplyAndReturnValidatorSetUpdates` methods no longer panics on any kind of errors but instead returns appropriate errors.
* [#18506](https://github.com/cosmos/cosmos-sdk/pull/18506) Detect the length of the ed25519 pubkey in CreateValidator to prevent panic.

### Bug Fixes

* [#19226](https://github.com/cosmos/cosmos-sdk/pull/19226) Ensure `GetLastValidators` in `x/staking` does not return an error when `MaxValidators` exceeds total number of bonded validators.

### API Breaking Changes

Expand Down Expand Up @@ -92,20 +90,16 @@ Ref: https://keepachangelog.com/en/1.0.0/
* remove from `types`: `GetValidatorByConsAddrKey`
* [#17248](https://github.com/cosmos/cosmos-sdk/pull/17248) Use collections for `UnbondingType`.
* 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), [#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
* [#17655](https://github.com/cosmos/cosmos-sdk/pull/17655) `QueryHistoricalInfo` was adjusted to return `HistoricalRecord` and marked `Hist` as deprecated.
* [#20295](https://github.com/cosmos/cosmos-sdk/pull/20295) `GetValidatorByConsAddr` now returns the Cosmos SDK `cryptotypes.Pubkey` instead of `cometcrypto.Publickey`. The caller is responsible to translate the returned value to the expected type.
* Remove `CmtConsPublicKey()` and `TmConsPublicKey()` from `Validator` interface and as methods on the `Validator` struct.
* [#20728](https://github.com/cosmos/cosmos-sdk/pull/20728) Remove `NewHistoricalInfo` and related functions to Historical Info & `GetCmtConsPubKey`, `ToCmtValidator` & `ToCmtValidators` as comet validator type is no longer used in the staking module.

### State Breaking changes

* [#18841](https://github.com/cosmos/cosmos-sdk/pull/18841) In a undelegation or redelegation if the shares being left delegated correspond to less than 1 token (in base denom) the entire delegation gets removed.
* [#18142](https://github.com/cosmos/cosmos-sdk/pull/18142) Introduce `key_rotation_fee` param to calculate fees while rotating the keys
* [#17655](https://github.com/cosmos/cosmos-sdk/pull/17655) `HistoricalInfo` was replaced with `HistoricalRecord`, it removes the validator set and comet header and only keep what is needed for IBC.
* [#19740](https://github.com/cosmos/cosmos-sdk/pull/19740) `InitGenesis` and `ExportGenesis` module code and keeper code do not panic but return errors.
* [#20845](https://github.com/cosmoc/cosmos-sdk/pull/20845) Remove HistoricalInfo from the staking modules storage
7 changes: 0 additions & 7 deletions x/staking/keeper/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ import (
"github.com/cosmos/cosmos-sdk/telemetry"
)

// BeginBlocker will persist the current header and validator set as a historical entry
// and prune the oldest entry based on the HistoricalEntries parameter
func (k *Keeper) BeginBlocker(ctx context.Context) error {
defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyBeginBlocker)
return k.TrackHistoricalInfo(ctx)
}

// EndBlocker called at every block, update validator set
func (k *Keeper) EndBlocker(ctx context.Context) ([]appmodule.ValidatorUpdate, error) {
start := telemetry.Now()
Expand Down
11 changes: 1 addition & 10 deletions x/staking/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,16 +409,7 @@ func (k Querier) HistoricalInfo(ctx context.Context, req *types.QueryHistoricalI
return nil, status.Error(codes.InvalidArgument, "empty request")
}

if req.Height < 0 {
return nil, status.Error(codes.InvalidArgument, "height cannot be negative")
}

hi, err := k.Keeper.HistoricalInfo.Get(ctx, uint64(req.Height))
if err != nil {
return nil, status.Errorf(codes.NotFound, "historical info for height %d not found", req.Height)
}

return &types.QueryHistoricalInfoResponse{HistoricalRecord: &hi}, nil
return nil, status.Error(codes.Internal, "this endpoint has been deprecated and removed in 0.52")
}

// Redelegations queries redelegations of given address
Expand Down
53 changes: 0 additions & 53 deletions x/staking/keeper/historical_info.go

This file was deleted.

173 changes: 0 additions & 173 deletions x/staking/keeper/historical_info_test.go

This file was deleted.

19 changes: 0 additions & 19 deletions x/staking/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,6 @@ var _ types.ValidatorSet = Keeper{}
// Implements DelegationSet interface
var _ types.DelegationSet = Keeper{}

func HistoricalInfoCodec(cdc codec.BinaryCodec) collcodec.ValueCodec[types.HistoricalRecord] {
return collcodec.NewAltValueCodec(codec.CollValue[types.HistoricalRecord](cdc), func(b []byte) (types.HistoricalRecord, error) {
historicalinfo := types.HistoricalInfo{} //nolint: staticcheck // HistoricalInfo is deprecated
err := historicalinfo.Unmarshal(b)
if err != nil {
return types.HistoricalRecord{}, err
}

return types.HistoricalRecord{
Apphash: historicalinfo.Header.AppHash,
Time: &historicalinfo.Header.Time,
ValidatorsHash: historicalinfo.Header.NextValidatorsHash,
}, nil
})
}

type rotationHistoryIndexes struct {
Block *indexes.Multi[uint64, collections.Pair[[]byte, uint64], types.ConsPubKeyRotationHistory]
}
Expand Down Expand Up @@ -81,8 +65,6 @@ type Keeper struct {

Schema collections.Schema

// HistoricalInfo key: Height | value: HistoricalInfo
HistoricalInfo collections.Map[uint64, types.HistoricalRecord]
// LastTotalPower value: LastTotalPower
LastTotalPower collections.Item[math.Int]
// DelegationsByValidator key: valAddr+delAddr | value: none used (index key for delegations by validator index)
Expand Down Expand Up @@ -172,7 +154,6 @@ func NewKeeper(
consensusAddressCodec: consensusAddressCodec,
cometInfoService: cometInfoService,
LastTotalPower: collections.NewItem(sb, types.LastTotalPowerKey, "last_total_power", sdk.IntValue),
HistoricalInfo: collections.NewMap(sb, types.HistoricalInfoKey, "historical_info", collections.Uint64Key, HistoricalInfoCodec(cdc)),
Delegations: collections.NewMap(
sb, types.DelegationKey, "delegations",
collections.PairKeyCodec(
Expand Down
5 changes: 4 additions & 1 deletion x/staking/migrations/v6/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ package v6

import "cosmossdk.io/collections"

var ValidatorUpdatesKey = collections.NewPrefix(97)
var (
ValidatorUpdatesKey = collections.NewPrefix(97)
HistoricalInfoKey = collections.NewPrefix(80) // prefix for the historical info
)
1 change: 1 addition & 0 deletions x/staking/migrations/v6/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ import (
// It deletes the ValidatorUpdatesKey from the store.
func MigrateStore(ctx context.Context, store storetypes.KVStore, cdc codec.BinaryCodec) error {
store.Delete(ValidatorUpdatesKey)
store.Delete(HistoricalInfoKey)
return nil
}
6 changes: 0 additions & 6 deletions x/staking/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ var (
_ module.HasABCIEndBlock = AppModule{}

_ appmodule.AppModule = AppModule{}
_ appmodule.HasBeginBlocker = AppModule{}
_ appmodule.HasServices = AppModule{}
_ appmodule.HasMigrations = AppModule{}
_ appmodule.HasRegisterInterfaces = AppModule{}
Expand Down Expand Up @@ -171,11 +170,6 @@ func (am AppModule) ExportGenesis(ctx context.Context) (json.RawMessage, error)
// ConsensusVersion implements HasConsensusVersion
func (AppModule) ConsensusVersion() uint64 { return consensusVersion }

// BeginBlock returns the begin blocker for the staking module.
func (am AppModule) BeginBlock(ctx context.Context) error {
return am.keeper.BeginBlocker(ctx)
}

// EndBlock returns the end blocker for the staking module.
func (am AppModule) EndBlock(ctx context.Context) ([]appmodule.ValidatorUpdate, error) {
return am.keeper.EndBlocker(ctx)
Expand Down
3 changes: 3 additions & 0 deletions x/staking/proto/cosmos/staking/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ service Query {

// HistoricalInfo queries the historical info for given height.
rpc HistoricalInfo(QueryHistoricalInfoRequest) returns (QueryHistoricalInfoResponse) {
option deprecated = true;
option (cosmos.query.v1.module_query_safe) = true;
option (google.api.http).get = "/cosmos/staking/v1beta1/historical_info/{height}";
}
Expand Down Expand Up @@ -367,13 +368,15 @@ message QueryDelegatorValidatorResponse {
// QueryHistoricalInfoRequest is request type for the Query/HistoricalInfo RPC
// method.
message QueryHistoricalInfoRequest {
option deprecated = true;
// height defines at which height to query the historical info.
int64 height = 1;
}

// QueryHistoricalInfoResponse is response type for the Query/HistoricalInfo RPC
// method.
message QueryHistoricalInfoResponse {
option deprecated = true;
// hist defines the historical info at the given height.
HistoricalInfo hist = 1 [deprecated = true];
HistoricalRecord historical_record = 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Expand Down
Loading
Loading