mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-14 04:01:10 +00:00
Contracts add code_len to ContractsInfo (#14523)
* add code_len to v12 * fix * Update frame/contracts/src/wasm/mod.rs * fix * fixes * rm test * add test back * fix * update test * Fix comments * fix build * del * fix clippy * fix * re-rename
This commit is contained in:
@@ -92,6 +92,8 @@ pub struct CodeInfo<T: Config> {
|
||||
/// to be run on-chain. Specifically, such a code can never be instantiated into a contract
|
||||
/// and can just be used through a delegate call.
|
||||
determinism: Determinism,
|
||||
/// length of the code in bytes.
|
||||
code_len: u32,
|
||||
}
|
||||
|
||||
/// Defines the required determinism level of a wasm blob when either running or uploading code.
|
||||
@@ -268,15 +270,11 @@ impl<T: Config> WasmBlob<T> {
|
||||
fn load_code(
|
||||
code_hash: CodeHash<T>,
|
||||
gas_meter: &mut GasMeter<T>,
|
||||
) -> Result<CodeVec<T>, DispatchError> {
|
||||
let max_code_len = T::MaxCodeLen::get();
|
||||
let charged = gas_meter.charge(CodeLoadToken(max_code_len))?;
|
||||
|
||||
) -> Result<(CodeVec<T>, CodeInfo<T>), DispatchError> {
|
||||
let code_info = <CodeInfoOf<T>>::get(code_hash).ok_or(Error::<T>::CodeNotFound)?;
|
||||
gas_meter.charge(CodeLoadToken(code_info.code_len))?;
|
||||
let code = <PristineCode<T>>::get(code_hash).ok_or(Error::<T>::CodeNotFound)?;
|
||||
let code_len = code.len() as u32;
|
||||
gas_meter.adjust_gas(charged, CodeLoadToken(code_len));
|
||||
|
||||
Ok(code)
|
||||
Ok((code, code_info))
|
||||
}
|
||||
|
||||
/// Create the module without checking the passed code.
|
||||
@@ -309,13 +307,7 @@ impl<T: Config> Executable<T> for WasmBlob<T> {
|
||||
code_hash: CodeHash<T>,
|
||||
gas_meter: &mut GasMeter<T>,
|
||||
) -> Result<Self, DispatchError> {
|
||||
let code = Self::load_code(code_hash, gas_meter)?;
|
||||
// We store `code_info` at the same time as contract code,
|
||||
// therefore this query shouldn't really fail.
|
||||
// We consider its failure equal to `CodeNotFound`, as contract code without
|
||||
// `code_info` is unusable in this pallet.
|
||||
let code_info = <CodeInfoOf<T>>::get(code_hash).ok_or(Error::<T>::CodeNotFound)?;
|
||||
|
||||
let (code, code_info) = Self::load_code(code_hash, gas_meter)?;
|
||||
Ok(Self { code, code_info, code_hash })
|
||||
}
|
||||
|
||||
|
||||
@@ -286,11 +286,12 @@ where
|
||||
validate::<E, T>(code.as_ref(), schedule, determinism)?;
|
||||
|
||||
// Calculate deposit for storing contract code and `code_info` in two different storage items.
|
||||
let bytes_added = code.len().saturating_add(<CodeInfo<T>>::max_encoded_len()) as u32;
|
||||
let code_len = code.len() as u32;
|
||||
let bytes_added = code_len.saturating_add(<CodeInfo<T>>::max_encoded_len() as u32);
|
||||
let deposit = Diff { bytes_added, items_added: 2, ..Default::default() }
|
||||
.update_contract::<T>(None)
|
||||
.charge_or_zero();
|
||||
let code_info = CodeInfo { owner, deposit, determinism, refcount: 0 };
|
||||
let code_info = CodeInfo { owner, deposit, determinism, refcount: 0, code_len };
|
||||
let code_hash = T::Hashing::hash(&code);
|
||||
|
||||
Ok(WasmBlob { code, code_info, code_hash })
|
||||
@@ -320,6 +321,7 @@ pub mod benchmarking {
|
||||
// this is a helper function for benchmarking which skips deposit collection
|
||||
deposit: Default::default(),
|
||||
refcount: 0,
|
||||
code_len: code.len() as u32,
|
||||
determinism,
|
||||
};
|
||||
let code_hash = T::Hashing::hash(&code);
|
||||
|
||||
Reference in New Issue
Block a user