Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Better handling of error in inherents logic. #14521

Merged
merged 7 commits into from
Jul 10, 2023

Conversation

gui1117
Copy link
Contributor

@gui1117 gui1117 commented Jul 6, 2023

Currently the code generated by construct_runtime for the check of inherent have a expect with a quite light proof.

In case multiple non fatal error are reported for an inherent the proof is not accurate.
This code makes a more explicit handling of the error and handle this case more appropriately.

IMO we should modify more deeply the inherents logic so that CheckInherentResult could handle multiple non fatal error for an inherent. Or only allow one error by inherent. And maybe remove non fatal error if it is considered superfluous.

But prior to a more consequent refactor to be discussed I think it is better to have an accurate handling of the result from put_error.

@gui1117 gui1117 requested review from a team July 6, 2023 03:45
@@ -110,9 +138,9 @@ pub fn expand_outer_inherent(
if #pallet_names::is_inherent(call) {
is_inherent = true;
if let Err(e) = #pallet_names::check_inherent(call, self) {
result.put_error(
handle_put_error_result(result.put_error(
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest that we move the if fata_error { return } part also to a helper function as this is the part that is still important and ensures we bail after seeing one error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not exactly sure how to factorise it out. something like this?

@@ -138,10 +138,12 @@ pub fn expand_outer_inherent(
                                                                if #pallet_names::is_inherent(call) {
                                                                        is_inherent = true;
                                                                        if let Err(e) = #pallet_names::check_inherent(call, self) {
-                                                                               handle_put_error_result(result.put_error(
-                                                                                       #pallet_names::INHERENT_IDENTIFIER, &e
+                                                                               let is_fatal = put_error_and_is_error_fatal(
+                                                                                       result,
+                                                                                       #pallet_names::INHERENT_IDENTIFIER,
+                                                                                       &e
                                                                                ));
-                                                                               if e.is_fatal_error() {
+                                                                               if is_fatal {
                                                                                        return result;
                                                                                }
                                                                        }

only one fatal error",
),
Err(Error::DecodingFailed(_, _)) | Err(Error::Application(_)) =>
log::error!(
Copy link
Contributor

Choose a reason for hiding this comment

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

Could use defensive macro here instead, as we still know these should (almost) never happen.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but defensive doesn't support renaming of frame_support contrary to construct_runtime.

(by renaming mean if somebody rename in its Cargo.toml like this:

s = { version = "*", package = "frame-support" }

)

@kianenigma kianenigma added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed. labels Jul 7, 2023
@gui1117 gui1117 requested a review from a team July 8, 2023 04:56
"Fatal error already reported, unexpected considering there is \
only one fatal error",
),
Err(_) =>
Copy link
Contributor Author

@gui1117 gui1117 Jul 8, 2023

Choose a reason for hiding this comment

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

error variant are different when sp-inherents is compiled with std or not.
but some test crate use construct_runtime without having a std feature. So there is no way to know what is the actual error type.

EDIT: Anyway I will do a follow up issue with proposals for improving inherent code

@bkchr bkchr merged commit b9e9723 into paritytech:master Jul 10, 2023
4 checks passed
nathanwhit pushed a commit to nathanwhit/substrate that referenced this pull request Jul 19, 2023
* impl

* trigger CI

* Revert "trigger CI"

This reverts commit 9426361.

* Fix

* fix

* fix

* fix
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D5-nicetohaveaudit ⚠️ PR contains trivial changes to logic that should be properly reviewed.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants