pallet_revive/
debug.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18use crate::{Config, DebugSettingsOf};
19use codec::{Decode, Encode, MaxEncodedLen};
20use scale_info::TypeInfo;
21use serde::{Deserialize, Serialize};
22use sp_core::Get;
23use sp_runtime::RuntimeDebug;
24
25/// Debugging settings that can be configured when DebugEnabled config is true.
26#[derive(
27	Encode,
28	Decode,
29	Default,
30	Clone,
31	PartialEq,
32	RuntimeDebug,
33	TypeInfo,
34	MaxEncodedLen,
35	Serialize,
36	Deserialize,
37)]
38pub struct DebugSettings {
39	/// Whether to allow unlimited contract size.
40	allow_unlimited_contract_size: bool,
41	/// Whether to allow bypassing EIP-3607 (allowing transactions coming from contract or
42	/// precompile accounts).
43	bypass_eip_3607: bool,
44	/// Whether to enable PolkaVM logs.
45	pvm_logs: bool,
46}
47
48impl DebugSettings {
49	pub fn new(allow_unlimited_contract_size: bool, bypass_eip_3607: bool, pvm_logs: bool) -> Self {
50		Self { allow_unlimited_contract_size, bypass_eip_3607, pvm_logs }
51	}
52
53	/// Returns true if unlimited contract size is allowed.
54	pub fn is_unlimited_contract_size_allowed<T: Config>() -> bool {
55		T::DebugEnabled::get() && DebugSettingsOf::<T>::get().allow_unlimited_contract_size
56	}
57
58	/// Returns true if transactions coming from contract or precompile accounts are allowed
59	/// (bypassing EIP-3607)
60	pub fn bypass_eip_3607<T: Config>() -> bool {
61		T::DebugEnabled::get() && DebugSettingsOf::<T>::get().bypass_eip_3607
62	}
63
64	/// Returns true if PolkaVM logs are enabled.
65	pub fn is_pvm_logs_enabled<T: Config>() -> bool {
66		T::DebugEnabled::get() && DebugSettingsOf::<T>::get().pvm_logs
67	}
68
69	/// Write the debug settings to storage.
70	pub fn write_to_storage<T: Config>(&self) {
71		DebugSettingsOf::<T>::put(self);
72		if !T::DebugEnabled::get() {
73			log::warn!(
74				target: crate::LOG_TARGET,
75				"Debug settings changed, but debug features are disabled in the runtime configuration."
76			);
77		}
78	}
79}