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: index submitted txs in tx client and improve nonce management #3830

Open
wants to merge 36 commits into
base: main
Choose a base branch
from

Conversation

ninabarbakadze
Copy link
Member

@ninabarbakadze ninabarbakadze commented Aug 28, 2024

Overview

Fixes #3899

@ninabarbakadze ninabarbakadze self-assigned this Aug 28, 2024
@ninabarbakadze ninabarbakadze marked this pull request as ready for review September 2, 2024 13:27
@ninabarbakadze ninabarbakadze requested a review from a team as a code owner September 2, 2024 13:27
@ninabarbakadze ninabarbakadze requested review from staheri14 and rach-id and removed request for a team September 2, 2024 13:27
Copy link
Contributor

coderabbitai bot commented Sep 2, 2024

Walkthrough

Walkthrough

The changes introduce a new struct, txInfo, to manage transaction information within the TxClient. A local transaction tracker is established to monitor submitted transactions, enhancing nonce management and error handling. The TxClient methods are updated to incorporate this new tracker, improving transaction confirmation and recovery from evictions. Additionally, a new test file is created to validate the pruning functionality of the transaction tracker.

Changes

Files Change Summary
pkg/user/tx_client.go Introduced txInfo struct for transaction information, added txTracker map to TxClient, modified methods for transaction management and confirmation.
pkg/user/pruning_test.go Implemented tests for pruning logic in the transaction tracker, validating the removal of old transactions.

Assessment against linked issues

Objective Addressed Explanation
Improve transaction submission handling evictions (#3768)
Enhance nonce management for multiple transactions (#3768)
Improve error handling in transaction confirmation (#3768)

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:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • 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.

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.

@ninabarbakadze ninabarbakadze marked this pull request as draft September 2, 2024 14:21
Copy link
Member Author

@ninabarbakadze ninabarbakadze left a comment

Choose a reason for hiding this comment

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

square size test started failing, investigating that.

@ninabarbakadze ninabarbakadze marked this pull request as ready for review September 3, 2024 09:15
@ninabarbakadze ninabarbakadze marked this pull request as draft September 3, 2024 09:36
@@ -137,6 +148,9 @@ type TxClient struct {
defaultGasPrice float64
defaultAccount string
defaultAddress sdktypes.AccAddress
txPool map[string]poolTxInfo
Copy link
Member Author

Choose a reason for hiding this comment

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

[Question] do we want to have a way of periodically clearing the cache?

Copy link
Member Author

Choose a reason for hiding this comment

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

@evan-forbes @cmwaters I'd appreciate your input here

Copy link
Member

Choose a reason for hiding this comment

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

ideally, it seems like we should never be a scenario where we need this to be cleared. Either a tx is included and we continually try to get it included, or we handle each case when that does not occur and remove the tx at that point

Copy link
Member Author

Choose a reason for hiding this comment

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

the only time tx doesn't get removed from this local cache is if context gets cancelled while polling for tx status which means that the said tx was never confirmed. If the transaction doesn't get confirmed it can linger in that cache until it ooms

Copy link
Member

@evan-forbes evan-forbes Sep 5, 2024

Choose a reason for hiding this comment

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

by periodically, do we mean a ttl?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes!

Copy link
Contributor

Choose a reason for hiding this comment

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

The scenario that I see as more problematic is if a user decides to use BroadcastTx which creates the map entry and doesn't use ConfirmTx which cleans it up (because maybe they don't care if it lands or not).

I think we should garbage collect, but not as a separate go routine but within BroadcastTx.

I would give at least 10 minutes before we clean up.

@celestia-bot celestia-bot requested a review from a team September 18, 2024 13:07
@rootulp rootulp self-requested a review September 18, 2024 18:00
rootulp
rootulp previously approved these changes Sep 18, 2024
Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

nit: consistently use the term txTracker instead of txTracker in some places and local pool in other places.

pkg/user/tx_client.go Outdated Show resolved Hide resolved
pkg/user/tx_client.go Outdated Show resolved Hide resolved
pkg/user/tx_client.go Outdated Show resolved Hide resolved
pkg/user/tx_client.go Outdated Show resolved Hide resolved
pkg/user/tx_client.go Outdated Show resolved Hide resolved
pkg/user/tx_client.go Outdated Show resolved Hide resolved
pkg/user/tx_client.go Outdated Show resolved Hide resolved
pkg/user/tx_client.go Outdated Show resolved Hide resolved
Co-authored-by: Rootul P <rootulp@gmail.com>
Co-authored-by: Rootul P <rootulp@gmail.com>
@celestia-bot celestia-bot requested a review from a team September 18, 2024 18:12
ninabarbakadze and others added 7 commits September 18, 2024 20:12
Co-authored-by: Rootul P <rootulp@gmail.com>
Co-authored-by: Rootul P <rootulp@gmail.com>
Co-authored-by: Rootul P <rootulp@gmail.com>
Co-authored-by: Rootul P <rootulp@gmail.com>
Co-authored-by: Rootul P <rootulp@gmail.com>
Co-authored-by: Rootul P <rootulp@gmail.com>
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: 1

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 1e1de7f and def40f2.

Files selected for processing (2)
  • pkg/user/pruning_test.go (1 hunks)
  • pkg/user/tx_client.go (9 hunks)
Files skipped from review as they are similar to previous changes (1)
  • pkg/user/tx_client.go
Additional comments not posted (1)
pkg/user/pruning_test.go (1)

11-51: Excellent test coverage for the transaction tracker pruning functionality!

The test is well-structured and covers the essential aspects of pruning:

  • It sets up a controlled environment with transactions of different ages.
  • It calls the pruneTxTracker method to trigger the pruning process.
  • It verifies the expected state of the transaction tracker after pruning, ensuring that only transactions older than the pruning threshold are removed.

The test provides confidence in the correctness of the pruning implementation.

txClient.pruneTxTracker()
// Prunes the transactions that are 10 minutes old
// 5 transactions will be pruned
require.Equal(t, txTrackerBeforePruning-txsToBePruned, txsToBePruned)
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix the assertion by swapping the expected and actual values.

The assertion on line 48 compares the wrong values. It should compare the difference between the tracker size before pruning and the number of transactions to be pruned with the actual size of the tracker after pruning.

Swap the expected and actual values in the assertion:

-require.Equal(t, txTrackerBeforePruning-txsToBePruned, txsToBePruned)
+require.Equal(t, txsToBePruned, txTrackerBeforePruning-txsToBePruned)
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
require.Equal(t, txTrackerBeforePruning-txsToBePruned, txsToBePruned)
require.Equal(t, txsToBePruned, txTrackerBeforePruning-txsToBePruned)

Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] Would be nice to apply this comment of coderabbit.

Copy link
Collaborator

@rootulp rootulp left a comment

Choose a reason for hiding this comment

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

Fixes #3768

The PR description will close that issue when this PR merges which doesn't seem like what you want. Since #3768 is large in scope, it is not immediately obvious which parts of that issue this PR addresses. One idea is to convert that issue into a tracking issue with several smaller issues. Then this PR can close one of the smaller issues and leave the remaining ones open.

}
numTransactions := 10

// Add 10 transactions to the tracker that are 10 minutes old
Copy link
Collaborator

Choose a reason for hiding this comment

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

this comment seems incorrect. It looks like the implementation below adds 5 transactions that are 10 minutes old and 5 transactions that are 5 minutes old.

Suggested change
// Add 10 transactions to the tracker that are 10 minutes old

@ninabarbakadze
Copy link
Member Author

Fixes #3768

The PR description will close that issue when this PR merges which doesn't seem like what you want. Since #3768 is large in scope, it is not immediately obvious which parts of that issue this PR addresses. One idea is to convert that issue into a tracking issue with several smaller issues. Then this PR can close one of the smaller issues and leave the remaining ones open.

The 'evictions issue' became its own epic which we discussed during the offsite. I can update #3768 to be more accurate to what this pr resolves and the other issues will follow shortly.

@celestia-bot celestia-bot requested a review from a team September 23, 2024 10:17
@ninabarbakadze
Copy link
Member Author

Fixes #3768

The PR description will close that issue when this PR merges which doesn't seem like what you want. Since #3768 is large in scope, it is not immediately obvious which parts of that issue this PR addresses. One idea is to convert that issue into a tracking issue with several smaller issues. Then this PR can close one of the smaller issues and leave the remaining ones open.

Created a new issue that this pr directly resolves #3899 i decided to keep the old one for context. Me and Callum can groom it/close it/delete it when we pm best txs stuff.

@ninabarbakadze ninabarbakadze changed the title fix: evictions issue in tx client refactor: index submitted txs in tx client and improve nonce management Sep 23, 2024
@ninabarbakadze ninabarbakadze enabled auto-merge (squash) September 23, 2024 21:09
@celestia-bot celestia-bot requested a review from a team September 23, 2024 21:09
Copy link
Contributor

@staheri14 staheri14 left a comment

Choose a reason for hiding this comment

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

LGTM!

txClient.pruneTxTracker()
// Prunes the transactions that are 10 minutes old
// 5 transactions will be pruned
require.Equal(t, txTrackerBeforePruning-txsToBePruned, txsToBePruned)
Copy link
Contributor

Choose a reason for hiding this comment

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

[nit] Would be nice to apply this comment of coderabbit.

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.

Index submitted transactions for nonce tracking in tx client
5 participants