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

x/epochs: AfterEpochEnd called with wrong epoch number #830

Closed
ValarDragon opened this issue Feb 7, 2022 · 6 comments
Closed

x/epochs: AfterEpochEnd called with wrong epoch number #830

ValarDragon opened this issue Feb 7, 2022 · 6 comments

Comments

@ValarDragon
Copy link
Member

What the logic should be:

Suppose epoch N ends at “time T”.
Suppose block 5 is at time T - 1. (The epoch shouldn’t have ended yet)
Suppose block 6 is at time T + 1. The epoch should have ended at time T. Since time T is after “block 5", and “before block 6”, we end epoch N as soon as we can within block 6 — namely at the beginning of the block before everything else.
We then start Epoch N+1 immediately, since all of the the txs in block 6 should be executed in epoch N+1.

Whats the bug

We are doing that, but if you look in the relevant code https://github.com/osmosis-labs/osmosis/blob/main/x/epochs/abci.go#L34-L43, we are modifying the EpochIdentifier before the AfterEpochEndCall!

epochInfo.CurrentEpoch += 1
epochInfo.CurrentEpochStartTime = epochInfo.CurrentEpochStartTime.Add(epochInfo.Duration)
k.AfterEpochEnd(ctx, epochInfo.Identifier, epochInfo.CurrentEpoch)

This results in the current epoch argument being wrong. However if you get the epoch from the Identifier, you would still get the correct result.

The fix is relatively simple, but the complex thing is making sure this:

  • Doesn't break any data gathering workflows (The event emitted has the same error)
  • We don't serialize anything by the CurrentEpoch number or else we'll have a migration error
  • Ensure that the thirdening won't have an off by one error on epoch day

Superfluid component

This is tagged for superfluid, because we either need to:

  • Fix the epochs bug for superfluid staking to work
  • Change superfluid logic to get Epoch from reading from identifier (which will gracefully work across whenever the fix occurs)
@ValarDragon ValarDragon moved this to 🔍 Needs Review in Osmosis Chain Development Feb 7, 2022
@ValarDragon ValarDragon changed the title x/epochs: BeforeEpochBegin and AfterEpochEnd called in wrong order x/epochs: AfterEpochEnd called with wrong epoch number Feb 7, 2022
@ValarDragon ValarDragon moved this from 🔍 Needs Review to 🕒 Todo in Osmosis Chain Development Feb 10, 2022
@ValarDragon
Copy link
Member Author

I suggest for the immediate problem of getting this release out, we just fix "Change superfluid logic to get Epoch from reading from identifier (which will gracefully work across whenever the fix occurs)"

@daniel-farina
Copy link
Contributor

daniel-farina commented Mar 3, 2022

  • We need to coordinate with integrators and explain the fix.
  • We need an official message to send to integrators @czarcas7ic

Integrators to reach out to:

  • Imperator
  • Staketax
  • Mintscan
  • Citadel.one

Anything else?

@czarcas7ic
Copy link
Member

I made the PR mentioned above and explained the change in the newly created Integrators discord channel. If I get sufficient engagement through that and no issues are heard, we can probably include this in the next release.

The only thing I have not tested is the potential for an off by one error during the thirdening. I can prioritize testing this on a local net if we feel this to be necessary.

@ValarDragon
Copy link
Member Author

I think we should do thirdening testing separately and not block this on it!

@czarcas7ic czarcas7ic moved this from 🕒 Todo to 🏃 In Progress in Osmosis Chain Development Mar 7, 2022
@czarcas7ic czarcas7ic moved this from 🏃 In Progress to 🔍 Needs Review in Osmosis Chain Development Mar 8, 2022
@daniel-farina
Copy link
Contributor

daniel-farina commented Mar 17, 2022

@czarcas7ic to merge to main.
backport to 7.x once tested

@czarcas7ic
Copy link
Member

Merged and notified integrators. Will post here if any issues are heard

@ValarDragon ValarDragon moved this from 🔍 Needs Review to ✅ Done in Osmosis Chain Development Mar 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

No branches or pull requests

4 participants