Skip to content

Commit b9e9723

Browse files
authored
Better handling of error in inherents logic. (paritytech#14521)
* impl * trigger CI * Revert "trigger CI" This reverts commit 9426361. * Fix * fix * fix * fix
1 parent 2cc2646 commit b9e9723

2 files changed

Lines changed: 40 additions & 6 deletions

File tree

frame/support/procedural/src/construct_runtime/expand/inherent.rs

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,37 @@ pub fn expand_outer_inherent(
9090
use #scrate::inherent::{ProvideInherent, IsFatalError};
9191
use #scrate::traits::{IsSubType, ExtrinsicCall};
9292
use #scrate::sp_runtime::traits::Block as _;
93+
use #scrate::_private::sp_inherents::Error;
94+
use #scrate::log;
9395

9496
let mut result = #scrate::inherent::CheckInherentsResult::new();
9597

98+
// This handle assume we abort on the first fatal error.
99+
fn handle_put_error_result(res: Result<(), Error>) {
100+
const LOG_TARGET: &str = "runtime::inherent";
101+
match res {
102+
Ok(()) => (),
103+
Err(Error::InherentDataExists(id)) =>
104+
log::debug!(
105+
target: LOG_TARGET,
106+
"Some error already reported for inherent {:?}, new non fatal \
107+
error is ignored",
108+
id
109+
),
110+
Err(Error::FatalErrorReported) =>
111+
log::error!(
112+
target: LOG_TARGET,
113+
"Fatal error already reported, unexpected considering there is \
114+
only one fatal error",
115+
),
116+
Err(_) =>
117+
log::error!(
118+
target: LOG_TARGET,
119+
"Unexpected error from `put_error` operation",
120+
),
121+
}
122+
}
123+
96124
for xt in block.extrinsics() {
97125
// Inherents are before any other extrinsics.
98126
// And signed extrinsics are not inherents.
@@ -110,9 +138,9 @@ pub fn expand_outer_inherent(
110138
if #pallet_names::is_inherent(call) {
111139
is_inherent = true;
112140
if let Err(e) = #pallet_names::check_inherent(call, self) {
113-
result.put_error(
141+
handle_put_error_result(result.put_error(
114142
#pallet_names::INHERENT_IDENTIFIER, &e
115-
).expect("There is only one fatal error; qed");
143+
));
116144
if e.is_fatal_error() {
117145
return result;
118146
}
@@ -153,19 +181,19 @@ pub fn expand_outer_inherent(
153181
});
154182

155183
if !found {
156-
result.put_error(
184+
handle_put_error_result(result.put_error(
157185
#pallet_names::INHERENT_IDENTIFIER, &e
158-
).expect("There is only one fatal error; qed");
186+
));
159187
if e.is_fatal_error() {
160188
return result;
161189
}
162190
}
163191
},
164192
Ok(None) => (),
165193
Err(e) => {
166-
result.put_error(
194+
handle_put_error_result(result.put_error(
167195
#pallet_names::INHERENT_IDENTIFIER, &e
168-
).expect("There is only one fatal error; qed");
196+
));
169197
if e.is_fatal_error() {
170198
return result;
171199
}

frame/support/src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,12 @@ pub mod tests {
15211521
}
15221522
}
15231523

1524+
/// Private module re-exporting items used by frame support macros.
1525+
#[doc(hidden)]
1526+
pub mod _private {
1527+
pub use sp_inherents;
1528+
}
1529+
15241530
/// Prelude to be used for pallet testing, for ease of use.
15251531
#[cfg(feature = "std")]
15261532
pub mod testing_prelude {

0 commit comments

Comments
 (0)