From 603a9c151ba2e1be6126497eb7c6c87ffce9c73b Mon Sep 17 00:00:00 2001 From: gui Date: Thu, 6 Jul 2023 12:33:53 +0900 Subject: [PATCH] impl --- .../src/construct_runtime/expand/inherent.rs | 40 ++++++++++++++++--- frame/support/src/lib.rs | 6 +++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/frame/support/procedural/src/construct_runtime/expand/inherent.rs b/frame/support/procedural/src/construct_runtime/expand/inherent.rs index 2f1cf75ab7ce9..5f0def8aaa9f3 100644 --- a/frame/support/procedural/src/construct_runtime/expand/inherent.rs +++ b/frame/support/procedural/src/construct_runtime/expand/inherent.rs @@ -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(Error::DecodingFailed(_, _)) | Err(Error::Application(_)) => + log::error!( + 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( #pallet_names::INHERENT_IDENTIFIER, &e - ).expect("There is only one fatal error; qed"); + )); if e.is_fatal_error() { return result; } @@ -153,9 +181,9 @@ 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; } @@ -163,9 +191,9 @@ pub fn expand_outer_inherent( }, 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; } diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index 01eec8d2ef79f..2a183b00ee14a 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -1521,6 +1521,12 @@ pub mod tests { } } +/// Private module re-exporting items used by frame support macros. +#[doc(hidden)] +pub mod _private { + pub use sp_inherents; +} + /// Prelude to be used for pallet testing, for ease of use. #[cfg(feature = "std")] pub mod testing_prelude {