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:
PG Herveou
2023-07-14 14:49:47 +02:00
committed by GitHub
parent 70694b903a
commit e8a9559696
5 changed files with 54 additions and 24 deletions
+7 -15
View File
@@ -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 })
}