Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions prdoc/pr_12684.prdoc
Original file line number Diff line number Diff line change
@@ -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: <message>` 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
28 changes: 14 additions & 14 deletions substrate/primitives/io/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions substrate/primitives/io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down
Loading