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: move rate limiter to zetaclient and add metrics #2110

Merged
merged 50 commits into from
May 7, 2024

Conversation

ws4charlie
Copy link
Contributor

@ws4charlie ws4charlie commented May 2, 2024

Description

  • move rate limiter logic to zetaclient. The method is named as ApplyRateLimiter
  • leave query part in zetacore to be performant. The method is named as RateLimiterInput.
  • order pending cctxs by height across all chains to be first-come-first-serve
  • add metrics of percentage_of_rate_reached to monitor current rate.

Closes: 2074
Closes: 2082
Closes: 2092
Closes: 2093

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Include instructions and any relevant details so others can reproduce.

  • Tested CCTX in localnet
  • Tested in development environment
  • Go unit tests
  • Go integration tests
  • Tested via GitHub Actions

Checklist:

  • I have added unit tests that prove my fix feature works

ws4charlie and others added 30 commits April 17, 2024 21:02
Copy link

github-actions bot commented May 2, 2024

!!!WARNING!!!
nosec detected in the following files: x/crosschain/keeper/grpc_query_cctx_rate_limit.go, x/crosschain/keeper/grpc_query_cctx_rate_limit_test.go, zetaclient/zetacore_observer.go, zetaclient/zetacore_observer_test.go

Be very careful about using #nosec in code. It can be a quick way to suppress security warnings and move forward with development, it should be employed with caution. Suppressing warnings with #nosec can hide potentially serious vulnerabilities. Only use #nosec when you're absolutely certain that the security issue is either a false positive or has been mitigated in another way.

Only suppress a single rule (or a specific set of rules) within a section of code, while continuing to scan for other problems. To do this, you can list the rule(s) to be suppressed within the #nosec annotation, e.g: /* #nosec G401 */ or //#nosec G201 G202 G203
Broad #nosec annotations should be avoided, as they can hide other vulnerabilities. The CI will block you from merging this PR until you remove #nosec annotations that do not target specific rules.

Pay extra attention to the way #nosec is being used in the files listed above.

@github-actions github-actions bot added the nosec label May 2, 2024
@ws4charlie ws4charlie marked this pull request as ready for review May 2, 2024 23:46
Copy link

codecov bot commented May 3, 2024

Codecov Report

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

Project coverage is 72.30%. Comparing base (b460556) to head (ebc87ee).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2110      +/-   ##
===========================================
+ Coverage    71.87%   72.30%   +0.43%     
===========================================
  Files          245      247       +2     
  Lines        13730    13921     +191     
===========================================
+ Hits          9868    10066     +198     
+ Misses        3405     3394      -11     
- Partials       457      461       +4     
Files Coverage Δ
pkg/math/float.go 100.00% <100.00%> (ø)
x/crosschain/keeper/cctx_utils.go 100.00% <100.00%> (ø)
x/crosschain/keeper/rate_limiter_flags.go 100.00% <100.00%> (ø)
zetaclient/core_context/zeta_core_context.go 91.45% <100.00%> (+0.62%) ⬆️
zetaclient/metrics/metrics.go 75.00% <ø> (ø)
zetaclient/ratelimiter/rate_limiter.go 100.00% <100.00%> (ø)
x/crosschain/keeper/grpc_query_cctx_rate_limit.go 94.92% <95.55%> (-1.16%) ⬇️
x/crosschain/types/rate_limiter_flags.go 93.54% <90.90%> (-6.46%) ⬇️
zetaclient/zetabridge/query.go 67.27% <87.27%> (+0.93%) ⬆️
zetaclient/zetacore_observer.go 27.31% <42.85%> (+10.94%) ⬆️

cmd/zetae2e/local/local.go Outdated Show resolved Hide resolved
changelog.md Outdated Show resolved Hide resolved
x/crosschain/keeper/grpc_query_cctx_rate_limit.go Outdated Show resolved Hide resolved
x/crosschain/keeper/grpc_query_cctx_rate_limit.go Outdated Show resolved Hide resolved
x/crosschain/keeper/rate_limiter_flags.go Outdated Show resolved Hide resolved
zetaclient/core_context/zeta_core_context.go Outdated Show resolved Hide resolved
zetaclient/ratelimiter/rate_limiter.go Show resolved Hide resolved
zetaclient/zetacore_observer.go Outdated Show resolved Hide resolved
zetaclient/zetacore_observer.go Outdated Show resolved Hide resolved
zetaclient/zetacore_observer.go Outdated Show resolved Hide resolved
Copy link
Contributor

@skosito skosito left a comment

Choose a reason for hiding this comment

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

looks good, just some comments to consider before merging, mostly refactoring suggestions

pkg/math/float.go Outdated Show resolved Hide resolved
x/crosschain/types/rate_limiter_flags.go Outdated Show resolved Hide resolved
x/crosschain/types/rate_limiter_flags.go Show resolved Hide resolved
@ws4charlie ws4charlie merged commit 7c98376 into develop May 7, 2024
21 checks passed
@ws4charlie ws4charlie deleted the refactor-rate-limiter branch May 7, 2024 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
4 participants