Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
8 changes: 6 additions & 2 deletions substrate/frame/revive/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,8 +1288,12 @@ where
// if we are dealing with EVM bytecode
// We upload the new runtime code, and update the code
if !is_pvm {
// Only keep return data for tracing
let data = if crate::tracing::if_tracing(|_| {}).is_none() {
// Only keep return data for tracing and for dry runs.
// When a dry-run simulates contract deployment, keep the execution result's
// data.
let data = if crate::tracing::if_tracing(|_| {}).is_none() &&
!self.exec_config.is_dry_run
{
core::mem::replace(&mut output.data, Default::default())
} else {
output.data.clone()
Expand Down
5 changes: 3 additions & 2 deletions substrate/frame/revive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,7 @@ impl<T: Config> Pallet<T> {
call_info.encoded_len,
base_info.total_weight(),
)
.dry_run()
};

// emulate transaction behavior
Expand Down Expand Up @@ -2335,7 +2336,7 @@ macro_rules! impl_runtime_apis_plus_revive_traits {
gas_limit.unwrap_or(blockweights.max_block),
storage_deposit_limit.unwrap_or(u128::MAX),
input_data,
$crate::ExecConfig::new_substrate_tx(),
$crate::ExecConfig::new_substrate_tx().dry_run(),
)
}

Expand All @@ -2361,7 +2362,7 @@ macro_rules! impl_runtime_apis_plus_revive_traits {
code,
data,
salt,
$crate::ExecConfig::new_substrate_tx(),
$crate::ExecConfig::new_substrate_tx().dry_run(),
)
}

Expand Down
19 changes: 17 additions & 2 deletions substrate/frame/revive/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,20 @@ pub struct ExecConfig {
///
/// It is determined when transforming `eth_transact` into a proper extrinsic.
pub effective_gas_price: Option<U256>,
/// Whether this configuration was created for a dry-run execution.
/// Use to enable logic that should only run in dry-run mode.
pub is_dry_run: bool,
}

impl ExecConfig {
/// Create a default config appropriate when the call originated from a subtrate tx.
/// Create a default config appropriate when the call originated from a substrate tx.
pub fn new_substrate_tx() -> Self {
Self { bump_nonce: true, collect_deposit_from_hold: None, effective_gas_price: None }
Self {
bump_nonce: true,
collect_deposit_from_hold: None,
effective_gas_price: None,
is_dry_run: false,
}
}

/// Create a default config appropriate when the call originated from a ethereum tx.
Expand All @@ -362,8 +370,15 @@ impl ExecConfig {
bump_nonce: false,
collect_deposit_from_hold: Some((encoded_len, base_weight)),
effective_gas_price: Some(effective_gas_price),
is_dry_run: false,
}
}

/// Set this config to be a dry-run.
pub fn dry_run(mut self) -> Self {
self.is_dry_run = true;
self
}
}

/// Indicates whether the code was removed after the last refcount was decremented.
Expand Down
Loading