Skip to content
Open
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ This patch update also includes minor dependency bumps.

## [v0.53.0](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.53.0) - 2025-04-29

### Improvements

* (x/staking) [#25486](https://github.com/cosmos/cosmos-sdk/pull/25486) Optimize staking endblocker execution by caching queue entries from iterators.

### Breaking Changes

Expand Down
2 changes: 1 addition & 1 deletion proto/cosmos/staking/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -384,4 +384,4 @@ message QueryParamsRequest {}
message QueryParamsResponse {
// params holds all the parameters of this module.
Params params = 1 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}
}
14 changes: 14 additions & 0 deletions server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ type MempoolConfig struct {
MaxTxs int `mapstructure:"max-txs"`
}

// StakingConfig defines the staking module configuration
type StakingConfig struct {
// CacheSize defines the maximum number of time-based queue entries to cache
// for unbonding validators, unbonding delegations, and redelegations.
// cache-size = 0 means unlimited cache (no size limit).
// cache-size < 0 means the cache is disabled.
// cache-size > 0 sets a size limit for the cache.
CacheSize int `mapstructure:"cache-size"`
}

// State Streaming configuration
type (
// StreamingConfig defines application configuration for external streaming services
Expand All @@ -197,6 +207,7 @@ type Config struct {
StateSync StateSyncConfig `mapstructure:"state-sync"`
Streaming StreamingConfig `mapstructure:"streaming"`
Mempool MempoolConfig `mapstructure:"mempool"`
Staking StakingConfig `mapstructure:"staking"`
}

// SetMinGasPrices sets the validator's minimum gas prices.
Expand Down Expand Up @@ -269,6 +280,9 @@ func DefaultConfig() *Config {
Mempool: MempoolConfig{
MaxTxs: -1,
},
Staking: StakingConfig{
CacheSize: 0,
},
}
}

Expand Down
12 changes: 12 additions & 0 deletions server/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,18 @@ stop-node-on-err = {{ .Streaming.ABCI.StopNodeOnErr }}
# Note, this configuration only applies to SDK built-in app-side mempool
# implementations.
max-txs = {{ .Mempool.MaxTxs }}

###############################################################################
### Modules ###
###############################################################################

[staking]
# cache-size defines the maximum number of time-based queue entries to cache
# for unbonding validators, unbonding delegations, and redelegations.
# cache-size = 0 means unlimited cache (no size limit).
# cache-size < 0 means the cache is disabled.
# cache-size > 0 sets a size limit for the cache.
cache-size = {{ .Staking.CacheSize }}
`

var configTemplate *template.Template
Expand Down
4 changes: 4 additions & 0 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ const (

FlagMempoolMaxTxs = "mempool.max-txs"

// staking flags //nolint: revive // we can ignore this, to be consistent with the other flags' comments
FlagStakingCacheSize = "staking.cache-size"

// testnet keys

KeyIsTestnet = "is-testnet"
Expand Down Expand Up @@ -998,6 +1001,7 @@ func addStartNodeFlags(cmd *cobra.Command, opts StartCmdOptions) {
cmd.Flags().Uint32(FlagStateSyncSnapshotKeepRecent, 2, "State sync snapshot to keep")
cmd.Flags().Bool(FlagDisableIAVLFastNode, false, "Disable fast node for IAVL tree")
cmd.Flags().Int(FlagMempoolMaxTxs, mempool.DefaultMaxTx, "Sets MaxTx value for the app-side mempool")
cmd.Flags().Int(FlagStakingCacheSize, 0, "Sets the cache size for staking unbonding queues (0 = unlimited, negative = disabled)")
cmd.Flags().Duration(FlagShutdownGrace, 0*time.Second, "On Shutdown, duration to wait for resource clean up")

// support old flags name for backwards compatibility
Expand Down
3 changes: 3 additions & 0 deletions simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ func NewSimApp(
}
app.txConfig = txConfig

stakingCacheSize := cast.ToInt(appOpts.Get(server.FlagStakingCacheSize))

app.StakingKeeper = stakingkeeper.NewKeeper(
appCodec,
runtime.NewKVStoreService(keys[stakingtypes.StoreKey]),
Expand All @@ -327,6 +329,7 @@ func NewSimApp(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
authcodec.NewBech32Codec(sdk.Bech32PrefixValAddr),
authcodec.NewBech32Codec(sdk.Bech32PrefixConsAddr),
stakingCacheSize,
)
app.MintKeeper = mintkeeper.NewKeeper(
appCodec,
Expand Down
6 changes: 6 additions & 0 deletions simapp/app_di.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"

dbm "github.com/cosmos/cosmos-db"
"github.com/spf13/cast"

clienthelpers "cosmossdk.io/client/v2/helpers"
"cosmossdk.io/depinject"
Expand Down Expand Up @@ -91,6 +92,10 @@ func init() {
}
}

func ProvideStakingCacheSize(appOpts servertypes.AppOptions) int {
return cast.ToInt(appOpts.Get(server.FlagStakingCacheSize))
}

// NewSimApp returns a reference to an initialized SimApp.
func NewSimApp(
logger log.Logger,
Expand Down Expand Up @@ -152,6 +157,7 @@ func NewSimApp(
// custom minting function that implements the mintkeeper.MintFn
// interface.
),
depinject.Provide(ProvideStakingCacheSize),
)
)

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/distribution/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func initFixture(tb testing.TB) *fixture {
log.NewNopLogger(),
)

stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), 0)

distrKeeper := distrkeeper.NewKeeper(
cdc, runtime.NewKVStoreService(keys[distrtypes.StoreKey]), accountKeeper, bankKeeper, stakingKeeper, distrtypes.ModuleName, authority.String(),
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/evidence/keeper/infraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func initFixture(tb testing.TB) *fixture {
log.NewNopLogger(),
)

stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), 0)

slashingKeeper := slashingkeeper.NewKeeper(cdc, codec.NewLegacyAmino(), runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), stakingKeeper, authority.String())

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/gov/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func initFixture(tb testing.TB) *fixture {
log.NewNopLogger(),
)

stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), 0)

// set default staking params
assert.NilError(tb, stakingKeeper.SetParams(newCtx, stakingtypes.DefaultParams()))
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/slashing/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func initFixture(tb testing.TB) *fixture {
log.NewNopLogger(),
)

stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), 0)

slashingKeeper := slashingkeeper.NewKeeper(cdc, &codec.LegacyAmino{}, runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), stakingKeeper, authority.String())

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/staking/keeper/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func initFixture(tb testing.TB) *fixture {
log.NewNopLogger(),
)

stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[types.StoreKey]), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[types.StoreKey]), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), 0)

authModule := auth.NewAppModule(cdc, accountKeeper, authsims.RandomGenesisAccounts, nil)
bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper, nil)
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/staking/keeper/determinstic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func initDeterministicFixture(t *testing.T) *deterministicFixture {
log.NewNopLogger(),
)

stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr))
stakingKeeper := stakingkeeper.NewKeeper(cdc, runtime.NewKVStoreService(keys[stakingtypes.StoreKey]), accountKeeper, bankKeeper, authority.String(), addresscodec.NewBech32Codec(sdk.Bech32PrefixValAddr), addresscodec.NewBech32Codec(sdk.Bech32PrefixConsAddr), 0)

authModule := auth.NewAppModule(cdc, accountKeeper, authsims.RandomGenesisAccounts, nil)
bankModule := bank.NewAppModule(cdc, bankKeeper, accountKeeper, nil)
Expand Down
Loading