hedera-mirror-node icon indicating copy to clipboard operation
hedera-mirror-node copied to clipboard

08135: Add gas throttle implementation

Open bilyana-gospodinova opened this issue 1 year ago • 2 comments

Description: Currently we are only using a rate limiter per request in the web3 module. But if there are a lot of requests that require a small amount of the gas the system may be a able to handle a larger number of request than in the current rate limit capacity.

This PR introduces a new limiter based on the used gas per second. It will continue to work alongside the existing rate limiter. The new limiter uses the bucket4j's SynchronizedBucket. The flow is like this:

  1. When a request is made the passed gasLimit parameter value is consumed by the bucket.
  2. After the request is processed the unused gas is returned back to the bucket and is available to be consumed by another request.

There are two new properties that are introduced:

  • hedera.mirror.web3.evm.throttleGasLimit - the default value is 50 000 000. This is the amount of gas that can be consumed per second. The bucket automatically restores this amount as available to be used on each second.
  • hedera.mirror.web3.evm.throttleGasLimitRefundPercent - the default value is 20. This is the maximum percent of the gas limit that will be returned back to the bucket if it has remained unused. For example, if the passed gas limit in the request is 1 000 000, the transaction used 200 000 gas, the unused gas is 800 000. The minimum of 800 000 and 20% of the initial 1 000 000 = 200 000 will be returned to the bucket, so in this case this will be 200 000 gas. This implementation is similar to the one in services. Without this percent there are cases such as an EXCEPTIONAL_HALT where the remaining gas in the frame is cleared by the EVM and we need to have a way to control how much gas needs to be restored.

Fixes https://github.com/hashgraph/hedera-mirror-node/issues/8135

The results from the testing are described in https://github.com/hashgraph/hedera-mirror-node/issues/8136.

Checklist

  • [X] Documented (Code comments, README, etc.)
  • [X] Tested (unit, integration, etc.)

bilyana-gospodinova avatar May 10 '24 09:05 bilyana-gospodinova

Codecov Report

Attention: Patch coverage is 97.50000% with 1 lines in your changes are missing coverage. Please review.

Project coverage is 92.31%. Comparing base (302212e) to head (aa10c52). Report is 33 commits behind head on main.

Files Patch % Lines
...edera/mirror/web3/throttle/ThrottleProperties.java 80.00% 1 Missing :warning:
Additional details and impacted files
@@            Coverage Diff            @@
##               main    #8266   +/-   ##
=========================================
  Coverage     92.30%   92.31%           
- Complexity     7290     7301   +11     
=========================================
  Files           899      900    +1     
  Lines         29363    29394   +31     
  Branches       3583     3587    +4     
=========================================
+ Hits          27104    27134   +30     
- Misses         1439     1440    +1     
  Partials        820      820           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov[bot] avatar May 10 '24 09:05 codecov[bot]