-
Notifications
You must be signed in to change notification settings - Fork 324
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
[evm] panic on unrecoverable error #4178
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #4178 +/- ##
==========================================
+ Coverage 75.38% 76.51% +1.12%
==========================================
Files 303 340 +37
Lines 25923 29273 +3350
==========================================
+ Hits 19541 22397 +2856
- Misses 5360 5761 +401
- Partials 1022 1115 +93 ☔ View full report in Codecov by Sentry. |
action/protocol/context.go
Outdated
@@ -263,6 +264,7 @@ func WithFeatureCtx(ctx context.Context) context.Context { | |||
CandidateRegisterMustWithStake: !g.IsToBeEnabled(height), | |||
DisableDelegateEndorsement: !g.IsToBeEnabled(height), | |||
SuicideTxLogMismatchPanic: g.IsToBeEnabled(height), | |||
PanicOnDuplicateRevert: g.IsToBeEnabled(height), |
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.
default value (false) as the value after hard fork
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.
ok, to me using a positive (enable after height) flag name is more natural, which help improve code readability and reduce chance of programming mistake, IMO that's more valuable than keeping the default value = false after hard-fork
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.
readability is related to https://github.com/iotexproject/iotex-core/pull/4178/files#diff-8d0192f25f9daf6c1bfa70c3b75949444fe5d1d47193e6b7c1210c39a19ed52aR409, but not the default value in the feature context
@@ -561,16 +570,19 @@ func (stateDB *StateDBAdapter) Empty(evmAddr common.Address) bool { | |||
|
|||
// RevertToSnapshot reverts the state factory to the state at a given snapshot | |||
func (stateDB *StateDBAdapter) RevertToSnapshot(snapshot int) { | |||
ds, ok := stateDB.suicideSnapshot[snapshot] | |||
if !ok && stateDB.panicOnDuplicateRevert { | |||
log.L().Panic("Failed to revert to snapshot.", zap.Int("snapshot", snapshot)) |
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.
according to offline discussion, this won't happen. Thus, hard fork may not be needed. Add a TODO if you insist.
Two more places we need to handle, especially the second one, which was observed before.
https://github.com/iotexproject/iotex-core/pull/4178/files#diff-d4f14fe3911e27971891bedc8bb75529dfdad400cf2beaf785e93e81f1746fc0R581
https://github.com/iotexproject/iotex-core/pull/4178/files#diff-d4f14fe3911e27971891bedc8bb75529dfdad400cf2beaf785e93e81f1746fc0R653
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.
- for safety add hard-fork, can remove after hard-fork, added TODO
Two more places: - the first will be taken care of by this change? after hard-fork it will panic, code won't be able to reach here
- the second is related to
fixSnapshotOrder
flag (which is mostly fixed by trie.db.patch), but I think there are still some cases that error will happen (mostly seen in 13-16m block heights). so we should keep the code as-is, or what is your suggestion here?
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.
- adding TODO is fine
- if we believe so, using log.Panic instead of log.Error?
- We need a follow up issue to capture all the cases and fix them
action/protocol/context.go
Outdated
@@ -263,6 +264,7 @@ func WithFeatureCtx(ctx context.Context) context.Context { | |||
CandidateRegisterMustWithStake: !g.IsToBeEnabled(height), | |||
DisableDelegateEndorsement: !g.IsToBeEnabled(height), | |||
SuicideTxLogMismatchPanic: g.IsToBeEnabled(height), | |||
PanicOnDuplicateRevert: g.IsToBeEnabled(height), |
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.
readability is related to https://github.com/iotexproject/iotex-core/pull/4178/files#diff-8d0192f25f9daf6c1bfa70c3b75949444fe5d1d47193e6b7c1210c39a19ed52aR409, but not the default value in the feature context
@@ -561,16 +570,19 @@ func (stateDB *StateDBAdapter) Empty(evmAddr common.Address) bool { | |||
|
|||
// RevertToSnapshot reverts the state factory to the state at a given snapshot | |||
func (stateDB *StateDBAdapter) RevertToSnapshot(snapshot int) { | |||
ds, ok := stateDB.suicideSnapshot[snapshot] | |||
if !ok && stateDB.panicOnDuplicateRevert { | |||
log.L().Panic("Failed to revert to snapshot.", zap.Int("snapshot", snapshot)) |
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.
- adding TODO is fine
- if we believe so, using log.Panic instead of log.Error?
- We need a follow up issue to capture all the cases and fix them
@@ -220,14 +241,11 @@ func (stateDB *StateDBAdapter) accountCreationOpts() []state.AccountCreationOpti | |||
// CreateAccount creates an account in iotx blockchain | |||
func (stateDB *StateDBAdapter) CreateAccount(evmAddr common.Address) { | |||
addr, err := address.FromBytes(evmAddr.Bytes()) | |||
if err != nil { | |||
log.L().Error("Failed to convert evm address.", zap.Error(err)) | |||
if stateDB.assertError(err, "Failed to convert evm address.", zap.Error(err)) { |
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.
it will call stateDB.logError(err)
in new behaviours, does it matters?
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.
it does not matter much. stateDB.logError(err)
just updates the most recent error of EVM, does not affect consensus
ds, ok := stateDB.suicideSnapshot[snapshot] | ||
if !ok && stateDB.panicUnrecoverableError { | ||
log.L().Panic("Failed to revert to snapshot.", zap.Int("snapshot", snapshot)) | ||
} | ||
if err := stateDB.sm.Revert(snapshot); err != nil { |
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.
panic if it returns error?
@@ -499,11 +499,11 @@ func (stateDB *StateDBAdapter) Exist(evmAddr common.Address) bool { | |||
return true | |||
} | |||
recorded, err := accountutil.Recorded(stateDB.sm, addr) | |||
if !recorded { | |||
log.L().Debug("Account does not exist.", zap.String("address", addr.String())) | |||
if stateDB.assertError(err, "Account does not exist.", zap.Error(err), zap.String("address", evmAddr.Hex())) { |
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.
if error happens, it returns false, err
, so should check error first
if err != nil { | ||
log.L().Error("Failed to create account.", zap.Error(err)) | ||
stateDB.logError(err) | ||
if stateDB.assertError(err, "Failed to create account.", zap.Error(err), zap.String("address", evmAddr.Hex())) { |
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.
zap.Error(err)
could be found in all places which calls stateDB.assertError(
, thus, it could be added inside of the function given err
.
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.
it's possible, yet inside assertError()
, would have to manually add it to the beginning of ...fields
var f []zap.Field
f = append(zap.Error(err), fields...)
log.L().Panic(msg, f)
which is kind of inefficient
so would keep it as-is for now, can refactor if we feel there's a need later
Quality Gate failedFailed conditions |
Description
Fixes #(issue)
Type of change
Please delete options that are not relevant.
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
Test Configuration:
Checklist: