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

Prevent panic in TransactionByHash for non-existent transactions #2373

Merged
merged 1 commit into from
Jan 14, 2025

Conversation

wojciechos
Copy link
Contributor

@wojciechos wojciechos commented Jan 14, 2025

Fixes an issue where the code could panic when attempting to adapt a nil transaction in the pending block. This ensures the function gracefully handles non-existent transactions by returning ErrTxnHashNotFound.

Copy link

codecov bot commented Jan 14, 2025

Codecov Report

Attention: Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.

Project coverage is 74.67%. Comparing base (d99e28b) to head (3c1e532).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
rpc/transaction.go 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2373      +/-   ##
==========================================
- Coverage   74.70%   74.67%   -0.03%     
==========================================
  Files         110      110              
  Lines       12021    12024       +3     
==========================================
- Hits         8980     8979       -1     
  Misses       2349     2349              
- Partials      692      696       +4     

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

Copy link
Contributor

@AnkushinDaniil AnkushinDaniil left a comment

Choose a reason for hiding this comment

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

Need some tests

@wojciechos wojciechos force-pushed the wojciechos/fix-panic branch from 5131bee to 1760dc8 Compare January 14, 2025 11:49
When searching for a transaction in the pending block, the code would continue
to AdaptTransaction even if no matching transaction was found. This could lead
to a panic when trying to adapt a nil transaction. Added a nil check and an
early break from the loop to ensure we properly handle non-existent transactions
with ErrTxnHashNotFound.

Changes:
- Add break statement to exit loop once matching transaction is found
- Add explicit nil check for txn before attempting to adapt it
- Return ErrTxnHashNotFound if no matching transaction is found
@wojciechos wojciechos force-pushed the wojciechos/fix-panic branch from 1760dc8 to 3c1e532 Compare January 14, 2025 12:20
Copy link
Contributor

@rodrigo-pino rodrigo-pino left a comment

Choose a reason for hiding this comment

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

LGTM

@IronGauntlets
Copy link
Contributor

IronGauntlets commented Jan 14, 2025

nit: for the commit message I would recommend focusing on "what" and "why" while letting the code say "how". In my opinion, the changes in bullet points are unnecessary.

@wojciechos wojciechos merged commit 0239e77 into main Jan 14, 2025
13 checks passed
@wojciechos wojciechos deleted the wojciechos/fix-panic branch January 14, 2025 16:41
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.

4 participants