diff --git a/runtime/common/src/compilation_checks.rs b/runtime/common/src/compilation_checks.rs new file mode 100644 index 0000000000..41a084a0c6 --- /dev/null +++ b/runtime/common/src/compilation_checks.rs @@ -0,0 +1,34 @@ +// Copyright 2025 Moonbeam foundation +// This file is part of Moonbeam. + +// Moonbeam is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Moonbeam is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Moonbeam. If not, see . + +/// Macro to trigger a compile-time error if the `on-chain-release-build` feature is enabled. +/// +/// This ensures that certain code paths are not compiled when the code is built in an +/// on-chain environment, specifically when the `on-chain-release-build` feature is active. +/// This can be useful for enforcing restrictions or preventing undesirable behavior in on-chain +/// builds, ensuring that critical or forbidden code is excluded at compile time. +/// +/// # Usage +/// ```rust +/// moonbeam_runtime_common::fail_to_compile_if_on_chain_build!(); +/// ``` +#[macro_export] +macro_rules! fail_to_compile_if_on_chain_build { + () => { + #[cfg(feature = "on-chain-release-build")] + compile_error!("Not allowed in on-chain builds."); + }; +} diff --git a/runtime/common/src/lib.rs b/runtime/common/src/lib.rs index 38647e2943..bfffaeec51 100644 --- a/runtime/common/src/lib.rs +++ b/runtime/common/src/lib.rs @@ -19,6 +19,7 @@ mod apis; #[cfg(feature = "runtime-benchmarks")] pub mod benchmarking; +pub mod compilation_checks; pub mod deal_with_fees; mod impl_moonbeam_xcm_call; mod impl_moonbeam_xcm_call_tracing; diff --git a/runtime/moonbase/src/lib.rs b/runtime/moonbase/src/lib.rs index 82cc15e691..9e26969737 100644 --- a/runtime/moonbase/src/lib.rs +++ b/runtime/moonbase/src/lib.rs @@ -222,6 +222,13 @@ pub const EXTRINSIC_BASE_WEIGHT: Weight = Weight::from_parts(10000 * WEIGHT_PER_ pub struct RuntimeBlockWeights; impl Get for RuntimeBlockWeights { + #[cfg(feature = "evm-tracing")] + fn get() -> frame_system::limits::BlockWeights { + moonbeam_runtime_common::fail_to_compile_if_on_chain_build!(); + frame_system::limits::BlockWeights::simple_max(Weight::MAX) + } + + #[cfg(not(feature = "evm-tracing"))] fn get() -> frame_system::limits::BlockWeights { frame_system::limits::BlockWeights::builder() .for_class(DispatchClass::Normal, |weights| { diff --git a/runtime/moonbeam/src/lib.rs b/runtime/moonbeam/src/lib.rs index 4b0a18b035..35162cd91e 100644 --- a/runtime/moonbeam/src/lib.rs +++ b/runtime/moonbeam/src/lib.rs @@ -219,6 +219,13 @@ pub const EXTRINSIC_BASE_WEIGHT: Weight = Weight::from_parts(10000 * WEIGHT_PER_ pub struct RuntimeBlockWeights; impl Get for RuntimeBlockWeights { + #[cfg(feature = "evm-tracing")] + fn get() -> frame_system::limits::BlockWeights { + moonbeam_runtime_common::fail_to_compile_if_on_chain_build!(); + frame_system::limits::BlockWeights::simple_max(Weight::MAX) + } + + #[cfg(not(feature = "evm-tracing"))] fn get() -> frame_system::limits::BlockWeights { frame_system::limits::BlockWeights::builder() .for_class(DispatchClass::Normal, |weights| { diff --git a/runtime/moonriver/src/lib.rs b/runtime/moonriver/src/lib.rs index 906fa7fb85..f7d501dda3 100644 --- a/runtime/moonriver/src/lib.rs +++ b/runtime/moonriver/src/lib.rs @@ -224,6 +224,13 @@ pub const EXTRINSIC_BASE_WEIGHT: Weight = Weight::from_parts(10000 * WEIGHT_PER_ pub struct RuntimeBlockWeights; impl Get for RuntimeBlockWeights { + #[cfg(feature = "evm-tracing")] + fn get() -> frame_system::limits::BlockWeights { + moonbeam_runtime_common::fail_to_compile_if_on_chain_build!(); + frame_system::limits::BlockWeights::simple_max(Weight::MAX) + } + + #[cfg(not(feature = "evm-tracing"))] fn get() -> frame_system::limits::BlockWeights { frame_system::limits::BlockWeights::builder() .for_class(DispatchClass::Normal, |weights| {