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

R4R: Support min fees-based anti spam strategy #2328

Merged
merged 4 commits into from
Sep 19, 2018

Conversation

alessio
Copy link
Contributor

@alessio alessio commented Sep 13, 2018

Create cosmos.toml configuration file and handle minimum_fees
setting/flag to provide validators with a simple and flexible
anti-spam mechanism.

Closes: #1921

  • Linked to github-issue with discussion and accepted design OR link to spec that describes this work.
  • Wrote tests
  • Updated relevant documentation (docs/)
  • Added entries in PENDING.md with issue #
  • rereviewed Files changed in the github PR explorer

For Admin Use:

  • Added appropriate labels to PR (ex. wip, ready-for-review, docs)
  • Reviewers Assigned
  • Squashed all commits, uses message "Merge pull request #XYZ: [title]" (coding standards)

@codecov
Copy link

codecov bot commented Sep 14, 2018

Codecov Report

Merging #2328 into develop will decrease coverage by 0.24%.
The diff coverage is 45.33%.

@@             Coverage Diff             @@
##           develop    #2328      +/-   ##
===========================================
- Coverage    64.97%   64.73%   -0.25%     
===========================================
  Files          135      137       +2     
  Lines         8418     8467      +49     
===========================================
+ Hits          5470     5481      +11     
- Misses        2587     2622      +35     
- Partials       361      364       +3

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

Thanks @alessio -- left some minor initial feedback 👍

baseapp/baseapp.go Outdated Show resolved Hide resolved
baseapp/options.go Outdated Show resolved Hide resolved
func (c *Config) MinimumFees() sdk.Coins {
fees, err := sdk.ParseCoins(c.MinFees)
if err != nil {
panic(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

panic(fmt.Sprintf("invalid minimum fees: %v", err))

server/config/config.go Outdated Show resolved Hide resolved
server/config/toml.go Outdated Show resolved Hide resolved
server/config/toml.go Outdated Show resolved Hide resolved
server/start.go Outdated Show resolved Hide resolved
types/context.go Outdated Show resolved Hide resolved
x/auth/ante.go Outdated Show resolved Hide resolved
x/auth/ante.go Outdated
if ctx.MinimumFees().Minus(fee.Amount).IsNotNegative() {
fee = NewStdFee(fee.Gas, ctx.MinimumFees()...)
}
// Validators reject any tx from the mempool with less than the required fee per gas
Copy link
Contributor

Choose a reason for hiding this comment

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

validators

Copy link
Contributor

Choose a reason for hiding this comment

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

Where does the rejection actually occur? If the fee amount is zero?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

validators

ACKd.

Where does the rejection actually occur? If the fee amount is zero?

Currently the rejection occurs at deductFees().

@alessio alessio force-pushed the alessio/1921-minimum-fee branch 2 times, most recently from 227830b to b2ce856 Compare September 15, 2018 12:59
@zmanian
Copy link
Member

zmanian commented Sep 15, 2018

I think the way min-fees should related to gas prices is some absolute minimium value + a factor * gas consumed

@alessio alessio force-pushed the alessio/1921-minimum-fee branch 2 times, most recently from d470c25 to a2c7116 Compare September 15, 2018 14:55
@alessio alessio changed the title WIP: Support min fees-based anti spam strategy R4R: Support min fees-based anti spam strategy Sep 15, 2018
baseapp/baseapp.go Outdated Show resolved Hide resolved
@alessio
Copy link
Contributor Author

alessio commented Sep 17, 2018

@alexanderbez your comments were addressed, please review

@alexanderbez
Copy link
Contributor

alexanderbez commented Sep 17, 2018

Hmmm I don't recall test_sim_gaia_nondeterminism failing on develop before (recently). Any chance this PR introduces any non-determinism?

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

Left a few more minor questions and suggestions, but otherwise, it looks good.

server/config/config.go Show resolved Hide resolved
types/context.go Outdated Show resolved Hide resolved
x/auth/ante.go Outdated Show resolved Hide resolved
Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

Structure looks good, see comments.

PENDING.md Outdated Show resolved Hide resolved
baseapp/baseapp.go Show resolved Hide resolved
docs/getting-started/full-node.md Outdated Show resolved Hide resolved
server/config/config.go Show resolved Hide resolved
types/context.go Show resolved Hide resolved
x/auth/ante.go Outdated Show resolved Hide resolved
x/auth/ante.go Outdated
if ctx.IsCheckTx() && !simulate {
// required fees must be greater than the minimum set by the validator
if ctx.MinimumFees().Minus(fee.Amount).IsNotNegative() {
fee = NewStdFee(fee.Gas, ctx.MinimumFees()...)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we setting fee here? Do we only want users to pay the minimum fee even if they set a higher one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When MinimumFees > Fee (MinimumFees - Fee > 0), we pick MinimumFees

Copy link
Contributor

Choose a reason for hiding this comment

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

What if the user supplies Fee > MinimumFees?

Copy link
Contributor

Choose a reason for hiding this comment

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

We shouldn't auto set the fee to min fee if the provided fee isn't enough. There are several issues with that. It will cause a consensus fault, since every validator would subtract it differently. Even if this didn't happen, it provides a validator a way to drain your entire account.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What if the user supplies Fee > MinimumFees?

That just works.

We shouldn't auto set the fee to min fee if the provided fee isn't enough.

I thourougly agree, I've just stumbled upon such a case while performing some testing.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should do neither - if the user didn't sign a transaction with high-enough fees, we should reject the transaction, not subtract fees from their account which they didn't sign. The only check we should perform is that the fees provided in the transaction are greater than the minimum fee - the user should always pay exactly the fee they specified.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Please review @cwgoes @ValarDragon @alexanderbez

Copy link
Contributor

Choose a reason for hiding this comment

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

Mhmmm, what about refunds in the case where they specify a greater amount? Are we relying on the user to know a safe estimate ahead of time?

Copy link
Contributor Author

@alessio alessio Sep 18, 2018

Choose a reason for hiding this comment

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

Are we relying on the user to know a safe estimate ahead of time?

Short answer: yes. A solution may be returning an estimate of the fees along with the gas in --dry-run mode

@alessio alessio force-pushed the alessio/1921-minimum-fee branch 3 times, most recently from b166630 to 0d354a6 Compare September 18, 2018 08:50
@alessio
Copy link
Contributor Author

alessio commented Sep 18, 2018

@alexanderbez I noticed that too - @cwgoes any help/clues are appreciated

x/auth/ante.go Outdated Show resolved Hide resolved
x/auth/ante_test.go Show resolved Hide resolved
Create cosmos.toml configuration file and handle minimum_fees
setting/flag to provide validators with a simple and flexible
anti-spam mechanism.

Closes: #1921
Copy link
Contributor

@cwgoes cwgoes left a comment

Choose a reason for hiding this comment

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

Tested ACK

Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

One small minor remark, otherwise utACK 👍

x/auth/ante.go Outdated Show resolved Hide resolved
Copy link
Contributor

@alexanderbez alexanderbez left a comment

Choose a reason for hiding this comment

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

utACK -- thanks @alessio

@cwgoes cwgoes merged commit b74a6a9 into develop Sep 19, 2018
@cwgoes cwgoes deleted the alessio/1921-minimum-fee branch September 19, 2018 15:25
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.

5 participants