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

Recover from action handling panic #4513

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

envestcc
Copy link
Member

@envestcc envestcc commented Dec 5, 2024

Description

Capture exceptions when processing transactions to prevent the program from exiting abnormally, and instead remove problematic transactions.

Type of change

Please delete options that are not relevant.

  • [] Bug fix (non-breaking change which fixes an issue)
  • [] New feature (non-breaking change which adds functionality)
  • Code refactor or improvement
  • [] Breaking change (fix or feature that would cause a new or changed behavior of existing functionality)
  • [] This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • [] make test
  • [] fullsync
  • [] Other test (please specify)

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist:

  • [] My code follows the style guidelines of this project
  • [] I have performed a self-review of my code
  • [] I have commented my code, particularly in hard-to-understand areas
  • [] I have made corresponding changes to the documentation
  • [] My changes generate no new warnings
  • [] I have added tests that prove my fix is effective or that my feature works
  • [] New and existing unit tests pass locally with my changes
  • [] Any dependent changes have been merged and published in downstream modules

@envestcc envestcc changed the title Recover action handling panic Recover from action handling panic Dec 5, 2024
defer func() {
if r := recover(); r != nil {
receipt = nil
err = errors.Wrapf(action.ErrPanic, "panic when running action: %v", r)
Copy link
Member

Choose a reason for hiding this comment

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

define a local errPanic so no need to change action/const.go

defer func() {
if r := recover(); r != nil {
receipt = nil
err = errors.Wrapf(action.ErrPanic, "panic when running action: %v", r)
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is an error which should be caught and handled appropriately in pickAndRunActions such that the block mint process can continue

Copy link
Member Author

Choose a reason for hiding this comment

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

If we want to continue minting block, we need to revert to the state after the previous transaction is executed. This may require calling Snapshot() before transaction execution, which would likely result in a hard fork.

Copy link

sonarcloud bot commented Dec 9, 2024

@envestcc envestcc requested a review from CoderZhi December 9, 2024 12:58
ap.DeleteAction(caller)
actionIterator.PopAccount()
continue
case action.ErrPanicButReverted:
Copy link
Member Author

Choose a reason for hiding this comment

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

if panic but reverted, continue when mint and terminate when validate block

sn := ws.Snapshot()
defer func() {
if err != nil {
if e := ws.Revert(sn); e != nil {
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if the Revert() will be a hard fork here. We may need run fullsync

Copy link
Collaborator

@CoderZhi CoderZhi left a comment

Choose a reason for hiding this comment

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

can we add some unit test?

defer func() {
if err != nil {
if e := ws.Revert(sn); e != nil {
log.T(ctx).Error("Failed to revert snapshot", zap.Error(e))
Copy link
Collaborator

Choose a reason for hiding this comment

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

let's also log err

@@ -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() {
Copy link
Collaborator

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

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.

3 participants