Skip to content

fix: handle zero port values in ENR field display#48

Merged
nflaig merged 1 commit intoChainSafe:masterfrom
lodekeeper:fix/falsy-zero-port-values
Mar 19, 2026
Merged

fix: handle zero port values in ENR field display#48
nflaig merged 1 commit intoChainSafe:masterfrom
lodekeeper:fix/falsy-zero-port-values

Conversation

@lodekeeper
Copy link
Copy Markdown
Contributor

Problem

ENR records can have port values of 0 (tcp, udp, tcp6, etc.) when a node is not listening on that transport. The viewer crashes when decoding these records because the check:

if (!field) {
  throw new Error("Field not found.");
}

treats 0 as falsy and throws.

Repro: paste this ENR into the viewer:

enr:-Nu4QKe3WxoAFYdg7DURBvJz7wuqaeM4-pr4x2QDRXaIPQaNEbOPDOM8bQ8RIf7ZxASbekpY-zlp2mVQWDBFF4hVhW6B9odhdHRuZXRziAAAAAAAMAAAg2NnYxKEZXRoMpCMn2L-BgAAAP__________gmlkgnY0gmlwhK1C3CyDbmZkhAAAAACJc2VjcDI1NmsxoQJ_TOs84c3Cfp5Y12nmopXHFIzTCgqWLBVbouMLKqhWc4hzeW5jbmV0cwCDdGNwggAAhHRjcDaCAACDdWRwgrgyhHVkcDaCAAA

This ENR has tcp: 0, tcp6: 0, udp6: 0 — all valid, meaning the node doesn't listen on those transports.

Fix

Use field == null instead of !field to only throw on truly missing fields (undefined/null), correctly displaying port 0 as a valid value.


Note

This PR was authored with AI assistance (Lodekeeper 🌟).

ENR records can have port values of 0 (tcp, udp, tcp6, etc.) when a
node is not listening on that transport. The previous check used `!field`
which treats 0 as falsy, throwing 'Field not found' and crashing the
viewer.

Use `field == null` to only throw on truly missing fields (undefined/null),
correctly displaying port 0 as a valid value.

Co-authored-by: lodekeeper <lodekeeper@users.noreply.github.com>
@nflaig nflaig merged commit 4b62b31 into ChainSafe:master Mar 19, 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