-
Notifications
You must be signed in to change notification settings - Fork 131
Correct error handling in EndBlocker #839
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
base: dev
Are you sure you want to change the base?
Conversation
3ac264a to
142e49d
Compare
amimart
left a comment
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 like a good standard to adopt
However I think through this initiative we also need to carefully hunt down all the false-errors that are expected situations and non state breaking, as returning an error in an ABCI method will halt the chain.
Also as a side not, I think we should have less error types as most of them denotes the same type but in different context
| logger := sdkCtx.Logger().With( | ||
| "abci_step", "EndBlock", | ||
| "height", sdkCtx.BlockHeight(), | ||
| ) | ||
| sdkCtx = sdkCtx.WithLogger(logger) |
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 is great, I think we should also systematically set the module logger field to allow proper filtering through configuration as it is done 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.
We actually do it in mint module :D
and in the tests, although here we use "submodules"
| return types.ErrNoQualifiedInferers | ||
| return errors.Wrap(err, "failed: fetch active inferrers for topic") | ||
| } else if len(activeInfererAddresses) == 0 { | ||
| return errors.Wrap(types.ErrNoQualifiedInferers, "no qualified inferrers") |
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.
I think this should not be an error as it seems to be a situation expected to happen, by returning an error for a normal behaviour we'll halt the chain
x/emissions/module/abci.go
Outdated
| if err != nil { | ||
| sdkCtx.Logger().Info("Error closing worker nonce", "error", err) | ||
| } | ||
| return errors.WrapWithFields(err, "failed: close worker nonce", "topic_id", topicId) |
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 we want to return the error here, on any case of any error, then we need to carefully review all of the errors we currently have, and either classify them as unexpected (then halt) or recoverable, or just do not return and propagate such recoverable errors on those functions if they are expected to be handled.
This change would need careful review of our error handling within all Begin/EndBlocker code, so it'd be better done in a separate effort than the current fixes on BeginBlocker/EndBlocker.
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.
And I think we would need to do that, for safety; because we are treating equally (= ignoring) both a business-as-usual error like "no inferers in this epoch" or a critical one like "no access to store".
|
|
||
| // EndBlock returns the end blocker for the emissions module. | ||
| func (am AppModule) EndBlock(ctx context.Context) error { | ||
| func (am AppModule) EndBlock(ctx context.Context) (err error) { |
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.
Good one, I'll move this pattern to our current Begin/EndBlocker.
142e49d to
7ba7ff9
Compare
Purpose of Changes and their Description
Link(s) to Ticket(s) or Issue(s) resolved by this PR
Are these changes tested and documented?
Unreleasedsection ofCHANGELOG.md?Still Left Todo
Fill this out if this is a Draft PR so others can help.