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

perf: isSmartAccountActive param cache #8189

Merged
merged 7 commits into from
May 2, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [#8147](https://github.com/osmosis-labs/osmosis/pull/8147) Process unbonding locks once per minute, rather than every single block
* [#8157](https://github.com/osmosis-labs/osmosis/pull/8157) Speedup protorev by not unmarshalling pools in cost-estimation phase
* [#8177](https://github.com/osmosis-labs/osmosis/pull/8177) Change consensus params to match unbonding period
* [#8189](https://github.com/osmosis-labs/osmosis/pull/8189) Perf: Use local cache for isSmartAccountActive param


### State Compatible
Expand Down
4 changes: 2 additions & 2 deletions x/smart-account/ante/circuit_breaker.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ func IsCircuitBreakActive(
tx sdk.Tx,
smartAccountKeeper *smartaccountkeeper.Keeper,
) (bool, smartaccounttypes.AuthenticatorTxOptions) {
authenticatorParams := smartAccountKeeper.GetParams(ctx)
isSmartAccountActive := smartAccountKeeper.GetIsSmartAccountActive(ctx)
// If the smart accounts are not active, the circuit breaker activates (i.e. return true).
if !authenticatorParams.IsSmartAccountActive {
if !isSmartAccountActive {
return true, nil
}

Expand Down
10 changes: 6 additions & 4 deletions x/smart-account/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
}

type Keeper struct {
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
paramSpace paramtypes.Subspace
CircuitBreakerGovernor sdk.AccAddress
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
paramSpace paramtypes.Subspace
CircuitBreakerGovernor sdk.AccAddress
isSmartAccountActiveBz []byte
isSmartAccountActiveVal bool

AuthenticatorManager *authenticator.AuthenticatorManager
}
Expand Down
21 changes: 21 additions & 0 deletions x/smart-account/keeper/params.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package keeper

import (
"bytes"
"encoding/json"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/osmosis-labs/osmosis/v25/x/smart-account/types"
Expand All @@ -16,3 +19,21 @@ func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) {
func (k Keeper) SetParams(ctx sdk.Context, params types.Params) {
k.paramSpace.SetParamSet(ctx, &params)
}

// GetIsSmartAccountActive returns the value of the isSmartAccountActive parameter.
// If the value has not been set, it will return false.
// If there is an error unmarshalling the value, it will return false.
func (k *Keeper) GetIsSmartAccountActive(ctx sdk.Context) bool {
isSmartAccountActiveBz := k.paramSpace.GetRaw(ctx, types.KeyIsSmartAccountActive)
if !bytes.Equal(isSmartAccountActiveBz, k.isSmartAccountActiveBz) {
var isSmartAccountActiveValue bool
err := json.Unmarshal(isSmartAccountActiveBz, &isSmartAccountActiveValue)
if err != nil {
k.Logger(ctx).Error("failed to unmarshal isSmartAccountActive", "error", err)
isSmartAccountActiveValue = false
}
k.isSmartAccountActiveVal = isSmartAccountActiveValue
k.isSmartAccountActiveBz = isSmartAccountActiveBz
}
return k.isSmartAccountActiveVal
}