-
Notifications
You must be signed in to change notification settings - Fork 328
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
Recover from action handling panic #4513
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,7 +168,7 @@ func withActionCtx(ctx context.Context, selp *action.SealedEnvelope) (context.Co | |
func (ws *workingSet) runAction( | ||
ctx context.Context, | ||
selp *action.SealedEnvelope, | ||
) (*action.Receipt, error) { | ||
) (receipt *action.Receipt, err error) { | ||
actCtx := protocol.MustGetActionCtx(ctx) | ||
if protocol.MustGetBlockCtx(ctx).GasLimit < actCtx.IntrinsicGas { | ||
return nil, action.ErrGasLimit | ||
|
@@ -207,6 +207,24 @@ func (ws *workingSet) runAction( | |
return nil, errors.Wrapf(err, "Failed to get hash") | ||
} | ||
defer ws.ResetSnapshots() | ||
sn := ws.Snapshot() | ||
defer func() { | ||
if err != nil { | ||
if e := ws.Revert(sn); e != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if the |
||
log.T(ctx).Error("Failed to revert snapshot", zap.Error(e)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's also log |
||
return | ||
} | ||
if errors.Is(err, action.ErrPanic) { | ||
err = errors.Wrap(action.ErrPanicButReverted, err.Error()) | ||
} | ||
} | ||
}() | ||
defer func() { | ||
if r := recover(); r != nil { | ||
receipt = nil | ||
err = errors.Wrapf(action.ErrPanic, "panic and reverted when running action: %v", r) | ||
} | ||
}() | ||
if err := ws.freshAccountConversion(ctx, &actCtx); err != nil { | ||
return nil, err | ||
} | ||
|
@@ -736,6 +754,8 @@ func (ws *workingSet) pickAndRunActions( | |
actionIterator.PopAccount() | ||
continue | ||
} | ||
actCtx := protocol.MustGetActionCtx(actionCtx) | ||
l := log.L().With(log.Hex("actHash", actCtx.ActionHash[:]), zap.Uint64("height", ws.height)) | ||
receipt, err := ws.runAction(actionCtx, nextAction) | ||
switch errors.Cause(err) { | ||
case nil: | ||
|
@@ -744,7 +764,12 @@ func (ws *workingSet) pickAndRunActions( | |
actionIterator.PopAccount() | ||
continue | ||
case action.ErrChainID, errUnfoldTxContainer, errDeployerNotWhitelisted: | ||
log.L().Debug("runAction() failed", zap.Uint64("height", ws.height), zap.Error(err)) | ||
l.Debug("runAction() failed", zap.Error(err)) | ||
ap.DeleteAction(caller) | ||
actionIterator.PopAccount() | ||
continue | ||
case action.ErrPanicButReverted: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if panic but reverted, continue when mint and terminate when validate block |
||
l.Warn("runAction() panic but reverted", zap.Error(err)) | ||
ap.DeleteAction(caller) | ||
actionIterator.PopAccount() | ||
continue | ||
|
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.
could these two defer functions been merged which will make it easier to read and maintain