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

fix: check tx gas limit against block gas limit #16547

Merged
merged 27 commits into from
Jun 20, 2023
Merged

Conversation

alexanderbez
Copy link
Contributor

@alexanderbez alexanderbez commented Jun 14, 2023

Description

CometBFT has an explicit post-CheckTx check that asserts the gas limit of a tx cannot exceed the block gas limit. However, with the advent of ABCI++ and app-side mempools, this would would not prevent txs that exceed the block gas limit to enter the app's mempool since the CometBFT check is ran after the app returns from CheckTx. I.e., the CometBFT check is too late, so we need to ensure we do this app-side.

Changelog

  • Update Setup ante decorator to account for block max gas
  • Update default PrepareProposal handler to account for block max gas
  • Update default ProcessProposal handler to account for block max gas

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...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • 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 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)

@alexanderbez alexanderbez marked this pull request as ready for review June 14, 2023 15:49
@alexanderbez alexanderbez requested a review from a team as a code owner June 14, 2023 15:49
@github-prbot github-prbot requested review from a team, facundomedica and samricotta and removed request for a team June 14, 2023 15:49
@alexanderbez alexanderbez added backport/v0.47.x PR scheduled for inclusion in the v0.47's next stable release backport/v0.50.x PR scheduled for inclusion in the v0.50's next stable release and removed backport/v0.47.x PR scheduled for inclusion in the v0.47's next stable release labels Jun 14, 2023
@@ -40,6 +40,14 @@ func (sud SetUpContextDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate

newCtx = SetGasMeter(simulate, ctx, gasTx.GetGas())

if cp := ctx.ConsensusParams(); cp.Block != nil {
Copy link
Member

Choose a reason for hiding this comment

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

i dont think this fixes the issue at hand, the mempool could still put in an amount of txs that is larger the maxgas.

Copy link
Contributor Author

@alexanderbez alexanderbez Jun 15, 2023

Choose a reason for hiding this comment

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

No, because txs are only inserted into the app's mempool if CheckTx passes. CheckTx would fail here so such a tx would never enter the app's mempool.

However, we also need to update the SDK's default ABCI++ proposal handlers so we can handle an entire proposal.

Copy link
Member

@tac0turtle tac0turtle left a comment

Choose a reason for hiding this comment

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

looks good, two asks:

  1. testcase on prepareproposal
  2. update the building app section to include this as a warning. Users must check both gas and size

@@ -186,9 +191,15 @@ func (h DefaultProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHand
return &abci.ResponsePrepareProposal{Txs: req.Txs}, nil
Copy link
Member

Choose a reason for hiding this comment

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

can we add a testcase that covers this.

@facundomedica
Copy link
Member

facundomedica commented Jun 20, 2023

Meant to restart only the e2e cause it seems like the issue is on github and ended up restarting also tests(00) which has a couple of unit test fails. I'll try to fix them

baseapp/abci_utils.go Outdated Show resolved Hide resolved
@facundomedica
Copy link
Member

@alexanderbez I was checking this and pushed the fix for the tests. Maybe we need to add a test that shows that if we set gas limit higher than the max block gas then we get an invalid gas error (panic)

@alexanderbez
Copy link
Contributor Author

alexanderbez commented Jun 20, 2023

@alexanderbez I was checking this and pushed the fix for the tests. Maybe we need to add a test that shows that if we set gas limit higher than the max block gas then we get an invalid gas error (panic)

I already have a test in setup_test.go. Any tx with a gas limit that exceeds the block gas limit, it'll fail CheckTx. Is that what you meant?

@facundomedica
Copy link
Member

I already have a test in setup_test.go. Any tx with a gas limit that exceeds the block gas limit, it'll fail CheckTx. Is that what you meant?
Yes 👌👌

@alexanderbez alexanderbez added this pull request to the merge queue Jun 20, 2023
Merged via the queue into main with commit 75b4918 Jun 20, 2023
50 checks passed
@alexanderbez alexanderbez deleted the bez/check-tx-gas-block branch June 20, 2023 18:41
mergify bot pushed a commit that referenced this pull request Jun 20, 2023
Co-authored-by: Facundo Medica <facundomedica@gmail.com>
Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com>
(cherry picked from commit 75b4918)
julienrbrt added a commit that referenced this pull request Jun 22, 2023
…6628)

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
@julienrbrt
Copy link
Member

@Mergifyio backport release/v0.47.x

@mergify
Copy link
Contributor

mergify bot commented Jul 27, 2023

backport release/v0.47.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Jul 27, 2023
Co-authored-by: Facundo Medica <facundomedica@gmail.com>
Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com>
(cherry picked from commit 75b4918)

# Conflicts:
#	CHANGELOG.md
#	baseapp/abci_test.go
#	baseapp/abci_utils.go
#	baseapp/block_gas_test.go
#	baseapp/utils_test.go
#	x/auth/ante/setup_test.go
facundomedica added a commit that referenced this pull request Aug 3, 2023
…7161)

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
Co-authored-by: Devon Bear <itsdevbear@berachain.com>
Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.50.x PR scheduled for inclusion in the v0.50's next stable release C:x/auth
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants