Skip to content

Commit

Permalink
Add local cache inside the takerfee (backport #8148) (#8260)
Browse files Browse the repository at this point in the history
* Add local cache inside the takerfee (#8148)

* Add local cache inside the takerfee

* add error handling

* Add Changelog

* Fix cache per @adam's comment

* Update x/poolmanager/taker_fee.go

(cherry picked from commit b8fd642)

# Conflicts:
#	CHANGELOG.md

* chore: fix merge errors

---------

Co-authored-by: Dev Ojha <[email protected]>
Co-authored-by: PaddyMc <[email protected]>
  • Loading branch information
3 people authored May 14, 2024
1 parent 4cc7cd8 commit 1981b82
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ 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

## v25.0.0

### State Breaking

* [#7935](https://github.com/osmosis-labs/osmosis/pull/7935) Add block sdk and top of block auction from skip-mev
Expand Down Expand Up @@ -71,6 +75,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()

## v24.0.4

Expand Down
3 changes: 3 additions & 0 deletions x/poolmanager/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,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/v24/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

0 comments on commit 1981b82

Please sign in to comment.