Skip to content

fix: use overlay prefix and correct depth for rchash command#675

Open
crtahlin wants to merge 4 commits into
ethersphere:masterfrom
crtahlin:fix/rchash-anchor-prefix
Open

fix: use overlay prefix and correct depth for rchash command#675
crtahlin wants to merge 4 commits into
ethersphere:masterfrom
crtahlin:fix/rchash-anchor-prefix

Conversation

@crtahlin
Copy link
Copy Markdown

Summary

Fixes #673

  • Truncate overlay to a short even-length hex prefix for the anchor parameter instead of passing the full 64-char overlay address, which caused 400 Bad Request or 500 Internal Server Error from the Bee API
  • Use committedDepth from node status as the default depth instead of topology.depth, which is the Kademlia routing depth and unrelated to the redistribution game
  • Add --depth option to allow overriding the sampling depth (range 0-32), useful for benchmarking at different depths (e.g. storageRadius vs committedDepth)
  • Add integration test for the utility rchash command

Details

The rchash command benchmarks the reserve commitment hash calculation that nodes perform during the Schelling game (storage incentives lottery). The previous implementation had two issues:

  1. The full overlay address was passed as the anchor, but the Bee API expects a short hex prefix (enough bytes to cover the depth bits). This caused API errors.
  2. topology.depth (Kademlia neighborhood depth) was used instead of committedDepth (the actual depth the node commits to the redistribution contract). These are different values — committedDepth = storageRadius + capacityDoubling.

The --depth flag allows operators to benchmark at specific depths, which is useful since sampling time varies significantly with depth (the node iterates through more reserve chunks at lower depths).

Test plan

  • npm run build succeeds
  • npm run check passes
  • npm run lint:check passes
  • New integration test test/command/utility.spec.ts passes
  • Full test suite shows no regressions
  • Verified against running Bee cluster (local dev and full node)

The rchash command was passing the full 64-char overlay address as anchor
and using topology.depth instead of the correct depth from node status.
This caused API errors and did not reflect the actual sampling parameters.

Changes:
- Truncate overlay to a short even-length hex prefix for the anchor
- Use committedDepth from node status as the default depth
- Add optional --depth flag to override the sampling depth
- Add integration test for the rchash command

Co-authored-by: AI
@Cafe137 Cafe137 requested a review from slapec93 as a code owner May 13, 2026 12:42
@Cafe137
Copy link
Copy Markdown
Collaborator

Cafe137 commented May 13, 2026

The tests probably fail because we need to wait 152 blocks. Claude explains why:

blocksPerRound is hardcoded to 152. When currentBlock < 152:

  • 0 / 152 = 0
  • 0 - 1 on uint64 underflows to 18446744073709551615
  • Multiplied by 152 → 18446744073709551464 (still larger than int64 max)
  • This huge number gets passed to HeaderByNumber → go-ethereum JSON-RPC rejects it with "block number larger than int64"

@Cafe137
Copy link
Copy Markdown
Collaborator

Cafe137 commented May 13, 2026

Also it seems there is a requirement of 16 chunks:

bee/pkg/storageincentives/proof.go:41-42 requires exactly 16 chunks in the sample:
if len(reserveSampleItems) != storer.SampleSize {
return ..., fmt.Errorf("reserve sample items should have %d elements", storer.SampleSize)
}

ReserveSample iterates the reserve and filters chunks by:

  1. Proximity to the anchor ≥ committedDepth
  2. Stamp timestamp ≤ consensusTime (from the previous round block — the same call that fails above)
  3. Batch balance ≥ minBatchBalance
  4. Valid stamp signature

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.

utility rchash passes full overlay address as anchor instead of prefix — causes BeeResponseError / ECONNRESET

2 participants