@@ -40,39 +40,48 @@ pub const INSTR_BENCHMARK_BATCH_SIZE: u32 = 1_000;
40
40
41
41
/// Definition of the cost schedule and other parameterizations for the wasm vm.
42
42
///
43
- /// Its fields are private to the crate in order to allow addition of new contract
44
- /// callable functions without bumping to a new major version. The supplied [`Config::Schedule`]
45
- /// should rely on public functions of this type.
43
+ /// Its [`Default`] implementation is the designated way to initialize this type. It uses
44
+ /// the benchmarked information supplied by [`Config::WeightInfo`]. All of its fields are
45
+ /// public and can therefore be modified. For example in order to change some of the limits
46
+ /// and set a custom instruction weight version the following code could be used:
47
+ /// ```rust
48
+ /// use pallet_contracts::{Schedule, Limits, InstructionWeights, Config};
49
+ ///
50
+ /// fn create_schedule<T: Config>() -> Schedule<T> {
51
+ /// Schedule {
52
+ /// limits: Limits {
53
+ /// globals: 3,
54
+ /// parameters: 3,
55
+ /// memory_pages: 16,
56
+ /// table_size: 3,
57
+ /// br_table_size: 3,
58
+ /// .. Default::default()
59
+ /// },
60
+ /// instruction_weights: InstructionWeights {
61
+ /// version: 5,
62
+ /// .. Default::default()
63
+ /// },
64
+ /// .. Default::default()
65
+ /// }
66
+ /// }
67
+ /// ```
68
+ ///
69
+ /// # Note
70
+ ///
71
+ /// Please make sure to bump the [`InstructionWeights::version`] whenever substantial
72
+ /// changes are made to its values.
46
73
#[ cfg_attr( feature = "std" , derive( Serialize , Deserialize ) ) ]
47
74
#[ cfg_attr( feature = "std" , serde( bound( serialize = "" , deserialize = "" ) ) ) ]
48
75
#[ derive( Clone , Encode , Decode , PartialEq , Eq , ScheduleDebug , DefaultNoBound ) ]
49
76
pub struct Schedule < T : Config > {
50
77
/// Describes the upper limits on various metrics.
51
- pub ( crate ) limits : Limits ,
78
+ pub limits : Limits ,
52
79
53
80
/// The weights for individual wasm instructions.
54
- pub ( crate ) instruction_weights : InstructionWeights < T > ,
81
+ pub instruction_weights : InstructionWeights < T > ,
55
82
56
83
/// The weights for each imported function a contract is allowed to call.
57
- pub ( crate ) host_fn_weights : HostFnWeights < T > ,
58
- }
59
-
60
- impl < T : Config > Schedule < T > {
61
- /// Set the version of the instruction weights.
62
- ///
63
- /// # Note
64
- ///
65
- /// Should be incremented whenever any instruction weight is changed. The
66
- /// reason is that changes to instruction weights require a re-instrumentation
67
- /// in order to apply the changes to an already deployed code. The re-instrumentation
68
- /// is triggered by comparing the version of the current schedule with the the code was
69
- /// instrumented with. Changes usually happen when pallet_contracts is re-benchmarked.
70
- ///
71
- /// Changes to other parts of the schedule should not increment the version in
72
- /// order to avoid unnecessary re-instrumentations.
73
- pub fn set_instruction_weights_version ( & mut self , version : u32 ) {
74
- self . instruction_weights . version = version;
75
- }
84
+ pub host_fn_weights : HostFnWeights < T > ,
76
85
}
77
86
78
87
/// Describes the upper limits on various metrics.
@@ -169,8 +178,17 @@ impl Limits {
169
178
pub struct InstructionWeights < T : Config > {
170
179
/// Version of the instruction weights.
171
180
///
172
- /// See [`Schedule::set_instruction_weights_version`].
173
- pub ( crate ) version : u32 ,
181
+ /// # Note
182
+ ///
183
+ /// Should be incremented whenever any instruction weight is changed. The
184
+ /// reason is that changes to instruction weights require a re-instrumentation
185
+ /// in order to apply the changes to an already deployed code. The re-instrumentation
186
+ /// is triggered by comparing the version of the current schedule with the version the code was
187
+ /// instrumented with. Changes usually happen when pallet_contracts is re-benchmarked.
188
+ ///
189
+ /// Changes to other parts of the schedule should not increment the version in
190
+ /// order to avoid unnecessary re-instrumentations.
191
+ pub version : u32 ,
174
192
pub i64const : u32 ,
175
193
pub i64load : u32 ,
176
194
pub i64store : u32 ,
0 commit comments