diff --git a/prdoc/pr_12684.prdoc b/prdoc/pr_12684.prdoc new file mode 100644 index 000000000000..e76b82f5d99e --- /dev/null +++ b/prdoc/pr_12684.prdoc @@ -0,0 +1,17 @@ +title: 'sp-io: report runtime panic messages to the host by default' +doc: +- audience: Runtime Dev + description: |- + The runtime panic handler in `sp-io` now marshals panic (and OOM) messages + to the host via the `PanicHandler::abort_on_panic` host function by + default, so callers receive `Runtime panicked: ` instead of an + opaque `wasm trap: wasm 'unreachable' instruction executed` error. This + was previously opt-in behind the `improved_panic_error_reporting` feature, + which is now a deprecated no-op. Runtimes targeting a host client without + the `PanicHandler` host functions can restore the previous behavior with + the new `legacy_panic_error_reporting` feature. The polkadot PVF executor + instantiates with `allow_missing_func_imports`, so parachain validation is + unaffected: a panic during validation traps exactly as before. +crates: +- name: sp-io + bump: minor diff --git a/substrate/primitives/io/Cargo.toml b/substrate/primitives/io/Cargo.toml index 38ff09e0cdf0..84941fe56f9b 100644 --- a/substrate/primitives/io/Cargo.toml +++ b/substrate/primitives/io/Cargo.toml @@ -83,24 +83,24 @@ disable_panic_handler = [] disable_oom = [] disable_allocator = [] -# This feature flag controls the runtime's behavior when encountering -# a panic or when it runs out of memory, improving the diagnostics. -# -# When enabled the runtime will marshal the relevant error message -# to the host through the `PanicHandler::abort_on_panic` runtime interface. -# This gives the caller direct programmatic access to the error message. +# DEPRECATED: Marshalling the panic message to the host through the +# `PanicHandler::abort_on_panic` runtime interface is the default behavior +# now; this feature flag is a no-op kept for backwards compatibility. +# See `legacy_panic_error_reporting` to opt out of it. +improved_panic_error_reporting = [] + +# Restores the legacy behavior when encountering a panic or running out of +# memory: the error message is only printed to the logs and execution aborts +# via the `unreachable` instruction, with the caller receiving a generic +# "wasm `unreachable` instruction executed" error message instead of the +# panic message. # -# When disabled the error message will only be printed out in the -# logs, with the caller receiving a generic "wasm `unreachable` instruction executed" -# error message. +# Only needed when targeting a host client that does not provide the +# `PanicHandler::abort_on_panic` host function. # # This has no effect if both `disable_panic_handler` and `disable_oom` # are enabled. -# -# WARNING: Enabling this feature flag requires the `PanicHandler::abort_on_panic` -# host function to be supported by the host. Do *not* enable it for your -# runtime without first upgrading your host client! -improved_panic_error_reporting = [] +legacy_panic_error_reporting = [] # This feature adds BLS crypto primitives. # It should not be used in production since the implementation and interface may still diff --git a/substrate/primitives/io/src/lib.rs b/substrate/primitives/io/src/lib.rs index 7a8fbb7da016..0318415b45be 100644 --- a/substrate/primitives/io/src/lib.rs +++ b/substrate/primitives/io/src/lib.rs @@ -1957,26 +1957,22 @@ pub fn unreachable() -> ! { #[panic_handler] pub fn panic(info: &core::panic::PanicInfo) -> ! { let message = alloc::format!("{}", info); - #[cfg(feature = "improved_panic_error_reporting")] - { - panic_handler::abort_on_panic(&message); - } - #[cfg(not(feature = "improved_panic_error_reporting"))] + #[cfg(feature = "legacy_panic_error_reporting")] { logging::log(RuntimeInterfaceLogLevel::Error, "runtime", message.as_bytes()); unreachable(); } + #[cfg(not(feature = "legacy_panic_error_reporting"))] + { + panic_handler::abort_on_panic(&message); + } } /// A default OOM handler for the runtime environment. #[cfg(all(not(feature = "disable_oom"), enable_alloc_error_handler))] #[alloc_error_handler] pub fn oom(_: core::alloc::Layout) -> ! { - #[cfg(feature = "improved_panic_error_reporting")] - { - panic_handler::abort_on_panic("Runtime memory exhausted."); - } - #[cfg(not(feature = "improved_panic_error_reporting"))] + #[cfg(feature = "legacy_panic_error_reporting")] { logging::log( RuntimeInterfaceLogLevel::Error, @@ -1985,6 +1981,10 @@ pub fn oom(_: core::alloc::Layout) -> ! { ); unreachable(); } + #[cfg(not(feature = "legacy_panic_error_reporting"))] + { + panic_handler::abort_on_panic("Runtime memory exhausted."); + } } /// Type alias for Externalities implementation used in tests.