Commit Graph

21 Commits

Author SHA1 Message Date
mergify[bot] f67928a86d
fix: nil pointer panic on `NewIntFromBigInt` (backport #9627) (#10845)
* types: fix nil pointer panic on `NewIntFromBigInt` (#9627)

(cherry picked from commit 7f9037490b)

# Conflicts:
#	CHANGELOG.md

* fix conflicts

Co-authored-by: Federico Kunze Küllmer <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Aleksandr Bezobchuk <aleks.bezobchuk@gmail.com>
2021-12-29 21:21:31 +01:00
Venkatesh Mankena 3841df6468
fix: Handle MAX_INT_256 (#9511)
Change maxBitLen of sdk.Int to handle max Erc20 value.

<!--
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

Closes: #XXXX

<!-- 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
- [ ] 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))
- [ ] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules)
- [ ] 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`
- [ ] 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...

- [ ] 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)
2021-06-16 14:18:02 +00:00
Hanjun Kim 8ee9da775e
types: add Abs() method to sdk.Int (#8963)
Fixes #8962

Co-authored-by: Alessio Treglia <alessio@tendermint.com>
2021-03-24 16:33:55 +00:00
Emmanuel T Odeke a534a960db
types: use (*math/big.Int).BitLen() == 0 to check if value is 0 (#8580)
Instead of using len((*math/big.Int).Bytes()) == 0, which expensively
creates a byte slice and marshals a value, on the majority hot path,
instead use the cheaper method .BitLen() to check if 0.

Benchmarking results, just from types:

name                                           old time/op    new time/op    delta
CoinsAdditionIntersect/sizes:_A_1,_B_1-8          132ns ± 2%     126ns ±13%   -4.55%  (p=0.050 n=10+10)
CoinsAdditionIntersect/sizes:_A_5,_B_5-8         1.41µs ± 3%    1.41µs ± 2%     ~     (p=1.000 n=10+10)
CoinsAdditionIntersect/sizes:_A_5,_B_20-8        2.30µs ± 1%    2.27µs ± 3%     ~     (p=0.066 n=10+10)
CoinsAdditionIntersect/sizes:_A_1,_B_1000-8      30.9µs ± 3%    30.7µs ± 1%     ~     (p=0.218 n=10+10)
CoinsAdditionIntersect/sizes:_A_2,_B_1000-8      31.4µs ± 3%    30.8µs ± 2%   -1.94%  (p=0.015 n=10+10)
CoinsAdditionNoIntersect/sizes:_A_1,_B_1-8        116ns ± 1%     114ns ± 4%     ~     (p=0.142 n=10+10)
CoinsAdditionNoIntersect/sizes:_A_5,_B_5-8       1.11µs ± 1%    1.08µs ± 3%   -2.36%  (p=0.003 n=8+10)
CoinsAdditionNoIntersect/sizes:_A_5,_B_20-8      1.85µs ± 2%    1.82µs ± 1%   -1.38%  (p=0.001 n=10+9)
CoinsAdditionNoIntersect/sizes:_A_1,_B_1000-8    30.7µs ± 1%    30.6µs ± 3%     ~     (p=0.393 n=10+10)
CoinsAdditionNoIntersect/sizes:_A_2,_B_1000-8    31.1µs ± 1%    30.7µs ± 2%   -1.32%  (p=0.015 n=10+10)
CoinsAdditionNoIntersect/sizes:_A_1000,_B_2-8    31.0µs ± 2%    30.7µs ± 2%     ~     (p=0.190 n=10+10)
Bech32ifyPubKey-8                                28.8µs ± 5%    28.8µs ± 3%     ~     (p=0.965 n=10+8)
GetPubKeyFromBech32-8                            38.8µs ± 3%    39.4µs ± 2%   +1.70%  (p=0.013 n=9+10)
ParseCoin-8                                      16.7µs ± 6%    15.8µs ± 4%   -5.21%  (p=0.001 n=10+10)
MarshalTo-8                                       521ns ± 5%     508ns ± 3%   -2.56%  (p=0.029 n=10+10)
UintMarshal-8                                    3.10µs ±17%    2.56µs ± 3%  -17.45%  (p=0.000 n=10+9)
IntMarshal-8                                     2.52µs ±10%    1.94µs ± 2%  -23.10%  (p=0.000 n=10+10)

name                                           old alloc/op   new alloc/op   delta
Bech32ifyPubKey-8                                4.02kB ± 0%    4.02kB ± 0%     ~     (all equal)
GetPubKeyFromBech32-8                            2.48kB ± 0%    2.48kB ± 0%     ~     (all equal)
ParseCoin-8                                      2.21kB ± 0%    2.21kB ± 0%     ~     (all equal)
MarshalTo-8                                       80.0B ± 0%     80.0B ± 0%     ~     (all equal)
UintMarshal-8                                      440B ± 0%      392B ± 0%  -10.91%  (p=0.000 n=10+10)
IntMarshal-8                                       216B ± 0%      168B ± 0%  -22.22%  (p=0.000 n=10+10)

name                                           old allocs/op  new allocs/op  delta
Bech32ifyPubKey-8                                  25.0 ± 0%      25.0 ± 0%     ~     (all equal)
GetPubKeyFromBech32-8                              85.0 ± 0%      85.0 ± 0%     ~     (all equal)
ParseCoin-8                                        71.0 ± 0%      71.0 ± 0%     ~     (all equal)
MarshalTo-8                                        2.00 ± 0%      2.00 ± 0%     ~     (all equal)
UintMarshal-8                                      31.0 ± 0%      25.0 ± 0%  -19.35%  (p=0.000 n=10+10)
IntMarshal-8                                       24.0 ± 0%      18.0 ± 0%  -25.00%  (p=0.000 n=10+10)

name                                           old speed      new speed      delta
UintMarshal-8                                  2.27MB/s ±15%  2.75MB/s ± 2%  +20.87%  (p=0.000 n=10+8)
IntMarshal-8                                   2.78MB/s ± 9%  3.60MB/s ± 2%  +29.69%  (p=0.000 n=10+10)

Fixes #8575

Co-authored-by: Alessio Treglia <alessio@tendermint.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2021-02-15 10:53:10 +00:00
Alessio Treglia ddaa3c5176
types: tests -> test suites migration (#7405) 2020-09-29 13:29:10 +02:00
Federico Kunze 7f0c3f0093
Merge PR #7084: types: fix panic on Int.BigInt() 2020-08-18 09:16:23 -04:00
Alessio Treglia da5c6ced1d
types: add test cases (#5747)
Upgrade gomock dependency.
2020-03-04 17:49:59 +00:00
Alexander Bezobchuk 26d6e49d6a
Merge PR #5491: Protobuf Introduction + Types 2020-01-24 10:32:00 -05:00
Sunny Aggarwal 3fc6240c94 Merge PR #5447: Added nth root function to sdk.Decimal type 2020-01-04 15:16:12 -05:00
Federico Kunze 9c65e47329 Merge PR #4485: rename expected pkg to exported
* rename expected pkg to exported

* rename pkg
2019-06-05 13:42:25 -04:00
frog power 4000 a814e5ce66
Merge PR #3679: Consistent Operators
* Minus->Sub Plus->Add Div->Quo

* pending

* Update PENDING.md

Co-Authored-By: rigelrozanski <rigel.rozanski@gmail.com>

* fix

* typo
2019-02-21 12:35:55 -05:00
Alessio Treglia b67d024fe3 Merge PR #3665: Uint overhaul 2019-02-19 14:59:03 -08:00
Alexander Bezobchuk fd5e7b9b80 Merge PR #3552: General Sanitization & Gas Cost Review 2019-02-08 23:33:29 +01:00
Joon 08e62fb157 Store Refactor 1 (#2985) 2019-02-01 17:03:09 -08:00
Alexander Bezobchuk a984a22373 Merge PR #2694: Vesting Account(s) Implementation 2019-01-14 17:11:24 +01:00
Alexander Bezobchuk 41fc538ac7 Add Safety Measures to Coin/Coins (#2797) 2018-11-20 01:22:35 -08:00
Alexander Bezobchuk 6e813ab3a8 Change gas & related fields to unsigned integer type (#2839)
* Change gas & related fields to unsigned integer type
* Implement AddUint64Overflow
2018-11-19 09:13:45 -08:00
Dev Ojha 10199c9159 Merge PR #1936: types: Reduce size of TestImmutability<Arith\U>Int tests
Currently they take ~1 minute on circle CI. There isn't a significant reason
for this to delay all our tests. This commit reduces the time spent on these
tests by a factor of 20.
2018-08-08 12:05:20 +02:00
Joon 93457aac33 Merge PR #1626: Increase coverage of types/ 2018-08-06 21:00:49 +02:00
Dev Ojha 955a0c9af7 Switch asserts to require (#1483)
* meta: Switch the majority of asserts to require

Switch most assert statements to require, to ease debugging.
Closes #1418

* Fix imports
2018-06-30 03:10:15 +02:00
Joon 314b5a854d Merge PR #1218: sdk.Int in sdk.Coin
implement Int, Int256, Uint256
pass ci
pass ci
add to changelog, add boundcheck to test
add comments, fix cli_test.go
fix errors
apply requested changes
panics on New*WithDecimal
fix Int.BigInt()
fix stake tests
* Panic on uint division-by-zero
* Set ok=false on NewIntFromString, NewUintFromString failure
* Nuke CircleCI caches
2018-06-15 23:16:45 +02:00