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

feat: add gov spam prevention antehandler #2251

Closed
wants to merge 9 commits into from
Closed

feat: add gov spam prevention antehandler #2251

wants to merge 9 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Feb 24, 2023

Closes: #2246.
This should fix the spam issue from the Cosmos Hub.
This ports CosmosContracts/juno#394 from @vuong177 and @faddat.

x/gov/ante/gov_filter.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Feb 26, 2023

Codecov Report

Merging #2251 (848551f) into main (189d017) will decrease coverage by 1.90%.
The diff coverage is 30.18%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2251      +/-   ##
==========================================
- Coverage   84.76%   82.86%   -1.90%     
==========================================
  Files          21       22       +1     
  Lines        1483     1535      +52     
==========================================
+ Hits         1257     1272      +15     
- Misses        181      212      +31     
- Partials       45       51       +6     
Impacted Files Coverage Δ
ante/ante.go 48.93% <25.00%> (-3.34%) ⬇️
ante/gov_ante.go 27.65% <27.65%> (ø)
app/app.go 75.43% <100.00%> (+0.21%) ⬆️

x/gov/ante/gov_filter.go Outdated Show resolved Hide resolved
grpcproto and others added 2 commits February 26, 2023 12:34
Co-authored-by: vuong <56973102+vuong177@users.noreply.github.com>
@ghost
Copy link
Author

ghost commented Feb 27, 2023

I don't think we can fix the SDK simulations, as the deposit fees generation does not take in account our minimum deposit constraint. Fixing e2e however.

ante/ante.go Outdated
paramtypes "github.com/cosmos/cosmos-sdk/x/params/types"
ibcante "github.com/cosmos/ibc-go/v4/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v4/modules/core/keeper"

gaiafeeante "github.com/cosmos/gaia/v9/x/globalfee/ante"
gaiagovante "github.com/cosmos/gaia/v9/x/gov/ante"
Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't be under x/ as it's not a module.

Copy link
Author

Choose a reason for hiding this comment

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

Where should it live sir?

Copy link
Contributor

Choose a reason for hiding this comment

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

you can move it to gaia/ante/

@@ -75,7 +75,7 @@ var (
stakingAmountCoin = sdk.NewCoin(uatomDenom, stakingAmount)
tokenAmount = sdk.NewCoin(uatomDenom, sdk.NewInt(3300000000)) // 3,300uatom
standardFees = sdk.NewCoin(uatomDenom, sdk.NewInt(330000)) // 0.33uatom
depositAmount = sdk.NewCoin(uatomDenom, sdk.NewInt(10000000)) // 10uatom
depositAmount = sdk.NewCoin(uatomDenom, sdk.NewInt(3300000000)) // 3,300uatom
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you give more context on this change and how it tests the new ante handler?

Copy link
Contributor

Choose a reason for hiding this comment

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

unit tests and e2e tests need to be added:

  • gov proposal with deposit less than MiniumInitialDepositRate
  • gov proposal with deposit more than/equal toMiniumInitialDepositRate
  • authz.msg contains gov proposal with deposit less than MiniumInitialDepositRate
  • authz.msg contains gov proposal with deposit more than/equal toMiniumInitialDepositRate

Copy link
Contributor

Choose a reason for hiding this comment

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

the depositAmount = 3,300uatom, is this enough ? depositAmount need to be >= 2,000,000uatom due to
MiniumInitialDepositRate = sdk.NewDecWithPrec(10, 2), gas = 200,000

@ghost ghost requested a review from mpoke February 28, 2023 17:34
// prevent spam gov msg
depositParams := gpsd.govKeeper.GetDepositParams(ctx)
miniumInitialDeposit := gpsd.calcMiniumInitialDeposit(depositParams.MinDeposit)
if msg.InitialDeposit.IsAllLT(miniumInitialDeposit) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if deposit IsAllLT than the required deposit, fail.
may use
if deposit IsAnyGTE than the required deposit, pass. This can do a fast looping, when find one coin GTE, return nil ?
both are fine

@ghost
Copy link
Author

ghost commented Mar 1, 2023

@yaruwangway would you mind doing the changes? I will let the pro do it.

@ghost ghost closed this Mar 1, 2023
@ghost ghost deleted the gov-spam branch March 1, 2023 14:32
This pull request was closed.
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.

Gov Spam Prevention Mechanism
4 participants