Commit Graph

28 Commits

Author SHA1 Message Date
mergify[bot] 147720c8d3
feat: min and max operators on coins (backport #11200) (#11249)
* feat: min and max operators on coins (#11200)

## Description

Closes: #10995

Adds `Min()` and `Max()` operations on `sdk.Coins` for per-denom minimum and maximum.

Replaced an example of manual low-level construction of `Coins` with higher-level operators.
Upcoming enhancements to vesting accounts make heavy use of this pattern.

---

### 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
- [ ] 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)

(cherry picked from commit afbb0bd194)

# Conflicts:
#	CHANGELOG.md

* fix conflicts

Co-authored-by: Jim Larson <32469398+JimLarson@users.noreply.github.com>
Co-authored-by: marbar3778 <marbar3778@yahoo.com>
2022-02-24 00:51:55 +01:00
Emmanuel T Odeke 6344d626db
types/Coin: compile and reuse Regexps to reduce massive RAM+CPU burn (#7989)
* types/Coin: compile and reuse Regexps to reduce massive RAM+CPU burn

Fixes a resource (CPU+RAM) burn from recompiling Regexps which would
consume 1.2+MiB of RAM and 1.1ms per ParseCoin invocation, which means
that 1,000 invocations would consume 1.2GiB of RAM and >1second.

With the change, ParseCoin now takes 3.2us down from 1.1ms, with
dramatic results:

name         old time/op    new time/op    delta
ParseCoin-8    1.04ms ± 4%    0.00ms ± 1%  -99.69%  (p=0.000 n=9+10)

name         old alloc/op   new alloc/op   delta
ParseCoin-8    1.20MB ± 0%    0.00MB ± 0%  -99.94%  (p=0.000 n=10+10)

name         old allocs/op  new allocs/op  delta
ParseCoin-8     17.8k ± 0%      0.0k ± 0%  -99.89%  (p=0.000 n=10+10)

Fixes #7986.

* replace the CoinDenomRegex variable with SetCoinDenomRegex() (#7998)

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Alessio Treglia <alessio@tendermint.com>
2020-11-20 19:37:45 +00:00
billy rennekamp 3e6089dc0e
R4R: Add custom validation for denom (#6755)
Allow ValidateDenom to be customized per application.

closes: #6744
2020-10-06 18:06:41 +01:00
dauTT 30f9862b4b
Remove zero coins from ParseCoins and ParseDecCoins (#7348)
* Remove zero coins from ParseCoins and ParseDecCoins

* Implement requested changes

* Update types/coin_test.go

* Revert

* Align the behaviour of NewCoins and ParseCoins (respectively NewDecCoins and ParseDecCoins)

* Amend comments

* Update types/dec_coin.go

Co-authored-by: Alessio Treglia <alessio@tendermint.com>
Co-authored-by: Alessio Treglia <quadrispro@ubuntu.com>
Co-authored-by: SaReN <sahithnarahari@gmail.com>
Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
2020-09-25 08:31:31 +00:00
Federico Kunze 1b08e1032c
types: update coin regex (#7027)
* types: update coin regex

* more tests

* fix test case

* increase coverage

* changelog

* fix tests

* support unicode letters and numbers

* remove ToUpper

* Update types/coin.go

Co-authored-by: Aaron Craelius <aaron@regen.network>

* Validate function

* fix ICS20 test

* table tests and revert unicodes

* add test case

* add test cases and comment

Co-authored-by: Aaron Craelius <aaron@regen.network>
2020-08-14 09:09:53 +00:00
Ira Miller 282afcdb12
Fix for 6786 removeZeroCoins mutates original slice (#6811)
* added test cases to show errors identified in 6786

* mods to fix remove zero coin mutation in slice

Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2020-07-28 10:17:58 +00:00
Marko bef3689245
linter: enable nolintlint (#6162)
* nolintlint enable

* remove space

* fix tests

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
2020-05-08 08:46:12 +00:00
Alexander Bezobchuk 26d6e49d6a
Merge PR #5491: Protobuf Introduction + Types 2020-01-24 10:32:00 -05:00
Ferenc Fabian 066dd1114f Merge PR #5449: Add New constructor for the DecCoin 2020-01-03 15:44:53 -05:00
Federico Kunze fb0a2c46d3
fix DecCoins constructor (#5410)
* fix decCoins

* minor changes for standardization

* changelog

* add test cases
2019-12-16 19:10:18 -03:00
Alexander Bezobchuk 9f03b57fe3
Merge PR #5359: Params Validation 2019-12-10 11:48:57 -05:00
Xuefeng Zhu 3428291a61 Merge PR #5160: Simply Dec and Int sign check
* Simply Dec and Int sign check

* address comment
2019-10-14 16:05:42 -04:00
Marko 3a4f1fc4d4 Merge PR #4881: Linting Galore 2019-08-19 12:06:27 -04:00
Aleksandr Bezobchuk de720660db
Remove panic on zero input during MulDecTruncate 2019-04-10 21:44:24 -04:00
Alexander Bezobchuk 576eb51928
Merge PR #4058: Fix DecCoins Bugs 2019-04-05 14:13:22 -04:00
Alexander Bezobchuk dd7de2acaf
Merge PR #3951: Remove ';' delimiting support from ParseDecCoins 2019-03-25 10:38:15 -04:00
Alexander Bezobchuk 5f92fef4b0
Fix TruncateDecimal (#3913) 2019-03-16 16:14:37 -07:00
Alexander Bezobchuk b316c477c1 Merge PR #3836: Fix WithdrawValidatorCommission 2019-03-12 16:10:20 +01:00
Christopher Goes 4c50380181
Merge PR #3750: Outstanding per-validator rewards; correctly handle same-BeginBlock redelegation-double-slash 2019-03-06 19:54:12 +01:00
Alessio Treglia b47032d280 Merge PR #3666: improve denom validation 2019-03-01 12:10:22 -08:00
Jae Kwon 7e08b62f4e Merge PR #3726: Cap(clip) reward to remaining coins in AllocateTokens 2019-02-27 21:38:57 +01: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
frog power 4000 ab9de3a7f1
Merge PR #3680: Convenience ToDec()
* NewDecFromInt -> ToDec

* pending

* Update PENDING.md

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

* test typo

* typo
2019-02-21 03:05:31 -05:00
Alexander Bezobchuk 26c13b28cd Merge PR #3607: Reconcile DecCoin/s API with Coin/s API 2019-02-15 16:33:23 +01:00
Alexander Bezobchuk 7bc837aa06 Merge PR #3555: Reintroduce Fees OR Semantics 2019-02-07 18:14:54 -08:00
Jack Zampolin af60c75dd3 Merge PR #3352: Reenable simulation tests 2019-01-24 22:01:32 +01:00
Alexander Bezobchuk 36d1736a08 Refactor Gas/Fee Model (#3258) 2019-01-18 08:45:20 -08:00
Christopher Goes 2942f83ff5
Merge PR #3099: F1 fee distribution 2019-01-16 22:38:05 +01:00