Skip to content
This repository has been archived by the owner on Jun 9, 2024. It is now read-only.

perf(comet): Eject the comet mempool on ReCheckTx to keep it clean #1237

Merged
merged 6 commits into from
Oct 19, 2023

Conversation

itsdevbear
Copy link

@itsdevbear itsdevbear commented Oct 19, 2023

Summary by CodeRabbit

  • New Feature: Introduced a new transaction validation mechanism to enhance the security and reliability of our system. This update includes a new feature that checks and prevents recheck transactions, improving the overall transaction processing efficiency.
  • Improvement: Updated the system's build function to incorporate the new transaction validation mechanism, ensuring that all transactions are processed through this enhanced security layer.

These changes aim to improve the user experience by increasing the system's reliability and efficiency.

@coderabbitai
Copy link

coderabbitai bot commented Oct 19, 2023

Rate Limit Exceeded

@itsdevbear has exceeded the limit for the number of files or commits that can be reviewed per hour. Please wait 0 minutes and 15 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, convert this PR to a draft and then mark it as ready for review again to re-trigger the review. Alternatively, you can push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per repository.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 41dcf94 and df04eef.

Walkthrough

The changes introduce a new AnteHandler function in the ante package, which creates a chain of sdk.AnteDecorator instances. The EjectOnRecheckTxDecorator is added as the outermost decorator. The runtime.go file is updated to import the ante package and use the new AnteHandler in the SetAnteHandler function.

Changes

File Summary
cosmos/lib/ante/eject.go New file added. Defines AnteHandler function and EjectOnRecheckTxDecorator struct.
cosmos/runtime/runtime.go Import statement added for ante package. Build function and SetAnteHandler method updated to use new AnteHandler.

🐇

In the land of code, changes are afoot,

New functions and decorators, aren't they a hoot?

With a hop, skip, and a jump, we enhance our app,

Making it stronger, no time for a nap! 🥕


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • Mention @coderabbitai in any review comment for bot assistance.
  • Note: Review comments are made on code diffs or files, not on the PR overview.

Pause Incremental Reviews

  • Insert @coderabbitai: ignore in the PR description to halt the bot's ongoing reviews. Remove the line to resume.
  • Additionally, enter @coderabbitai pause to halt the bot's ongoing reviews as any issue or review comment. To
    resume reviews, enter @coderabbitai resume as any issue or review comment.

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.

Review Status

Actionable comments generated: 0

Commits Files that changed from the base of the PR and between 2a687a2 and 866a7c5.
Files selected for processing (2)
  • cosmos/lib/ante/eject.go (1 hunks)
  • cosmos/runtime/runtime.go (3 hunks)
Files skipped from review due to trivial changes (1)
  • cosmos/lib/ante/eject.go
Additional comments (Suppressed): 3
cosmos/runtime/runtime.go (3)
  • 32-38: The new import statement for the ante package is added. Ensure that the package is available at the specified location and that it is compatible with the current version of the application.

  • 97-103: The Build function of the Polaris struct now sets the WrappedTxPool field using the txpool.New function with an additional argument p.ExecutionLayer.Backend(). Ensure that this change does not break the existing functionality and that the Backend method of the ExecutionLayer struct returns a value compatible with the txpool.New function.

-    p.WrappedTxPool = txpool.New(p.TxPool())
+    p.WrappedTxPool = txpool.New(p.TxPool(), p.ExecutionLayer.Backend())
  • 110-114: The SetAnteHandler function of the CosmosApp interface is now called with an instance of antelib.NewAnteHandler(), replacing the previous nil value. Ensure that the NewAnteHandler function from the ante package returns a value compatible with the SetAnteHandler function and that this change does not break the existing functionality.
-    app.SetAnteHandler(nil)
+    app.SetAnteHandler(antelib.NewAnteHandler())

@codecov
Copy link

codecov bot commented Oct 19, 2023

Codecov Report

Merging #1237 (b6fdace) into main (2a687a2) will not change coverage.
The diff coverage is 0.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1237   +/-   ##
=======================================
  Coverage   49.23%   49.23%           
=======================================
  Files          77       77           
  Lines        4613     4613           
=======================================
  Hits         2271     2271           
  Misses       2179     2179           
  Partials      163      163           
Files Coverage Δ
cosmos/txpool/mempool.go 50.00% <0.00%> (ø)

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.

Review Status

Actionable comments generated: 2

Commits Files that changed from the base of the PR and between 2a687a2 and 14d4925.
Files selected for processing (5)
  • contracts/scripts/DeployAndCallERC20.sol (1 hunks)
  • cosmos/lib/ante/eject.go (1 hunks)
  • cosmos/runtime/runtime.go (2 hunks)
  • eth/eth.go (2 hunks)
  • eth/polar/backend.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • eth/eth.go
Additional comments (Suppressed): 7
contracts/scripts/DeployAndCallERC20.sol (1)
  • 39-42: The loop iteration count has been increased from 66 to 10066, and the quantity variable is incremented by 50000 in each iteration. This will significantly increase the number of tokens minted and the gas cost of the run function. Ensure that this is the intended behavior and that the contract has enough gas to complete the operation.
-    for (uint256 i = 0; i < 66; i++) {
+    for (uint256 i = 0; i < 10066; i++) {
eth/polar/backend.go (2)
  • 219-221: No changes have been made to the Blockchain method. It continues to return the blockchain associated with the Polaris instance.

  • 223-230: The new IncludedInBlock method checks if a transaction, identified by its hash, has been included in a block. It retrieves the transaction lookup entry (tle) for the given hash from the blockchain. If the tle is nil, it means the transaction does not exist in the blockchain, so it returns false. Otherwise, it checks if the BlockHash field of the tle is not an empty hash, which would indicate that the transaction has been included in a block. This method provides a way to verify the inclusion of a transaction in a block, which can be useful in various scenarios, such as confirming transaction finality.

cosmos/runtime/runtime.go (2)
  • 35-38: The import statement for the antelib package has been added. Ensure that the package is available and accessible in the project's dependencies.

  • 108-113: The SetAnteHandler function is no longer being set to nil. Instead, it's being set to antelib.NewAnteHandler(). This change implies that the AnteHandler is now required for the application. Make sure that this change is intentional and that the NewAnteHandler function from the antelib package is correctly implemented and tested.

-    app.SetAnteHandler(nil)
+    app.SetAnteHandler(antelib.NewAnteHandler())
cosmos/lib/ante/eject.go (2)
  • 29-35: The NewAnteHandler function creates a chain of sdk.AnteDecorator instances and returns an sdk.AnteHandler. It currently only includes EjectOnRecheckTxDecorator in the chain. If more decorators are to be added in the future, they should be appended to the anteDecorators slice in the order they should be executed.

  • 39-45: The AnteHandle method of EjectOnRecheckTxDecorator checks if the transaction context is a recheck and returns an error if it is. This prevents rechecked transactions from being processed further. If the transaction is not a recheck, it calls the next AnteHandler in the chain. Ensure that this behavior is intended and that it doesn't interfere with the normal operation of the application.

eth/polar/backend.go Outdated Show resolved Hide resolved
cosmos/lib/ante/eject.go Outdated Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 4

Commits Files that changed from the base of the PR and between 2a687a2 and 14d4925.
Files selected for processing (5)
  • contracts/scripts/DeployAndCallERC20.sol (1 hunks)
  • cosmos/lib/ante/eject.go (1 hunks)
  • cosmos/runtime/runtime.go (2 hunks)
  • eth/eth.go (2 hunks)
  • eth/polar/backend.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • eth/eth.go
Additional comments (Suppressed): 4
cosmos/lib/ante/eject.go (1)
  • 39-45: The AnteHandle method of EjectOnRecheckTxDecorator checks if the transaction context is a recheck and returns an error if it is. This effectively ejects the transaction from the mempool during a recheck. Ensure that this behavior is intended and that it won't cause any unwanted side effects, such as valid transactions being ejected during a recheck.
contracts/scripts/DeployAndCallERC20.sol (1)
  • 39-42: The loop iteration count has been increased from 66 to 10066. This will significantly increase the number of tokens minted and the time taken to execute the run() function. Ensure that this change is intentional and that the system can handle this increased load.
cosmos/runtime/runtime.go (2)
  • 32-38: The import statement for the antelib package has been added. This package is used to create a new AnteHandler in the Build function. Ensure that the package is correctly imported and available in the project.

  • 108-114: The SetAnteHandler function is now being called with an instance of antelib.NewAnteHandler(), instead of nil. This change introduces a new AnteHandler that will handle the transaction validation and processing. Make sure that the NewAnteHandler function from the antelib package is correctly implemented and that it returns an AnteHandler that is compatible with the SetAnteHandler function.

-    app.SetAnteHandler(nil)
+    app.SetAnteHandler(antelib.NewAnteHandler())

cosmos/lib/ante/eject.go Outdated Show resolved Hide resolved
cosmos/lib/ante/eject.go Outdated Show resolved Hide resolved
contracts/scripts/DeployAndCallERC20.sol Outdated Show resolved Hide resolved
eth/polar/backend.go Outdated Show resolved Hide resolved
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.

Review Status

Actionable comments generated: 1

Commits Files that changed from the base of the PR and between 2a687a2 and 41dcf94.
Files selected for processing (2)
  • cosmos/lib/ante/eject.go (1 hunks)
  • cosmos/runtime/runtime.go (2 hunks)
Additional comments (Suppressed): 4
cosmos/lib/ante/eject.go (2)
  • 29-35: The NewAnteHandler function creates a new sdk.AnteHandler interface with a chain of sdk.AnteDecorator instances. It currently only includes EjectOnRecheckTxDecorator. If more decorators are to be added in the future, ensure they are added in the correct order as the order of decorators can affect the execution flow.

  • 39-47: The AnteHandle method of EjectOnRecheckTxDecorator returns an error if the transaction context is a recheck. This is a good practice as it prevents unnecessary processing of transactions that are being rechecked, potentially improving performance.

cosmos/runtime/runtime.go (2)
  • 33-38: The import statement for the antelib package has been added. This package contains the new AnteHandler function that will be used to set the AnteHandler for the application.

  • 108-114: The SetAnteHandler function is now being called with an instance of antelib.NewAnteHandler(). This is a change from the previous version where it was set to nil. This change is part of the effort to eject the comet mempool on ReCheckTx to keep it clean and improve performance. However, it's important to ensure that the NewAnteHandler function from the antelib package is correctly implemented and that it doesn't introduce any unexpected behavior or errors.

-    app.SetAnteHandler(nil)
+    app.SetAnteHandler(antelib.NewAnteHandler())

cosmos/lib/ante/eject.go Outdated Show resolved Hide resolved
@itsdevbear itsdevbear merged commit d49ee37 into main Oct 19, 2023
13 checks passed
@itsdevbear itsdevbear deleted the reject-recheck-tx branch October 19, 2023 14:59
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants