Skip to content

Conversation

@quiet-node
Copy link
Contributor

@quiet-node quiet-node commented Dec 1, 2025

Description

This PR:

  • Introduces RateLimitStoreFactory to encapsulate the logic for selecting the storage implementation based on configuration.
  • Updates IPRateLimiterService to accept a RateLimitStore interface in its constructor.
  • Updates RedisRateLimitStore to accept a RedisClient in its constructor instead of creating it internally.
  • Updates server.ts and webSocketServer.ts to use the factory and inject the store.
  • Improves unit test coverage by allowing easy mocking of the rate limit store.

Related issue(s)

Fixes #4599

Changes from original design (optional)

  • Updates RedisRateLimitStore to accept a RedisClient in its constructor instead of creating it internally.

Additional work needed (optional)

N/A

Checklist

  • I've assigned an assignee to this PR and related issue(s) (if applicable)
  • I've assigned a label to this PR and related issue(s) (if applicable)
  • I've assigned a milestone to this PR and related issue(s) (if applicable)
  • I've updated documentation (code comments, README, etc. if applicable)
  • I've done sufficient testing (unit, integration, etc.)

@quiet-node quiet-node added this to the 0.74.0 milestone Dec 1, 2025
@quiet-node quiet-node self-assigned this Dec 1, 2025
@quiet-node quiet-node requested review from a team as code owners December 1, 2025 21:09
@quiet-node quiet-node added the enhancement New feature or request label Dec 1, 2025
@quiet-node quiet-node requested a review from acuarica December 1, 2025 21:09
@quiet-node quiet-node linked an issue Dec 1, 2025 that may be closed by this pull request
3 tasks
@github-actions
Copy link

github-actions bot commented Dec 1, 2025

Test Results

 20 files  ± 0  261 suites   - 12   20m 48s ⏱️ - 1m 30s
759 tests  - 35  753 ✅  - 36  4 💤 ±0  2 ❌ +1 
774 runs   - 36  768 ✅  - 37  4 💤 ±0  2 ❌ +1 

For more details on these failures, see this check.

Results for commit 59f6388. ± Comparison against base commit 75f8196.

This pull request removes 36 and adds 1 tests. Note that renamed tests count towards both.
@release Expect Unsupported Method Error message when subscribing for "other" method ‑ RPC Server Acceptance Tests Acceptance tests @web-socket-batch-3 eth_subscribe Connection @release Expect Unsupported Method Error message when subscribing for "other" method
@release Socket server responds to the eth_chainId event ‑ RPC Server Acceptance Tests Acceptance tests @web-socket-batch-3 eth_subscribe Connection @release Socket server responds to the eth_chainId event
@release Subscribes for contract logs for a specific contract address (using evmAddress) ‑ RPC Server Acceptance Tests Acceptance tests @web-socket-batch-3 eth_subscribe Subscribes to log events @release Subscribes for contract logs for a specific contract address (using evmAddress)
@release Subscribes for contract logs for a specific contract address (using long zero address) ‑ RPC Server Acceptance Tests Acceptance tests @web-socket-batch-3 eth_subscribe Subscribes to log events @release Subscribes for contract logs for a specific contract address (using long zero address)
@release captures approve and transferFrom events ‑ RPC Server Acceptance Tests Acceptance tests @web-socket-batch-3 eth_subscribe Subscribes to hts tokens and listens for synthetic log events @release captures approve and transferFrom events
@release captures transfer events ‑ RPC Server Acceptance Tests Acceptance tests @web-socket-batch-3 eth_subscribe Subscribes to hts tokens and listens for synthetic log events @release captures transfer events
Calling eth_subscribe Logs with a non existent address should fail ‑ RPC Server Acceptance Tests Acceptance tests @web-socket-batch-3 eth_subscribe ethSubscribe Logs Params Validations Calling eth_subscribe Logs with a non existent address should fail
Calling eth_subscribe Logs with an empty address should fail ‑ RPC Server Acceptance Tests Acceptance tests @web-socket-batch-3 eth_subscribe ethSubscribe Logs Params Validations Calling eth_subscribe Logs with an empty address should fail
Calling eth_subscribe Logs with an invalid topics should fail ‑ RPC Server Acceptance Tests Acceptance tests @web-socket-batch-3 eth_subscribe ethSubscribe Logs Params Validations Calling eth_subscribe Logs with an invalid topics should fail
Calling eth_unsubscribe decrements the internal counters ‑ RPC Server Acceptance Tests Acceptance tests @web-socket-batch-3 eth_subscribe Connection subscription limits Calling eth_unsubscribe decrements the internal counters
…
"before all" hook in "@web-socket-batch-3 eth_subscribe" ‑ RPC Server Acceptance Tests Acceptance tests @web-socket-batch-3 eth_subscribe "before all" hook in "@web-socket-batch-3 eth_subscribe"

♻️ This comment has been updated with latest results.

natanasow
natanasow previously approved these changes Dec 3, 2025
Copy link
Contributor

@jasuwienas jasuwienas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@quiet-node It looks great overall! There’s just one thing I’m wondering about.

simzzz
simzzz previously approved these changes Dec 4, 2025
@quiet-node quiet-node dismissed stale reviews from simzzz and natanasow via 8072dab December 4, 2025 15:57
natanasow
natanasow previously approved these changes Dec 5, 2025
jasuwienas
jasuwienas previously approved these changes Dec 5, 2025
Copy link
Contributor

@jasuwienas jasuwienas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm @quiet-node

There’s one thing I dislike in our code (not introduced in this PR). Sometimes, when we create new interfaces, we prefix them with I (e.g., ICacheClient, IAccountInfo, IFeeHistory, and many others), and other times we don’t (e.g., the TxPool interfaces, global config, RateLimitStore, etc.). Maybe we should consider addressing this inconsistency later.

simzzz
simzzz previously approved these changes Dec 5, 2025
this.logger = logger.child({ name: 'redis-rate-limit-store' });
this.duration = duration;
this.rateLimitStoreFailureCounter = rateLimitStoreFailureCounter;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amaziing, much cleaner!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great glad you find it better!


describe('create', () => {
it('should return LruRateLimitStore when redisClient is not provided', () => {
const store = RateLimitStoreFactory.create(logger, testDuration);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aren't not provided and undefined basically the same?

Copy link
Contributor Author

@quiet-node quiet-node Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was thinking to not provided anything with undefined but with the counter. But you're right it's basically the same. I'll remove it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed it

@quiet-node
Copy link
Contributor Author

lgtm @quiet-node

There’s one thing I dislike in our code (not introduced in this PR). Sometimes, when we create new interfaces, we prefix them with I (e.g., ICacheClient, IAccountInfo, IFeeHistory, and many others), and other times we don’t (e.g., the TxPool interfaces, global config, RateLimitStore, etc.). Maybe we should consider addressing this inconsistency later.

Yessir I definitely agree. Consistency makes everything so much more organized and tuitive! But yeah the I-prefixed-interfaces were the old ones and we're aiming to drop the I-prefix. That said we should have a new PR in future to align everything, even with the linting as well.

@quiet-node quiet-node dismissed stale reviews from simzzz, jasuwienas, and natanasow via c3b7928 December 5, 2025 16:09
@quiet-node quiet-node force-pushed the 4599-ratelimiter-refactor-storage-selection-to-use-factory-pattern branch from c3b7928 to 59f6388 Compare December 5, 2025 16:55
@codecov
Copy link

codecov bot commented Dec 5, 2025

Codecov Report

❌ Patch coverage is 96.96970% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/server/src/server.ts 92.59% 2 Missing ⚠️
packages/ws-server/src/webSocketServer.ts 92.85% 2 Missing ⚠️
@@            Coverage Diff             @@
##             main    #4662      +/-   ##
==========================================
- Coverage   95.67%   95.62%   -0.05%     
==========================================
  Files         131      132       +1     
  Lines       21028    20989      -39     
  Branches     1785     1761      -24     
==========================================
- Hits        20118    20071      -47     
- Misses        892      903      +11     
+ Partials       18       15       -3     
Flag Coverage Δ
config-service 98.83% <ø> (ø)
relay 91.36% <100.00%> (+0.01%) ⬆️
server 88.99% <91.66%> (-0.01%) ⬇️
ws-server 97.72% <85.71%> (-0.21%) ⬇️

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

Files with missing lines Coverage Δ
packages/relay/src/lib/services/index.ts 100.00% <100.00%> (ø)
...rvices/rateLimiterService/RateLimitStoreFactory.ts 100.00% <100.00%> (ø)
...services/rateLimiterService/RedisRateLimitStore.ts 100.00% <100.00%> (+1.86%) ⬆️
.../services/rateLimiterService/rateLimiterService.ts 100.00% <100.00%> (+1.44%) ⬆️
packages/server/src/koaJsonRpc/index.ts 91.78% <100.00%> (+0.08%) ⬆️
packages/server/src/server.ts 88.21% <92.59%> (+0.29%) ⬆️
packages/ws-server/src/webSocketServer.ts 95.79% <92.85%> (-0.37%) ⬇️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ratelimiter: Refactor Storage Selection to Use Factory Pattern

6 participants