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: set block gas meter on prepare/process proposal #15012

Merged
merged 14 commits into from
Feb 15, 2023
Merged

Conversation

alexanderbez
Copy link
Contributor

Description

Closes: #14998

Set block gas meter on the Context provided to PrepareProposal and ProcessProposal handlers.

Note, @JayT106, this only allows gas consumption checks up and until the AnteHandler phase, since in the SDK's default handlers of Prepare/Process proposal we do NOT execute messages. So it would be equivalent to calling CheckTx


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)

@@ -625,8 +625,10 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re
}()

blockGasConsumed := false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This files contains cosmetic changes only FYI.

@alexanderbez alexanderbez added the backport/v0.47.x PR scheduled for inclusion in the v0.47's next stable release label Feb 13, 2023
Comment on lines 625 to 633
}()

blockGasConsumed := false
// consumeBlockGas makes sure block gas is consumed at most once. It must happen after
// tx processing, and must be executed even if tx processing fails. Hence, we use trick with `defer`

// consumeBlockGas makes sure block gas is consumed at most once. It must
// happen after tx processing, and must be executed even if tx processing
// fails. Hence, it's execution is deferred.
consumeBlockGas := func() {
if !blockGasConsumed {
Copy link
Contributor

Choose a reason for hiding this comment

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

Change potentially affects state.

Call sequence:

(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).runTx (baseapp/baseapp.go:604)
(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).DeliverTx (baseapp/baseapp.go:385)

@alexanderbez alexanderbez marked this pull request as ready for review February 13, 2023 17:54
@alexanderbez alexanderbez requested a review from a team as a code owner February 13, 2023 17:54
@github-prbot github-prbot requested review from a team, samricotta and testinginprod and removed request for a team February 13, 2023 17:54
@JayT106
Copy link
Contributor

JayT106 commented Feb 13, 2023

Thanks, @alexanderbez. I've tried PR #14984 to address the new handler issue. But I am unsure of the goal of ABCI 1.0 after phase 1. Maybe it needs a broad discussion, but the goal will be to fix #2150 and the block fills issue with gas transactions.

@JayT106
Copy link
Contributor

JayT106 commented Feb 13, 2023

I don't understand why the gas meter uses deliverState.ctx instead of using prepareproposal.ctx or processproposal.ctx? Isn't the gas meter should relate to the block param of the context's consensus param (so theoretically will be the same between these contexts?)

@alexanderbez
Copy link
Contributor Author

Thanks, @alexanderbez. I've tried PR #14984 to address the new handler issue. But I am unsure of the goal of ABCI 1.0 after phase 1. Maybe it needs a broad discussion, but the goal will be to fix #2150 and the block fills issue with gas transactions.

Yes, so the goal of ABCI++ integration is as follows:

  • SDK v0.47.x: ABCI++ 1.0, i.e. PrepareProposal and ProcessProposal (RELEASED!)
  • SDK v0.48.x: ABCI++ 2.0, i.e ExtendVote, VerifyVoteExtension and FinalizeBlock (Soon, maybe end of q1)
  • SDK v0.49.x: Optimistic execution, i.e. process the entire block in ProcessProposal and slim down FinalizeBlock which will allow for gas refunds and similar features (Soon-ish, most likely q2)

I don't understand why the gas meter uses deliverState.ctx instead of using prepareproposal.ctx or processproposal.ctx? Isn't the gas meter should relate to the block param of the context's consensus param (so theoretically will be the same between these contexts?)

Yes, you're right, it was a bug and I didn't have my coffee yet lol

@alexanderbez
Copy link
Contributor Author

Pushed fixes.

@JayT106
Copy link
Contributor

JayT106 commented Feb 13, 2023

  • SDK v0.47.x: ABCI++ 1.0, i.e. PrepareProposal and ProcessProposal (RELEASED!)
  • SDK v0.48.x: ABCI++ 2.0, i.e ExtendVote, VerifyVoteExtension and FinalizeBlock (Soon, maybe end of q1)
  • SDK v0.49.x: Optimistic execution, i.e. process the entire block in ProcessProposal and slim down FinalizeBlock which will allow for gas refunds and similar features (Soon-ish, most likely q2)

Thanks for the explanation!

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

lgtm!

@julienrbrt
Copy link
Member

nit: Unrelated to this PR but maybe this can be updated for style consistency:

cosmos-sdk/baseapp/abci.go

Lines 179 to 185 in 80dd55f

// add block gas meter
var gasMeter storetypes.GasMeter
if maxGas := app.GetMaximumBlockGas(app.deliverState.ctx); maxGas > 0 {
gasMeter = storetypes.NewGasMeter(maxGas)
} else {
gasMeter = storetypes.NewInfiniteGasMeter()
}
with the current changes.

@alexanderbez
Copy link
Contributor Author

Good idea. I'll be sure to make them consistent!

@alexanderbez alexanderbez enabled auto-merge (squash) February 13, 2023 21:30
@julienrbrt
Copy link
Member

julienrbrt commented Feb 13, 2023

Mmmh, this is still failing: https://github.com/cosmos/cosmos-sdk/actions/runs/4168353062/jobs/7215053213
The logs do not say much.

Copy link
Contributor

@likhita-809 likhita-809 left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@testinginprod testinginprod left a comment

Choose a reason for hiding this comment

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

lgtm!

@alexanderbez
Copy link
Contributor Author

I can't run localnet locally to figure out what's up... :(

@alexanderbez alexanderbez merged commit b3f9506 into main Feb 15, 2023
@alexanderbez alexanderbez deleted the bez/14998 branch February 15, 2023 15:55
mergify bot pushed a commit that referenced this pull request Feb 15, 2023
(cherry picked from commit b3f9506)

# Conflicts:
#	baseapp/abci.go
alexanderbez added a commit that referenced this pull request Feb 15, 2023
#15040)

Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Julien Robert <julien@rbrt.fr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.47.x PR scheduled for inclusion in the v0.47's next stable release C:Store Type: Build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PrepareProposal/ProcessProposal with block gas meter
5 participants