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

feat: Add repositories for the redesigned hbar limiter #2870

Merged

Conversation

victor-yanev
Copy link
Contributor

@victor-yanev victor-yanev commented Aug 22, 2024

Description:

This PR introduces repositories for managing spending plans for HBAR rate limiting and managing links between ETH addresses and a spending plan (IP address limiting could also be added the same way by adding IpAddressPlan and IpAddressPlanRepository).

Changes

Repositories:

  • HbarLimitPlanRepository: Provides methods to create, retrieve, and manage HBAR limit plans, including:
    • findById
    • findByIdWithDetails
    • create
    • checkExistsAndActive
    • getSpendingHistory
    • addAmountToSpendingHistory
    • getSpentToday
    • addAmountToSpentToday
  • EthAddressPlanRepository: Provides methods to manage Ethereum address plans, including:
    • findByAddress
    • save
    • delete

Testing

  • Added unit tests for HbarLimitPlanRepository and EthAddressPlanRepository to ensure proper functionality.
  • Tests cover scenarios such as creating plans, retrieving plans by ID, managing spending history, and handling non-existent plans.

Related issue(s):

Fixes #2869

Notes

  • The new repositories are designed to work with the existing cache service for data storage and retrieval.
  • Logging has been integrated into the repositories to provide traceability for operations performed.

Checklist

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

@victor-yanev victor-yanev added enhancement New feature or request P1 design Design, pilot and prototyping exploration work labels Aug 22, 2024
@victor-yanev victor-yanev added this to the 0.55.0 milestone Aug 22, 2024
@victor-yanev victor-yanev self-assigned this Aug 22, 2024
Copy link

github-actions bot commented Aug 22, 2024

Acceptance Tests

  19 files  249 suites   29m 1s ⏱️
611 tests 590 ✔️ 4 💤 17
834 runs  813 ✔️ 4 💤 17

Results for commit 01b6c2e.

♻️ This comment has been updated with latest results.

@victor-yanev victor-yanev marked this pull request as draft August 23, 2024 08:04
Copy link

github-actions bot commented Aug 23, 2024

Tests

       3 files     246 suites   18s ⏱️
1 114 tests 1 113 ✔️ 1 💤 0
1 126 runs  1 125 ✔️ 1 💤 0

Results for commit 01b6c2e.

♻️ This comment has been updated with latest results.

@victor-yanev victor-yanev marked this pull request as ready for review August 23, 2024 12:34
@victor-yanev victor-yanev changed the title feat: add hbar limit entities and repository feat: Add entities and repositories for the redesigned HbarLimiter Aug 23, 2024
@victor-yanev victor-yanev changed the base branch from main to 2866-add-hbar-limit-entities August 27, 2024 08:50
@victor-yanev victor-yanev changed the title feat: Add entities and repositories for the redesigned HbarLimiter feat: Add repositories for the redesigned HbarLimiter Aug 27, 2024
@victor-yanev victor-yanev changed the title feat: Add repositories for the redesigned HbarLimiter feat: Add repositories for the redesigned hbar limiter Aug 27, 2024
Copy link

codecov bot commented Aug 27, 2024

Codecov Report

Attention: Patch coverage is 95.48872% with 6 lines in your changes missing coverage. Please review.

Project coverage is 83.43%. Comparing base (b2a240b) to head (79e7be8).

Files Patch % Lines
...elay/src/lib/services/cacheService/cacheService.ts 84.21% 2 Missing and 4 partials ⚠️
Additional details and impacted files
@@                       Coverage Diff                        @@
##           2866-add-hbar-limit-entities    #2870      +/-   ##
================================================================
+ Coverage                         82.70%   83.43%   +0.73%     
================================================================
  Files                                47       38       -9     
  Lines                              3457     2922     -535     
  Branches                            731      615     -116     
================================================================
- Hits                               2859     2438     -421     
+ Misses                              371      289      -82     
+ Partials                            227      195      -32     
Flag Coverage Δ
relay 83.43% <95.48%> (+0.65%) ⬆️
server ?
ws-server ?

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

Files Coverage Δ
...kages/relay/src/lib/clients/cache/localLRUCache.ts 80.55% <100.00%> (+1.76%) ⬆️
packages/relay/src/lib/clients/cache/redisCache.ts 92.10% <100.00%> (+1.62%) ⬆️
...positories/hbarLimiter/EthAddressPlanRepository.ts 100.00% <100.00%> (ø)
...epositories/hbarLimiter/HbarLimitPlanRepository.ts 100.00% <100.00%> (ø)
...kages/relay/src/lib/db/types/hbarLimiter/errors.ts 100.00% <100.00%> (ø)
...elay/src/lib/services/cacheService/cacheService.ts 92.72% <84.21%> (-3.11%) ⬇️

... and 20 files with indirect coverage changes

victor-yanev and others added 4 commits August 27, 2024 12:05
Signed-off-by: Victor Yanev <[email protected]>
* feat: Create skeleton for `HbarLimitService`

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

* test: add hbarLimitService.spec.ts

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

---------

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

@ebadiere ebadiere merged commit e9fd7b5 into 2866-add-hbar-limit-entities Aug 27, 2024
12 of 13 checks passed
@ebadiere ebadiere deleted the add-hbar-limit-subscription-repository branch August 27, 2024 17:19
victor-yanev added a commit that referenced this pull request Aug 28, 2024
…2883)

* feat: Add entities for the redesigned hbar limiter

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

* feat: Add repositories for the redesigned hbar limiter (#2870)

* feat: add hbar limit entities and repository

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

* feat: add hbar limit entities and repository

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

* feat: add hbar limit entities and repository

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

* feat: add hbar limit entities and repository

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

* feat: add hbar limit entities and repository

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

* chore: remove redundant return

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

* chore: use custom errors

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

* chore: use `CacheService` instead of directly using redis client

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

* fix: build

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

* fix: conflicting redis port in tests

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

* chore: do not reconnect client before each test

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

* chore: rename entities

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

* chore: add EthAddressPlan entity and repository

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

* chore: remove redundant interface

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

* chore: extend tests for redisCache and cacheService

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

* chore: fix useless tests in cacheService.spec.ts

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

* chore: small fix in cacheService.spec.ts

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

* chore: add UML diagram

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

* chore: simplify UML-diagram.md

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

* chore: rename entities

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

* fix: cacheService.spec.ts

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

* fix: in-memory redis server port in ethAddressPlanRepository.spec.ts

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

* fix: revert unneeded changes in cacheService.spec.ts

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

* feat: Implement `shouldLimit` method of `HbarLimitService` (#2887)

* feat: Create skeleton for `HbarLimitService`

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

* test: add hbarLimitService.spec.ts

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

---------

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

---------

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

* chore: address comments

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

* chore: rename specs to match the names of the repositories

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

* chore: use uuidV4 for mocked data in hbarLimitService.spec.ts

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

* test: extend hbarLimitService.spec.ts

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

* test: remove duplicated tests in hbarLimitService.spec.ts

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

* chore: add types to jsdocs where missing

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

---------

Signed-off-by: Victor Yanev <[email protected]>
Signed-off-by: Victor Yanev <[email protected]>
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 enhancement New feature or request P1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[HBAR Rate Limit Redesign] Create DB entity repository [HBAR Rate Limit Redesign] Create DB entity classes
2 participants