From 91364c5e232d10fd1a68e559cee9e4c0f80a5532 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 1 May 2024 13:16:15 -0600 Subject: [PATCH 1/7] isSmartAccountActive param cache --- x/smart-account/ante/circuit_breaker.go | 4 ++-- x/smart-account/keeper/keeper.go | 10 ++++++---- x/smart-account/keeper/params.go | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/x/smart-account/ante/circuit_breaker.go b/x/smart-account/ante/circuit_breaker.go index cbef91f9b25..7809fafa30a 100644 --- a/x/smart-account/ante/circuit_breaker.go +++ b/x/smart-account/ante/circuit_breaker.go @@ -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 } diff --git a/x/smart-account/keeper/keeper.go b/x/smart-account/keeper/keeper.go index 23dd0b35d4a..a91f25cdb30 100644 --- a/x/smart-account/keeper/keeper.go +++ b/x/smart-account/keeper/keeper.go @@ -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 } diff --git a/x/smart-account/keeper/params.go b/x/smart-account/keeper/params.go index 68febf4c857..3d4b69aefcf 100644 --- a/x/smart-account/keeper/params.go +++ b/x/smart-account/keeper/params.go @@ -1,9 +1,13 @@ package keeper import ( + "bytes" + "encoding/json" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/osmosis-labs/osmosis/v25/x/smart-account/types" + smartaccounttypes "github.com/osmosis-labs/osmosis/v25/x/smart-account/types" ) // GetParams get all parameters as types.Params @@ -16,3 +20,16 @@ func (k Keeper) GetParams(ctx sdk.Context) (params types.Params) { func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { k.paramSpace.SetParamSet(ctx, ¶ms) } + +func (k Keeper) GetIsSmartAccountActive(ctx sdk.Context) bool { + isSmartAccountActiveBz := k.paramSpace.GetRaw(ctx, smartaccounttypes.KeyIsSmartAccountActive) + if !bytes.Equal(isSmartAccountActiveBz, k.isSmartAccountActiveBz) { + var isSmartAccountActiveValue bool + err := json.Unmarshal(isSmartAccountActiveBz, &isSmartAccountActiveValue) + if err != nil { + isSmartAccountActiveValue = false + } + k.isSmartAccountActiveVal = isSmartAccountActiveValue + } + return k.isSmartAccountActiveVal +} From d1f43a355b73ebaca4ef6154023f50d858ba182e Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 1 May 2024 13:19:46 -0600 Subject: [PATCH 2/7] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ab32b98579..186d3ddcbae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 From 555f7c1bf598e427a048b6dd344c5a2809aec1ea Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 1 May 2024 13:26:29 -0600 Subject: [PATCH 3/7] lint --- x/smart-account/keeper/params.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/x/smart-account/keeper/params.go b/x/smart-account/keeper/params.go index 3d4b69aefcf..88059c265b3 100644 --- a/x/smart-account/keeper/params.go +++ b/x/smart-account/keeper/params.go @@ -7,7 +7,6 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" "github.com/osmosis-labs/osmosis/v25/x/smart-account/types" - smartaccounttypes "github.com/osmosis-labs/osmosis/v25/x/smart-account/types" ) // GetParams get all parameters as types.Params @@ -22,7 +21,7 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { } func (k Keeper) GetIsSmartAccountActive(ctx sdk.Context) bool { - isSmartAccountActiveBz := k.paramSpace.GetRaw(ctx, smartaccounttypes.KeyIsSmartAccountActive) + isSmartAccountActiveBz := k.paramSpace.GetRaw(ctx, types.KeyIsSmartAccountActive) if !bytes.Equal(isSmartAccountActiveBz, k.isSmartAccountActiveBz) { var isSmartAccountActiveValue bool err := json.Unmarshal(isSmartAccountActiveBz, &isSmartAccountActiveValue) From 836cc18395413128a83869fe81f6592cb57a77fc Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 1 May 2024 13:58:17 -0600 Subject: [PATCH 4/7] add comment --- x/smart-account/keeper/params.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/x/smart-account/keeper/params.go b/x/smart-account/keeper/params.go index 88059c265b3..526826aa526 100644 --- a/x/smart-account/keeper/params.go +++ b/x/smart-account/keeper/params.go @@ -20,6 +20,9 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.Params) { k.paramSpace.SetParamSet(ctx, ¶ms) } +// 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) { From 355d5c765d52a258eb49a080074d294922d605c7 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 1 May 2024 14:26:21 -0600 Subject: [PATCH 5/7] logger --- x/smart-account/keeper/params.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/smart-account/keeper/params.go b/x/smart-account/keeper/params.go index 526826aa526..f6de8403fcb 100644 --- a/x/smart-account/keeper/params.go +++ b/x/smart-account/keeper/params.go @@ -29,6 +29,7 @@ func (k Keeper) GetIsSmartAccountActive(ctx sdk.Context) bool { 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 From 7893ab4646e96810aa60906879f0ef6f9c63d375 Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 1 May 2024 14:29:56 -0600 Subject: [PATCH 6/7] assign bz --- x/smart-account/keeper/params.go | 1 + 1 file changed, 1 insertion(+) diff --git a/x/smart-account/keeper/params.go b/x/smart-account/keeper/params.go index f6de8403fcb..09ea1176c69 100644 --- a/x/smart-account/keeper/params.go +++ b/x/smart-account/keeper/params.go @@ -33,6 +33,7 @@ func (k Keeper) GetIsSmartAccountActive(ctx sdk.Context) bool { isSmartAccountActiveValue = false } k.isSmartAccountActiveVal = isSmartAccountActiveValue + k.isSmartAccountActiveBz = isSmartAccountActiveBz } return k.isSmartAccountActiveVal } From 12f205ade51bcd2cbf00e3905167e53375f2588a Mon Sep 17 00:00:00 2001 From: Adam Tucker Date: Wed, 1 May 2024 14:40:46 -0600 Subject: [PATCH 7/7] use pointer --- x/smart-account/keeper/params.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/smart-account/keeper/params.go b/x/smart-account/keeper/params.go index 09ea1176c69..a54532fa6c8 100644 --- a/x/smart-account/keeper/params.go +++ b/x/smart-account/keeper/params.go @@ -23,7 +23,7 @@ func (k Keeper) SetParams(ctx sdk.Context, params types.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 { +func (k *Keeper) GetIsSmartAccountActive(ctx sdk.Context) bool { isSmartAccountActiveBz := k.paramSpace.GetRaw(ctx, types.KeyIsSmartAccountActive) if !bytes.Equal(isSmartAccountActiveBz, k.isSmartAccountActiveBz) { var isSmartAccountActiveValue bool