Idea: Gas cost split for background compilation #7625
Labels
A-contract-runtime
Area: contract compilation and execution, virtual machines, etc
T-contract-runtime
Team: issues relevant to the contract runtime team
This is a tentative tracking issue describing a development idea. It is not a project we actually started working on.
Introduction
Right now, we charge for some amount of gas per action. We have a 300Tgas limit per transaction, with a 1.3Pgas limit per chunk (1Pgas plus "spillover" that can currently happen if the last receipt goes beyond 1Pgas). (Reminder: 1Tgas accounts for 1ms of computation time, 1Pgas is 1s)
However, we would like to be able to deploy smart contracts that take more than 300ms to compile, and ideally have contract deployment be cheaper at the same time.
High-level design
In order to do this, this design suggests that we split the gas cost in two types: "main thread CPU time" and "background thread CPU time". We could then use a background thread to compile, and charge for the compilation with background gas.
This has no impact on UX, as contract compilation is charged without the user having to ever know how it is computed, and the user only really cares about the amount of near tokens consumed.
Mid-level design
Unresolved questions
Can we just disallow this?
Related changes that will probably happen as by-products
The 1.3Pgas limit per chunk is currently a byproduct of a 1Pgas limit where we allow the last receipt to go overboard by its size. This is wrong and we should probably decide whether we actually want the limit to be 1Pgas or 1.3Pgas. Given we probably do not want to reduce the number of transactions per chunk, my guess would be we will stay with 1.3Pgas.
Right now, our behavior is that we have a 1.3Pgas limit, and as soon as less than 300Tgas remain we stop executing receipts, fearing that they may go overboard.
However, once we actually define the gas limit as 1.3Pgas, we can fill chunk more: so long as there is gas left, we can continue iterating over the receipts, and just execute them until we find one that would actually make us go beyond the 1.3Pgas limit: as not all receipts actually consume 300Tgas (or have 300Tgas attached for function call receipts), this would increase our block fullness and so number of transactions per block.
A further change would be to allow reordering receipts (say we're currently at 1.1Pgas and we have in the receipt queue first a 250Tgas receipt then a 150Tgas receipt, we could execute the 150Tgas receipt but it's after in the queue so even with the currently-proposed related change it wouldn't be executed), but given this would change receipt ordering it's not something I currently suggest.
Future improvements
Splitting the gas cost this way sets up the whole infrastructure for splitting gas costs further. In particular, it paves the way to splitting IO gas costs out, so that we can parallelize IO operations and CPU operations during both receipt and contract execution.
However, given taking full advantage of splitting IO gas costs out would also require contract-guided prefetching to take full advantage of it (and have an impact on UI as contract calls would then need to attach two kinds of gas), this is kept as future work that may or may not happen unrelated to this specific idea.
Planned process
The text was updated successfully, but these errors were encountered: