-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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: increase sdk.Dec maxApproxRootIterations #12229
fix: increase sdk.Dec maxApproxRootIterations #12229
Conversation
Can we add a benchmark on |
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.
LGTM, lets just add a test case that used to fail?
We merged this into Osmosis
Also the current AppproxRoot behavior is imo unsafe, it needs to be returning an error or a flag at minimum, if it can't converege within max iterations, so the caller doesn't have incorrect expectations.
This actually would have seriously affected Osmosis in edge-cases that (thankfully) were not hit on mainnet.
@catShaark could you possibly address @ValarDragon's concerns (test case + returning an error) prior to us merging this PR? |
Can we just start migrating to APD soon? |
Yes, and from playing around with the function, I have some concerns of mine as well :
|
Yes, I'll handle this. |
Agreed that sqrt and cubed root should generally be different, dedicated functions. Also agreed that we should switch to apd, but I'm not sure that we get to avoid maintenance for decimal for quite some time. Perhaps we compile the issues you point out as well @catShaark into a second issue, and the flag for could-not-converge? IMO it suffices for this PR if we just get a test case that would return something way off before, and is now fixed by bumping the iteration count |
See #11783. Regen has prior work with apd that we can leverage |
Also not sure we can avoid maintaining the current dec or not. It would be state machine breaking but maybe that's okay in the next release? At least we need something that supports Dec's (incorrect) binary encoding |
@catShaark approved! Please add a changelog entry and I'll merge this. Should we backport this to 0.45? |
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.
I am not sure that this is the right way to test this. Now we just test ApproxRoot
with different maxApproxRootIterations
values, without actually testing the actual implementation (although it tests with 300
it is not clear from the test only that it is the default value).
I think we should just add one test case in TestApproxRoot
that fails with 100 but passes with 300.
I don't think we need that extra TestApproxRootLargeDec
nor having MaxApproxRootIterations
public.
Moreover, we should update the comments in the tests that still mention 100 iterations.
Agreed that the variable shouldn't be exposed / altered, a simple one-off test vector suffices |
Got it |
ece4440
to
b8040fc
Compare
1a35c3f
to
7f7fc97
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.
lgtm
## Description `ApproxRoot` return incorrect value for large `sdk.Dec` because maxApproxRootIterations is not big enough, I increase it to 300 --- ### 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] 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... - [x] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] confirmed `!` in the type prefix if API or client breaking change - [x] confirmed all author checklist items have been addressed - [x] reviewed state machine logic - [x] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [x] manually tested (if applicable) (cherry picked from commit 6a3d10b)
## Description `ApproxRoot` return incorrect value for large `sdk.Dec` because maxApproxRootIterations is not big enough, I increase it to 300 --- ### 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] 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... - [x] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] confirmed `!` in the type prefix if API or client breaking change - [x] confirmed all author checklist items have been addressed - [x] reviewed state machine logic - [x] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [x] manually tested (if applicable) (cherry picked from commit 6a3d10b) Co-authored-by: khanh <50263489+catShaark@users.noreply.github.com>
…12275) ## Description `ApproxRoot` return incorrect value for large `sdk.Dec` because maxApproxRootIterations is not big enough, I increase it to 300 --- ### 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](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] added `!` to the type prefix if API or client breaking change - [ ] targeted the correct branch (see [PR Targeting](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/main/docs/building-modules) - [ ] included the necessary unit and integration [tests](https://github.com/cosmos/cosmos-sdk/blob/main/CONTRIBUTING.md#testing) - [ ] added a changelog entry to `CHANGELOG.md` - [ ] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] 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... - [x] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] confirmed `!` in the type prefix if API or client breaking change - [x] confirmed all author checklist items have been addressed - [x] reviewed state machine logic - [x] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [x] manually tested (if applicable) (cherry picked from commit 6a3d10b) Co-authored-by: khanh <50263489+catShaark@users.noreply.github.com>
Description
ApproxRoot
return incorrect value for largesdk.Dec
because maxApproxRootIterations is not big enough, I increase it to 300Author 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...
!
to the type prefix if API or client breaking changeCHANGELOG.md
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...
!
in the type prefix if API or client breaking change