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

split alpha for increasing and decreasing limits #11

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

dshiell
Copy link
Member

@dshiell dshiell commented Nov 13, 2024

Introduces a different alpha for EMA gas/blob price limit updates depending on whether the limit is increasing or decreasing.

Usually when we increase the price limits the batcher retires for long periods of time which can bring up the limit. Once high it could take many batcher cycles for the price limit to decrease because if the limit is high already the batcher will like do only a single price limit update per batch interval.

This change sets the default so that we adjust downwards at 10x the rate of increases by default. The alphas are configurable and should result in the same behavior if they are set equal. Setting to 0 effectively disables EMA and uses the initial price limits as static limits. An alpha of 100 would always move the limit immediately to the current gas/blob price.

Summary by CodeRabbit

  • New Features

    • Improved handling of transaction limits with separate parameters for increases and decreases.
    • Enhanced logic for fee adjustments based on market conditions.
  • Bug Fixes

    • Streamlined transaction limit management for better clarity and control.

Copy link

coderabbitai bot commented Nov 13, 2024

Walkthrough

The changes in this pull request primarily focus on enhancing the handling of transaction parameters and limits within the src/server.ts file. A new helper function, minBigInt, is introduced to determine the minimum of two bigint values. The existing variable TX_ALPHA is replaced by two separate variables, TX_ALPHA_INCREASE and TX_ALPHA_DECREASE, which are initialized using minBigInt. The computeLimitEMA function is modified to remove the alpha parameter, adapting the logic for price handling based on market conditions.

Changes

File Change Summary
src/server.ts - Added function: minBigInt(a: bigint, b: bigint): bigint
- Added variables: let TX_ALPHA_INCREASE, let TX_ALPHA_DECREASE
- Updated function signature: computeLimitEMA(price: bigint, limit: bigint, alpha: bigint) to computeLimitEMA(price: bigint, limit: bigint)
- Updated calls to computeLimitEMA in feesTooHigh to remove TX_ALPHA argument

Possibly related PRs

Suggested reviewers

  • Inkvi
  • jlafiandra6
  • alfredo-stonk

🐇 In the garden where numbers play,
New limits bloom, bright as the day.
With minBigInt, we find our way,
Fees dance to the market's sway.
A hop, a skip, adjustments made,
In the world of transactions, we're not afraid! 🌼


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (3)
src/server.ts (3)

8-8: LGTM! Consider adding input validation for negative values.

The implementation of separate alpha values with appropriate defaults (0.01 for increase, 0.1 for decrease) aligns well with the PR objective of faster downward adjustments. The minBigInt helper correctly caps values at 100.

Consider adding validation for negative values:

-const minBigInt = (a: bigint, b: bigint): bigint => (a < b ? a : b);
+const minBigInt = (a: bigint, b: bigint): bigint => {
+  if (a < 0n || b < 0n) throw new Error("Alpha values must be non-negative");
+  return a < b ? a : b;
+};

Also applies to: 23-24


77-81: LGTM! Consider updating the function documentation.

The implementation correctly applies different alpha values based on whether the price is increasing or decreasing, which aligns with the PR objective.

Update the JSDoc to reflect the removal of the alpha parameter and document the dual-alpha behavior:

/**
* Computes a new gas limit using exponential moving average.
* @param price Current transaction price
* @param limit Current gas limit
+ * @remarks Uses TX_ALPHA_INCREASE when price > limit, TX_ALPHA_DECREASE otherwise
* @returns New gas limit
* @brief Assumes that all inputs are non-negative
*/

111-118: LGTM! Consider adding overflow protection.

The limit updates are correctly implemented with appropriate logging. However, since we're dealing with bigint arithmetic, it would be prudent to add overflow protection.

Consider wrapping the computations in a try-catch to handle potential arithmetic overflow:

-      const newGasLimit = computeLimitEMA(gasPrice, TX_GASPRICE_LIMIT);
-      console.log('Updating TX_GASPRICE_LIMIT: %d -> %d', TX_GASPRICE_LIMIT, newGasLimit);
-      TX_GASPRICE_LIMIT = newGasLimit;
+      try {
+        const newGasLimit = computeLimitEMA(gasPrice, TX_GASPRICE_LIMIT);
+        console.log('Updating TX_GASPRICE_LIMIT: %d -> %d', TX_GASPRICE_LIMIT, newGasLimit);
+        TX_GASPRICE_LIMIT = newGasLimit;
+      } catch (error) {
+        console.error('Failed to update gas limit:', error);
+        // Continue with existing limit
+      }

Apply similar protection to the blob limit update.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 4640587 and 2573269.

📒 Files selected for processing (1)
  • src/server.ts (4 hunks)

src/server.ts Show resolved Hide resolved
@dshiell dshiell marked this pull request as draft November 13, 2024 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant