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