Skip to content

fix: handle blocks missing size and totalDifficulty fields#18

Merged
rswanson merged 1 commit intosignet-mainfrom
fix/handle-missing-block-fields
Apr 16, 2026
Merged

fix: handle blocks missing size and totalDifficulty fields#18
rswanson merged 1 commit intosignet-mainfrom
fix/handle-missing-block-fields

Conversation

@rswanson
Copy link
Copy Markdown
Member

Summary

Fixes the prod blockscout backend crashloop caused by Signet chain blocks missing size and totalDifficulty fields in JSON-RPC responses.

Two crashes fixed:

  • FunctionClauseError in EthereumJSONRPC.Block.do_elixir_to_params/1 — All 4 existing pattern-match clauses require "size" in the block map. Signet blocks don't include size or totalDifficulty, so none match. Added a catch-all clause (placed last so existing specific clauses take priority) that uses Map.get with defaults for optional fields.

  • Protocol.UndefinedError in EmptyBlocksSanitizer.classify_blocks_from_result/1Enum.empty?(block["transactions"]) crashes when transactions is nil (atom doesn't implement Enumerable). Fixed by defaulting nil transactions to [] before enumeration.

Evidence

Dev cluster (old image sha256:9450e2c7...) is healthy at 35d uptime. Prod cluster (new image sha256:5b265961...) crashloops in ~13 seconds with these exact errors in logs.

Test plan

  • Added unit test for elixir_to_params/1 with a block missing size, totalDifficulty, and baseFeePerGas (mirrors actual Signet block from crash logs)
  • Existing tests unaffected — blocks with size still match the more specific clauses first
  • Verify prod pod stabilizes after deploying the new image

🤖 Generated with Claude Code

Some chains (e.g. Signet) return blocks without `size` or
`totalDifficulty` fields in their JSON-RPC responses. This caused two
fatal crashes:

1. `FunctionClauseError` in `EthereumJSONRPC.Block.do_elixir_to_params/1`
   because all existing clauses required `size` in their pattern match.
   Added a catch-all clause that uses `Map.get` with defaults for
   `size`, `totalDifficulty`, and `baseFeePerGas`.

2. `Protocol.UndefinedError` in `EmptyBlocksSanitizer.classify_blocks_from_result/1`
   because `block["transactions"]` could be `nil`, and `Enum.empty?/1`
   does not accept atoms. Fixed by defaulting nil transactions to `[]`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@rswanson rswanson requested a review from a team April 16, 2026 11:43
@rswanson rswanson merged commit 7948a37 into signet-main Apr 16, 2026
1 check passed
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.

2 participants