From 603a9c151ba2e1be6126497eb7c6c87ffce9c73b Mon Sep 17 00:00:00 2001 From: gui Date: Thu, 6 Jul 2023 12:33:53 +0900 Subject: [PATCH 1/7] 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 { From 9426361416cb051b0507576b010efbc1a6ac65b7 Mon Sep 17 00:00:00 2001 From: gui Date: Sat, 8 Jul 2023 12:57:44 +0900 Subject: [PATCH 2/7] trigger CI --- frame/support/src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index 2a183b00ee14a..b0b64e1e27f3d 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -1525,6 +1525,7 @@ pub mod tests { #[doc(hidden)] pub mod _private { pub use sp_inherents; + } /// Prelude to be used for pallet testing, for ease of use. From 327b853325e73f8158e95031277c502ee49c7ed3 Mon Sep 17 00:00:00 2001 From: gui Date: Sat, 8 Jul 2023 12:57:48 +0900 Subject: [PATCH 3/7] Revert "trigger CI" This reverts commit 9426361416cb051b0507576b010efbc1a6ac65b7. --- frame/support/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index b0b64e1e27f3d..2a183b00ee14a 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -1525,7 +1525,6 @@ pub mod tests { #[doc(hidden)] pub mod _private { pub use sp_inherents; - } /// Prelude to be used for pallet testing, for ease of use. From e7054cf6cf25a6f7f462e284769961d08bca9736 Mon Sep 17 00:00:00 2001 From: gui Date: Sat, 8 Jul 2023 13:37:00 +0900 Subject: [PATCH 4/7] Fix --- .../procedural/src/construct_runtime/expand/inherent.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/frame/support/procedural/src/construct_runtime/expand/inherent.rs b/frame/support/procedural/src/construct_runtime/expand/inherent.rs index 5f0def8aaa9f3..dcbb250aad759 100644 --- a/frame/support/procedural/src/construct_runtime/expand/inherent.rs +++ b/frame/support/procedural/src/construct_runtime/expand/inherent.rs @@ -113,7 +113,13 @@ pub fn expand_outer_inherent( "Fatal error already reported, unexpected considering there is \ only one fatal error", ), - Err(Error::DecodingFailed(_, _)) | Err(Error::Application(_)) => + Err(Error::DecodingFailed(_, _)) => + log::error!( + target: LOG_TARGET, + "Unexpected error from `put_error` operation", + ), + #[cfg(feature = "std")] + Err(Error::Application(_)) => log::error!( target: LOG_TARGET, "Unexpected error from `put_error` operation", From ae100120d896f2ae973727dfecf0dbadae749e74 Mon Sep 17 00:00:00 2001 From: gui Date: Sat, 8 Jul 2023 13:56:26 +0900 Subject: [PATCH 5/7] fix --- frame/nomination-pools/test-staking/Cargo.toml | 5 +++++ .../procedural/src/construct_runtime/expand/inherent.rs | 8 +------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/frame/nomination-pools/test-staking/Cargo.toml b/frame/nomination-pools/test-staking/Cargo.toml index 8ff7895a328dc..95c07ae73f028 100644 --- a/frame/nomination-pools/test-staking/Cargo.toml +++ b/frame/nomination-pools/test-staking/Cargo.toml @@ -35,3 +35,8 @@ pallet-nomination-pools = { version = "1.0.0-dev", path = ".." } sp-tracing = { version = "10.0.0", path = "../../../primitives/tracing" } log = { version = "0.4.0" } + + +[features] +default = ["std"] +std = [] diff --git a/frame/support/procedural/src/construct_runtime/expand/inherent.rs b/frame/support/procedural/src/construct_runtime/expand/inherent.rs index dcbb250aad759..8218f3746e2c3 100644 --- a/frame/support/procedural/src/construct_runtime/expand/inherent.rs +++ b/frame/support/procedural/src/construct_runtime/expand/inherent.rs @@ -113,13 +113,7 @@ pub fn expand_outer_inherent( "Fatal error already reported, unexpected considering there is \ only one fatal error", ), - Err(Error::DecodingFailed(_, _)) => - log::error!( - target: LOG_TARGET, - "Unexpected error from `put_error` operation", - ), - #[cfg(feature = "std")] - Err(Error::Application(_)) => + Err(_) => log::error!( target: LOG_TARGET, "Unexpected error from `put_error` operation", From 3ba412217e6b234268b9ef24893c2257a180a422 Mon Sep 17 00:00:00 2001 From: gui Date: Sat, 8 Jul 2023 14:04:41 +0900 Subject: [PATCH 6/7] fix --- .../nomination-pools/test-staking/Cargo.toml | 5 ---- primitives/inherents/src/lib.rs | 25 +++++++++++++++++-- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/frame/nomination-pools/test-staking/Cargo.toml b/frame/nomination-pools/test-staking/Cargo.toml index 95c07ae73f028..8ff7895a328dc 100644 --- a/frame/nomination-pools/test-staking/Cargo.toml +++ b/frame/nomination-pools/test-staking/Cargo.toml @@ -35,8 +35,3 @@ pallet-nomination-pools = { version = "1.0.0-dev", path = ".." } sp-tracing = { version = "10.0.0", path = "../../../primitives/tracing" } log = { version = "0.4.0" } - - -[features] -default = ["std"] -std = [] diff --git a/primitives/inherents/src/lib.rs b/primitives/inherents/src/lib.rs index dd7c294f1e245..e697a421639bf 100644 --- a/primitives/inherents/src/lib.rs +++ b/primitives/inherents/src/lib.rs @@ -292,6 +292,27 @@ impl Default for CheckInherentsResult { } } +/// Errors that occur in context of [CheckInherentsResult::put_error]. +#[derive(Debug)] +#[cfg_attr(feature = "std", derive(thiserror::Error))] +#[allow(missing_docs)] +pub enum CheckInherentsResultPutErrorError { + #[cfg_attr( + feature = "std", + error("Inherent data already exists for identifier: {}", "String::from_utf8_lossy(_0)") + )] + InherentDataExists(InherentIdentifier), + #[cfg_attr( + feature = "std", + error("Failed to decode inherent data for identifier: {}", "String::from_utf8_lossy(_1)") + )] + #[cfg_attr( + feature = "std", + error("There was already a fatal error reported and no other errors are allowed") + )] + FatalErrorReported, +} + impl CheckInherentsResult { /// Create a new instance. pub fn new() -> Self { @@ -310,10 +331,10 @@ impl CheckInherentsResult { &mut self, identifier: InherentIdentifier, error: &E, - ) -> Result<(), Error> { + ) -> Result<(), CheckInherentsResultPutErrorError> { // Don't accept any other error if self.fatal_error { - return Err(Error::FatalErrorReported) + return Err(CheckInherentsResultPutErrorError::FatalErrorReported) } if error.is_fatal_error() { From c746c9c54a3f46dfa9c6411257fc978a8b448af1 Mon Sep 17 00:00:00 2001 From: gui Date: Sat, 8 Jul 2023 14:28:01 +0900 Subject: [PATCH 7/7] fix --- primitives/inherents/src/lib.rs | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/primitives/inherents/src/lib.rs b/primitives/inherents/src/lib.rs index e697a421639bf..dd7c294f1e245 100644 --- a/primitives/inherents/src/lib.rs +++ b/primitives/inherents/src/lib.rs @@ -292,27 +292,6 @@ impl Default for CheckInherentsResult { } } -/// Errors that occur in context of [CheckInherentsResult::put_error]. -#[derive(Debug)] -#[cfg_attr(feature = "std", derive(thiserror::Error))] -#[allow(missing_docs)] -pub enum CheckInherentsResultPutErrorError { - #[cfg_attr( - feature = "std", - error("Inherent data already exists for identifier: {}", "String::from_utf8_lossy(_0)") - )] - InherentDataExists(InherentIdentifier), - #[cfg_attr( - feature = "std", - error("Failed to decode inherent data for identifier: {}", "String::from_utf8_lossy(_1)") - )] - #[cfg_attr( - feature = "std", - error("There was already a fatal error reported and no other errors are allowed") - )] - FatalErrorReported, -} - impl CheckInherentsResult { /// Create a new instance. pub fn new() -> Self { @@ -331,10 +310,10 @@ impl CheckInherentsResult { &mut self, identifier: InherentIdentifier, error: &E, - ) -> Result<(), CheckInherentsResultPutErrorError> { + ) -> Result<(), Error> { // Don't accept any other error if self.fatal_error { - return Err(CheckInherentsResultPutErrorError::FatalErrorReported) + return Err(Error::FatalErrorReported) } if error.is_fatal_error() {