-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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: revert tx when block gas limit exceeded (backport: #10770) #10814
Conversation
oh nice, thanks a lot. I'm putting in draft for now, let's merge #10770 first. |
41009cb
to
e73a18e
Compare
I guess we better write a unit test for this too, but I find it not easy to do that? which test suite is the best place to write a test case for this? |
d6862eb
to
fc6b209
Compare
@@ -586,11 +586,6 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re | |||
return gInfo, nil, nil, sdkerrors.Wrap(sdkerrors.ErrOutOfGas, "no block gas left to run tx") | |||
} | |||
|
|||
var startingGas uint64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no need to check overflow since it's already handled in ConsumeGas
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seems correct to me, @yihuang did you think of how we can write a test for this?
Edit: maybe in TestMaxBlockGasLimits in baseapp_test?
baseapp/baseapp.go
Outdated
defer func() { | ||
if mode == runTxModeDeliver { | ||
ctx.BlockGasMeter().ConsumeGas( | ||
ctx.GasMeter().GasConsumedToLimit(), "block gas meter", | ||
) | ||
|
||
if ctx.BlockGasMeter().GasConsumed() < startingGas { | ||
panic(sdk.ErrorGasOverflow{Descriptor: "tx gas summation"}) | ||
} | ||
consumeBlockGas() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove this defer func?
AFAIK, there's no gas consumption after runMsgs. So if we put consumeBlockGas
in runTx, before store write, then it should be okay?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need defer function to consume block gas when panic happens I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, let's maybe keep it for now
I tried before, find it very tedious to set up the environment, let me try it again. |
We can't do that in |
- used a different solution. changelog
4f9cf40
to
3d67fa8
Compare
tests added. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks a lot
Let's get this released today 😎
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK, left few tiny comments.
@@ -677,6 +677,9 @@ func (app *BaseApp) runTx(mode runTxMode, txBytes []byte) (gInfo sdk.GasInfo, re | |||
// Result if any single message fails or does not have a registered Handler. | |||
result, err = app.runMsgs(runMsgCtx, msgs, mode) | |||
if err == nil && mode == runTxModeDeliver { | |||
// When block gas exceeds, it'll panic and won't commit the cached store. | |||
consumeBlockGas() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to call it here? It's already called in defer
(line 614)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to call it here? It's already called in
defer
(line 614)
That's the main purpose of this PR, call it here so if block gas limit exceeded, it'll panic and won't execute the msCache.Write()
, so the tx msg side effects are not persisted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makes sense. Thanks!
Co-authored-by: Robert Zaremba <robert@zaremba.ch>
Merging! |
…cosmos#10814) * revert tx when block gas limit exceeded (backport: cosmos#10770) - used a different solution. changelog * add unit test * Update baseapp/baseapp.go Co-authored-by: Robert Zaremba <robert@zaremba.ch> * simplfy the defer function Co-authored-by: Robert Zaremba <robert@zaremba.ch>
…cosmos#10814) * revert tx when block gas limit exceeded (backport: cosmos#10770) - used a different solution. changelog * add unit test * Update baseapp/baseapp.go Co-authored-by: Robert Zaremba <robert@zaremba.ch> * simplfy the defer function Co-authored-by: Robert Zaremba <robert@zaremba.ch>
…cosmos#10814) * revert tx when block gas limit exceeded (backport: cosmos#10770) - used a different solution. changelog * add unit test * Update baseapp/baseapp.go Co-authored-by: Robert Zaremba <robert@zaremba.ch> * simplfy the defer function Co-authored-by: Robert Zaremba <robert@zaremba.ch>
…cosmos#10814) * revert tx when block gas limit exceeded (backport: cosmos#10770) - used a different solution. changelog * add unit test * Update baseapp/baseapp.go Co-authored-by: Robert Zaremba <robert@zaremba.ch> * simplfy the defer function Co-authored-by: Robert Zaremba <robert@zaremba.ch>
Description
backport from #10770, but used a different solution from the master one, because of difference in code structure.
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...
!
to the type prefix if API or client breaking changeCHANGELOG.md
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...
!
in the type prefix if API or client breaking change