Skip to content

fix: prevent nil pointer dereference when admin_nodeInfo omits difficulty#153

Open
MysticRyuujin wants to merge 2 commits intoethpandaops:mainfrom
MysticRyuujin:fix/admin-nodeinfo-nil-difficulty
Open

fix: prevent nil pointer dereference when admin_nodeInfo omits difficulty#153
MysticRyuujin wants to merge 2 commits intoethpandaops:mainfrom
MysticRyuujin:fix/admin-nodeinfo-nil-difficulty

Conversation

@MysticRyuujin
Copy link

@MysticRyuujin MysticRyuujin commented Feb 26, 2026

Problem

The exporter panics with a nil pointer dereference when calling admin_nodeInfo against Geth (and potentially other clients) that omit the difficulty field from the response. This commonly occurs with post-merge clients where difficulty is no longer relevant.

panic: runtime error: invalid memory address or nil pointer dereference
github.com/ethpandaops/ethereum-metrics-exporter/pkg/exporter/execution/api/types.(*EthProtocol).UnmarshalJSON
    pkg/exporter/execution/api/types/admin.go:53

Root Cause

In EthProtocol.UnmarshalJSON, the code dereferences objMap["difficulty"] without checking if the key exists. When difficulty is missing from the JSON, objMap["difficulty"] is nil and *objMap["difficulty"] causes the panic.

Solution

  • Add a nil check before accessing objMap["difficulty"]
  • When the key is present: preserve existing behavior (parse as hex string or fall back to standard unmarshal)
  • When the key is missing: unmarshal the rest of the struct and leave Difficulty as nil

…ulty

Post-merge Geth and other clients may omit the difficulty field from
admin_nodeInfo responses. The EthProtocol.UnmarshalJSON was dereferencing
objMap["difficulty"] without checking for nil, causing a panic.

Add nil check before accessing difficulty; when missing, unmarshal the
rest of the struct and leave Difficulty as nil.

Made-with: Cursor
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.

1 participant