Repository: paritytech/substrate
File: frame/contracts/src/schedule.rs (Rust)

Code before:
	/// real setting.
	pub runtime_memory: u32,
}

impl Limits {
	/// The maximum memory size in bytes that a contract can occupy.
	pub fn max_memory_size(&self) -> u32 {
		self.memory_pages * 64 * 1024
	}
}

/// Describes the weight for all categories of supported wasm instructions.
///
/// There there is one field for each wasm instruction that describes the weight to
/// execute one instruction of that name. There are a few exceptions:
///
/// 1. If there is a i64 and a i32 variant of an instruction we use the weight
///    of the former for both.
/// 2. The following instructions are free of charge because they merely structure the
///    wasm module and cannot be spammed without making the module invalid (and rejected):
///    End, Unreachable, Return, Else
/// 3. The following instructions cannot be benchmarked because they are removed by any
///    real world execution engine as a preprocessing step and therefore don't yield a
///    meaningful benchmark result. However, in contrast to the instructions mentioned
///    in 2. they can be spammed. We price them with the same weight as the "default"
///    instruction (i64.const): Block, Loop, Nop
/// 4. We price both i64.const and drop as InstructionWeights.i64const / 2. The reason
///    for that is that we cannot benchmark either of them on its own but we need their
///    individual values to derive (by subtraction) the weight of all other instructions
///    that use them as supporting instructions. Supporting means mainly pushing arguments
///    and dropping return values in order to maintain a valid module.
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Clone, Encode, Decode, PartialEq, Eq, ScheduleDebug, TypeInfo)]
#[scale_info(skip_type_params(T))]
pub struct InstructionWeights<T: Config> {
	/// Version of the instruction weights.
	///
	/// # Note
	///
	/// Should be incremented whenever any instruction weight is changed. The
	/// reason is that changes to instruction weights require a re-instrumentation
	/// in order to apply the changes to an already deployed code. The re-instrumentation
	/// is triggered by comparing the version of the current schedule with the version the code was
	/// instrumented with. Changes usually happen when pallet_contracts is re-benchmarked.
	///
	/// Changes to other parts of the schedule should not increment the version in
	/// order to avoid unnecessary re-instrumentations.
	pub version: u32,
	/// Weight to be used for instructions which don't have benchmarks assigned.
	///
	/// This weight is used whenever a code is uploaded with [`Determinism::Relaxed`]

Review comment (suggestion):
```suggestion
/// 4. We price both `i64.const` and drop as `InstructionWeights.i64.const` / 2. The reason for that is
```

Code after:
	/// real setting.
	pub runtime_memory: u32,
}

impl Limits {
	/// The maximum memory size in bytes that a contract can occupy.
	pub fn max_memory_size(&self) -> u32 {
		self.memory_pages * 64 * 1024
	}
}

/// Describes the weight for all categories of supported wasm instructions.
///
/// There there is one field for each wasm instruction that describes the weight to
/// execute one instruction of that name. There are a few exceptions:
///
/// 1. If there is a i64 and a i32 variant of an instruction we use the weight of the former for
///    both.
/// 2. The following instructions are free of charge because they merely structure the wasm module
///    and cannot be spammed without making the module invalid (and rejected): End, Unreachable,
///    Return, Else
/// 3. The following instructions cannot be benchmarked because they are removed by any real world
///    execution engine as a preprocessing step and therefore don't yield a meaningful benchmark
///    result. However, in contrast to the instructions mentioned in 2. they can be spammed. We
///    price them with the same weight as the "default" instruction (i64.const): Block, Loop, Nop
/// 4. We price both i64.const and drop as InstructionWeights.i64const / 2. The reason for that is
///    that we cannot benchmark either of them on its own but we need their individual values to
///    derive (by subtraction) the weight of all other instructions that use them as supporting
///    instructions. Supporting means mainly pushing arguments and dropping return values in order
///    to maintain a valid module.
#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Clone, Encode, Decode, PartialEq, Eq, ScheduleDebug, TypeInfo)]
#[scale_info(skip_type_params(T))]
pub struct InstructionWeights<T: Config> {
	/// Version of the instruction weights.
	///
	/// # Note
	///
	/// Should be incremented whenever any instruction weight is changed. The
	/// reason is that changes to instruction weights require a re-instrumentation
	/// in order to apply the changes to an already deployed code. The re-instrumentation
	/// is triggered by comparing the version of the current schedule with the version the code was
	/// instrumented with. Changes usually happen when pallet_contracts is re-benchmarked.
	///
	/// Changes to other parts of the schedule should not increment the version in
	/// order to avoid unnecessary re-instrumentations.
	pub version: u32,
	/// Weight to be used for instructions which don't have benchmarks assigned.
	///
	/// This weight is used whenever a code is uploaded with [`Determinism::Relaxed`]
	/// and an instruction (usually a float instruction) is encountered. This weight is **not**