[go: up one dir, main page]

Proto: Optimize gas counting

This MR replaces metastatedev/tezos!361 (closed).

Context

The current implementation witnesses gas consumption by updating two gas levels, one to respect the operation gas limit and the other to respect the block gas limit. These updates decrement the levels by exactly the same amount. Two ZArith subtractions and two ZArith comparisons are paid while only one subtraction and only one comparison are actually needed. Indeed, let min_gas be the minimum between block_gas and operation_gas, and max_gas for their maximum. If one of the two counters has to hit 0, then it must be min_gas.

In this MR, gas updates and checks are only done on min_gas. By remembering which of block_gas and operation_gas was the minimum, we can update max_gas afterward. This piece of information helps to produce the right error message in case of gas exhaustion. This optimization removes two ZArith operations over four in the critical routine consume_gas.

This optimization is part of a sequence to optimize gas update and check for gas exhaustion documented here: https://hackmd.io/@yrg/rkLwB17wD

Related: #1013 (closed)

Manually testing the MR

dune exec src/proto_alpha/lib_protocol/test/main.exe -- test "gas levels"     

Checklist

  • Document the interface of any function added or modified (see the coding guidelines)
  • Provide automatic testing (see the testing guide).
  • [ ] Add item in the Development Version section of CHANGES.md (only for new features and bug fixes).

Reviewers

@mbouaziz @igarnier @rafoo_

Edited by Yann Regis-Gianas

Merge request reports

Loading