refactor!: deprecate blocktime on context (#17738)
This commit is contained in:
@@ -152,7 +152,7 @@ func (k Keeper) HandleValidatorSignature(ctx context.Context, addr cryptotypes.A
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
signInfo.JailedUntil = sdkCtx.BlockHeader().Time.Add(downtimeJailDur)
|
||||
signInfo.JailedUntil = sdkCtx.HeaderInfo().Time.Add(downtimeJailDur)
|
||||
|
||||
// We need to reset the counter & bitmap so that the validator won't be
|
||||
// immediately slashed for downtime upon re-bonding.
|
||||
|
||||
@@ -3,13 +3,13 @@ package keeper_test
|
||||
import (
|
||||
"encoding/binary"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
|
||||
cmttime "github.com/cometbft/cometbft/types/time"
|
||||
"github.com/golang/mock/gomock"
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
st "cosmossdk.io/api/cosmos/staking/v1beta1"
|
||||
"cosmossdk.io/core/header"
|
||||
sdkmath "cosmossdk.io/math"
|
||||
storetypes "cosmossdk.io/store/types"
|
||||
|
||||
@@ -46,7 +46,7 @@ func (s *KeeperTestSuite) SetupTest() {
|
||||
s.key = key
|
||||
storeService := runtime.NewKVStoreService(key)
|
||||
testCtx := sdktestutil.DefaultContextWithDB(s.T(), key, storetypes.NewTransientStoreKey("transient_test"))
|
||||
ctx := testCtx.Ctx.WithBlockHeader(cmtproto.Header{Time: cmttime.Now()})
|
||||
ctx := testCtx.Ctx.WithHeaderInfo(header.Info{Time: time.Now().Round(0).UTC()})
|
||||
encCfg := moduletestutil.MakeTestEncodingConfig()
|
||||
|
||||
// gomock initializations
|
||||
|
||||
@@ -267,7 +267,7 @@ func (s *KeeperTestSuite) TestUnjail() {
|
||||
s.Require().NoError(err)
|
||||
|
||||
info := slashingtypes.NewValidatorSigningInfo(sdk.ConsAddress(addr), int64(4), int64(3),
|
||||
s.ctx.BlockTime().AddDate(0, 0, 1), false, int64(10))
|
||||
s.ctx.HeaderInfo().Time.AddDate(0, 0, 1), false, int64(10))
|
||||
|
||||
s.Require().NoError(s.slashingKeeper.ValidatorSigningInfo.Set(s.ctx, sdk.ConsAddress(addr), info))
|
||||
s.stakingKeeper.EXPECT().Validator(s.ctx, valAddr).Return(val, nil)
|
||||
@@ -303,7 +303,7 @@ func (s *KeeperTestSuite) TestUnjail() {
|
||||
del := types.NewDelegation(addr.String(), valAddr.String(), sdkmath.LegacyNewDec(100))
|
||||
|
||||
s.stakingKeeper.EXPECT().Delegation(s.ctx, addr, valAddr).Return(del, nil)
|
||||
s.stakingKeeper.EXPECT().Unjail(s.ctx, sdk.ConsAddress(addr)).Return(nil)
|
||||
s.stakingKeeper.EXPECT().Unjail(s.ctx, sdk.ConsAddress(addr)).Return(nil).AnyTimes()
|
||||
|
||||
return &slashingtypes.MsgUnjail{
|
||||
ValidatorAddr: sdk.ValAddress(addr).String(),
|
||||
|
||||
@@ -64,7 +64,7 @@ func (k Keeper) Unjail(ctx context.Context, validatorAddr sdk.ValAddress) error
|
||||
|
||||
// cannot be unjailed until out of jail
|
||||
sdkCtx := sdk.UnwrapSDKContext(ctx)
|
||||
if sdkCtx.BlockHeader().Time.Before(info.JailedUntil) {
|
||||
if sdkCtx.HeaderInfo().Time.Before(info.JailedUntil) {
|
||||
return types.ErrValidatorJailed
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,13 +138,13 @@ func SimulateMsgUnjail(
|
||||
// - validator is still in jailed period
|
||||
// - self delegation too low
|
||||
if info.Tombstoned ||
|
||||
ctx.BlockHeader().Time.Before(info.JailedUntil) ||
|
||||
ctx.HeaderInfo().Time.Before(info.JailedUntil) ||
|
||||
validator.TokensFromShares(selfDel.GetShares()).TruncateInt().LT(validator.GetMinSelfDelegation()) {
|
||||
if res != nil && err == nil {
|
||||
if info.Tombstoned {
|
||||
return simtypes.NewOperationMsg(msg, true, ""), nil, errors.New("validator should not have been unjailed if validator tombstoned")
|
||||
}
|
||||
if ctx.BlockHeader().Time.Before(info.JailedUntil) {
|
||||
if ctx.HeaderInfo().Time.Before(info.JailedUntil) {
|
||||
return simtypes.NewOperationMsg(msg, true, ""), nil, errors.New("validator unjailed while validator still in jail period")
|
||||
}
|
||||
if validator.TokensFromShares(selfDel.GetShares()).TruncateInt().LT(validator.GetMinSelfDelegation()) {
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
"cosmossdk.io/collections"
|
||||
"cosmossdk.io/core/header"
|
||||
"cosmossdk.io/depinject"
|
||||
"cosmossdk.io/log"
|
||||
"cosmossdk.io/math"
|
||||
@@ -153,7 +154,7 @@ func (suite *SimTestSuite) TestWeightedOperations() {
|
||||
// Abonormal scenarios, where the message is created by an errors, are not tested here.
|
||||
func (suite *SimTestSuite) TestSimulateMsgUnjail() {
|
||||
blockTime := time.Now().UTC()
|
||||
ctx := suite.ctx.WithBlockTime(blockTime)
|
||||
ctx := suite.ctx.WithHeaderInfo(header.Info{Time: blockTime})
|
||||
|
||||
// setup accounts[0] as validator0
|
||||
validator0, err := getTestingValidator0(ctx, suite.stakingKeeper, suite.accounts)
|
||||
|
||||
Reference in New Issue
Block a user