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: increase sdk.Dec maxApproxRootIterations (backport #12229) #12275

Merged
merged 1 commit into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (genutil) [#12140](https://github.com/cosmos/cosmos-sdk/pull/12140) Fix staking's genesis JSON migrate in the `simd migrate v0.46` CLI command.
* (types) [#12154](https://github.com/cosmos/cosmos-sdk/pull/12154) Add `baseAccountGetter` to avoid invalid account error when create vesting account.
* (x/crisis) [#12208](https://github.com/cosmos/cosmos-sdk/pull/12208) Fix progress index of crisis invariant assertion logs.
* (types) [#12229](https://github.com/cosmos/cosmos-sdk/pull/12229) Increase sdk.Dec maxApproxRootIterations to 300

## [v0.46.0-rc1](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.0-rc1) - 2022-05-23

Expand Down
2 changes: 1 addition & 1 deletion types/decimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const (
maxDecBitLen = MaxBitLen + decimalTruncateBits

// max number of iterations in ApproxRoot function
maxApproxRootIterations = 100
maxApproxRootIterations = 300
)

var (
Expand Down
3 changes: 2 additions & 1 deletion types/decimal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,12 @@ func (s *decimalTestSuite) TestApproxRoot() {
{sdk.SmallestDec(), 2, sdk.NewDecWithPrec(1, 9)}, // 1e-18 ^ (0.5) => 1e-9
{sdk.SmallestDec(), 3, sdk.MustNewDecFromStr("0.000000999999999997")}, // 1e-18 ^ (1/3) => 1e-6
{sdk.NewDecWithPrec(1, 8), 3, sdk.MustNewDecFromStr("0.002154434690031900")}, // 1e-8 ^ (1/3) ≈ 0.00215443469
{sdk.MustNewDecFromStr("9000002314687921634000000000000000000021394871242000000000000000"), 2, sdk.MustNewDecFromStr("94868342004527103646332858502867.899477053226766107")},
}

// In the case of 1e-8 ^ (1/3), the result repeats every 5 iterations starting from iteration 24
// (i.e. 24, 29, 34, ... give the same result) and never converges enough. The maximum number of
// iterations (100) causes the result at iteration 100 to be returned, regardless of convergence.
// iterations (300) causes the result at iteration 300 to be returned, regardless of convergence.

for i, tc := range testCases {
res, err := tc.input.ApproxRoot(tc.root)
Expand Down