Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: configurations of HbarLimitService #3014

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

victor-yanev
Copy link
Contributor

@victor-yanev victor-yanev commented Sep 19, 2024

Description:

This PR includes changes to the configurations of the HbarLimitService to make use of the env variables for the total budget and the limit duration that were used for the old HbarLimit implementation.

As a result, also had to rename spentToday field to amountSpent since we are no longer doing daily limiting and we are limiting based on a configurable time window.

It also adds a Configurations section in the hbar-limiter.md doc which describes all configurations used for the redesigned HBAR limiter, and also added the new env vars used in the configurations.md doc.

Related issue(s):

Fixes #2970

Fixes #3018

Notes for reviewer:

As part of doing #2970 and #3018, I noticed a flaw in the configurations of the HbarLimitService - we use number for the type of the totalBudget and remainingBudget and if this value becomes too big, we would hit a bug of overflowing numbers.

Current limiting of the existing HbarLimit class is 110 ℏ per minute - if we want to keep this limit the same (but limit on a per day basis instead of per minute) that would be:

$$totalBudget = 110 \: ℏ * 1440 \: mins \: in \: a \: day = 158400 \: ℏ = 1.58400e13 \: tℏ \: per \: day$$

These numbers get increasingly big, especially if we decide to change the limit duration to be per month instead of per day - then we would overflow the Number.MAX_VALUE and break the hbar limiter.

This is why in this PR, I have changed the type of totalBudget and remainingBudget from number to Hbar, which internally uses the Long library.

Checklist

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

@victor-yanev victor-yanev self-assigned this Sep 19, 2024
@victor-yanev victor-yanev added this to the 0.57.0 milestone Sep 19, 2024
@victor-yanev victor-yanev added bug Something isn't working documentation Improvements or additions to documentation design Design, pilot and prototyping exploration work labels Sep 19, 2024
Copy link

github-actions bot commented Sep 19, 2024

Acceptance Tests

0 tests   0 ✔️  0s ⏱️
0 suites  0 💤
0 files    0

Results for commit 1083828.

♻️ This comment has been updated with latest results.

Copy link

🚨 Memory Leak Detected 🚨

A potential memory leak has been detected in the test titled should execute "eth_chainId". This may impact the application's performance and stability.

Details

📊 Memory Leak Detection Report 📊

GC Type: Scavenge
Cost: 3,102.97 ms

Heap Statistics (before vs after executing the test):

  • Total Heap Size: increased with 2.71 MB
  • Total Heap Size Executable: no changes
  • Total Physical Size: increased with 2.71 MB
  • Total Available Size: increased with 12.52 MB
  • Total Global Handles Size: no changes
  • Used Global Handles Size: decreased with 320.00 bytes
  • Used Heap Size: decreased with 11.90 MB
  • Heap Size Limit: no changes
  • Malloced Memory: no changes
  • External Memory: no changes
  • Peak Malloced Memory: no changes

Heap Space Statistics (before vs after executing the test):

  • Old Space:

    • Space Size: increased with 2.88 MB
    • Space Used Size: increased with 2.12 MB
    • Space Available Size: increased with 712.98 KB
    • Physical Space Size: increased with 2.88 MB
  • Large Object Space:

    • Space Size: increased with 507.90 KB
    • Space Used Size: increased with 496.33 KB
    • Space Available Size: no changes
    • Physical Space Size: increased with 507.90 KB

Recommendations

Please investigate the memory allocations in this test, focusing on objects that are not being properly deallocated.

Copy link

github-actions bot commented Sep 19, 2024

Tests

       3 files     300 suites   19s ⏱️
1 357 tests 1 356 ✔️ 1 💤 0
1 366 runs  1 365 ✔️ 1 💤 0

Results for commit 1083828.

♻️ This comment has been updated with latest results.

Signed-off-by: Victor Yanev <[email protected]>

# Conflicts:
#	packages/relay/src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository.ts
#	packages/relay/src/lib/services/hbarLimitService/index.ts
#	packages/relay/tests/lib/services/hbarLimitService/hbarLimitService.spec.ts
Signed-off-by: Victor Yanev <[email protected]>

# Conflicts:
#	packages/relay/src/lib/db/repositories/hbarLimiter/hbarSpendingPlanRepository.ts
#	packages/relay/src/lib/services/hbarLimitService/index.ts
#	packages/relay/tests/lib/services/hbarLimitService/hbarLimitService.spec.ts
@victor-yanev victor-yanev removed the bug Something isn't working label Sep 19, 2024
@victor-yanev victor-yanev added the enhancement New feature or request label Sep 19, 2024
Copy link

sonarcloud bot commented Sep 20, 2024

Copy link

codecov bot commented Sep 20, 2024

Codecov Report

Attention: Patch coverage is 98.30508% with 1 line in your changes missing coverage. Please review.

Project coverage is 89.97%. Comparing base (99ea48f) to head (1083828).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
packages/relay/src/lib/constants.ts 83.33% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3014      +/-   ##
==========================================
- Coverage   90.14%   89.97%   -0.17%     
==========================================
  Files          42       58      +16     
  Lines        3185     3911     +726     
  Branches      641      782     +141     
==========================================
+ Hits         2871     3519     +648     
- Misses        270      348      +78     
  Partials       44       44              
Flag Coverage Δ
relay 90.20% <98.30%> (+0.06%) ⬆️
server 88.15% <ø> (?)
ws-server 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...rc/lib/db/entities/hbarLimiter/hbarSpendingPlan.ts 100.00% <100.00%> (ø)
...barLimiter/ethAddressHbarSpendingPlanRepository.ts 100.00% <100.00%> (ø)
...sitories/hbarLimiter/hbarSpendingPlanRepository.ts 100.00% <100.00%> (ø)
...hbarLimiter/ipAddressHbarSpendingPlanRepository.ts 100.00% <100.00%> (ø)
packages/relay/src/lib/relay.ts 85.18% <100.00%> (ø)
...s/relay/src/lib/services/hbarLimitService/index.ts 99.17% <100.00%> (+2.59%) ⬆️
packages/relay/src/lib/constants.ts 92.00% <83.33%> (+0.88%) ⬆️

... and 17 files with indirect coverage changes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Design, pilot and prototyping exploration work documentation Improvements or additions to documentation enhancement New feature or request
Projects
None yet
1 participant