-
Notifications
You must be signed in to change notification settings - Fork 0
Don't proxy or log malformed requests #8
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
base: main
Are you sure you want to change the base?
Conversation
…handler to reduce direct malformed requests showing in logs as error
Summary of ChangesHello @hansr, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces robust error handling for malformed RPC requests, specifically targeting cases where essential parameters like 'chain_id' or 'epoch' are invalid or missing. By returning a 400 Bad Request response immediately, the system avoids unnecessary error logging and prevents these requests from being proxied, thereby improving system stability, reducing log clutter, and optimizing network resource usage. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request effectively addresses the issue of malformed requests by adding validation to prevent them from being proxied or logged as errors. The changes for dio_traffic and dio_tickets RPC methods are sound. I've included a few suggestions to improve code clarity, reduce duplication, and make the new logic more concise and maintainable.
| chain_id_param = | ||
| case params do | ||
| [] -> throw(:badrequest) | ||
| [nil | _] -> throw(:badrequest) | ||
| [param | _] -> param | ||
| end |
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.
This logic for extracting chain_id_param is duplicated in the dio_tickets handler (lines 313-318). To improve code reuse and maintainability, consider extracting this logic into a private function. For example:
defp get_chain_id_param(params) do
case params do
[] -> throw(:badrequest)
[nil | _] -> throw(:badrequest)
[param | _] -> param
end
endYou could then call get_chain_id_param(params) in both places.
chain_id_param = get_chain_id_param(params)
| case params do | ||
| [_chain_id, epoch] -> Base16.decode_int(epoch) | ||
| [_chain_id, epoch] when epoch != nil -> Base16.decode_int(epoch) | ||
| [_chain_id, _epoch] -> peak_epoch | ||
| [_chain_id] -> peak_epoch | ||
| end |
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.
| case params do | ||
| [_chain_id, epoch] when is_integer(epoch) -> epoch | ||
| [_chain_id, epoch] when is_binary(epoch) -> Base16.decode_int(epoch) | ||
| [_chain_id, epoch] when epoch == nil -> peak_epoch | ||
| [_chain_id] -> peak_epoch | ||
| end |
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.
Similar to the dio_traffic handler, the last two clauses in this case statement can be combined into a single clause for conciseness.
case params do
[_chain_id, epoch] when is_integer(epoch) -> epoch
[_chain_id, epoch] when is_binary(epoch) -> Base16.decode_int(epoch)
[_chain_id | _] -> peak_epoch
end
| invalid_params = | ||
| method in ["dio_traffic", "dio_tickets"] and | ||
| params != [] and | ||
| case params do | ||
| [nil | _] -> true | ||
| _ -> false | ||
| end |
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.
This PR just returns 400/failure to malformed requests (nil in chain_id or epoch) without a) logging as error (caught in code before exception handler) or b) sending the malformed request as a proxy.
This should at least remove the "error" from the logs - people are posting about this because they feel this is a problem with their node. It should also reduce network traffic somewhat because if the request was bogus we don't pass it along.
Minor, but real time potential improvement. No time urgency.