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: Update ctx BlockTime for simulations #10467

Merged

Conversation

fkneeland-figure
Copy link
Contributor

@fkneeland-figure fkneeland-figure commented Oct 29, 2021

Description

When running simulation tests with wasmd I am running into this error: https://github.com/CosmWasm/wasmd/blob/14e58bfa81ea2ade0ff00ebd067ac0bc75e37cf8/x/wasm/types/types.go#L258

This is because when we are running in simulation mode we randomly create a date before the year 9999. However, if a date is after the year 2262 UnixNano will overflow and possibly return a negative number. To fix this I updated how we set the random genesis start time to be between the epoch and 200 years from now which means this error won't show itself again for another 40+ years.

Closes: #10466


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@fkneeland-figure fkneeland-figure changed the title Update ctx time for simulations fix: Update ctx BlockTime for simulations Oct 29, 2021
@fkneeland-figure
Copy link
Contributor Author

This is ready for review

Copy link
Contributor

@ValarDragon ValarDragon left a comment

Choose a reason for hiding this comment

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

Seems fine to me, as it only affects the CheckTx state

@alexanderbez
Copy link
Contributor

using time.Now(), even if its just in CheckTx, scares me. Is there a reason we can't just default to having this change in NewEnv?

@fkneeland-figure
Copy link
Contributor Author

@alexanderbez I would prefer to make the change here instead of in NewEnv as that code is run in production where as this setting of the time in context is only done in simulation mode (at least as far as I can tell). Is there something better I can use than time.Now() ?

@fkneeland-figure
Copy link
Contributor Author

@alexanderbez I updated the way we create the genesis time to not be able to be so far into the future (it can still be up to 200 years from now) which also fixed this problem. Would you be okay with that solution?

Thanks for your feedback on this!

@fkneeland-figure
Copy link
Contributor Author

@alexanderbez I had to make a minor change to fix tests that required timestamps to be in the future and consistent results based on the random seed. Could you take a look at those changes when you have a chance? This should be ready for merge.

@amaury1093 amaury1093 added the A:automerge Automatically merge PR once all prerequisites pass. label Nov 9, 2021
@amaury1093 amaury1093 removed the A:automerge Automatically merge PR once all prerequisites pass. label Nov 9, 2021
@fkneeland-figure
Copy link
Contributor Author

@alexanderbez @AmauryM can this branch be merged?

@amaury1093 amaury1093 added the A:automerge Automatically merge PR once all prerequisites pass. label Nov 9, 2021
@mergify mergify bot merged commit b9c5a05 into cosmos:master Nov 9, 2021
blewater pushed a commit to e-money/cosmos-sdk that referenced this pull request Dec 8, 2021
<!--
The default pull request template is for types feat, fix, or refactor.
For other templates, add one of the following parameters to the url:
- template=docs.md
- template=other.md
-->

## Description

When running simulation tests with wasmd I am running into this error: https://github.com/CosmWasm/wasmd/blob/14e58bfa81ea2ade0ff00ebd067ac0bc75e37cf8/x/wasm/types/types.go#L258

This is because when we are running in simulation mode we randomly create a date before the year 9999.  However, if a date is after the year 2262 `UnixNano` will overflow and possibly return a negative number.  To fix this I updated how we set the random genesis start time to be between the epoch and 200 years from now which means this error won't show itself again for another 40+ years. 

Closes: cosmos#10466 

<!-- Add a description of the changes that this PR introduces and the files that
are the most critical to review. -->

---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [x] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [x] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/master/CONTRIBUTING.md#testing)
- [x] added a changelog entry to `CHANGELOG.md`
- [x] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [x] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [x] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed 
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
fkneeland-figure added a commit to provenance-io/cosmos-sdk that referenced this pull request Feb 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A:automerge Automatically merge PR once all prerequisites pass.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add time to simulation ctx
5 participants