From 5f72a2c466e412ce018f9c06dd3bc73679b1e9a3 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 19 Jun 2024 12:54:16 -0600 Subject: [PATCH] dont double unmarshal validator --- x/gov/testutil/expected_keepers_mocks.go | 6 +++--- x/slashing/keeper/infractions.go | 4 ++-- x/slashing/testutil/expected_keepers_mocks.go | 14 -------------- x/slashing/types/expected_keepers.go | 3 --- x/staking/keeper/validator.go | 9 --------- 5 files changed, 5 insertions(+), 31 deletions(-) diff --git a/x/gov/testutil/expected_keepers_mocks.go b/x/gov/testutil/expected_keepers_mocks.go index 63f03d9d5fd3..fe64420f1b6d 100644 --- a/x/gov/testutil/expected_keepers_mocks.go +++ b/x/gov/testutil/expected_keepers_mocks.go @@ -131,7 +131,7 @@ func (m *MockBankKeeper) EXPECT() *MockBankKeeperMockRecorder { } // AddSupplyOffset mocks base method. -func (m *MockBankKeeper) AddSupplyOffset(ctx types.Context, denom string, offsetAmount types.Int) { +func (m *MockBankKeeper) AddSupplyOffset(ctx types.Context, denom string, offsetAmount math.Int) { m.ctrl.T.Helper() m.ctrl.Call(m, "AddSupplyOffset", ctx, denom, offsetAmount) } @@ -493,10 +493,10 @@ func (mr *MockBankKeeperMockRecorder) GetSupply(ctx, denom interface{}) *gomock. } // GetSupplyOffset mocks base method. -func (m *MockBankKeeper) GetSupplyOffset(ctx types.Context, denom string) types.Int { +func (m *MockBankKeeper) GetSupplyOffset(ctx types.Context, denom string) math.Int { m.ctrl.T.Helper() ret := m.ctrl.Call(m, "GetSupplyOffset", ctx, denom) - ret0, _ := ret[0].(types.Int) + ret0, _ := ret[0].(math.Int) return ret0 } diff --git a/x/slashing/keeper/infractions.go b/x/slashing/keeper/infractions.go index cc5fd5e7db8d..7bfb4b495d96 100644 --- a/x/slashing/keeper/infractions.go +++ b/x/slashing/keeper/infractions.go @@ -23,7 +23,8 @@ func (k Keeper) HandleValidatorSignatureWithParams(ctx sdk.Context, params types consAddr := sdk.ConsAddress(addr) // don't update missed blocks when validator's jailed - if k.sk.IsValidatorJailed(ctx, consAddr) { + validator := k.sk.ValidatorByConsAddr(ctx, consAddr) + if validator.IsJailed() { return } @@ -112,7 +113,6 @@ func (k Keeper) HandleValidatorSignatureWithParams(ctx sdk.Context, params types // if we are past the minimum height and the validator has missed too many blocks, punish them if height > minHeight && signInfo.MissedBlocksCounter > maxMissed { modifiedSignInfo = true - validator := k.sk.ValidatorByConsAddr(ctx, consAddr) if validator != nil && !validator.IsJailed() { // Downtime confirmed: slash and jail the validator // We need to retrieve the stake distribution which signed the block, so we subtract ValidatorUpdateDelay from the evidence height, diff --git a/x/slashing/testutil/expected_keepers_mocks.go b/x/slashing/testutil/expected_keepers_mocks.go index 86d57c5e2d68..e4654b633f73 100644 --- a/x/slashing/testutil/expected_keepers_mocks.go +++ b/x/slashing/testutil/expected_keepers_mocks.go @@ -281,20 +281,6 @@ func (mr *MockStakingKeeperMockRecorder) GetAllValidators(ctx interface{}) *gomo return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "GetAllValidators", reflect.TypeOf((*MockStakingKeeper)(nil).GetAllValidators), ctx) } -// IsValidatorJailed mocks base method. -func (m *MockStakingKeeper) IsValidatorJailed(ctx types.Context, addr types.ConsAddress) bool { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "IsValidatorJailed", ctx, addr) - ret0, _ := ret[0].(bool) - return ret0 -} - -// IsValidatorJailed indicates an expected call of IsValidatorJailed. -func (mr *MockStakingKeeperMockRecorder) IsValidatorJailed(ctx, addr interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "IsValidatorJailed", reflect.TypeOf((*MockStakingKeeper)(nil).IsValidatorJailed), ctx, addr) -} - // IterateValidators mocks base method. func (m *MockStakingKeeper) IterateValidators(arg0 types.Context, arg1 func(int64, types2.ValidatorI) bool) { m.ctrl.T.Helper() diff --git a/x/slashing/types/expected_keepers.go b/x/slashing/types/expected_keepers.go index b506b4450de5..4bc3131c81c6 100644 --- a/x/slashing/types/expected_keepers.go +++ b/x/slashing/types/expected_keepers.go @@ -53,9 +53,6 @@ type StakingKeeper interface { // MaxValidators returns the maximum amount of bonded validators MaxValidators(sdk.Context) uint32 - - // IsValidatorJailed returns if the validator is jailed. - IsValidatorJailed(ctx sdk.Context, addr sdk.ConsAddress) bool } // StakingHooks event hooks for staking validator object (noalias) diff --git a/x/staking/keeper/validator.go b/x/staking/keeper/validator.go index d1315ed7793f..d336f64030fb 100644 --- a/x/staking/keeper/validator.go +++ b/x/staking/keeper/validator.go @@ -476,12 +476,3 @@ func (k Keeper) UnbondAllMatureValidators(ctx sdk.Context) { } } } - -func (k Keeper) IsValidatorJailed(ctx sdk.Context, addr sdk.ConsAddress) bool { - v, ok := k.GetValidatorByConsAddr(ctx, addr) - if !ok { - return false - } - - return v.Jailed -}