Skip to main content

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 Debug;
20use codec::{Decode, Encode, MaxEncodedLen};
21use scale_info::TypeInfo;
22use serde::{Deserialize, Serialize};
23use sp_core::Get;
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	Debug,
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	/// Whether to disable execution tracing.
47	disable_execution_tracing: bool,
48}
49
50impl DebugSettings {
51	pub fn set_bypass_eip_3607(mut self, value: bool) -> Self {
52		self.bypass_eip_3607 = value;
53		self
54	}
55
56	pub fn set_allow_unlimited_contract_size(mut self, value: bool) -> Self {
57		self.allow_unlimited_contract_size = value;
58		self
59	}
60
61	pub fn set_enable_pvm_logs(mut self, value: bool) -> Self {
62		self.pvm_logs = value;
63		self
64	}
65
66	pub fn is_execution_tracing_enabled<T: Config>() -> bool {
67		T::DebugEnabled::get() && !DebugSettingsOf::<T>::get().disable_execution_tracing
68	}
69
70	/// Returns true if unlimited contract size is allowed.
71	pub fn is_unlimited_contract_size_allowed<T: Config>() -> bool {
72		T::DebugEnabled::get() && DebugSettingsOf::<T>::get().allow_unlimited_contract_size
73	}
74
75	/// Returns true if transactions coming from contract or precompile accounts are allowed
76	/// (bypassing EIP-3607)
77	pub fn bypass_eip_3607<T: Config>() -> bool {
78		T::DebugEnabled::get() && DebugSettingsOf::<T>::get().bypass_eip_3607
79	}
80
81	/// Returns true if PolkaVM logs are enabled.
82	pub fn is_pvm_logs_enabled<T: Config>() -> bool {
83		T::DebugEnabled::get() && DebugSettingsOf::<T>::get().pvm_logs
84	}
85
86	/// Write the debug settings to storage.
87	pub fn write_to_storage<T: Config>(&self) {
88		DebugSettingsOf::<T>::put(self);
89		if !T::DebugEnabled::get() {
90			log::warn!(
91				target: crate::LOG_TARGET,
92				"Debug settings changed, but debug features are disabled in the runtime configuration."
93			);
94		}
95	}
96}