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

Problem: tx is not replaced by priority #1563

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

Conversation

yihuang
Copy link
Collaborator

@yihuang yihuang commented Sep 2, 2024

Closes: #1557

Solution:

  • add TxReplacement callback, only replace if priority is higher

👮🏻👮🏻👮🏻 !!!! REFERENCE THE PROBLEM YOUR ARE SOLVING IN THE PR TITLE AND DESCRIBE YOUR SOLUTION HERE !!!! DO NOT FORGET !!!! 👮🏻👮🏻👮🏻

PR Checklist:

  • Have you read the CONTRIBUTING.md?
  • Does your PR follow the C4 patch requirements?
  • Have you rebased your work on top of the latest master?
  • Have you checked your code compiles? (make)
  • Have you included tests for any non-trivial functionality?
  • Have you checked your code passes the unit tests? (make test)
  • Have you checked your code formatting is correct? (go fmt)
  • Have you checked your basic code style is fine? (golangci-lint run)
  • If you added any dependencies, have you checked they do not contain any known vulnerabilities? (go list -json -m all | nancy sleuth)
  • If your changes affect the client infrastructure, have you run the integration test?
  • If your changes affect public APIs, does your PR follow the C4 evolution of public contracts?
  • If your code changes public APIs, have you incremented the crate version numbers and documented your changes in the CHANGELOG.md?
  • If you are contributing for the first time, please read the agreement in CONTRIBUTING.md now and add a comment to this pull request stating that your PR is in accordance with the Developer's Certificate of Origin.

Thank you for your code, it's appreciated! :)

Summary by CodeRabbit

  • New Features

    • Improved transaction management by allowing higher-priority transactions to replace existing ones.
  • Bug Fixes

    • Enhanced reliability of transaction processing through updated handling logic.
  • Tests

    • Introduced a new test to validate transaction replacement behavior based on gas prices, ensuring integrity in transaction processing.

Closes: crypto-org-chain#1557

Solution:
- add TxReplacement callback, only replace if priority is higher
@yihuang yihuang requested a review from a team as a code owner September 2, 2024 03:40
@yihuang yihuang requested review from leejw51crypto and thomas-nguy and removed request for a team September 2, 2024 03:40
Copy link
Contributor

coderabbitai bot commented Sep 2, 2024

Walkthrough

The changes introduce a new transaction replacement mechanism in the application, allowing a transaction to be replaced only if the new transaction's priority is higher than the existing one. This is implemented through a new function in the codebase and is accompanied by a test to ensure correct behavior in various scenarios involving transaction priorities.

Changes

Files Change Summary
CHANGELOG.md, app/app.go Added a new function TxReplacement to manage transaction replacement based on priority.
integration_tests/test_mempool.py Introduced a new test function test_tx_replacement to verify transaction replacement behavior with varying gas prices.

Assessment against linked issues

Objective Addressed Explanation
Implement TxReplacement callback for higher gas price transactions (#1557)

🐰 Hopping through the code, oh what a sight,
Transactions now dance with priority in flight.
Higher gas wins, as it should be,
A merry mempool, joyful and free!
Let's celebrate this change, oh what a delight! 🎉


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 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.
Early access features: disabled

We are currently testing the following features in early access:

  • Anthropic claude-3-5-sonnet for code reviews: Anthropic claims that the new Claude model has stronger code understanding and code generation capabilities than their previous models. Note: Our default code review model was also updated late last week. Please compare the quality of the reviews between the two models by toggling the early access feature.

Note:

  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.
  • Please join our Discord Community to provide feedback and report issues on the discussion post.

CHANGELOG.md Outdated Show resolved Hide resolved
Signed-off-by: yihuang <[email protected]>
@yihuang yihuang requested a review from mmsqe September 2, 2024 03:41
Copy link

codecov bot commented Sep 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 36.11%. Comparing base (825c551) to head (14b147f).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1563      +/-   ##
==========================================
- Coverage   36.12%   36.11%   -0.02%     
==========================================
  Files          97       97              
  Lines        7725     7725              
==========================================
- Hits         2791     2790       -1     
- Misses       4585     4586       +1     
  Partials      349      349              

see 1 file with indirect coverage changes

@@ -375,6 +375,10 @@ func New(
TxPriority: mempool.NewDefaultTxPriority(),
SignerExtractor: evmapp.NewEthSignerExtractionAdapter(mempool.NewDefaultSignerExtractionAdapter()),
MaxTx: maxTxs,
TxReplacement: func(op, np int64, oTx, nTx sdk.Tx) bool {
// tx is only replaced if new priority is higher than old priority
return np > op
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we need align how ethereum replace tx

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  1. priceBump parameter
  2. Require both FeeCap and TipCap larger than the old one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the same nonce tx will fail in checkTx in the first place, might not be trivial to support this feature.

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

Outside diff range, codebase verification and nitpick comments (1)
integration_tests/test_mempool.py (1)

85-116: LGTM! The test case is well-structured and covers the essential scenarios of transaction replacement based on gas prices.

The use of @pytest.mark.flaky is appropriate to handle potential flakiness in the test.

Consider adding the following enhancements to further improve the test case:

  1. Add an assertion to explicitly verify the replacement of the first transaction by the second one. For example, you can check the transaction hash of the mined transaction and ensure it matches the hash of the second transaction.
receipt = w3.eth.wait_for_transaction_receipt(txhashes[1])
assert receipt.status == 1
assert receipt.transactionHash == txhashes[1]  # Add this assertion
  1. Add a brief docstring to describe the purpose of the test function. For example:
def test_tx_replacement(cronos_mempool):
    """
    Test the transaction replacement behavior based on gas prices.

    This test verifies that a transaction with a higher gas price replaces
    a pending transaction with a lower gas price, while a transaction with
    a lower gas price does not replace a pending transaction with a higher
    gas price.
    """
    # Test code goes here

These enhancements will make the test case more comprehensive and self-explanatory.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 825c551 and 14b147f.

Files selected for processing (3)
  • CHANGELOG.md (1 hunks)
  • app/app.go (1 hunks)
  • integration_tests/test_mempool.py (1 hunks)
Additional comments not posted (2)
CHANGELOG.md (1)

34-34: Looks good!

The new CHANGELOG entry accurately documents the feature added in PR #1563.

app/app.go (1)

378-381: LGTM!

The new TxReplacement callback looks good. It correctly compares the new transaction's priority with the old transaction's priority, allowing replacement only if the new priority is higher. This aligns with the PR objectives of implementing transaction replacement based on priority.

@yihuang yihuang marked this pull request as draft September 2, 2024 09:18
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.

feat: TxReplacement is not implemented
2 participants