Skip to content

Conversation

@hansr
Copy link
Member

@hansr hansr commented Dec 18, 2025

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.

…handler to reduce direct malformed requests showing in logs as error
@hansr hansr requested a review from dominicletz December 18, 2025 19:37
@gemini-code-assist
Copy link

Summary of Changes

Hello @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

  • Malformed Request Handling: Implements immediate rejection of malformed RPC requests with a 400 status.
  • Reduced Logging: Prevents malformed requests from being logged as errors, significantly reducing log noise.
  • Optimized Network Traffic: Avoids proxying bogus requests, thereby conserving network resources.
  • Parameter Validation: Adds explicit checks for 'nil' or missing 'chain_id' and 'epoch' parameters in 'dio_traffic' and 'dio_tickets' RPC calls.

🧠 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 Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a 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.

Comment on lines +263 to +268
chain_id_param =
case params do
[] -> throw(:badrequest)
[nil | _] -> throw(:badrequest)
[param | _] -> param
end

Choose a reason for hiding this comment

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

medium

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
end

You could then call get_chain_id_param(params) in both places.

        chain_id_param = get_chain_id_param(params)

Comment on lines 275 to 279
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

Choose a reason for hiding this comment

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

medium

The last two clauses in this case statement produce the same result. They can be combined into a single, more concise clause using a tail match.

          case params do
            [_chain_id, epoch] when epoch != nil -> Base16.decode_int(epoch)
            [_chain_id | _] -> peak_epoch
          end

Comment on lines 325 to 330
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

Choose a reason for hiding this comment

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

medium

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

Comment on lines +451 to +457
invalid_params =
method in ["dio_traffic", "dio_tickets"] and
params != [] and
case params do
[nil | _] -> true
_ -> false
end

Choose a reason for hiding this comment

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

medium

The logic to check for invalid parameters can be simplified. The params != [] check is redundant because [nil | _] will not match an empty list. You can use match?/2 for a more concise boolean check.

        invalid_params =
          method in ["dio_traffic", "dio_tickets"] and
            match?([nil | _], params)

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.

3 participants