near_parameters/
parameter.rs

1use crate::cost::ActionCosts;
2use std::slice;
3
4/// Protocol configuration parameter which may change between protocol versions.
5#[derive(
6    Clone,
7    Copy,
8    PartialEq,
9    Eq,
10    PartialOrd,
11    Ord,
12    Debug,
13    strum::Display,
14    strum::EnumString,
15    strum::IntoStaticStr,
16)]
17#[strum(serialize_all = "snake_case")]
18pub enum Parameter {
19    // Gas economics config
20    BurntGasReward,
21    PessimisticGasPriceInflation,
22    /// Ratio of refunded gas that gets taxed.
23    GasRefundPenalty,
24    /// Minimum gas refund tax.
25    MinGasRefundPenalty,
26
27    /// Stateless validation config
28    /// Size limit for storage proof generated while executing receipts in a chunk.
29    /// After this limit is reached we defer execution of any new receipts.
30    MainStorageProofSizeSoftLimit,
31    /// Hard limit on the size of storage proof generated while executing a single receipt.
32    PerReceiptStorageProofSizeLimit,
33    /// Soft size limit of storage proof used to validate new transactions in ChunkStateWitness.
34    NewTransactionsValidationStateSizeSoftLimit,
35    /// Maximum size of transactions contained inside ChunkStateWitness.
36    /// A witness contains transactions from both the previous chunk and the current one.
37    /// This parameter limits the sum of sizes of transactions from both of those chunks.
38    CombinedTransactionsSizeLimit,
39    /// The standard size limit for outgoing receipts aimed at a single shard.
40    /// This limit is pretty small to keep the size of source_receipt_proofs under control.
41    /// It limits the total sum of outgoing receipts, not individual receipts.
42    OutgoingReceiptsUsualSizeLimit,
43    /// Large size limit for outgoing receipts to a shard, used when it's safe
44    /// to send a lot of receipts without making the state witness too large.
45    /// It limits the total sum of outgoing receipts, not individual receipts.
46    OutgoingReceiptsBigSizeLimit,
47
48    // Account creation config
49    MinAllowedTopLevelAccountLength,
50    RegistrarAccountId,
51
52    // Storage usage config
53    StorageAmountPerByte,
54    StorageNumBytesAccount,
55    StorageNumExtraBytesRecord,
56
57    // Static action costs
58    // send_sir / send_not_sir is burned when creating a receipt on the signer shard.
59    // (SIR = signer is receiver, which guarantees the receipt is local.)
60    // Execution is burned when applying receipt on receiver shard.
61    ActionReceiptCreation,
62    DataReceiptCreationBase,
63    DataReceiptCreationPerByte,
64    ActionCreateAccount,
65    ActionDeleteAccount,
66    ActionDeployContract,
67    ActionDeployContractPerByte,
68    ActionFunctionCall,
69    ActionFunctionCallPerByte,
70    ActionTransfer,
71    ActionStake,
72    ActionAddFullAccessKey,
73    ActionAddFunctionCallKey,
74    ActionAddFunctionCallKeyPerByte,
75    ActionDeleteKey,
76    ActionDelegate,
77    ActionDeterministicStateInit,
78    ActionDeterministicStateInitPerEntry,
79    ActionDeterministicStateInitPerByte,
80
81    // Smart contract dynamic gas costs
82    WasmRegularOpCost,
83    WasmLinearOpBaseCost,
84    WasmLinearOpUnitCost,
85    WasmGrowMemCost,
86    /// Base cost for a host function
87    WasmBase,
88    WasmContractLoadingBase,
89    WasmContractLoadingBytes,
90    WasmReadMemoryBase,
91    WasmReadMemoryByte,
92    WasmWriteMemoryBase,
93    WasmWriteMemoryByte,
94    WasmReadRegisterBase,
95    WasmReadRegisterByte,
96    WasmWriteRegisterBase,
97    WasmWriteRegisterByte,
98    WasmUtf8DecodingBase,
99    WasmUtf8DecodingByte,
100    WasmUtf16DecodingBase,
101    WasmUtf16DecodingByte,
102    WasmSha256Base,
103    WasmSha256Byte,
104    WasmKeccak256Base,
105    WasmKeccak256Byte,
106    WasmKeccak512Base,
107    WasmKeccak512Byte,
108    WasmRipemd160Base,
109    WasmRipemd160Block,
110    WasmEcrecoverBase,
111    WasmEd25519VerifyBase,
112    WasmEd25519VerifyByte,
113    WasmLogBase,
114    WasmLogByte,
115    WasmStorageWriteBase,
116    WasmStorageWriteKeyByte,
117    WasmStorageWriteValueByte,
118    WasmStorageWriteEvictedByte,
119    WasmStorageReadBase,
120    WasmStorageReadKeyByte,
121    WasmStorageReadValueByte,
122    WasmStorageLargeReadOverheadBase,
123    WasmStorageLargeReadOverheadByte,
124    WasmStorageRemoveBase,
125    WasmStorageRemoveKeyByte,
126    WasmStorageRemoveRetValueByte,
127    WasmStorageHasKeyBase,
128    WasmStorageHasKeyByte,
129    WasmStorageIterCreatePrefixBase,
130    WasmStorageIterCreatePrefixByte,
131    WasmStorageIterCreateRangeBase,
132    WasmStorageIterCreateFromByte,
133    WasmStorageIterCreateToByte,
134    WasmStorageIterNextBase,
135    WasmStorageIterNextKeyByte,
136    WasmStorageIterNextValueByte,
137    WasmTouchingTrieNode,
138    WasmReadCachedTrieNode,
139    WasmPromiseAndBase,
140    WasmPromiseAndPerPromise,
141    WasmPromiseReturn,
142    WasmValidatorStakeBase,
143    WasmValidatorTotalStakeBase,
144    WasmAltBn128G1MultiexpBase,
145    WasmAltBn128G1MultiexpElement,
146    WasmAltBn128PairingCheckBase,
147    WasmAltBn128PairingCheckElement,
148    WasmAltBn128G1SumBase,
149    WasmAltBn128G1SumElement,
150    WasmYieldCreateBase,
151    WasmYieldCreateByte,
152    WasmYieldResumeBase,
153    WasmYieldResumeByte,
154    WasmBls12381P1SumBase,
155    WasmBls12381P1SumElement,
156    WasmBls12381P2SumBase,
157    WasmBls12381P2SumElement,
158    WasmBls12381G1MultiexpBase,
159    WasmBls12381G1MultiexpElement,
160    WasmBls12381G2MultiexpBase,
161    WasmBls12381G2MultiexpElement,
162    WasmBls12381MapFpToG1Base,
163    WasmBls12381MapFpToG1Element,
164    WasmBls12381MapFp2ToG2Base,
165    WasmBls12381MapFp2ToG2Element,
166    WasmBls12381PairingBase,
167    WasmBls12381PairingElement,
168    WasmBls12381P1DecompressBase,
169    WasmBls12381P1DecompressElement,
170    WasmBls12381P2DecompressBase,
171    WasmBls12381P2DecompressElement,
172
173    // Smart contract limits
174    MaxGasBurnt,
175    MaxGasBurntView,
176    MaxStackHeight,
177    InitialMemoryPages,
178    MaxMemoryPages,
179    RegistersMemoryLimit,
180    MaxRegisterSize,
181    MaxNumberRegisters,
182    MaxNumberLogs,
183    MaxTotalLogLength,
184    MaxTotalPrepaidGas,
185    MaxActionsPerReceipt,
186    MaxNumberBytesMethodNames,
187    MaxLengthMethodName,
188    MaxArgumentsLength,
189    MaxLengthReturnedData,
190    MaxContractSize,
191    MaxTransactionSize,
192    MaxReceiptSize,
193    MaxLengthStorageKey,
194    MaxLengthStorageValue,
195    MaxPromisesPerFunctionCallAction,
196    MaxNumberInputDataDependencies,
197    MaxFunctionsNumberPerContract,
198    MaxLocalsPerContract,
199    AccountIdValidityRulesVersion,
200    YieldTimeoutLengthInBlocks,
201    MaxYieldPayloadSize,
202    MaxTablesPerContract,
203    MaxElementsPerContractTable,
204
205    // Contract runtime features
206    FlatStorageReads,
207    ImplicitAccountCreation,
208    FixContractLoadingCost,
209    VmKind,
210    EthImplicitAccounts,
211    DiscardCustomSections,
212    SaturatingFloatToInt,
213    ReftypesBulkMemory,
214
215    // Congestion Control
216    MaxCongestionIncomingGas,
217    MaxCongestionOutgoingGas,
218    MaxCongestionMemoryConsumption,
219    MaxCongestionMissedChunks,
220
221    MaxOutgoingGas,
222    MinOutgoingGas,
223    AllowedShardOutgoingGas,
224    MaxTxGas,
225    MinTxGas,
226    RejectTxCongestionThreshold,
227
228    // Use the StateStoredReceipt structure when storing receipts in State.
229    UseStateStoredReceipt,
230
231    // Bandwidth scheduler
232    MaxShardBandwidth,
233    MaxSingleGrant,
234    MaxAllowance,
235    MaxBaseBandwidth,
236
237    // Global contracts
238    ActionDeployGlobalContract,
239    ActionDeployGlobalContractPerByte,
240    GlobalContractStorageAmountPerByte,
241
242    ActionUseGlobalContract,
243    ActionUseGlobalContractPerIdentifierByte,
244    GlobalContractHostFns,
245
246    // Flag to enabled deterministic account ids
247    DeterministicAccountIds,
248}
249
250#[derive(
251    Clone,
252    Copy,
253    PartialEq,
254    Eq,
255    PartialOrd,
256    Ord,
257    Debug,
258    strum::Display,
259    strum::EnumString,
260    strum::IntoStaticStr,
261)]
262#[strum(serialize_all = "snake_case")]
263pub enum FeeParameter {
264    ActionReceiptCreation,
265    DataReceiptCreationBase,
266    DataReceiptCreationPerByte,
267    ActionCreateAccount,
268    ActionDeleteAccount,
269    ActionDeployContract,
270    ActionDeployContractPerByte,
271    ActionFunctionCall,
272    ActionFunctionCallPerByte,
273    ActionTransfer,
274    ActionStake,
275    ActionAddFullAccessKey,
276    ActionAddFunctionCallKey,
277    ActionAddFunctionCallKeyPerByte,
278    ActionDeleteKey,
279    ActionDelegate,
280    ActionDeployGlobalContract,
281    ActionDeployGlobalContractPerByte,
282    ActionUseGlobalContract,
283    ActionUseGlobalContractPerIdentifierByte,
284    ActionDeterministicStateInit,
285    ActionDeterministicStateInitPerByte,
286    ActionDeterministicStateInitPerEntry,
287}
288
289impl Parameter {
290    /// Iterate through all parameters that define numerical limits for
291    /// contracts that are executed in the WASM VM.
292    pub fn vm_limits() -> slice::Iter<'static, Parameter> {
293        [
294            Parameter::MaxGasBurnt,
295            Parameter::MaxStackHeight,
296            Parameter::InitialMemoryPages,
297            Parameter::MaxMemoryPages,
298            Parameter::RegistersMemoryLimit,
299            Parameter::MaxRegisterSize,
300            Parameter::MaxNumberRegisters,
301            Parameter::MaxNumberLogs,
302            Parameter::MaxTotalLogLength,
303            Parameter::MaxTotalPrepaidGas,
304            Parameter::MaxActionsPerReceipt,
305            Parameter::MaxNumberBytesMethodNames,
306            Parameter::MaxLengthMethodName,
307            Parameter::MaxArgumentsLength,
308            Parameter::MaxLengthReturnedData,
309            Parameter::MaxContractSize,
310            Parameter::MaxTransactionSize,
311            Parameter::MaxReceiptSize,
312            Parameter::MaxLengthStorageKey,
313            Parameter::MaxLengthStorageValue,
314            Parameter::MaxPromisesPerFunctionCallAction,
315            Parameter::MaxNumberInputDataDependencies,
316            Parameter::MaxFunctionsNumberPerContract,
317            Parameter::MaxLocalsPerContract,
318            Parameter::AccountIdValidityRulesVersion,
319            Parameter::YieldTimeoutLengthInBlocks,
320            Parameter::MaxYieldPayloadSize,
321            Parameter::PerReceiptStorageProofSizeLimit,
322            Parameter::MaxTablesPerContract,
323            Parameter::MaxElementsPerContractTable,
324        ]
325        .iter()
326    }
327}
328
329// TODO: consider renaming parameters to "action_{ActionCosts}" and deleting
330// `FeeParameter` all together.
331impl From<ActionCosts> for FeeParameter {
332    fn from(other: ActionCosts) -> Self {
333        match other {
334            ActionCosts::create_account => Self::ActionCreateAccount,
335            ActionCosts::delete_account => Self::ActionDeleteAccount,
336            ActionCosts::delegate => Self::ActionDelegate,
337            ActionCosts::deploy_contract_base => Self::ActionDeployContract,
338            ActionCosts::deploy_contract_byte => Self::ActionDeployContractPerByte,
339            ActionCosts::function_call_base => Self::ActionFunctionCall,
340            ActionCosts::function_call_byte => Self::ActionFunctionCallPerByte,
341            ActionCosts::transfer => Self::ActionTransfer,
342            ActionCosts::stake => Self::ActionStake,
343            ActionCosts::add_full_access_key => Self::ActionAddFullAccessKey,
344            ActionCosts::add_function_call_key_base => Self::ActionAddFunctionCallKey,
345            ActionCosts::add_function_call_key_byte => Self::ActionAddFunctionCallKeyPerByte,
346            ActionCosts::delete_key => Self::ActionDeleteKey,
347            ActionCosts::new_action_receipt => Self::ActionReceiptCreation,
348            ActionCosts::new_data_receipt_base => Self::DataReceiptCreationBase,
349            ActionCosts::new_data_receipt_byte => Self::DataReceiptCreationPerByte,
350            ActionCosts::deploy_global_contract_base => Self::ActionDeployGlobalContract,
351            ActionCosts::deploy_global_contract_byte => Self::ActionDeployGlobalContractPerByte,
352            ActionCosts::use_global_contract_base => Self::ActionUseGlobalContract,
353            ActionCosts::use_global_contract_byte => Self::ActionUseGlobalContractPerIdentifierByte,
354            ActionCosts::deterministic_state_init_base => Self::ActionDeterministicStateInit,
355            ActionCosts::deterministic_state_init_byte => Self::ActionDeterministicStateInitPerByte,
356            ActionCosts::deterministic_state_init_entry => {
357                Self::ActionDeterministicStateInitPerEntry
358            }
359        }
360    }
361}