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

Submitter: cap transactions in chainConfirmQueue #2789

Merged
merged 4 commits into from
Jun 28, 2024

Conversation

dwasse
Copy link
Collaborator

@dwasse dwasse commented Jun 25, 2024

Addresses #2750

Summary by CodeRabbit

  • New Features

    • Added functionality to limit the number of transactions per chain during sorting, enhancing transaction management.
  • Bug Fixes

    • Updated test cases to ensure accurate sorting behavior with the new transaction cap.

@dwasse dwasse requested a review from trajan0x as a code owner June 25, 2024 17:32
Copy link
Contributor

coderabbitai bot commented Jun 25, 2024

Walkthrough

The code changes introduce a new parameter, maxPerChain, which limits the number of transactions sorted by chain ID across various functions and tests. This parameter is utilized in the sortTxesByChainID function to control the transaction count per chain, ensuring more granular sorting and processing. The changes span multiple files, updating function signatures and incorporating new logic to adhere to the maxPerChain constraint.

Changes

Files Change Summary
ethergo/submitter/export_test.go Updated SortTxes function to include maxPerChain parameter.
ethergo/submitter/queue.go Updated processConfirmedQueue method to pass maxTxesPerChain constant to sortTxesByChainID.
ethergo/submitter/util.go Enhanced sortTxesByChainID to accept maxPerChain and cap transactions accordingly.
ethergo/submitter/util_test.go Modified SortTxes function in SubmitterSuite to accept a transaction cap. Added test cases for the new sorting behavior.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Queue
    participant Util
    Caller->>Queue: call processConfirmedQueue()
    Queue->>Util: call sortTxesByChainID(txs, maxTxesPerChain)
    Util-->>Queue: sortedTxes
    Queue-->>Caller: processedTxes
Loading

Poem

In lines of code, we weave the change,
With new parameters to arrange. 🌟
Transactions sorted, capped with care,
Chain by chain, we plot and fare.
A dance of logic, swift and neat,
Our program's pulse, a steady beat. ✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@github-actions github-actions bot added go Pull requests that update Go code size/xs labels Jun 25, 2024
Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

  • Introduced maxTxesPerChain constant to cap transactions in processConfirmedQueue
  • Modified sortTxesByChainID to accept maxPerChain parameter
  • Updated SortTxes function in export_test.go to include maxPerChain
  • Added tests in util_test.go to verify transaction capping functionality

4 file(s) reviewed, no comment(s)

Copy link

codecov bot commented Jun 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 25.56528%. Comparing base (07d6d4d) to head (68029ac).

Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #2789         +/-   ##
===================================================
+ Coverage   25.53083%   25.56528%   +0.03444%     
===================================================
  Files            765         760          -5     
  Lines          54726       54398        -328     
  Branches          80          80                 
===================================================
- Hits           13972       13907         -65     
+ Misses         39315       39065        -250     
+ Partials        1439        1426         -13     
Flag Coverage Δ
cctp-relayer 31.93780% <ø> (ø)
ethergo 48.43337% <100.00000%> (+0.08447%) ⬆️
explorer 4.97877% <ø> (ø)
omnirpc 33.08129% <ø> (ø)
opbot 0.21067% <ø> (ø)
packages 90.47619% <ø> (ø)
promexporter 8.50242% <ø> (ø)
rfq 27.12163% <ø> (ø)
scribe 18.17597% <ø> (+0.06437%) ⬆️
tools 30.55118% <ø> (ø)

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

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

cloudflare-workers-and-pages bot commented Jun 25, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 68029ac
Status: ✅  Deploy successful!
Preview URL: https://a8800bbf.sanguine-fe.pages.dev
Branch Preview URL: https://feat-submitter-tx-cap.sanguine-fe.pages.dev

View logs

Copy link
Contributor

@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: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1183ca8 and 0780607.

Files selected for processing (4)
  • ethergo/submitter/export_test.go (1 hunks)
  • ethergo/submitter/queue.go (2 hunks)
  • ethergo/submitter/util.go (2 hunks)
  • ethergo/submitter/util_test.go (1 hunks)
Additional comments not posted (5)
ethergo/submitter/export_test.go (1)

42-43: Update to SortTxes function signature is consistent with PR objectives.

The addition of the maxPerChain parameter to the SortTxes function aligns with the PR's goal of capping the number of transactions per chain. This change is consistent with the alterations mentioned in the summary.

ethergo/submitter/util.go (1)

Line range hint 106-137: Refactoring and logic addition in sortTxesByChainID function.

The implementation of sorting and capping the transactions per chain ID is correctly executed. The use of sort.Slice for sorting by nonce and the conditional check to cap the transactions are well-implemented. However, ensure that the gas.CompareGas function's behavior is thoroughly tested, especially how it handles transactions with equal nonces but different gas settings.

Verification successful

Thorough Testing of gas.CompareGas Function

The gas.CompareGas function is well-implemented and thoroughly tested across various scenarios, including transactions with equal nonces but different gas settings. The test cases cover legacy transactions, dynamic fee transactions, and combinations of both, ensuring comprehensive validation.

  • Implementation: ethergo/chain/gas/cmp.go (lines 23-32)
  • Test Cases: ethergo/chain/gas/cmp_test.go

The tests ensure that the function behaves correctly under different conditions, including nil base fees and varying gas prices.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify behavior of gas.CompareGas function in various scenarios.

# Test: Search for the function usage and unit tests. Expect: Function calls and test cases.
rg --type go $'gas.CompareGas'

Length of output: 302



Script:

#!/bin/bash
# Locate the implementation of the CompareGas function
ast-grep --lang go --pattern 'func CompareGas($_, $_, $_) $_' 

# Display the contents of the test file to review the test cases
cat ethergo/chain/gas/cmp_test.go

Length of output: 14014

ethergo/submitter/queue.go (2)

102-103: Constant definition for maxTxesPerChain.

Defining maxTxesPerChain as a constant is a good practice for maintainability and readability. This constant is used effectively in the processConfirmedQueue method to limit transactions per chain, aligning with the PR's objectives.


115-115: Use of sorted transactions in processConfirmedQueue.

The use of sortTxesByChainID with the maxTxesPerChain limit in the processConfirmedQueue method is a direct application of the newly introduced logic. This ensures that transactions are processed up to the specified limit per chain, which is crucial for managing resources and maintaining system stability.

ethergo/submitter/util_test.go (1)

241-258: Testing the SortTxes function with and without transaction cap.

The tests for SortTxes function both with the exact number of transactions and with a cap provide a good coverage of scenarios. This ensures that the function behaves as expected in different conditions. It's important to verify that the sorting and capping of transactions are working correctly across various chain IDs.

Verification successful

Verified the comprehensive coverage of SortTxes function test cases.

The TestSortTxes function in ethergo/submitter/util_test.go demonstrates thorough testing of the SortTxes function, including both sorting and capping transactions across various chain IDs.

  • The test initializes transactions for multiple chain IDs.
  • It validates the sorting functionality with the exact number of transactions.
  • It checks the transaction capping functionality.

The tests cover the necessary scenarios to ensure the SortTxes function behaves as expected.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all test cases for SortTxes function to ensure comprehensive coverage.

# Test: Search for test cases in util_test.go. Expect: Comprehensive test scenarios.
rg --type go 'TestSortTxes' 'ethergo/submitter/util_test.go'

Length of output: 100



Script:

#!/bin/bash
# Retrieve the implementation of the TestSortTxes function to verify its coverage.
ast-grep --lang go --pattern 'func (s $_) TestSortTxes() { $$$ }'

Length of output: 4151

@trajan0x trajan0x merged commit 1d6c328 into master Jun 28, 2024
59 checks passed
@trajan0x trajan0x deleted the feat/submitter-tx-cap branch June 28, 2024 23:14
@trajan0x
Copy link
Contributor

Edget case: this will break if there's more than 100 atetmpts for a tx

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

  • Updated .codeclimate.yml to exclude certain generated files from analysis
  • Added signozEnabled field and middleware functions in contrib/opbot/botmd/botmd.go
  • Introduced requiresSignoz method in contrib/opbot/botmd/commands.go
  • Added tracing and metrics middleware in contrib/opbot/botmd/middleware.go
  • Updated contrib/screener-api/README.md to reflect Chainalysis integration

176 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code size/xs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants