TVM Upgrade 2024.04
Introduction of new instructions for cheap fee calculation
This upgrade is active in mainnet since March 16 (see https://t.me/tonstatus/101). Preview of this update for blueprint is available in @ton/sandbox@0.16.0-tvmbeta.3
, @ton-community/func-js@0.6.3-tvmbeta.3
and @ton-community/func-js-bin@0.4.5-tvmbeta.3
packages.
This update is activated by Config8 version
>= 6.
c7
c7 tuple extended from 14 to 16 elements:
- 14: tuple that contains some config parameters as cell slices. If the parameter is absent from the config, the value is null.
- 0:
StoragePrices
fromConfigParam 18
. Not the whole dict, but only the one StoragePrices entry that corresponds to the current time. - 1:
ConfigParam 19
(global id). - 2:
ConfigParam 20
(mc gas prices). - 3:
ConfigParam 21
(gas prices). - 4:
ConfigParam 24
(mc fwd fees). - 5:
ConfigParam 25
(fwd fees). - 6:
ConfigParam 43
(size limits).
- 0:
- 15: "due payment" - current debt for storage fee (nanotons). Asm opcode:
DUEPAYMENT
. - 16: "precompiled gas usage" - gas usage for the current contract if it is precompiled (see ConfigParam 45), null otherwise. Asm opcode:
GETPRECOMPILEDGAS
.
The idea behind this extension of c7 by unpacked config parameters is the following: this data will be retrieved from global configuration by transaction executor, so it is already presented in memory of executor. However (before extension) smart-contract need to get all of these parameters one-by-one from configuration dictionary which is expensive and potentially unpredictable by gas (since cost depends on number of parameters).
Due payment is needed so contract can properly assess storage fees: when message sent in default (bounceable) mode to smart-contract, storage fees are deducted (or added to due_payment field that contains storage fee related debt) prior message value is added to balance. Thus, if contract after processing message send gas excesses back with mode=64, that means that if contract balance hit 0, on next transactions storage fees start accruing in due_payment (and not deducted from incoming messages). That way debt will silently accumulate until account freezes. DUEPAYMENT
allows developer explicitly account/withhold commission for storage and thus prevent any issues.