perf(slasher): compare validator addresses as bytes, not hex strings

🔎 Visual review of a826b2ad: explainer, review flags and prompts to ask an AI about the change

Summary

BeginBlock calls HandleSuccessfulSign once per signing validator. Each call scans every validator pair, comparing addr.String() with pair.validatorAddress.String(). With about 111 votes × 55 pairs, that's roughly 12k hex-string allocations per block. On a 2,000-block mainnet replay (28124001..28125999), HexBytes.String was 83% of HandleSuccessfulSign and 1.6% of all block CPU.

HexBytes.String is the upper-case hex of the bytes, so two addresses have equal strings exactly when their bytes are equal. bytes.Equal gives the same answer without allocating. The same change applies to HandleMissingSign and the double-sign lookup.

Risk: high (BeginBlock slashing). The comparison result is identical, and no store reads or writes change.

Evidence

  • scripts/perf/guard.sh vs develop: PASS. All 2,481 regression output files match, including state, events and gas_used.
  • Slasher suites: 106 passed.
  • Mainnet replay profile (v3.20.3 + perf-replay-r4): HexBytes.String was 1.6% of block CPU, all of it from these comparisons.

Tests and coverage

  • The new TestSignHandlersSkipOtherValidators covers the mismatch branch in both sign handlers. A decoy pair for another validator comes first, and the test keeper fails any lookup of its node account, so the handlers succeed only if they skip it. It fails when the skip is removed.
  • Changed-line coverage: 7/7.

🤖 Generated with Claude Code

Edited by Huginn Ai

Merge request reports

Loading
Loading