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

fix: GetSupplyWithOffset returns int #308

Closed
wants to merge 4 commits into from

Conversation

czarcas7ic
Copy link
Member

@czarcas7ic czarcas7ic commented Aug 10, 2022

Closes: #XXX

What is the purpose of the change

Previously we made a PR that returned a zero coin value if the resulting supply was negative. This prevents us from checking what this offset actually is in tests such as this
https://github.com/osmosis-labs/osmosis/blob/main/x/mint/keeper/keeper_test.go#L354

Brief Changelog

  • returns an sdk.Int instead of a coin
  • fixes calls to this method to accept new return value

Testing and Verifying

This change is already covered by existing tests

Documentation and Release Note

  • Does this pull request introduce a new feature or user-facing behavior changes? no
  • Is a relevant changelog entry added to the Unreleased section in CHANGELOG.md? no
  • How is the feature or change documented? not applicable

@czarcas7ic czarcas7ic marked this pull request as ready for review August 10, 2022 18:19
@czarcas7ic czarcas7ic requested a review from a team August 10, 2022 18:19
p0mvn
p0mvn previously approved these changes Aug 10, 2022
Copy link
Member

@p0mvn p0mvn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - I think we might want to keep sdk.Coin as a return though

@@ -32,7 +32,7 @@ type Keeper interface {
IterateTotalSupply(ctx sdk.Context, cb func(sdk.Coin) bool)
GetSupplyOffset(ctx sdk.Context, denom string) sdk.Int
AddSupplyOffset(ctx sdk.Context, denom string, offsetAmount sdk.Int)
GetSupplyWithOffset(ctx sdk.Context, denom string) sdk.Coin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this change? I think we might want to maintain compatibility with APIs in the upstream

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is we need to be able to return a negative number and we can only do this with an int, otherwise we cannot compare the negative diff if we use Coin because Coin can be at a minimum 0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would supply with offset ever be negative? In my opinion, supply should not be negative by definition

The only reason we have the offset is because we over minted by 225m OSMO at genesis. So we are offsetting these 225m with the offset. Therefore, supply with offset should always be >= 0. If it's negative, there is probably a problem / misconfigiration somewhere

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh I see - so the claim is that it can be negative in theory so we would like to allow for that?

What is the use case for capturing this? Why would we need to capture by how much it is negative? In Osmosis x/mint with mainnet parameters supply with offset should never be negative

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea, this PR introduced tests and logic for negative supply due to offset, and when brought into osmosis causes test failures.

Copy link
Member Author

@czarcas7ic czarcas7ic Aug 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So should I just refactor the test to require 0 on an expected negative supply result? I can do this it just seemed...wrong

Copy link
Member

@p0mvn p0mvn Aug 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that's the only occurrence where this matters, I think we should instead refactor that test and pre-mint 225 million + 1, then SetInitialSupplyOffsetDuringMigration (-225m) and, finally test that the supply with offset == 1 is true.

The reason is that breaking the API compatibility between our fork and the upstream SDK is more difficult to maintain and has higher overhead than adjusting that test.

Sorry I didn't realize this earlier. Please let me know what you think.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense! I will close this PR and modify the test osmosis side. Thank you!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I just checked that supply with offsets have not been upsteamed.

They only exist on our fork so the compatibility limitation does not exist.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@czarcas7ic given the above, I think it is more flexible in terms of how we approach this. However, I still do not understand when supply with offset could be negative semantically. From my understanding, if that ever happens, I think we should panic and halt the chain.

Therefore, I'm not sure if allowing for it to be negative via APIs is what we want.

@p0mvn p0mvn self-requested a review August 10, 2022 21:25
@p0mvn p0mvn dismissed their stale review August 10, 2022 21:26

I would like to understand why it can be negative first

@czarcas7ic czarcas7ic closed this Aug 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants