-
Notifications
You must be signed in to change notification settings - Fork 608
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
Speedup TWAP pruning logic #7415
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |||||
"bytes" | ||||||
"errors" | ||||||
"fmt" | ||||||
"strconv" | ||||||
time "time" | ||||||
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types" | ||||||
|
@@ -66,12 +67,33 @@ func FormatHistoricalTimeIndexTWAPKey(accumulatorWriteTime time.Time, poolId uin | |||||
} | ||||||
|
||||||
func FormatHistoricalPoolIndexTWAPKey(poolId uint64, denom1, denom2 string, accumulatorWriteTime time.Time) []byte { | ||||||
var buffer bytes.Buffer | ||||||
timeS := osmoutils.FormatTimeString(accumulatorWriteTime) | ||||||
fmt.Fprintf(&buffer, "%s%d%s%s%s%s%s%s", HistoricalTWAPPoolIndexPrefix, poolId, KeySeparator, denom1, KeySeparator, denom2, KeySeparator, timeS) | ||||||
return FormatHistoricalPoolIndexTWAPKeyFromStrTime(poolId, denom1, denom2, timeS) | ||||||
} | ||||||
|
||||||
func FormatHistoricalPoolIndexTWAPKeyFromStrTime(poolId uint64, denom1, denom2 string, accumulatorWriteTimeString string) []byte { | ||||||
var buffer bytes.Buffer | ||||||
fmt.Fprintf(&buffer, "%s%d%s%s%s%s%s%s", HistoricalTWAPPoolIndexPrefix, poolId, KeySeparator, denom1, KeySeparator, denom2, KeySeparator, accumulatorWriteTimeString) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not relevant for this PR, but we may want to have a generic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also, should this end un a
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually, ignore that. It would require a migration of existing keys. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think your right, alas wasn't thought about before. would take a migration now |
||||||
return buffer.Bytes() | ||||||
} | ||||||
|
||||||
// returns timeString, poolIdString, denom1, denom2, error | ||||||
// nolint: revive | ||||||
func ParseFieldsFromHistoricalTimeKey(bz []byte) (string, uint64, string, string, error) { | ||||||
split := bytes.Split(bz, []byte(KeySeparator)) | ||||||
if len(split) != 5 { | ||||||
return "", 0, "", "", errors.New("invalid key") | ||||||
} | ||||||
timeS := string(split[1]) | ||||||
poolId, err := strconv.Atoi(string(split[2])) | ||||||
if err != nil { | ||||||
return "", 0, "", "", err | ||||||
} | ||||||
denom1 := string(split[3]) | ||||||
denom2 := string(split[4]) | ||||||
return timeS, uint64(poolId), denom1, denom2, err | ||||||
} | ||||||
|
||||||
func FormatHistoricalPoolIndexTimePrefix(poolId uint64, denom1, denom2 string) []byte { | ||||||
return []byte(fmt.Sprintf("%s%d%s%s%s%s%s", HistoricalTWAPPoolIndexPrefix, poolId, KeySeparator, denom1, KeySeparator, denom2, KeySeparator)) | ||||||
} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method now seems unused, can we delete the method as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hrmm, seems like a useful helper / reference implementation tho