Skip to content

Commit

Permalink
Speedup accumulator prefix keys (#5174)
Browse files Browse the repository at this point in the history
  • Loading branch information
ValarDragon authored May 13, 2023
1 parent 52fcea8 commit 01e4469
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
13 changes: 3 additions & 10 deletions osmoutils/accum/prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,16 @@ const (
positionPrefix = "pos"
)

// formatAccumPrefix returns the key prefix used for any
// accum module values to be stored in the KVStore.
// Returns "accum/{key}" as bytes.
func formatModulePrefixKey(key string) []byte {
return []byte(fmt.Sprintf("%s/%s", modulePrefix, key))
}

// formatAccumPrefix returns the key prefix used
// specifically for accumulator values in the KVStore.
// Returns "accum/acc/{name}" as bytes.
func formatAccumPrefixKey(name string) []byte {
return formatModulePrefixKey(fmt.Sprintf("%s/%s", accumulatorPrefix, name))
return []byte(fmt.Sprintf(modulePrefix+"/"+accumulatorPrefix+"/%s", name))
}

// FormatPositionPrefixKey returns the key prefix used
// specifically for position values in the KVStore.
// Returns "accum/pos/{accumName}/{name}" as bytes.
// Returns "accum/acc/pos/{accumName}/{name}" as bytes.
func FormatPositionPrefixKey(accumName, name string) []byte {
return formatAccumPrefixKey(fmt.Sprintf("%s/%s/%s", positionPrefix, accumName, name))
return []byte(fmt.Sprintf(modulePrefix+"/"+accumulatorPrefix+"/"+positionPrefix+"/%s/%s", accumName, name))
}
2 changes: 1 addition & 1 deletion x/concentrated-liquidity/swaps.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (ss *SwapState) updateFeeGrowthGlobal(feeChargeTotal sdk.Dec) {
// We round down here since we want to avoid overdistributing (the "fee charge" refers to
// the total fees that will be accrued to the fee accumulator)
feesAccruedPerUnitOfLiquidity := feeChargeTotal.QuoTruncate(ss.liquidity)
ss.feeGrowthGlobal = ss.feeGrowthGlobal.Add(feesAccruedPerUnitOfLiquidity)
ss.feeGrowthGlobal.AddMut(feesAccruedPerUnitOfLiquidity)
return
}
}
Expand Down

0 comments on commit 01e4469

Please sign in to comment.