-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
R4R: Make coins denoms case insensitive #3092
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #3092 +/- ##
===========================================
+ Coverage 55.01% 55.04% +0.02%
===========================================
Files 133 133
Lines 9435 9434 -1
===========================================
+ Hits 5191 5193 +2
+ Misses 3927 3924 -3
Partials 317 317 |
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.
Changes look good but I agree that I think it should be lowercase.
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 don't think we should do any runtime conversion - that's unnecessary and a waste of compute - but validating genesis / CLI / REST input for only-uppercase or only-lowercase makes sense.
@fedekunze @jackzampolin @alexanderbez @rigelrozanski dixit:
I agree with Rigel here - yet I'm open to change it lowercase if we reach a wider consensus |
@cwgoes the safest way to do this is to normalize the denom on |
Furthermore, IMHO |
Unfortunately, I think we don't use What would be fine, I think, is for |
I like that 👍 |
@cwgoes amended, please review |
I like this idea:
Grepping through the code revels that we aren't using |
160ca1e
to
d932fdb
Compare
|
@cwgoes amended as requested. Please review |
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.
One more requested change. Note also I think we'll need to sanitize input wherever we accept sdk.Coins
directly in user-input messages (mostly in x/bank
) to ensure maliciously crafted mixed-case denoms can't cause panics or unusual behaviour.
types/coin.go
Outdated
@@ -320,13 +323,14 @@ func (coins Coins) Empty() bool { | |||
|
|||
// Returns the amount of a denom from coins | |||
func (coins Coins) AmountOf(denom string) Int { | |||
lowercaseDenom := strings.ToLower(denom) |
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.
In this function, can we also check the case like we do on line 464? I think that would be preferable to just converting to lowercase - we should be enforcing that all "denoms" are lowercase.
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.
AmountOf
at the moment is just converting denom
to lowercase and process it (basically implementing real case insensitivity). I couldn't quite get what you would like to see instead - maybe you would prefer AmountOf
to panic if a non-all-lowcase string is encountered?
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.
Yes, exactly (instead of converting). Just want to ensure we don't accidentally have mixed-case somewhere in our code, which is implicitly converted in AmountOf
- better to panic (and find such places if they exist).
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.
amended @cwgoes, please review
5192b4c
to
e5667f0
Compare
Your changes look fine but now many tests seem to fail - are we panicking because of non-lowercase denominations somewhere? |
@cwgoes no, I needed to merge |
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.
Tested ACK
A reminder that we'll need to keep in mind the necessity of sanitizing user input (calling IsValid
on every JSON-parsed sdk.Coins
in ValidateBasic
, basically).
@cwgoes should that change be made with this PR or should we open an issue for that? |
Oh - it's already fine in |
(this needs a second review & approval, and it is a breaking change) |
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.
Changes LGTM -- as long as we're consistent and use the constructors (NewCoin
, NewInt64Coin
) 👍
Closes: #3064
docs/
)PENDING.md
with issue #Files changed
in the github PR explorerFor Admin Use: