Skip to content

Commit

Permalink
".git/.scripts/commands/fmt/fmt.sh"
Browse files Browse the repository at this point in the history
  • Loading branch information
command-bot committed Sep 27, 2024
1 parent f85b18b commit 6f3aa5e
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 48 deletions.
4 changes: 2 additions & 2 deletions substrate/frame/revive/src/benchmarking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ fn caller_funding<T: Config>() -> BalanceOf<T> {

/// The deposit limit we use for benchmarks.
fn default_deposit_limit<T: Config>() -> BalanceOf<T> {
(T::DepositPerByte::get() * 1024u32.into() * 1024u32.into())
+ T::DepositPerItem::get() * 1024u32.into()
(T::DepositPerByte::get() * 1024u32.into() * 1024u32.into()) +
T::DepositPerItem::get() * 1024u32.into()
}

#[benchmarks(
Expand Down
5 changes: 2 additions & 3 deletions substrate/frame/revive/src/exec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,9 +1129,8 @@ where
with_transaction(|| -> TransactionOutcome<Result<_, DispatchError>> {
let output = do_transaction();
match &output {
Ok(result) if !result.did_revert() => {
TransactionOutcome::Commit(Ok((true, output)))
},
Ok(result) if !result.did_revert() =>
TransactionOutcome::Commit(Ok((true, output))),
_ => TransactionOutcome::Rollback(Ok((false, output))),
}
});
Expand Down
17 changes: 8 additions & 9 deletions substrate/frame/revive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,8 @@ pub mod pallet {
.len() as u32;

let max_immutable_key_size = T::AccountId::max_encoded_len() as u32;
let max_immutable_size: u32 = ((max_block_ref_time
/ (<RuntimeCosts as gas::Token<T>>::weight(&RuntimeCosts::SetImmutableData(
let max_immutable_size: u32 = ((max_block_ref_time /
(<RuntimeCosts as gas::Token<T>>::weight(&RuntimeCosts::SetImmutableData(
limits::IMMUTABLE_BYTES,
))
.ref_time()))
Expand All @@ -684,8 +684,8 @@ pub mod pallet {

// We can use storage to store items using the available block ref_time with the
// `set_storage` host function.
let max_storage_size: u32 = ((max_block_ref_time
/ (<RuntimeCosts as gas::Token<T>>::weight(&RuntimeCosts::SetStorage {
let max_storage_size: u32 = ((max_block_ref_time /
(<RuntimeCosts as gas::Token<T>>::weight(&RuntimeCosts::SetStorage {
new_bytes: max_payload_size,
old_bytes: 0,
})
Expand All @@ -708,8 +708,8 @@ pub mod pallet {
// We can use storage to store events using the available block ref_time with the
// `deposit_event` host function. The overhead of stored events, which is around 100B,
// is not taken into account to simplify calculations, as it does not change much.
let max_events_size: u32 = ((max_block_ref_time
/ (<RuntimeCosts as gas::Token<T>>::weight(&RuntimeCosts::DepositEvent {
let max_events_size: u32 = ((max_block_ref_time /
(<RuntimeCosts as gas::Token<T>>::weight(&RuntimeCosts::DepositEvent {
num_topic: 0,
len: max_payload_size,
})
Expand Down Expand Up @@ -1067,9 +1067,8 @@ where
storage_deposit_limit.saturating_reduce(upload_deposit);
(executable, upload_deposit)
},
Code::Existing(code_hash) => {
(WasmBlob::from_storage(code_hash, &mut gas_meter)?, Default::default())
},
Code::Existing(code_hash) =>
(WasmBlob::from_storage(code_hash, &mut gas_meter)?, Default::default()),
};
let instantiate_origin = Origin::from_account_id(instantiate_account.clone());
let mut storage_meter =
Expand Down
9 changes: 4 additions & 5 deletions substrate/frame/revive/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,12 @@ impl<T: Config> ContractInfo<T> {
if let Some(storage_meter) = storage_meter {
let mut diff = meter::Diff::default();
match (old_len, new_value.as_ref().map(|v| v.len() as u32)) {
(Some(old_len), Some(new_len)) => {
(Some(old_len), Some(new_len)) =>
if new_len > old_len {
diff.bytes_added = new_len - old_len;
} else {
diff.bytes_removed = old_len - new_len;
}
},
},
(None, Some(new_len)) => {
diff.bytes_added = new_len;
diff.items_added = 1;
Expand Down Expand Up @@ -309,8 +308,8 @@ impl<T: Config> ContractInfo<T> {
/// of those keys can be deleted from the deletion queue given the supplied weight limit.
pub fn deletion_budget(meter: &WeightMeter) -> (Weight, u32) {
let base_weight = T::WeightInfo::on_process_deletion_queue_batch();
let weight_per_key = T::WeightInfo::on_initialize_per_trie_key(1)
- T::WeightInfo::on_initialize_per_trie_key(0);
let weight_per_key = T::WeightInfo::on_initialize_per_trie_key(1) -
T::WeightInfo::on_initialize_per_trie_key(0);

// `weight_per_key` being zero makes no sense and would constitute a failure to
// benchmark properly. We opt for not removing any keys at all in this case.
Expand Down
30 changes: 12 additions & 18 deletions substrate/frame/revive/src/storage/meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,16 @@ impl Diff {
info.storage_items =
info.storage_items.saturating_add(items_added).saturating_sub(items_removed);
match &bytes_deposit {
Deposit::Charge(amount) => {
info.storage_byte_deposit = info.storage_byte_deposit.saturating_add(*amount)
},
Deposit::Refund(amount) => {
info.storage_byte_deposit = info.storage_byte_deposit.saturating_sub(*amount)
},
Deposit::Charge(amount) =>
info.storage_byte_deposit = info.storage_byte_deposit.saturating_add(*amount),
Deposit::Refund(amount) =>
info.storage_byte_deposit = info.storage_byte_deposit.saturating_sub(*amount),
}
match &items_deposit {
Deposit::Charge(amount) => {
info.storage_item_deposit = info.storage_item_deposit.saturating_add(*amount)
},
Deposit::Refund(amount) => {
info.storage_item_deposit = info.storage_item_deposit.saturating_sub(*amount)
},
Deposit::Charge(amount) =>
info.storage_item_deposit = info.storage_item_deposit.saturating_add(*amount),
Deposit::Refund(amount) =>
info.storage_item_deposit = info.storage_item_deposit.saturating_sub(*amount),
}

bytes_deposit.saturating_add(&items_deposit)
Expand Down Expand Up @@ -265,9 +261,8 @@ impl<T: Config> Contribution<T> {
fn update_contract(&self, info: Option<&mut ContractInfo<T>>) -> DepositOf<T> {
match self {
Self::Alive(diff) => diff.update_contract::<T>(info),
Self::Terminated { deposit, beneficiary: _ } | Self::Checked(deposit) => {
deposit.clone()
},
Self::Terminated { deposit, beneficiary: _ } | Self::Checked(deposit) =>
deposit.clone(),
}
}
}
Expand Down Expand Up @@ -347,9 +342,8 @@ where
/// Returns the state of the currently executed contract.
fn contract_state(&self) -> ContractState<T> {
match &self.own_contribution {
Contribution::Terminated { deposit: _, beneficiary } => {
ContractState::Terminated { beneficiary: beneficiary.clone() }
},
Contribution::Terminated { deposit: _, beneficiary } =>
ContractState::Terminated { beneficiary: beneficiary.clone() },
_ => ContractState::Alive,
}
}
Expand Down
4 changes: 2 additions & 2 deletions substrate/frame/revive/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ pub mod test_utils {
let code_info_len = CodeInfo::<Test>::max_encoded_len() as u64;
// Calculate deposit to be reserved.
// We add 2 storage items: one for code, other for code_info
DepositPerByte::get().saturating_mul(code_len as u64 + code_info_len)
+ DepositPerItem::get().saturating_mul(2)
DepositPerByte::get().saturating_mul(code_len as u64 + code_info_len) +
DepositPerItem::get().saturating_mul(2)
}
pub fn ensure_stored(code_hash: sp_core::H256) -> usize {
// Assert that code_info is stored
Expand Down
15 changes: 6 additions & 9 deletions substrate/frame/revive/src/wasm/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,8 @@ impl<'a, E: Ext, M: PolkaVmInstance<E::T>> Runtime<'a, E, M> {
log::error!(target: LOG_TARGET, "polkavm execution error: {error}");
Some(Err(Error::<E::T>::ExecutionFailed.into()))
},
Ok(Finished) => {
Some(Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: Vec::new() }))
},
Ok(Finished) =>
Some(Ok(ExecReturnValue { flags: ReturnFlags::empty(), data: Vec::new() })),
Ok(Trap) => Some(Err(Error::<E::T>::ContractTrapped.into())),
Ok(Segfault(_)) => Some(Err(Error::<E::T>::ExecutionFailed.into())),
Ok(NotEnoughGas) => Some(Err(Error::<E::T>::OutOfGas.into())),
Expand All @@ -592,12 +591,11 @@ impl<'a, E: Ext, M: PolkaVmInstance<E::T>> Runtime<'a, E, M> {
instance.write_output(return_value);
None
},
Err(TrapReason::Return(ReturnData { flags, data })) => {
Err(TrapReason::Return(ReturnData { flags, data })) =>
match ReturnFlags::from_bits(flags) {
None => Some(Err(Error::<E::T>::InvalidCallFlags.into())),
Some(flags) => Some(Ok(ExecReturnValue { flags, data })),
}
},
},
Err(TrapReason::Termination) => Some(Ok(Default::default())),
Err(TrapReason::SupervisorError(error)) => Some(Err(error.into())),
}
Expand Down Expand Up @@ -1781,9 +1779,8 @@ pub mod env {
Environment::new(self, memory, id, input_ptr, input_len, output_ptr, output_len_ptr);
let ret = match chain_extension.call(env)? {
RetVal::Converging(val) => Ok(val),
RetVal::Diverging { flags, data } => {
Err(TrapReason::Return(ReturnData { flags: flags.bits(), data }))
},
RetVal::Diverging { flags, data } =>
Err(TrapReason::Return(ReturnData { flags: flags.bits(), data })),
};
self.chain_extension = Some(chain_extension);
ret
Expand Down

0 comments on commit 6f3aa5e

Please sign in to comment.