-
Notifications
You must be signed in to change notification settings - Fork 607
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
Fix: Flip existing twapRecords base/quote price denoms #5939
Conversation
1bb751a
to
23c923f
Compare
@stackman27 does anything need to change now that #5863 was merged? |
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.
Will do another pass when these are addressed, thank you!
i dont think so, i compared mainnet twap records with mainnet spot price. So if mainnet spot price is wrong twap should be wrong for ex: in the call below osmo is base and we are quoting dai incorrectly
|
d64828a
to
617d6af
Compare
c67904e
to
5c3b4cf
Compare
ee93924
to
8709c4a
Compare
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 looks good, but we should add the upgrade handler test described in comment before merging. Will approve after that, then will need a second approval from there. Thanks!
app/upgrades/v17/upgrades.go
Outdated
func FlipTwapSpotPriceRecords(ctx sdk.Context, poolIds []uint64, keepers *keepers.AppKeepers) error { | ||
for _, poolId := range poolIds { | ||
// check that this is a cl pool | ||
_, err := keepers.ConcentratedLiquidityKeeper.GetConcentratedPoolById(ctx, poolId) |
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.
Lets just take in an array of PoolI without the type check. Then in the upgrade handler we just call GetPools and pass in the result of GetPools directly in. No need to
- Get pools
- Extract pool IDs
- Get pool again
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.
fixed! 21a7552
app/upgrades/v17/upgrades_test.go
Outdated
clPoolTwapRecordPreUpgrade, err := keepers.TwapKeeper.GetAllMostRecentRecordsForPool(ctx, existingPool.GetId()) | ||
suite.Require().NoError(err) | ||
|
||
clPoolTwapRecordHistoricalPoolIndex, err := keepers.TwapKeeper.GetAllHistoricalPoolIndexedTWAPsForPoolId(ctx, existingPool.GetId()) | ||
suite.Require().NoError(err) |
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.
Its good that we added this here, but we need to add logic in the success cases that checks the new record post upgrade to ensure both records were changed as expected. I would also create more than one historical record. Then, after the upgrade, you can iterate over the historical records to see if the values were swapped, then just compare the current record to ensure that flipped 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.
oh yea sorry i had this test created but forgot to push 78c7cec#diff-8d0951a4357ce3ef3f57168835dcc72078bd30337d8f9882c3b0d1e64a815e77R180-R195
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.
the above test contains >1 historical records. lmk if this suffice, i can write more test too!
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.
added more detailed test here: 4ea33fa
169850f
to
78c7cec
Compare
78c7cec
to
21a7552
Compare
What I'm missing from approval is the answer to this question in the review. I think that after the earlier suggested refactor was complete, it is not present but would like a confirmation. |
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 cycle focuses on tests. I think the tests should be expanded prior to merge
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 LGTM after the latest test requests are addressed
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.
Nice work on working through a long series of feedbacks! LGTM
Have two more minor comments + a general suggestion that test code could benefit from more comments explaining the invariants being tested. Bumping up our recently updated guidelines here
app/upgrades/v17/upgrades_test.go
Outdated
|
||
}, | ||
func(ctx sdk.Context, keepers *keepers.AppKeepers, expectedCoinsUsedInUpgradeHandler sdk.Coins, lastPoolID uint64) { | ||
func(ctx sdk.Context, keepers *keepers.AppKeepers, expectedCoinsUsedInUpgradeHandler sdk.Coins, lastPoolID uint64, clPoolTwapRecordPreUpgrade []types.TwapRecord) { |
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.
Consider avoiding passing in clPoolTwapRecordPreUpgrade
here and returning them from pre-upgrade logic. Instead, use the pool id similar to the other pool
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.
okay that sounds good too
addressed 8460510
app/upgrades/v17/upgrades_test.go
Outdated
if (clPoolsTwapRecordHistoricalTimeIndexPostUpgrade[i].PoolId == lastPoolID) || (clPoolsTwapRecordHistoricalTimeIndexPostUpgrade[i].PoolId == lastPoolIdMinusOne) { | ||
suite.Require().Equal(clPoolsTwapRecordHistoricalTimeIndexPreUpgrade[i].Asset0Denom, clPoolsTwapRecordHistoricalTimeIndexPostUpgrade[i].Asset1Denom) | ||
suite.Require().Equal(clPoolsTwapRecordHistoricalTimeIndexPreUpgrade[i].Asset1Denom, clPoolsTwapRecordHistoricalTimeIndexPostUpgrade[i].Asset0Denom) | ||
suite.Require().Equal(clPoolsTwapRecordHistoricalTimeIndexPreUpgrade[i].P0LastSpotPrice, clPoolsTwapRecordHistoricalTimeIndexPostUpgrade[i].P1LastSpotPrice) | ||
suite.Require().Equal(clPoolsTwapRecordHistoricalTimeIndexPreUpgrade[i].P1LastSpotPrice, clPoolsTwapRecordHistoricalTimeIndexPostUpgrade[i].P0LastSpotPrice) | ||
} |
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.
Please also add an else case here and check that for other pools these are not switched. Please make sure that at least one other pool has historical time indexed twap record
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.
since all CL pool gets flipped & we delete old index and create new index this was a bit hard to check. I checked with balancer pool and confirmed records are not flipped
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.
Nice work! The changes you made to the test file make me feel much better about this change.
Side note, when we upgrade testnet, can you check that this flipped the testnet record as expected as well?
app/upgrades/v17/upgrades_test.go
Outdated
// check that all TWAP records aren't empty | ||
suite.Require().NotEmpty(clPool1TwapRecordPostUpgrade, "Most recent TWAP records should not be empty after upgrade.") | ||
suite.Require().NotEmpty(clPool1TwapRecordHistoricalPoolIndexPostUpgrade, "Historical Pool Index TWAP record should not be empty after upgrade.") | ||
suite.Require().NotEmpty(clPool2TwapRecordPostUpgrade, "Most recent TWAP records should not be empty after upgrade.") | ||
suite.Require().NotEmpty(clPool2TwapRecordHistoricalPoolIndexPostUpgrade, "Historical Pool Index TWAP record should not be empty after upgrade.") | ||
suite.Require().NotEmpty(clPoolsTwapRecordHistoricalTimeIndexPostUpgrade, "Historical Time Index TWAP record should not be empty after upgrade.") |
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.
nit: i think this is just unnecessary verbosity and that gets indirectly checked below
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.
removed the text but kept the check!
Merging since it has 2 approvals!! |
* added logic * added upgrade handler test * added changelog * flip spot price too * adams suggestions * rebased * adams final suggestion * roman comments * roman suggestion * cleanup * romans suggestion * lint * misc cleanup * added test * more tests * added verbose tests * nit * romans comment for different twap request * nit * roman suggestion * adams suggestion
Closes: #XXX
What is the purpose of the change
since twap depends on spot-price query and spot-price query base/quote denom is switched. We switch that back in TWAP too
Testing and Verifying
added test for upgrade handler
existing twap records
Documentation and Release Note
Unreleased
section ofCHANGELOG.md
?Where is the change documented?
x/{module}/README.md
)