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(abci/checktx): remove duplication and simplify the code #493

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

Conversation

EmilGeorgiev
Copy link

This PR removes duplication and simplifies the code:

sdkerrors.ResponseCheckTxWithEvents( fmt.Errorf("<some error message>: %w", err), 0, 0, nil, false, )

is replaced with

errorResponse(err).
  1. The CheckTx method of MempoolParityCheckTx only check transactions if the check Tx type is 'ReCheck'. If the check type is different, it immediately proceeds to the next checkTxHandler. This approach avoids redundant checks and logic, such as decoding the transaction, which is duplicated across all checkTxHandlers. It also eliminates the need to call isInvalidCheckTxExecution.

  2. By checking the mode of the check transaction at the beginning of the CheckTx method, additional checks in the if statements can be avoided. For example:

isReCheck := req.Type == cmtabci.CheckTxType_Recheck

// if the mode is ReCheck and the app's mempool does not contain the given tx, we fail
// immediately, to purge the tx from the comet mempool.
if isReCheck && !m.mempl.Contains(tx) {
    ...
}

Now is simpliefied and looks like:

if !m.mempl.Contains(tx) {
    ...
}

And

if isInvalidCheckTxExecution(res, checkTxError) && isReCheck {
  ...
}

is now:

if isInvalidCheckTxExecution(res, checkTxError) {
   ...
}   
  1. Removed the check for whether the mempool contains the transaction before deleting it because the Remove method already performs this check, making it redundant.

  2. Adjust method and function comments to aligns with Go best practices.

Copy link

codecov bot commented May 19, 2024

Codecov Report

Attention: Patch coverage is 30.55556% with 25 lines in your changes are missing coverage. Please review.

Project coverage is 53.04%. Comparing base (db739e9) to head (f45cdfc).

Files Patch % Lines
abci/checktx/mev_check_tx.go 20.00% 19 Missing and 1 partial ⚠️
abci/checktx/mempool_parity_check_tx.go 54.54% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #493      +/-   ##
==========================================
+ Coverage   52.07%   53.04%   +0.97%     
==========================================
  Files          48       48              
  Lines        1855     1804      -51     
==========================================
- Hits          966      957       -9     
+ Misses        798      756      -42     
  Partials       91       91              

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

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