refactor: x/staking 0.47 audit (#14303)
This commit is contained in:
parent
aba4e6efb3
commit
b17c2d902e
@ -1,9 +1,10 @@
|
||||
package keeper_test
|
||||
|
||||
import (
|
||||
"cosmossdk.io/math"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/testutil"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
@ -3,13 +3,13 @@ package keeper
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
"github.com/tendermint/tendermint/libs/log"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
@ -49,7 +49,7 @@ func NewKeeper(
|
||||
|
||||
// ensure that authority is a valid AccAddress
|
||||
if _, err := sdk.AccAddressFromBech32(authority); err != nil {
|
||||
panic(("authority is not a valid acc address"))
|
||||
panic("authority is not a valid acc address")
|
||||
}
|
||||
|
||||
return &Keeper{
|
||||
@ -68,16 +68,17 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
|
||||
}
|
||||
|
||||
// Hooks gets the hooks for staking *Keeper {
|
||||
func (keeper *Keeper) Hooks() types.StakingHooks {
|
||||
if keeper.hooks == nil {
|
||||
func (k *Keeper) Hooks() types.StakingHooks {
|
||||
if k.hooks == nil {
|
||||
// return a no-op implementation if no hooks are set
|
||||
return types.MultiStakingHooks{}
|
||||
}
|
||||
|
||||
return keeper.hooks
|
||||
return k.hooks
|
||||
}
|
||||
|
||||
// SetHooks Set the validator hooks
|
||||
// SetHooks Set the validator hooks. In contrast to other receivers, this method must take a pointer due to nature
|
||||
// of the hooks interface and SDK start up sequence.
|
||||
func (k *Keeper) SetHooks(sh types.StakingHooks) {
|
||||
if k.hooks != nil {
|
||||
panic("cannot set validator hooks twice")
|
||||
|
||||
@ -3,23 +3,23 @@ package keeper_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/suite"
|
||||
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
||||
tmtime "github.com/tendermint/tendermint/types/time"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/baseapp"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
||||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
|
||||
simtestutil "github.com/cosmos/cosmos-sdk/testutil/sims"
|
||||
moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil"
|
||||
stakingtestutil "github.com/cosmos/cosmos-sdk/x/staking/testutil"
|
||||
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@ -5,17 +5,15 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
|
||||
"github.com/armon/go-metrics"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
|
||||
"github.com/armon/go-metrics"
|
||||
|
||||
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
|
||||
"github.com/cosmos/cosmos-sdk/telemetry"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
|
||||
@ -9,7 +9,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
// UnbondingTime
|
||||
// UnbondingTime - The time duration for unbonding
|
||||
func (k Keeper) UnbondingTime(ctx sdk.Context) time.Duration {
|
||||
return k.GetParams(ctx).UnbondingTime
|
||||
}
|
||||
|
||||
@ -8,7 +8,7 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
|
||||
// Increments and returns a unique ID for an unbonding operation
|
||||
// IncrementUnbondingID increments and returns a unique ID for an unbonding operation
|
||||
func (k Keeper) IncrementUnbondingID(ctx sdk.Context) (unbondingID uint64) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
bz := store.Get(types.UnbondingIDKey)
|
||||
@ -27,7 +27,7 @@ func (k Keeper) IncrementUnbondingID(ctx sdk.Context) (unbondingID uint64) {
|
||||
return unbondingID
|
||||
}
|
||||
|
||||
// Remove a mapping from UnbondingId to unbonding operation
|
||||
// DeleteUnbondingIndex removes a mapping from UnbondingId to unbonding operation
|
||||
func (k Keeper) DeleteUnbondingIndex(ctx sdk.Context, id uint64) {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
store.Delete(types.GetUnbondingIndexKey(id))
|
||||
|
||||
@ -5,10 +5,11 @@ import (
|
||||
"fmt"
|
||||
"sort"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
gogotypes "github.com/cosmos/gogoproto/types"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
|
||||
"cosmossdk.io/math"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
)
|
||||
@ -309,7 +310,7 @@ func (k Keeper) bondValidator(ctx sdk.Context, validator types.Validator) (types
|
||||
return validator, err
|
||||
}
|
||||
|
||||
// perform all the store operations for when a validator begins unbonding
|
||||
// BeginUnbondingValidator performs all the store operations for when a validator begins unbonding
|
||||
func (k Keeper) BeginUnbondingValidator(ctx sdk.Context, validator types.Validator) (types.Validator, error) {
|
||||
params := k.GetParams(ctx)
|
||||
|
||||
|
||||
@ -4,6 +4,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
storetypes "github.com/cosmos/cosmos-sdk/store/types"
|
||||
"github.com/cosmos/cosmos-sdk/testutil"
|
||||
@ -14,7 +16,6 @@ import (
|
||||
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||
v4 "github.com/cosmos/cosmos-sdk/x/staking/migrations/v4"
|
||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
type mockSubspace struct {
|
||||
|
||||
@ -66,14 +66,14 @@ const (
|
||||
UnbondingType_ValidatorUnbonding
|
||||
)
|
||||
|
||||
// Returns a key for an index containing the type of unbonding operations
|
||||
// GetUnbondingTypeKey returns a key for an index containing the type of unbonding operations
|
||||
func GetUnbondingTypeKey(id uint64) []byte {
|
||||
bz := make([]byte, 8)
|
||||
binary.BigEndian.PutUint64(bz, id)
|
||||
return append(UnbondingTypeKey, bz...)
|
||||
}
|
||||
|
||||
// Returns a key for the index for looking up UnbondingDelegations by the UnbondingDelegationEntries they contain
|
||||
// GetUnbondingIndexKey returns a key for the index for looking up UnbondingDelegations by the UnbondingDelegationEntries they contain
|
||||
func GetUnbondingIndexKey(id uint64) []byte {
|
||||
bz := make([]byte, 8)
|
||||
binary.BigEndian.PutUint64(bz, id)
|
||||
|
||||
@ -403,8 +403,8 @@ func (msg MsgCancelUnbondingDelegation) ValidateBasic() error {
|
||||
|
||||
// GetSignBytes returns the raw bytes for a MsgUpdateParams message that
|
||||
// the expected signer needs to sign.
|
||||
func (m MsgUpdateParams) GetSignBytes() []byte {
|
||||
bz := ModuleCdc.MustMarshalJSON(&m)
|
||||
func (m *MsgUpdateParams) GetSignBytes() []byte {
|
||||
bz := ModuleCdc.MustMarshalJSON(m)
|
||||
return sdk.MustSortJSON(bz)
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user