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

Problem: hard fork logic don't check for chain-id #204

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func NewSimApp(
appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.ModuleAccountAddrs(),
)
stakingKeeper := stakingkeeper.NewKeeper(
appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName), 0,
appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName), nil,
)
app.MintKeeper = mintkeeper.NewKeeper(
appCodec, keys[minttypes.StoreKey], app.GetSubspace(minttypes.ModuleName), &stakingKeeper,
Expand Down
2 changes: 1 addition & 1 deletion x/auth/migrations/v043/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ func createValidator(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers i
app.AccountKeeper,
app.BankKeeper,
app.GetSubspace(stakingtypes.ModuleName),
0,
nil,
)

val1, err := stakingtypes.NewValidator(valAddrs[0], pks[0], stakingtypes.Description{})
Expand Down
2 changes: 1 addition & 1 deletion x/gov/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers
app.AccountKeeper,
app.BankKeeper,
app.GetSubspace(stakingtypes.ModuleName),
0,
nil,
)

val1, err := stakingtypes.NewValidator(valAddrs[0], pks[0], stakingtypes.Description{})
Expand Down
2 changes: 1 addition & 1 deletion x/staking/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func getBaseSimappWithCustomKeeper(t *testing.T) (*codec.LegacyAmino, *simapp.Si
app.AccountKeeper,
app.BankKeeper,
app.GetSubspace(types.ModuleName),
0,
nil,
)
app.StakingKeeper.SetParams(ctx, types.DefaultParams())

Expand Down
2 changes: 1 addition & 1 deletion x/staking/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func createTestInput(t *testing.T) (*codec.LegacyAmino, *simapp.SimApp, sdk.Cont
app.AccountKeeper,
app.BankKeeper,
app.GetSubspace(types.ModuleName),
0,
nil,
)
return app.LegacyAmino(), app, ctx
}
Expand Down
2 changes: 1 addition & 1 deletion x/staking/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@ func createValidators(t *testing.T, ctx sdk.Context, app *simapp.SimApp, powers
app.AccountKeeper,
app.BankKeeper,
app.GetSubspace(types.ModuleName),
0,
nil,
)

val1 := teststaking.NewValidator(t, valAddrs[0], pks[0])
Expand Down
14 changes: 11 additions & 3 deletions x/staking/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ type Keeper struct {
hooks types.StakingHooks
paramstore paramtypes.Subspace

hardForkHeight int64
// forkEnabledFunc returns true if the forked logic should be enabled.
// see: https://github.com/advisories/GHSA-86h5-xcpx-cfqc
forkEnabledFunc func(sdk.Context) bool
}

// NewKeeper creates a new staking Keeper instance
func NewKeeper(
cdc codec.BinaryCodec, key storetypes.StoreKey, ak types.AccountKeeper, bk types.BankKeeper,
ps paramtypes.Subspace,
hardForkHeight int64,
forkEnabledFunc func(sdk.Context) bool,
) Keeper {
// set KeyTable if it has not already been set
if !ps.HasKeyTable() {
Expand All @@ -51,6 +53,12 @@ func NewKeeper(
panic(fmt.Sprintf("%s module account has not been set", types.NotBondedPoolName))
}

if forkEnabledFunc == nil {
forkEnabledFunc = func(sdk.Context) bool {
return false
}
}

return Keeper{
storeKey: key,
cdc: cdc,
Expand All @@ -59,7 +67,7 @@ func NewKeeper(
paramstore: ps,
hooks: nil,

hardForkHeight: hardForkHeight,
forkEnabledFunc: forkEnabledFunc,
}
}

Expand Down
2 changes: 1 addition & 1 deletion x/staking/keeper/slash.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (k Keeper) SlashRedelegation(ctx sdk.Context, srcValidator types.Validator,
panic(err)
}

if k.hardForkHeight >= ctx.BlockHeight() {
if k.forkEnabledFunc(ctx) {
// Handle undelegation after redelegation
// Prioritize slashing unbondingDelegation than delegation
unbondingDelegation, found := k.GetUnbondingDelegation(ctx, sdk.MustAccAddressFromBech32(redelegation.DelegatorAddress), valDstAddr)
Expand Down
Loading