Skip to content

Commit

Permalink
rename unchecked to skip_transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
pgherveou committed Nov 26, 2024
1 parent 0733fb6 commit 0941800
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 24 deletions.
16 changes: 8 additions & 8 deletions substrate/frame/revive/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ pub struct Stack<'a, T: Config, E> {
/// Transient storage used to store data, which is kept for the duration of a transaction.
transient_storage: TransientStorage<T>,
/// Whether or not actual transfer of funds should be performed.
unchecked: bool,
skip_transfer: bool,
/// No executable is held by the struct but influences its behaviour.
_phantom: PhantomData<E>,
}
Expand Down Expand Up @@ -779,7 +779,7 @@ where
storage_meter: &'a mut storage::meter::Meter<T>,
value: U256,
input_data: Vec<u8>,
unchecked: bool,
skip_transfer: bool,
debug_message: Option<&'a mut DebugBuffer>,
) -> ExecResult {
let dest = T::AddressMapper::to_account_id(&dest);
Expand All @@ -789,7 +789,7 @@ where
gas_meter,
storage_meter,
value,
unchecked,
skip_transfer,
debug_message,
)? {
stack.run(executable, input_data).map(|_| stack.first_frame.last_frame_output)
Expand All @@ -816,7 +816,7 @@ where
value: U256,
input_data: Vec<u8>,
salt: Option<&[u8; 32]>,
unchecked: bool,
skip_transfer: bool,
debug_message: Option<&'a mut DebugBuffer>,
) -> Result<(H160, ExecReturnValue), ExecError> {
let (mut stack, executable) = Self::new(
Expand All @@ -830,7 +830,7 @@ where
gas_meter,
storage_meter,
value,
unchecked,
skip_transfer,
debug_message,
)?
.expect(FRAME_ALWAYS_EXISTS_ON_INSTANTIATE);
Expand Down Expand Up @@ -876,7 +876,7 @@ where
gas_meter: &'a mut GasMeter<T>,
storage_meter: &'a mut storage::meter::Meter<T>,
value: U256,
unchecked: bool,
skip_transfer: bool,
debug_message: Option<&'a mut DebugBuffer>,
) -> Result<Option<(Self, E)>, ExecError> {
origin.ensure_mapped()?;
Expand Down Expand Up @@ -904,7 +904,7 @@ where
frames: Default::default(),
debug_message,
transient_storage: TransientStorage::new(limits::TRANSIENT_STORAGE_BYTES),
unchecked,
skip_transfer,
_phantom: Default::default(),
};

Expand Down Expand Up @@ -1082,7 +1082,7 @@ where
&frame.account_id,
frame.contract_info.get(&frame.account_id),
executable.code_info(),
self.unchecked,
self.skip_transfer,
)?;
// Needs to be incremented before calling into the code so that it is visible
// in case of recursion.
Expand Down
13 changes: 3 additions & 10 deletions substrate/frame/revive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,17 +1241,10 @@ where
///
/// # Parameters
///
/// - `origin`: The origin of the call.
/// - `dest`: The destination address of the call.
/// - `value`: The EVM value to transfer.
/// - `input`: The input data.
/// - `tx`: The Ethereum transaction to simulate.
/// - `gas_limit`: The gas limit enforced during contract execution.
/// - `storage_deposit_limit`: The maximum balance that can be charged to the caller for storage
/// usage.
/// - `utx_encoded_size`: A function that takes a call and returns the encoded size of the
/// unchecked extrinsic.
/// - `debug`: Debugging configuration.
/// - `collect_events`: Event collection configuration.
pub fn bare_eth_transact(
mut tx: GenericTransaction,
gas_limit: Weight,
Expand Down Expand Up @@ -1498,10 +1491,10 @@ where
origin: T::AccountId,
code: Vec<u8>,
storage_deposit_limit: BalanceOf<T>,
unchecked: bool,
skip_transfer: bool,
) -> Result<(WasmBlob<T>, BalanceOf<T>), DispatchError> {
let mut module = WasmBlob::from_code(code, origin)?;
let deposit = module.store_code(unchecked)?;
let deposit = module.store_code(skip_transfer)?;
ensure!(storage_deposit_limit >= deposit, <Error<T>>::StorageDepositLimitExhausted);
Ok((module, deposit))
}
Expand Down
8 changes: 4 additions & 4 deletions substrate/frame/revive/src/storage/meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ where
pub fn try_into_deposit(
self,
origin: &Origin<T>,
unchecked: bool,
skip_transfer: bool,
) -> Result<DepositOf<T>, DispatchError> {
if !unchecked {
if !skip_transfer {
// Only refund or charge deposit if the origin is not root.
let origin = match origin {
Origin::Root => return Ok(Deposit::Charge(Zero::zero())),
Expand Down Expand Up @@ -437,14 +437,14 @@ impl<T: Config, E: Ext<T>> RawMeter<T, E, Nested> {
contract: &T::AccountId,
contract_info: &mut ContractInfo<T>,
code_info: &CodeInfo<T>,
unchecked: bool,
skip_transfer: bool,
) -> Result<(), DispatchError> {
debug_assert!(matches!(self.contract_state(), ContractState::Alive));

// We need to make sure that the contract's account exists.
let ed = Pallet::<T>::min_balance();
self.total_deposit = Deposit::Charge(ed);
if unchecked {
if skip_transfer {
T::Currency::set_balance(contract, ed);
} else {
T::Currency::transfer(origin, contract, ed, Preservation::Preserve)?;
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/revive/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ where
}

/// Puts the module blob into storage, and returns the deposit collected for the storage.
pub fn store_code(&mut self, unchecked: bool) -> Result<BalanceOf<T>, Error<T>> {
pub fn store_code(&mut self, skip_transfer: bool) -> Result<BalanceOf<T>, Error<T>> {
let code_hash = *self.code_hash();
<CodeInfoOf<T>>::mutate(code_hash, |stored_code_info| {
match stored_code_info {
Expand All @@ -196,7 +196,7 @@ where
None => {
let deposit = self.code_info.deposit;

if !unchecked {
if !skip_transfer {
T::Currency::hold(
&HoldReason::CodeUploadDepositReserve.into(),
&self.code_info.owner,
Expand Down

0 comments on commit 0941800

Please sign in to comment.