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 v10.x state incompatability #2268

Merged
merged 4 commits into from
Aug 3, 2022
Merged

Fix v10.x state incompatability #2268

merged 4 commits into from
Aug 3, 2022

Conversation

ValarDragon
Copy link
Member

What is the purpose of the change

There was a State machine incompatability in v10.x, due to the ordering of gas measuring methods. cref:

These two PRs caused several gas-behavior changing logics, it just happens that the subtle case is what we hit on mainnet:

They changed the order of operations in the normal case (which is what caused the out of gas bug. They also cause wholly different behavior on error situations.

Brief Changelog

  • Revert state machine incompatible changes

Testing and Verifying

I reviewed all the commits in https://github.com/osmosis-labs/osmosis/tree/v10.x to look for any other state machine incompatabilities due to ordering. I didn't see any. We changed ordering of things in mint, but that is begin block logic, which doesn't have gas measurement concerns.

I've tested that this syncs through the offending block in v10.1.x that caused app hash mismatches.

Documentation and Release Note

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

@ValarDragon ValarDragon requested a review from a team August 1, 2022 18:32
Copy link
Member

@mattverse mattverse left a comment

Choose a reason for hiding this comment

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

LGTM, confirmed that this PR reverts the aforementioned Prs

@ValarDragon ValarDragon mentioned this pull request Aug 2, 2022
}

if k.hooks == nil {
return lock, nil
}

k.hooks.AfterAddTokensToLock(ctx, lock.OwnerAddress(), lock.GetID(), sdk.NewCoins(tokensToAdd))

k.hooks.OnTokenLocked(ctx, lock.OwnerAddress(), lock.ID, sdk.Coins{coin}, lock.Duration, lock.EndTime)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is OnTokenLocked hook called when AfterAddTokensToLock is already called above? Are both the hook calls necessary?

err = suite.App.LockupKeeper.Lock(suite.Ctx, lock)
suite.Require().NoError(err)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

should we start writing test that checks gas at every intermediate steps of lock functions? Is that even possible?

Copy link
Member

@mattverse mattverse Aug 3, 2022

Choose a reason for hiding this comment

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

I really like this idea, want to use this for state compatibility testing :)

Copy link
Member Author

Choose a reason for hiding this comment

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

No this seems excessive. Let's just fix the reason that this was an issue

Copy link
Member

Choose a reason for hiding this comment

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

Im supposing its gonna take some time tho for this fix

Copy link
Member Author

Choose a reason for hiding this comment

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

Depends on if we have agreement for this approach: cosmos/cosmos-sdk#12788

Copy link
Member Author

Choose a reason for hiding this comment

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

agreeing on that & finishing tests in osmosis-labs/cosmos-sdk#304 << writing tooling for this lol.

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

🍍

if err != nil {
return nil, err
}
if err := k.bk.SendCoinsFromAccountToModule(ctx, lock.OwnerAddress(), types.ModuleName, sdk.NewCoins(coin)); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if err := k.bk.SendCoinsFromAccountToModule(ctx, lock.OwnerAddress(), types.ModuleName, sdk.NewCoins(coin)); err != nil {
if err := k.bk.SendCoinsFromAccountToModule(ctx, lock.OwnerAddress(), types.ModuleName, sdk.NewCoins(coin)); err != nil {

// modifications to accumulation store
k.accumulationStore(ctx, coin.Denom).Increase(accumulationKey(lock.Duration), coin.Amount)

// CONTRACT: lock will have synthetic lock only if it has a single coin
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// CONTRACT: lock will have synthetic lock only if it has a single coin
// CONTRACT: Lock will have synthetic lock only if it has a single coin

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 is a revert, can make these changes happen in another PR if we really care

@ValarDragon ValarDragon merged commit 9e178a6 into v10.x Aug 3, 2022
@ValarDragon ValarDragon deleted the dev/v10x-fix-incompat branch August 3, 2022 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

5 participants