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

Deduct min fee on error improvements and tests #364

Merged
merged 5 commits into from
Mar 4, 2019

Conversation

husio
Copy link
Contributor

@husio husio commented Feb 27, 2019

I wonder if this works as expected πŸ€”

Tests will show once they will arrive 🏎️

x/cash/dynamicfee_test.go Outdated Show resolved Hide resolved
x/cash/dynamicfee_test.go Outdated Show resolved Hide resolved
@husio husio marked this pull request as ready for review March 1, 2019 12:21
@husio husio requested a review from alpe as a code owner March 1, 2019 12:21
@husio husio changed the title Deduct min fee on error improvements Deduct min fee on error improvements and tests Mar 1, 2019
@husio husio requested review from ethanfrey and removed request for alpe March 1, 2019 12:26
x/cash/dynamicfee.go Outdated Show resolved Hide resolved
Copy link
Contributor

@alpe alpe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good tests. 🍨

x/cash/dynamicfee_test.go Outdated Show resolved Hide resolved
minumumFee: x.NewCoin(0, 23, ""),
txFee: x.NewCoin(0, 421, "ETH"),
wantCheckErr: errors.ErrInsufficientAmount,
wantCheckTxFee: x.NewCoin(0, 23, "BTC"),
Copy link
Contributor

@alpe alpe Mar 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: that's quite an expensive operation, now. (in terms of money). We better have tickers set. :-)

x/cash/dynamicfee_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@alpe alpe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the tests. I have marked some typos that I missed the last time.
Please Remove the TODO: If a transaction succeeded, but requested a RequiredFee higher than paid... in dynamicfee.go as you have implemented (and tested it)! good work πŸ’

x/cash/dynamicfee_test.go Outdated Show resolved Hide resolved
x/cash/dynamicfee_test.go Outdated Show resolved Hide resolved
x/cash/dynamicfee_test.go Outdated Show resolved Hide resolved
x/cash/dynamicfee_test.go Outdated Show resolved Hide resolved
x/cash/dynamicfee_test.go Show resolved Hide resolved
x/cash/dynamicfee_test.go Outdated Show resolved Hide resolved
x/cash/dynamicfee_test.go Outdated Show resolved Hide resolved
x/cash/dynamicfee_test.go Outdated Show resolved Hide resolved
if want.IsZero() {
// This is a weird case when a transaction was
// submitted but the signed does not have
// enough funds to pay the minumum (anty spam)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: the account does not exist so the signer never had any coins.

x/cash/dynamicfee.go Outdated Show resolved Hide resolved
Copy link
Contributor

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just went though the comments.

I want to clarify that a non-zero minimum fee without a ticker is a meaningless concept and should not be supported (explicitly return error as soon as detected). In fact gconf should not allow setting such coins in configuration, as they are invalid. (if !coin.IsZero() { return coin.Validate() } could be a good check in gconf parsing, as well as in the execution stack of enforcing such fee

x/cash/dynamicfee.go Outdated Show resolved Hide resolved
x/cash/dynamicfee_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@ethanfrey ethanfrey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work and nice test cases.

I would just like two minor cleanups addressed...
The shadowing of err in Check/Deliver on the decorator, which crucially depend on which err is referenced in the defer block. Let's make this more explicit.

Also, the embedding of the nil weave.Handler in mockHandler should be simplified. Integrating this into x.TestHelpers can be another PR, but a nice cleanup to make reusable helpers

x/cash/dynamicfee.go Outdated Show resolved Hide resolved
cache.Write()
res.GasPayment += toPayment(fee)
return res, err
if err := d.chargeFee(cache, payer, fee); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am very unsure of how all this relates to the returned error. Along with scoping.

I mean, we have err as a return value
And this line defines a local err
Then when we return below, defer is executed and gets the errors.Wrap(...) error, right?

I mean, on one hand it looks clean, on the other, this is depending quite a bit on the details of scoping. I would rather avoid shadowing if possible. I mean if the return value was eg. rerr for return error, then it is clear if we are refering to the function-local err or the return value one. In general, I would limit shadowing and redefinition of variables as it makes it easy for subtle bugs to drop in.

I think this code is correct, but would prefer to remove this crucial shadow that affects the defer() function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering the same thing. Tests are covering those cases and they seem to work as expected.

I do not know how to write it differently. I could define two anonymous functions or use goto. I think they all suffer the same issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the name of the returned values to ferr and fres (final error, final result), so they are not used at all in the normal code, just references for the defer function to use. Exact same logic and control flow you have, I just renamed one variable to avoid shadowing. I would consider adding an anti-shadowing lint rule.. or maybe I just got used to it from the TypeScript linting I was using in another project, where it is not allowed and prevents a number of gotchas.

if cmp.Ticker == "" {
cmp.Ticker = fee.Ticker
minFee := gconf.Coin(store, GconfMinimalFee)
// If the minimum fee has no currency accept anything.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we will address that in another issue #369

x/cash/dynamicfee_test.go Show resolved Hide resolved
x/cash/dynamicfee_test.go Show resolved Hide resolved
x/cash/dynamicfee_test.go Show resolved Hide resolved
@ethanfrey ethanfrey merged commit 72b63f6 into deduct-min-fee-on-error Mar 4, 2019
@ethanfrey ethanfrey deleted the deduct-min-fee-on-error-ng2 branch March 4, 2019 17:29
@husio husio mentioned this pull request Mar 5, 2019
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants