diff --git a/proto/exocore/dogfood/v1/dogfood.proto b/proto/exocore/dogfood/v1/dogfood.proto index a6c62855c..8db8a9493 100644 --- a/proto/exocore/dogfood/v1/dogfood.proto +++ b/proto/exocore/dogfood/v1/dogfood.proto @@ -4,7 +4,6 @@ package exocore.dogfood.v1; import "gogoproto/gogo.proto"; import "google/protobuf/any.proto"; -import "google/protobuf/timestamp.proto"; import "cosmos/staking/v1beta1/staking.proto"; import "cosmos_proto/cosmos.proto"; @@ -53,15 +52,3 @@ message Validators { // list is the list of validators. repeated cosmos.staking.v1beta1.Validator list = 1 [(gogoproto.nullable) = false]; } - -// HeaderSubset is a subset of the block header that is relevant to the IBC codebase. It is -// stored for each height and then converted to the `tm.Header` object after queried. It is -// pruned when the information is no longer needed according to the `HistoricalEntries` param. -message HeaderSubset { - // timestamp of the block - google.protobuf.Timestamp time = 1 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true]; - // validators for the next block - bytes next_validators_hash = 2; - // state after txs from the previous block - bytes app_hash = 3; -} \ No newline at end of file diff --git a/x/dogfood/keeper/abci.go b/x/dogfood/keeper/abci.go index f6d45e3d9..dbee49584 100644 --- a/x/dogfood/keeper/abci.go +++ b/x/dogfood/keeper/abci.go @@ -11,10 +11,7 @@ import ( ) func (k Keeper) EndBlock(ctx sdk.Context) []abci.ValidatorUpdate { - id, _ := k.getValidatorSetID(ctx, ctx.BlockHeight()) if !k.IsEpochEnd(ctx) { - // save the same id for the next block height. - k.setValidatorSetID(ctx, ctx.BlockHeight()+1, id) return []abci.ValidatorUpdate{} } defer k.ClearEpochEnd(ctx) @@ -114,6 +111,7 @@ func (k Keeper) EndBlock(ctx sdk.Context) []abci.ValidatorUpdate { } // the remaining validators in prevMap have been removed. // we need to queue a change in power to 0 for them. + // we cannot iterate over the map to retain determinism, so we iterate over the list. for _, validator := range prevList { // O(N) // #nosec G703 // already checked in the previous iteration over prevList. pubKey, _ := validator.ConsPubKey() @@ -130,9 +128,9 @@ func (k Keeper) EndBlock(ctx sdk.Context) []abci.ValidatorUpdate { }) } } + // call via wrapper function so that validator info is stored. - // the id is incremented by 1 for the next block. - return k.ApplyValidatorChanges(ctx, res, id+1) + return k.ApplyValidatorChanges(ctx, res) } // sortByPower sorts operators, their pubkeys, and their powers by the powers. diff --git a/x/dogfood/keeper/genesis.go b/x/dogfood/keeper/genesis.go index fef402ef8..48b051978 100644 --- a/x/dogfood/keeper/genesis.go +++ b/x/dogfood/keeper/genesis.go @@ -58,7 +58,7 @@ func (k Keeper) InitGenesis( // ApplyValidatorChanges will sort it internally return k.ApplyValidatorChanges( - ctx, out, types.InitialValidatorSetID, + ctx, out, ) } diff --git a/x/dogfood/keeper/impl_evm.go b/x/dogfood/keeper/impl_evm.go new file mode 100644 index 000000000..676e6840d --- /dev/null +++ b/x/dogfood/keeper/impl_evm.go @@ -0,0 +1,40 @@ +package keeper + +import ( + "github.com/ExocoreNetwork/exocore/utils" + sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + erc20types "github.com/evmos/evmos/v14/x/erc20/types" + evmtypes "github.com/evmos/evmos/v14/x/evm/types" +) + +// interface guards +var ( + _ erc20types.StakingKeeper = Keeper{} + _ evmtypes.StakingKeeper = Keeper{} +) + +// GetValidatorByConsAddr is an implementation of the StakingKeeper interface +// expected by the EVM module. It returns a validator given a consensus address. +// The EVM module uses it to determine the proposer's AccAddress for the block. +// ConsAddress -> lookup AccAddress -> convert to ValAddress -> bech32ify. +// ValAddress string is then decoded back by the EVM module to get bytes, which +// make the 0x address of the coinbase. +func (k Keeper) GetValidatorByConsAddr( + ctx sdk.Context, consAddr sdk.ConsAddress, +) (validator stakingtypes.Validator, found bool) { + val := k.ValidatorByConsAddr(ctx, consAddr) + if val == nil { + return stakingtypes.Validator{}, false + } + return val.(stakingtypes.Validator), true +} + +// BondDenom is an implementation of the StakingKeeper interface expected by the +// ERC20 module. It returns the bond denom for the module. The ERC20 module uses +// this function to determine whether a token sent (or received) over IBC is the +// staking (==native) token. If it is, then the module lets the token through. +// That is the behavior we wish to retain with our chain as well. +func (k Keeper) BondDenom(sdk.Context) string { + return utils.BaseDenom +} diff --git a/x/dogfood/keeper/impl_sdk.go b/x/dogfood/keeper/impl_sdk.go index 5b342af5c..3d5c44c0f 100644 --- a/x/dogfood/keeper/impl_sdk.go +++ b/x/dogfood/keeper/impl_sdk.go @@ -1,11 +1,17 @@ package keeper import ( + "sort" + "cosmossdk.io/math" + operatortypes "github.com/ExocoreNetwork/exocore/x/operator/types" abci "github.com/cometbft/cometbft/abci/types" + tmtypes "github.com/cometbft/cometbft/types" + cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" genutiltypes "github.com/cosmos/cosmos-sdk/x/genutil/types" + govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" @@ -17,6 +23,7 @@ var ( _ evidencetypes.StakingKeeper = Keeper{} _ genutiltypes.StakingKeeper = Keeper{} _ clienttypes.StakingKeeper = Keeper{} // implemented in `validators.go` + _ govtypes.StakingKeeper = Keeper{} ) // GetParams is an implementation of the staking interface expected by the SDK's evidence @@ -61,9 +68,7 @@ func (k Keeper) ValidatorByConsAddr( ctx sdk.Context, addr sdk.ConsAddress, ) stakingtypes.ValidatorI { - return stakingtypes.Validator{ - Jailed: k.operatorKeeper.IsOperatorJailedForChainID(ctx, addr, ctx.ChainID()), - } + return k.operatorKeeper.ValidatorByConsAddrForChainID(ctx, addr, ctx.ChainID()) } // Slash is an implementation of the staking interface expected by the SDK's slashing module. @@ -158,3 +163,95 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates( ) (updates []abci.ValidatorUpdate, err error) { return } + +// IterateBondedValidatorsByPower is an implementation of the staking interface expected by +// the SDK's gov module. It is used to iterate through the validators by power. We do not +// implement this function intentionally, since our model of governance is not designed yet. +// Instead of staked tokens representing vote power for governance, the balance (or locked) +// balance of the native token (by operator or delegator) should be used. +// See interchain-security as a reference (although I did not understand some of it), +func (k Keeper) IterateBondedValidatorsByPower( + sdk.Context, func(int64, stakingtypes.ValidatorI) bool, +) { + // // we will have at most a 100 validators bonded. + // // so it is safe to load all of them up and then call. + // validators := k.GetAllExocoreValidators(ctx) + // sort.SliceStable(validators, func(i, j int) bool { + // return validators[i].Power > validators[j].Power + // }) + // for i, v := range validators { + // pk, err := v.ConsPubKey() + // if err != nil { + // // since we stored the validator in the first place, something like this + // // should never happen, but if it does it is an extremely grave error + // // that will result in a block mismatch and hence that node will halt. + // continue + // } + // val, err := stakingtypes.NewValidator(nil, pk, stakingtypes.Description{}) + // if err != nil { + // // same as above. + // continue + // } + + // // Set validator to bonded status + // val.Status = stakingtypes.Bonded + // // Compute tokens from voting power + // val.Tokens = sdk.TokensFromConsensusPower(v.Power, sdk.DefaultPowerReduction) + // // #nosec G701 // ok on 64-bit systems. + // if f(int64(i), val) { + // break + // } + // } + panic("unimplemented on this keeper") +} + +// TotalBondedTokens is an implementation of the staking interface expected by the SDK's +// gov module. See note above to understand why this is not implemented. +func (k Keeper) TotalBondedTokens(sdk.Context) math.Int { + panic("unimplemented on this keeper") +} + +// IterateDelegations is an implementation of the staking interface expected by the SDK's +// gov module. See note above to understand why this is not implemented. +func (k Keeper) IterateDelegations( + sdk.Context, sdk.AccAddress, + func(int64, stakingtypes.DelegationI) bool, +) { + panic("unimplemented on this keeper") +} + +func (k Keeper) WriteValidators(ctx sdk.Context) ([]tmtypes.GenesisValidator, error) { + validators := k.GetAllExocoreValidators(ctx) + sort.SliceStable(validators, func(i, j int) bool { + return validators[i].Power > validators[j].Power + }) + vals := make([]tmtypes.GenesisValidator, len(validators)) + var retErr error + for i, val := range validators { + pk, err := val.ConsPubKey() + if err != nil { + retErr = err + break + } + tmPk, err := cryptocodec.ToTmPubKeyInterface(pk) + if err != nil { + retErr = err + break + } + consAddress := sdk.GetConsAddress(pk) + found, addr := k.operatorKeeper.GetOperatorAddressForChainIDAndConsAddr( + ctx, ctx.ChainID(), consAddress, + ) + if !found { + retErr = operatortypes.ErrNoKeyInTheStore + break + } + vals[i] = tmtypes.GenesisValidator{ + Address: consAddress.Bytes(), + PubKey: tmPk, + Power: val.Power, + Name: addr.String(), // TODO + } + } + return vals, retErr +} diff --git a/x/dogfood/keeper/validators.go b/x/dogfood/keeper/validators.go index ed9f1b7d4..aa2394873 100644 --- a/x/dogfood/keeper/validators.go +++ b/x/dogfood/keeper/validators.go @@ -10,7 +10,6 @@ import ( "github.com/ExocoreNetwork/exocore/x/dogfood/types" abci "github.com/cometbft/cometbft/abci/types" - tmproto "github.com/cometbft/cometbft/proto/tendermint/types" cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec" sdk "github.com/cosmos/cosmos-sdk/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" @@ -36,7 +35,7 @@ func (k Keeper) UnbondingTime(ctx sdk.Context) time.Duration { // on the keeper to be executed. Lastly, it stores the validator set against the // provided validator set id. func (k Keeper) ApplyValidatorChanges( - ctx sdk.Context, changes []abci.ValidatorUpdate, valSetID uint64, + ctx sdk.Context, changes []abci.ValidatorUpdate, ) []abci.ValidatorUpdate { ret := []abci.ValidatorUpdate{} for _, change := range changes { @@ -90,26 +89,6 @@ func (k Keeper) ApplyValidatorChanges( ret = append(ret, change) } - // store the updated validator set against the provided validator set id - lastVals := types.Validators{} - for _, v := range k.GetAllExocoreValidators(ctx) { - // we stored the validators above, so this will never fail. - pubkey, _ := v.ConsPubKey() // #nosec G703 - // #nosec G703 // This calls NewAnyWithValue internally, which we have already done. - val, _ := stakingtypes.NewValidator( - nil, pubkey, stakingtypes.Description{}, - ) - // Set validator to bonded status - val.Status = stakingtypes.Bonded - // Compute tokens from voting power - val.Tokens = sdk.TokensFromConsensusPower(v.Power, sdk.DefaultPowerReduction) - lastVals.List = append(lastVals.List, val) - } - k.setValidatorSet(ctx, valSetID, &lastVals) - // this validator set is effective as of the next block, so use height + 1. - // this statement is true for genesis as well, since ctx.BlockHeight() is - // reported as 0 during InitGenesis. - k.setValidatorSetID(ctx, ctx.BlockHeight()+1, valSetID) // sort for determinism sort.Slice(ret, func(i, j int) bool { if ret[i].Power != ret[j].Power { @@ -168,78 +147,47 @@ func (k Keeper) GetAllExocoreValidators( return validators } -// GetHistoricalInfo gets the historical info at a given height. It is part of the -// implementation of the staking keeper expected by IBC. +// GetHistoricalInfo gets the historical info at a given height func (k Keeper) GetHistoricalInfo( ctx sdk.Context, height int64, ) (stakingtypes.HistoricalInfo, bool) { - headerSubset, found := k.getBlockHeader(ctx, height) - if !found { - // only panic in the case of an unmarshal error - return stakingtypes.HistoricalInfo{}, false - } - valSetID, found := k.getValidatorSetID(ctx, height) - if !found { - // only panic in the case of an unmarshal error - return stakingtypes.HistoricalInfo{}, false - } - valSet, found := k.getValidatorSet(ctx, valSetID) - if !found { - // only panic in the case of an unmarshal error + store := ctx.KVStore(k.storeKey) + key, _ := types.HistoricalInfoKey(height) + + value := store.Get(key) + if value == nil { return stakingtypes.HistoricalInfo{}, false } - header := tmproto.Header{ - Time: headerSubset.Time, - NextValidatorsHash: headerSubset.NextValidatorsHash, - AppHash: headerSubset.AppHash, - } - return stakingtypes.NewHistoricalInfo( - header, stakingtypes.Validators(valSet.GetList()), sdk.DefaultPowerReduction, - ), true + + return stakingtypes.MustUnmarshalHistoricalInfo(k.cdc, value), true } -// setValidatorSet sets the validator set at a given id. This is -// (intentionally) not exported in the genesis state. It can therefore -// be a private function. -func (k Keeper) setValidatorSet( - ctx sdk.Context, id uint64, vs *types.Validators, +// SetHistoricalInfo sets the historical info at a given height +func (k Keeper) SetHistoricalInfo( + ctx sdk.Context, height int64, hi *stakingtypes.HistoricalInfo, ) { store := ctx.KVStore(k.storeKey) - key := types.ValidatorSetKey(id) - value := k.cdc.MustMarshal(vs) + key, _ := types.HistoricalInfoKey(height) + value := k.cdc.MustMarshal(hi) + store.Set(key, value) } -// getValidatorSet gets the validator set at a given id. -func (k Keeper) getValidatorSet( - ctx sdk.Context, id uint64, -) (*types.Validators, bool) { +// DeleteHistoricalInfo deletes the historical info at a given height +func (k Keeper) DeleteHistoricalInfo(ctx sdk.Context, height int64) { store := ctx.KVStore(k.storeKey) - key := types.ValidatorSetKey(id) - if !store.Has(key) { - return nil, false - } - value := store.Get(key) - var hi types.Validators - k.cdc.MustUnmarshal(value, &hi) - return &hi, true -} + key, _ := types.HistoricalInfoKey(height) -// deleteValidatorSet deletes the validator set at a given id. -func (k Keeper) deleteValidatorSet(ctx sdk.Context, id uint64) { - store := ctx.KVStore(k.storeKey) - key := types.ValidatorSetKey(id) store.Delete(key) } // TrackHistoricalInfo saves the latest historical info and deletes the ones eligible to be -// pruned. The historical info is stored in two parts: one is the header and the other is the -// validator set. Within an epoch, the validator set will only change if there is a slashing -// event. Otherwise, it is constant. The header, however, will change at every block. Since -// the Cosmos SDK does not allow for the retrieval of a past block header, we store the header -// ourselves in this function. The validator set is stored when it changes at the end of an -// epoch or at a slashing event in the corresponding functions. The function is called within -// the EndBlock of the module, so it is kept public. +// pruned. The function is called within the EndBlock of the module, so it is kept public. +// It is mostly a copy of the function used by interchain-security. +// If the historical info were only used by IBC, this function would store a subset of the +// header for each block, since only those parts were used. +// However, the historical info is used by the EVM keeper as well, which hashes the full header +// to report it via Solidity to the caller. Therefore, the full header must be stored. func (k Keeper) TrackHistoricalInfo(ctx sdk.Context) { // Get the number of historical entries to persist, as the number of block heights. // #nosec G701 // uint32 fits into int64 always. @@ -248,48 +196,50 @@ func (k Keeper) TrackHistoricalInfo(ctx sdk.Context) { ) // we are deleting headers, say, from, 0 to 999 at block 1999 - // for these headers, we must find the corresponding validator set ids to delete. - // they must be only deleted if no other block is using them. - lastDeletedID := uint64(0) // contract: starts from 1. for i := ctx.BlockHeight() - numHistoricalEntries; i >= 0; i-- { - _, found := k.getBlockHeader(ctx, i) + _, found := k.GetHistoricalInfo(ctx, i) if found { - // because they are deleted together, and saved one after the other, - // since the block header exists, so must the validator set id. - lastDeletedID, _ = k.getValidatorSetID(ctx, i+1) - // clear both the header and the mapping - k.deleteBlockHeader(ctx, i) - k.deleteValidatorSetID(ctx, i) + k.DeleteHistoricalInfo(ctx, i) } else { break } } - // even if numHistoricalEntries is 0, this will work because it is called after the - // validatorSetID for height + 1 is stored. - // on the opposite side of things, if numHistoricalEntries is too large, currentID - // will be 0, and the loop will not run. - currentID, _ := k.getValidatorSetID(ctx, - ctx.BlockHeight()-numHistoricalEntries+1, - ) - // lastDeletedID will be the lowest deleted id since we are working backwards - // from the latest height to the oldest height. this, and upto but not including - // currentID, are the ids to delete. - for i := lastDeletedID; i < currentID; i++ { - k.deleteValidatorSet(ctx, i) - } // if there is no need to persist historicalInfo, return. if numHistoricalEntries == 0 { return } - // store the header - k.storeBlockHeader(ctx) + // Create HistoricalInfo struct + lastVals := []stakingtypes.Validator{} + for _, v := range k.GetAllExocoreValidators(ctx) { + pk, err := v.ConsPubKey() + if err != nil { + // since we stored the validator in the first place, something like this + // should never happen, but if it does it is an extremely grave error + // that will result in a block mismatch and hence that node will halt. + continue + } + val, err := stakingtypes.NewValidator(nil, pk, stakingtypes.Description{}) + if err != nil { + // same as above. + continue + } + + // Set validator to bonded status + val.Status = stakingtypes.Bonded + // Compute tokens from voting power + val.Tokens = sdk.TokensFromConsensusPower(v.Power, sdk.DefaultPowerReduction) + lastVals = append(lastVals, val) + } + + // Create historical info entry which sorts the validator set by voting power + historicalEntry := stakingtypes.NewHistoricalInfo( + ctx.BlockHeader(), lastVals, sdk.DefaultPowerReduction, + ) - // we have stored: - // outside of TrackHistoricalInfo: ValidatorSetID for height, and the validator set. - // within TrackHistoricalInfo: the header. - // this is enough information to answer the GetHistoricalInfo query. + // Set latest HistoricalInfo at current height + k.SetHistoricalInfo(ctx, ctx.BlockHeight(), &historicalEntry) } // MustGetCurrentValidatorsAsABCIUpdates gets all validators converted @@ -312,82 +262,6 @@ func (k Keeper) MustGetCurrentValidatorsAsABCIUpdates(ctx sdk.Context) []abci.Va } valUpdates = append(valUpdates, abci.ValidatorUpdate{PubKey: tmPK, Power: v.Power}) } - return valUpdates -} - -// getValidatorSetID returns the identifier of the validator set at a given height. -// It is used to "share" the validator set entries across multiple heights within an epoch. -// Typically, the validator set should change only at the end of an epoch. However, in the -// case of a slashing occurrence, the validator set may change within an epoch. This info -// is not exported in the genesis, so it is private. -func (k Keeper) getValidatorSetID(ctx sdk.Context, height int64) (uint64, bool) { - store := ctx.KVStore(k.storeKey) - key, ok := types.ValidatorSetIDKey(height) - if !ok { - return 0, false - } - value := store.Get(key) - if value == nil { - return 0, false - } - return sdk.BigEndianToUint64(value), true -} - -// setValidatorSetID sets the identifier of the validator set at a given height. -func (k Keeper) setValidatorSetID(ctx sdk.Context, height int64, id uint64) { - store := ctx.KVStore(k.storeKey) - // SetValidatorSetID is called with ctx.BlockHeight which Cosmos - // guarantees to be positive. - key, _ := types.ValidatorSetIDKey(height) - value := sdk.Uint64ToBigEndian(id) - store.Set(key, value) -} - -// deleteValidatorSetID deletes the identifier of the validator set at a given height. -func (k Keeper) deleteValidatorSetID(ctx sdk.Context, height int64) { - store := ctx.KVStore(k.storeKey) - // i don't care if we delete a key that is meaningless - key, _ := types.ValidatorSetIDKey(height) - store.Delete(key) -} - -// getBlockHeader returns the block header at a given height. It is called during IBC's -// GetHistoricalInfo call. Since it is an external call, we will validate that height -// should be non-negative. This info is not exported in the genesis, so it is private. -func (k Keeper) getBlockHeader(ctx sdk.Context, height int64) (types.HeaderSubset, bool) { - store := ctx.KVStore(k.storeKey) - key, ok := types.HeaderKey(height) - if !ok { - return types.HeaderSubset{}, false - } - value := store.Get(key) - if value == nil { - return types.HeaderSubset{}, false - } - var header types.HeaderSubset - k.cdc.MustUnmarshal(value, &header) - return header, true -} - -// deleteBlockHeader deletes the block header at a given height. -func (k Keeper) deleteBlockHeader(ctx sdk.Context, height int64) { - store := ctx.KVStore(k.storeKey) - // i don't care if we delete a key that is meaningless - key, _ := types.HeaderKey(height) - store.Delete(key) -} -// storeBlockHeader stores the block header subset as of the current height. -func (k Keeper) storeBlockHeader(ctx sdk.Context) { - // ctx.BlockHeight() is positive so we don't need to validate - key, _ := types.HeaderKey(ctx.BlockHeight()) - sdkHeader := ctx.BlockHeader() - header := types.HeaderSubset{ - Time: sdkHeader.Time, - NextValidatorsHash: sdkHeader.NextValidatorsHash, - AppHash: sdkHeader.GetAppHash(), - } - store := ctx.KVStore(k.storeKey) - value := k.cdc.MustMarshal(&header) - store.Set(key, value) + return valUpdates } diff --git a/x/dogfood/module.go b/x/dogfood/module.go index 5cc548046..36c8d81e4 100644 --- a/x/dogfood/module.go +++ b/x/dogfood/module.go @@ -81,7 +81,9 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes( clientCtx client.Context, mux *runtime.ServeMux, ) { - if err := types.RegisterQueryHandlerClient(context.Background(), mux, types.NewQueryClient(clientCtx)); err != nil { + if err := types.RegisterQueryHandlerClient( + context.Background(), mux, types.NewQueryClient(clientCtx), + ); err != nil { // this panic is safe to do because it means an error in setting up the module. panic(err) } @@ -159,7 +161,9 @@ func (am AppModule) ExportGenesis(ctx sdk.Context, cdc codec.JSONCodec) json.Raw func (AppModule) ConsensusVersion() uint64 { return 1 } // BeginBlock contains the logic that is automatically triggered at the beginning of each block -func (am AppModule) BeginBlock(_ sdk.Context, _ abci.RequestBeginBlock) {} +func (am AppModule) BeginBlock(ctx sdk.Context, _ abci.RequestBeginBlock) { + am.keeper.TrackHistoricalInfo(ctx) +} // EndBlock contains the logic that is automatically triggered at the end of each block func (am AppModule) EndBlock(ctx sdk.Context, _ abci.RequestEndBlock) []abci.ValidatorUpdate { diff --git a/x/dogfood/types/dogfood.pb.go b/x/dogfood/types/dogfood.pb.go index a2f921a52..53b91a0fb 100644 --- a/x/dogfood/types/dogfood.pb.go +++ b/x/dogfood/types/dogfood.pb.go @@ -10,19 +10,15 @@ import ( types1 "github.com/cosmos/cosmos-sdk/x/staking/types" _ "github.com/cosmos/gogoproto/gogoproto" proto "github.com/cosmos/gogoproto/proto" - github_com_cosmos_gogoproto_types "github.com/cosmos/gogoproto/types" - _ "google.golang.org/protobuf/types/known/timestamppb" io "io" math "math" math_bits "math/bits" - time "time" ) // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal var _ = fmt.Errorf var _ = math.Inf -var _ = time.Kitchen // This is a compile-time assertion to ensure that this generated file // is compatible with the proto package it is being compiled against. @@ -284,117 +280,44 @@ func (m *Validators) GetList() []types1.Validator { return nil } -// HeaderSubset is a subset of the block header that is relevant to the IBC codebase. It is -// stored for each height and then converted to the `tm.Header` object after queried. It is -// pruned when the information is no longer needed according to the `HistoricalEntries` param. -type HeaderSubset struct { - // timestamp of the block - Time time.Time `protobuf:"bytes,1,opt,name=time,proto3,stdtime" json:"time"` - // validators for the next block - NextValidatorsHash []byte `protobuf:"bytes,2,opt,name=next_validators_hash,json=nextValidatorsHash,proto3" json:"next_validators_hash,omitempty"` - // state after txs from the previous block - AppHash []byte `protobuf:"bytes,3,opt,name=app_hash,json=appHash,proto3" json:"app_hash,omitempty"` -} - -func (m *HeaderSubset) Reset() { *m = HeaderSubset{} } -func (m *HeaderSubset) String() string { return proto.CompactTextString(m) } -func (*HeaderSubset) ProtoMessage() {} -func (*HeaderSubset) Descriptor() ([]byte, []int) { - return fileDescriptor_071b9989c501c3f2, []int{5} -} -func (m *HeaderSubset) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *HeaderSubset) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_HeaderSubset.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *HeaderSubset) XXX_Merge(src proto.Message) { - xxx_messageInfo_HeaderSubset.Merge(m, src) -} -func (m *HeaderSubset) XXX_Size() int { - return m.Size() -} -func (m *HeaderSubset) XXX_DiscardUnknown() { - xxx_messageInfo_HeaderSubset.DiscardUnknown(m) -} - -var xxx_messageInfo_HeaderSubset proto.InternalMessageInfo - -func (m *HeaderSubset) GetTime() time.Time { - if m != nil { - return m.Time - } - return time.Time{} -} - -func (m *HeaderSubset) GetNextValidatorsHash() []byte { - if m != nil { - return m.NextValidatorsHash - } - return nil -} - -func (m *HeaderSubset) GetAppHash() []byte { - if m != nil { - return m.AppHash - } - return nil -} - func init() { proto.RegisterType((*ExocoreValidator)(nil), "exocore.dogfood.v1.ExocoreValidator") proto.RegisterType((*AccountAddresses)(nil), "exocore.dogfood.v1.AccountAddresses") proto.RegisterType((*ConsensusAddresses)(nil), "exocore.dogfood.v1.ConsensusAddresses") proto.RegisterType((*UndelegationRecordKeys)(nil), "exocore.dogfood.v1.UndelegationRecordKeys") proto.RegisterType((*Validators)(nil), "exocore.dogfood.v1.Validators") - proto.RegisterType((*HeaderSubset)(nil), "exocore.dogfood.v1.HeaderSubset") } func init() { proto.RegisterFile("exocore/dogfood/v1/dogfood.proto", fileDescriptor_071b9989c501c3f2) } var fileDescriptor_071b9989c501c3f2 = []byte{ - // 504 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x53, 0xcd, 0x6e, 0xd3, 0x40, - 0x10, 0xce, 0x92, 0x50, 0xaa, 0x4d, 0x0e, 0xd5, 0x2a, 0x82, 0x34, 0x07, 0x27, 0x44, 0x08, 0xe5, - 0x00, 0x36, 0x49, 0x2f, 0x08, 0x4e, 0x09, 0x42, 0x2a, 0x8a, 0x84, 0x90, 0xf9, 0x39, 0x70, 0x89, - 0xd6, 0xf6, 0xd4, 0xb1, 0x92, 0x78, 0x56, 0xde, 0x75, 0x1a, 0xbf, 0x45, 0x2f, 0x3c, 0x02, 0x6f, - 0xc0, 0x43, 0x54, 0x9c, 0x7a, 0xe4, 0x54, 0x50, 0xf2, 0x06, 0x3c, 0x01, 0x8a, 0x77, 0x37, 0x20, - 0x40, 0xbd, 0xcd, 0xe7, 0xef, 0x9b, 0xd9, 0x4f, 0xf3, 0x79, 0x68, 0x17, 0xd6, 0x18, 0x62, 0x06, - 0x5e, 0x84, 0xf1, 0x19, 0x62, 0xe4, 0xad, 0x06, 0xb6, 0x74, 0x45, 0x86, 0x0a, 0x19, 0x33, 0x0a, - 0xd7, 0x7e, 0x5e, 0x0d, 0xda, 0xcd, 0x18, 0x63, 0x2c, 0x69, 0x6f, 0x57, 0x69, 0x65, 0xfb, 0x38, - 0x46, 0x8c, 0x17, 0xe0, 0x95, 0x28, 0xc8, 0xcf, 0x3c, 0x9e, 0x16, 0x86, 0xea, 0xfc, 0x4d, 0xa9, - 0x64, 0x09, 0x52, 0xf1, 0xa5, 0x30, 0x82, 0x07, 0x21, 0xca, 0x25, 0x4a, 0x4f, 0x2a, 0x3e, 0x4f, - 0xd2, 0xd8, 0x5b, 0x0d, 0x02, 0x50, 0x7c, 0x60, 0xb1, 0x7d, 0x41, 0xab, 0xa6, 0xfa, 0x69, 0x0d, - 0x34, 0xd5, 0xfb, 0x4c, 0xe8, 0xd1, 0x4b, 0xed, 0xf4, 0x03, 0x5f, 0x24, 0x11, 0x57, 0x98, 0xb1, - 0x16, 0xbd, 0xc3, 0xa3, 0x28, 0x03, 0x29, 0x5b, 0xa4, 0x4b, 0xfa, 0x0d, 0xdf, 0x42, 0xd6, 0xa4, - 0xb7, 0x05, 0x9e, 0x43, 0xd6, 0xba, 0xd5, 0x25, 0xfd, 0xaa, 0xaf, 0x01, 0xe3, 0xf4, 0x40, 0xe4, - 0xc1, 0x1c, 0x8a, 0x56, 0xb5, 0x4b, 0xfa, 0xf5, 0x61, 0xd3, 0xd5, 0xbe, 0x5d, 0xeb, 0xdb, 0x1d, - 0xa5, 0xc5, 0xf8, 0xe4, 0xe7, 0x75, 0xe7, 0x5e, 0xc1, 0x97, 0x8b, 0x67, 0xbd, 0x10, 0x53, 0x09, - 0xa9, 0xcc, 0xe5, 0x54, 0xf7, 0xf5, 0xbe, 0x7e, 0x79, 0xdc, 0x34, 0xbe, 0xc2, 0xac, 0x10, 0x0a, - 0xdd, 0x37, 0x79, 0x30, 0x81, 0xc2, 0x37, 0x83, 0x7b, 0x0f, 0xe9, 0xd1, 0x28, 0x0c, 0x31, 0x4f, - 0xd5, 0x48, 0x5b, 0x01, 0xc9, 0x18, 0xad, 0x2d, 0x12, 0xa9, 0x5a, 0xa4, 0x5b, 0xed, 0x37, 0xfc, - 0xb2, 0xee, 0xf5, 0x29, 0x7b, 0x61, 0x87, 0xdf, 0xac, 0x7c, 0x44, 0xef, 0xbe, 0x4f, 0x23, 0x58, - 0x40, 0xcc, 0x55, 0x82, 0xa9, 0x0f, 0x21, 0x66, 0xd1, 0x04, 0x8a, 0xff, 0xab, 0x5f, 0x51, 0xba, - 0xdf, 0x8f, 0x64, 0xcf, 0xff, 0x50, 0xd4, 0x87, 0xf7, 0x5d, 0x63, 0xdd, 0x6e, 0xdd, 0xa4, 0xe0, - 0xee, 0x3b, 0xc6, 0xb5, 0xcb, 0xeb, 0x4e, 0xc5, 0x8c, 0xfa, 0x44, 0x68, 0xe3, 0x14, 0x78, 0x04, - 0xd9, 0xdb, 0x3c, 0x90, 0xa0, 0xd8, 0x53, 0x5a, 0xdb, 0xe5, 0x5a, 0xee, 0xba, 0x3e, 0x6c, 0xff, - 0xb3, 0xbc, 0x77, 0x36, 0xf4, 0xf1, 0xe1, 0x6e, 0xcc, 0xc5, 0xf7, 0x0e, 0xf1, 0xcb, 0x0e, 0xf6, - 0x84, 0x36, 0x53, 0x58, 0xab, 0xe9, 0x6a, 0x6f, 0x6d, 0x3a, 0xe3, 0x72, 0x56, 0xa6, 0xd3, 0xf0, - 0xd9, 0x8e, 0xfb, 0xed, 0xfa, 0x94, 0xcb, 0x19, 0x3b, 0xa6, 0x87, 0x5c, 0x08, 0xad, 0xaa, 0x9a, - 0x6c, 0x85, 0xd8, 0x51, 0xe3, 0xc9, 0xe5, 0xc6, 0x21, 0x57, 0x1b, 0x87, 0xfc, 0xd8, 0x38, 0xe4, - 0x62, 0xeb, 0x54, 0xae, 0xb6, 0x4e, 0xe5, 0xdb, 0xd6, 0xa9, 0x7c, 0x1c, 0xc4, 0x89, 0x9a, 0xe5, - 0x81, 0x1b, 0xe2, 0xd2, 0x33, 0x3f, 0xcb, 0x6b, 0x50, 0xe7, 0x98, 0xcd, 0x3d, 0x7b, 0x07, 0xeb, - 0xfd, 0x25, 0xa8, 0x42, 0x80, 0x0c, 0x0e, 0x4a, 0xf7, 0x27, 0xbf, 0x02, 0x00, 0x00, 0xff, 0xff, - 0x51, 0xed, 0x1d, 0xa0, 0x29, 0x03, 0x00, 0x00, + // 412 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x92, 0xc1, 0x6e, 0xd3, 0x40, + 0x10, 0x86, 0xb3, 0xa4, 0x14, 0x69, 0xdb, 0x43, 0xb5, 0x8a, 0xc0, 0xf4, 0xe0, 0x1a, 0x0b, 0x21, + 0x1f, 0x60, 0x57, 0x6e, 0x6f, 0x70, 0x4a, 0x10, 0x07, 0x14, 0x09, 0x21, 0x4b, 0x70, 0xe0, 0x52, + 0xad, 0xed, 0xa9, 0xb1, 0xe2, 0x78, 0xac, 0xdd, 0x75, 0xda, 0x7d, 0x0b, 0x5e, 0x82, 0x37, 0xe0, + 0x21, 0x2a, 0x4e, 0x3d, 0x72, 0x8a, 0x50, 0xf2, 0x06, 0x3c, 0x01, 0x22, 0xeb, 0x8d, 0x38, 0x20, + 0x6e, 0xf3, 0xef, 0xfc, 0xfb, 0xeb, 0xd3, 0xcc, 0xd0, 0x08, 0x6e, 0xb0, 0x40, 0x05, 0xa2, 0xc4, + 0xea, 0x0a, 0xb1, 0x14, 0xab, 0xd4, 0x97, 0xbc, 0x53, 0x68, 0x90, 0xb1, 0xc1, 0xc1, 0xfd, 0xf3, + 0x2a, 0x3d, 0x9d, 0x54, 0x58, 0xe1, 0xae, 0x2d, 0xfe, 0x54, 0xce, 0x79, 0xfa, 0xb8, 0x42, 0xac, + 0x1a, 0x10, 0x3b, 0x95, 0xf7, 0x57, 0x42, 0xb6, 0x76, 0x68, 0x3d, 0x2d, 0x50, 0x2f, 0x51, 0x0b, + 0x6d, 0xe4, 0xa2, 0x6e, 0x2b, 0xb1, 0x4a, 0x73, 0x30, 0x32, 0xf5, 0xda, 0x07, 0x38, 0xd7, 0xa5, + 0x4b, 0x76, 0xc2, 0xb5, 0xe2, 0xaf, 0x84, 0x9e, 0xbc, 0x71, 0x20, 0x1f, 0x65, 0x53, 0x97, 0xd2, + 0xa0, 0x62, 0x01, 0x7d, 0x20, 0xcb, 0x52, 0x81, 0xd6, 0x01, 0x89, 0x48, 0x72, 0x9c, 0x79, 0xc9, + 0x26, 0xf4, 0x7e, 0x87, 0xd7, 0xa0, 0x82, 0x7b, 0x11, 0x49, 0xc6, 0x99, 0x13, 0x4c, 0xd2, 0xc3, + 0xae, 0xcf, 0x17, 0x60, 0x83, 0x71, 0x44, 0x92, 0xa3, 0xf3, 0x09, 0x77, 0xc4, 0xdc, 0x13, 0xf3, + 0x69, 0x6b, 0x67, 0x17, 0xbf, 0xd6, 0x67, 0x8f, 0xac, 0x5c, 0x36, 0x2f, 0xe3, 0x02, 0x5b, 0x0d, + 0xad, 0xee, 0xf5, 0xa5, 0xfb, 0x17, 0x7f, 0xff, 0xf6, 0x62, 0x32, 0x70, 0x15, 0xca, 0x76, 0x06, + 0xf9, 0xfb, 0x3e, 0x9f, 0x83, 0xcd, 0x86, 0xe0, 0xf8, 0x19, 0x3d, 0x99, 0x16, 0x05, 0xf6, 0xad, + 0x99, 0x3a, 0x14, 0xd0, 0x8c, 0xd1, 0x83, 0xa6, 0xd6, 0x26, 0x20, 0xd1, 0x38, 0x39, 0xce, 0x76, + 0x75, 0x9c, 0x50, 0xf6, 0xda, 0x87, 0xff, 0xdf, 0xf9, 0x9c, 0x3e, 0xfc, 0xd0, 0x96, 0xd0, 0x40, + 0x25, 0x4d, 0x8d, 0x6d, 0x06, 0x05, 0xaa, 0x72, 0x0e, 0xf6, 0xdf, 0xee, 0xb7, 0x94, 0xee, 0xe7, + 0xa3, 0xd9, 0xab, 0xbf, 0x1c, 0x47, 0xe7, 0x4f, 0xf8, 0x80, 0xee, 0xa7, 0x3e, 0x6c, 0x81, 0xef, + 0x7f, 0xcc, 0x0e, 0x6e, 0xd7, 0x67, 0x23, 0x17, 0x35, 0x9b, 0xdf, 0x6e, 0x42, 0x72, 0xb7, 0x09, + 0xc9, 0xcf, 0x4d, 0x48, 0xbe, 0x6c, 0xc3, 0xd1, 0xdd, 0x36, 0x1c, 0xfd, 0xd8, 0x86, 0xa3, 0x4f, + 0x69, 0x55, 0x9b, 0xcf, 0x7d, 0xce, 0x0b, 0x5c, 0x8a, 0x61, 0x29, 0xef, 0xc0, 0x5c, 0xa3, 0x5a, + 0x08, 0x7f, 0x4e, 0x37, 0xfb, 0x83, 0x32, 0xb6, 0x03, 0x9d, 0x1f, 0xee, 0x46, 0x7c, 0xf1, 0x3b, + 0x00, 0x00, 0xff, 0xff, 0xbf, 0xcf, 0x53, 0x6a, 0x70, 0x02, 0x00, 0x00, } func (m *ExocoreValidator) Marshal() (dAtA []byte, err error) { @@ -577,51 +500,6 @@ func (m *Validators) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *HeaderSubset) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *HeaderSubset) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *HeaderSubset) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if len(m.AppHash) > 0 { - i -= len(m.AppHash) - copy(dAtA[i:], m.AppHash) - i = encodeVarintDogfood(dAtA, i, uint64(len(m.AppHash))) - i-- - dAtA[i] = 0x1a - } - if len(m.NextValidatorsHash) > 0 { - i -= len(m.NextValidatorsHash) - copy(dAtA[i:], m.NextValidatorsHash) - i = encodeVarintDogfood(dAtA, i, uint64(len(m.NextValidatorsHash))) - i-- - dAtA[i] = 0x12 - } - n2, err2 := github_com_cosmos_gogoproto_types.StdTimeMarshalTo(m.Time, dAtA[i-github_com_cosmos_gogoproto_types.SizeOfStdTime(m.Time):]) - if err2 != nil { - return 0, err2 - } - i -= n2 - i = encodeVarintDogfood(dAtA, i, uint64(n2)) - i-- - dAtA[i] = 0xa - return len(dAtA) - i, nil -} - func encodeVarintDogfood(dAtA []byte, offset int, v uint64) int { offset -= sovDogfood(v) base := offset @@ -713,25 +591,6 @@ func (m *Validators) Size() (n int) { return n } -func (m *HeaderSubset) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - l = github_com_cosmos_gogoproto_types.SizeOfStdTime(m.Time) - n += 1 + l + sovDogfood(uint64(l)) - l = len(m.NextValidatorsHash) - if l > 0 { - n += 1 + l + sovDogfood(uint64(l)) - } - l = len(m.AppHash) - if l > 0 { - n += 1 + l + sovDogfood(uint64(l)) - } - return n -} - func sovDogfood(x uint64) (n int) { return (math_bits.Len64(x|1) + 6) / 7 } @@ -1207,157 +1066,6 @@ func (m *Validators) Unmarshal(dAtA []byte) error { } return nil } -func (m *HeaderSubset) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDogfood - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: HeaderSubset: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: HeaderSubset: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Time", wireType) - } - var msglen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDogfood - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - msglen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if msglen < 0 { - return ErrInvalidLengthDogfood - } - postIndex := iNdEx + msglen - if postIndex < 0 { - return ErrInvalidLengthDogfood - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - if err := github_com_cosmos_gogoproto_types.StdTimeUnmarshal(&m.Time, dAtA[iNdEx:postIndex]); err != nil { - return err - } - iNdEx = postIndex - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field NextValidatorsHash", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDogfood - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthDogfood - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthDogfood - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.NextValidatorsHash = append(m.NextValidatorsHash[:0], dAtA[iNdEx:postIndex]...) - if m.NextValidatorsHash == nil { - m.NextValidatorsHash = []byte{} - } - iNdEx = postIndex - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field AppHash", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowDogfood - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= int(b&0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthDogfood - } - postIndex := iNdEx + byteLen - if postIndex < 0 { - return ErrInvalidLengthDogfood - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.AppHash = append(m.AppHash[:0], dAtA[iNdEx:postIndex]...) - if m.AppHash == nil { - m.AppHash = []byte{} - } - iNdEx = postIndex - default: - iNdEx = preIndex - skippy, err := skipDogfood(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthDogfood - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func skipDogfood(dAtA []byte) (n int, err error) { l := len(dAtA) iNdEx := 0 diff --git a/x/dogfood/types/expected_keepers.go b/x/dogfood/types/expected_keepers.go index b490fd855..11fb3e85c 100644 --- a/x/dogfood/types/expected_keepers.go +++ b/x/dogfood/types/expected_keepers.go @@ -51,6 +51,9 @@ type OperatorKeeper interface { sdk.Context, sdk.AccAddress, int64, int64, sdk.Dec, stakingtypes.Infraction, ) math.Int + ValidatorByConsAddrForChainID( + ctx sdk.Context, consAddr sdk.ConsAddress, chainID string, + ) stakingtypes.ValidatorI } // DelegationKeeper represents the expected keeper interface for the delegation module. diff --git a/x/dogfood/keeper/hooks.go b/x/dogfood/types/hooks.go similarity index 79% rename from x/dogfood/keeper/hooks.go rename to x/dogfood/types/hooks.go index cfbd66959..577c8f5a1 100644 --- a/x/dogfood/keeper/hooks.go +++ b/x/dogfood/types/hooks.go @@ -1,21 +1,20 @@ -package keeper +package types import ( - "github.com/ExocoreNetwork/exocore/x/dogfood/types" sdk "github.com/cosmos/cosmos-sdk/types" ) // interface guard -var _ types.DogfoodHooks = &MultiDogfoodHooks{} +var _ DogfoodHooks = &MultiDogfoodHooks{} // MultiDogfoodHooks is a collection of DogfoodHooks. It calls the hook for each element in the // collection one-by-one. The hook is called in the order in which the collection is created. -type MultiDogfoodHooks []types.DogfoodHooks +type MultiDogfoodHooks []DogfoodHooks // NewMultiDogfoodHooks is used to create a collective object of dogfood hooks from a list of // the hooks. It follows the "accept interface, return concrete types" philosophy. Other modules // may set the hooks by calling k := (*k).SetHooks(NewMultiDogfoodHooks(hookI)) -func NewMultiDogfoodHooks(hooks ...types.DogfoodHooks) MultiDogfoodHooks { +func NewMultiDogfoodHooks(hooks ...DogfoodHooks) MultiDogfoodHooks { return hooks } diff --git a/x/dogfood/types/keys.go b/x/dogfood/types/keys.go index 849b5ec54..3a7e78a20 100644 --- a/x/dogfood/types/keys.go +++ b/x/dogfood/types/keys.go @@ -12,9 +12,6 @@ const ( StoreKey = ModuleName ) -// InitialValidatorSetID is the initial validator set id. -const InitialValidatorSetID = uint64(1) - const ( // ExocoreValidatorBytePrefix is the prefix for the validator store. ExocoreValidatorBytePrefix byte = iota + 1 @@ -54,20 +51,11 @@ const ( // mature at the end of the current block. PendingUndelegationsByte - // ValidatorSetBytePrefix is the prefix for the historical validator set store. - ValidatorSetBytePrefix - - // ValidatorSetIDBytePrefix is the prefix for the validator set id store. - ValidatorSetIDBytePrefix - - // HeaderBytePrefix is the prefix for the header store. - HeaderBytePrefix - // EpochEndByte is the byte key for the epoch end store. EpochEndByte - // KeyPowerMappingByte is the byte key for the consensus key to vote power mapping store. - KeyPowerMappingByte + // HistoricalInfoBytePrefix is the byte prefix for the historical info store. + HistoricalInfoBytePrefix ) // ExocoreValidatorKey returns the key for the validator store. @@ -75,36 +63,6 @@ func ExocoreValidatorKey(address sdk.AccAddress) []byte { return append([]byte{ExocoreValidatorBytePrefix}, address.Bytes()...) } -// ValidatorSetKey returns the key for the historical validator set store. -func ValidatorSetKey(id uint64) []byte { - bz := sdk.Uint64ToBigEndian(id) - return append([]byte{ValidatorSetBytePrefix}, bz...) -} - -// ValidatorSetIDKey returns the key for the validator set id store. -func ValidatorSetIDKey(height int64) ([]byte, bool) { - uheight, ok := SafeInt64ToUint64(height) - if !ok { - return nil, false - } - return append( - []byte{ValidatorSetIDBytePrefix}, - sdk.Uint64ToBigEndian(uheight)..., - ), true -} - -// HeaderKey returns the key for the header store. -func HeaderKey(height int64) ([]byte, bool) { - uheight, ok := SafeInt64ToUint64(height) - if !ok { - return nil, false - } - return append( - []byte{HeaderBytePrefix}, - sdk.Uint64ToBigEndian(uheight)..., - ), true -} - // QueuedOperationsKey returns the key for the queued operations store. func QueuedOperationsKey() []byte { return []byte{QueuedOperationsByte} @@ -181,11 +139,6 @@ func EpochEndKey() []byte { return []byte{EpochEndByte} } -// KeyPowerMappingKey returns the key for the consensus key to vote power mapping store. -func KeyPowerMappingKey() []byte { - return []byte{KeyPowerMappingByte} -} - // SafeInt64ToUint64 is a wrapper function to convert an int64 // to a uint64. It returns (0, false) if the conversion is not possible. // This is safe as long as the int64 is non-negative. @@ -195,3 +148,14 @@ func SafeInt64ToUint64(id int64) (uint64, bool) { } return uint64(id), true // #nosec G701 // already checked. } + +// HistoricalInfoKey returns the key to historical info to a given block height +func HistoricalInfoKey(height int64) ([]byte, bool) { + uheight, ok := SafeInt64ToUint64(height) + if !ok { + return nil, false + } + return append( + []byte{HistoricalInfoBytePrefix}, sdk.Uint64ToBigEndian(uheight)..., + ), true +} diff --git a/x/operator/keeper/consensus_keys.go b/x/operator/keeper/consensus_keys.go index 8e188a673..125e210e8 100644 --- a/x/operator/keeper/consensus_keys.go +++ b/x/operator/keeper/consensus_keys.go @@ -3,15 +3,15 @@ package keeper import ( "fmt" - "github.com/ExocoreNetwork/exocore/x/operator/types" - errorsmod "cosmossdk.io/errors" "github.com/cometbft/cometbft/libs/log" sdk "github.com/cosmos/cosmos-sdk/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" assetstypes "github.com/ExocoreNetwork/exocore/x/assets/types" delegationtypes "github.com/ExocoreNetwork/exocore/x/delegation/types" + "github.com/ExocoreNetwork/exocore/x/operator/types" tmprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto" ) @@ -456,3 +456,19 @@ func (k *Keeper) GetActiveOperatorsForChainID( } return activeOperator, activePks } + +func (k *Keeper) ValidatorByConsAddrForChainID( + ctx sdk.Context, consAddr sdk.ConsAddress, chainID string, +) stakingtypes.ValidatorI { + found, operatorAddr := k.GetOperatorAddressForChainIDAndConsAddr( + ctx, chainID, consAddr, + ) + if !found { + return stakingtypes.Validator{} + } + jailed := k.IsOperatorJailedForChainID(ctx, consAddr, chainID) + return stakingtypes.Validator{ + Jailed: jailed, + OperatorAddress: sdk.ValAddress(operatorAddr).String(), + } +}