Skip to content

Commit

Permalink
perf: isSmartAccountActive param cache (#8189) (#8206)
Browse files Browse the repository at this point in the history
* isSmartAccountActive param cache

* changelog

* lint

* add comment

* logger

* assign bz

* use pointer

(cherry picked from commit d1076da)

Co-authored-by: Adam Tucker <[email protected]>
  • Loading branch information
mergify[bot] and czarcas7ic authored May 2, 2024
1 parent 5f51967 commit cdbe2a7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
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
}

0 comments on commit cdbe2a7

Please sign in to comment.