-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Better handling of error in inherents logic. #14521
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 |
---|---|---|
|
@@ -90,9 +90,37 @@ pub fn expand_outer_inherent( | |
use #scrate::inherent::{ProvideInherent, IsFatalError}; | ||
use #scrate::traits::{IsSubType, ExtrinsicCall}; | ||
use #scrate::sp_runtime::traits::Block as _; | ||
use #scrate::_private::sp_inherents::Error; | ||
use #scrate::log; | ||
|
||
let mut result = #scrate::inherent::CheckInherentsResult::new(); | ||
|
||
// This handle assume we abort on the first fatal error. | ||
fn handle_put_error_result(res: Result<(), Error>) { | ||
const LOG_TARGET: &str = "runtime::inherent"; | ||
match res { | ||
Ok(()) => (), | ||
Err(Error::InherentDataExists(id)) => | ||
log::debug!( | ||
target: LOG_TARGET, | ||
"Some error already reported for inherent {:?}, new non fatal \ | ||
error is ignored", | ||
id | ||
), | ||
Err(Error::FatalErrorReported) => | ||
log::error!( | ||
target: LOG_TARGET, | ||
"Fatal error already reported, unexpected considering there is \ | ||
only one fatal error", | ||
), | ||
Err(_) => | ||
log::error!( | ||
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. Could use 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. but (by renaming mean if somebody rename in its Cargo.toml like this:
) |
||
target: LOG_TARGET, | ||
"Unexpected error from `put_error` operation", | ||
), | ||
} | ||
} | ||
|
||
for xt in block.extrinsics() { | ||
// Inherents are before any other extrinsics. | ||
// And signed extrinsics are not inherents. | ||
|
@@ -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( | ||
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. I would suggest that we move the 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. 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;
}
} |
||
#pallet_names::INHERENT_IDENTIFIER, &e | ||
).expect("There is only one fatal error; qed"); | ||
)); | ||
if e.is_fatal_error() { | ||
return result; | ||
} | ||
|
@@ -153,19 +181,19 @@ pub fn expand_outer_inherent( | |
}); | ||
|
||
if !found { | ||
result.put_error( | ||
handle_put_error_result(result.put_error( | ||
#pallet_names::INHERENT_IDENTIFIER, &e | ||
).expect("There is only one fatal error; qed"); | ||
)); | ||
if e.is_fatal_error() { | ||
return result; | ||
} | ||
} | ||
}, | ||
Ok(None) => (), | ||
Err(e) => { | ||
result.put_error( | ||
handle_put_error_result(result.put_error( | ||
#pallet_names::INHERENT_IDENTIFIER, &e | ||
).expect("There is only one fatal error; qed"); | ||
)); | ||
if e.is_fatal_error() { | ||
return result; | ||
} | ||
|
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.
error variant are different when sp-inherents is compiled with
std
or not.but some test crate use
construct_runtime
without having astd
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