Skip to content

Delete dead code, adjust misleading errors, and remove panic-on-input #644

Description

@emlautarom1

Dead code (zero constructions / zero callers)

Misleading errors and wrong identities

  • ssz from_0x_hex_str reports a decoded byte-length mismatch as hex InvalidStringLength — a parse error identity for a length condition.
  • eth2util epoch_from_slot maps a slots_per_epoch == 0 division failure to FetchSlotsPerEpoch — after the fetch already succeeded.
  • deposit errors render Gwei constants as ETH: errors.rs#L18/L39 produce "must be >= 1000000000 ETH" (MIN_DEPOSIT_AMOUNT is Gwei).
  • enr FailedToVerifySignature reads "Signature verification succeeded, but the signature is invalid" — internally contradictory.
  • cluster definition.rs formats serde conversion errors with {:?} instead of {} (six sites, L130–L184).
  • eip712 keccak_hash returns Result but is infallible; four call sites ? a never-Err.
  • Two wrong comments in consensus/core: the timer's negative-round guard (timer.rs#L398-L405) is an unreachable-in-practice divergence from Go's immediate-fire with no comment acknowledging it — add the note (or drop the guard); and analysis.rs#L284-L290 describes a missing cancellation tier that is actually dead code in Go (tracker.go re-assigns the initial value), so the behavior already matches — fix the comment.

Panic on bad or edge input

  • cli format_enr: the guard is byte-length <= 17, so an 18+-byte ENR containing multi-byte UTF-8 reaches from_utf8(&bytes[..13]).expect("ENR must be ASCII") or the tail slice mid-codepoint and panics; reached from config-supplied ENR strings. Use char-boundary-safe slicing.
  • p2p backup_priv_key panic!s on a pre-existing backup directory and .expect()s a parent-exists invariant — effectively unreachable (the path embeds a timestamp + random nonce) but they are unhandled panics in a Result-returning function; return K1Error.
  • frost evaluate_polynomial .expect()s non-empty coefficients — internal callers are guarded by validate_num_of_signers, but the fn is re-exported pub API; make the contract explicit (typed error or documented invariant).
  • The eth2api new()/Default constructor that parses the literal "{server_url}" placeholder (guaranteed panic, zero callers) lives in a generated, gitignored file — it belongs to the client replacement (replace the oas3-gen generated eth2 client with a tailor-made one #611).

Idioms

Acceptance

The dead items are deleted (cargo build --all-features + full test suite green); error messages carry the right identity and units; no panic!/expect reachable from config or peer input in the listed sites; the idiom sweep changes no behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    rustPull requests that update rust code

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions