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

Add local cache inside the takerfee (backport #8148) #8261

Merged
merged 1 commit into from
May 14, 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 @@ -43,6 +43,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased

* [#8128](https://github.com/osmosis-labs/osmosis/pull/8128) Cache the result for poolmanager.GetPoolModule
* [#8148](https://github.com/osmosis-labs/osmosis/pull/8148) Remove the deserialization time for GetDefaultTakerFee()

## v25.0.0

Expand Down
3 changes: 3 additions & 0 deletions x/poolmanager/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ type Keeper struct {
poolModules []types.PoolModuleI

paramSpace paramtypes.Subspace

defaultTakerFeeBz []byte
defaultTakerFeeVal sdk.Dec
}

func NewKeeper(storeKey storetypes.StoreKey, paramSpace paramtypes.Subspace, gammKeeper types.PoolModuleI, concentratedKeeper types.PoolModuleI, cosmwasmpoolKeeper types.PoolModuleI, bankKeeper types.BankI, accountKeeper types.AccountI, communityPoolKeeper types.CommunityPoolI, stakingKeeper types.StakingKeeper, protorevKeeper types.ProtorevKeeper) *Keeper {
Expand Down
18 changes: 14 additions & 4 deletions x/poolmanager/taker_fee.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package poolmanager

import (
"bytes"
"encoding/json"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -12,10 +14,18 @@ import (
txfeestypes "github.com/osmosis-labs/osmosis/v25/x/txfees/types"
)

func (k Keeper) GetDefaultTakerFee(ctx sdk.Context) sdk.Dec {
var defaultTakerFee sdk.Dec
k.paramSpace.Get(ctx, types.KeyDefaultTakerFee, &defaultTakerFee)
return defaultTakerFee
func (k *Keeper) GetDefaultTakerFee(ctx sdk.Context) sdk.Dec {
defaultTakerFeeBz := k.paramSpace.GetRaw(ctx, types.KeyDefaultTakerFee)
if !bytes.Equal(defaultTakerFeeBz, k.defaultTakerFeeBz) {
var defaultTakerFeeValue sdk.Dec
err := json.Unmarshal(defaultTakerFeeBz, &defaultTakerFeeValue)
if err != nil {
defaultTakerFeeValue = sdk.ZeroDec()
}
k.defaultTakerFeeBz = defaultTakerFeeBz
k.defaultTakerFeeVal = defaultTakerFeeValue
}
return k.defaultTakerFeeVal
}

// SetDenomPairTakerFee sets the taker fee for the given trading pair.
Expand Down