-
Notifications
You must be signed in to change notification settings - Fork 10
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
Bugfix invalid block number or hash #313
Conversation
WalkthroughThe changes across Changes
Poem
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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 as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Outside diff range and nitpick comments (1)
api/api.go (1)
Line range hint
786-803
: Correct error handling for block number retrieval.The use of
errors.Join
should be replaced withfmt.Errorf
for consistency and correctness. Additionally, ensure the error message clarity and handling logic are correct.- err := errors.Join(errs.ErrInvalid, fmt.Errorf("neither block number nor hash specified")) + err := fmt.Errorf("%w: neither block number nor hash specified", errs.ErrInvalid)
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- api/api.go (7 hunks)
- api/encode_transaction.go (2 hunks)
Additional comments not posted (1)
api/api.go (1)
497-497
: Ensure consistent error handling in API calls.The
handleError
function is used correctly here to handle errors uniformly across API methods. This change improves the maintainability and consistency of error management.
return tx.MarshalBinary() | ||
enc, err := tx.MarshalBinary() | ||
if err != nil { | ||
return nil, errors.Join(err, errs.ErrInvalid) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct error wrapping syntax.
The errors.Join
function does not exist in the standard Go errors
package. Use fmt.Errorf
for wrapping errors to maintain consistency and compatibility.
- return nil, errors.Join(err, errs.ErrInvalid)
+ return nil, fmt.Errorf("%w: %v", errs.ErrInvalid, err)
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.
return nil, errors.Join(err, errs.ErrInvalid) | |
return nil, fmt.Errorf("%w: %v", errs.ErrInvalid, err) |
@@ -549,7 +548,7 @@ func (b *BlockChainAPI) GetLogs( | |||
|
|||
l, err := b.blocks.LatestEVMHeight() | |||
if err != nil { | |||
return nil, err | |||
return handleError[[]*types.Log](b.logger, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor repeated error handling in GetLogs
.
The handleError
function is used multiple times in the same method. Consider refactoring to reduce redundancy and improve code clarity.
func (b *BlockChainAPI) GetLogs(ctx context.Context, criteria filters.FilterCriteria) ([]*types.Log, error) {
if err := rateLimit(ctx, b.limiter, b.logger); err != nil {
return nil, err
}
// Existing logic...
latest, err := b.blocks.LatestEVMHeight()
if err != nil {
return handleError[[]*types.Log](b.logger, err)
}
latestInt := big.NewInt(int64(latest))
// Adjusted logic to use `handleError` once at the end.
res, err := logs.NewRangeFilter(*from, *to, filter, b.receipts).Match()
return handleError[[]*types.Log](b.logger, err)
}
Also applies to: 565-565, 570-570
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Description
Bugfix for a crasher when the block hash or number is nil.
Also improve handling of invalid requests errors.
For contributor use:
master
branchFiles changed
in the Github PR explorerSummary by CodeRabbit
Bug Fixes
New Features
handleError
function to standardize error handling across the API.Chores