erigontech / erigontech/erigon

execution/stagedsync: improve findExecutedDiffsetAtHeight multi-header fallback + branch coverage

Open
#22,117 1 comment 0 reactions 1 assignee Claimed by @AskAlexSharov View on GitHub
tech debt reduction
Dominant language
Go
Stars
3.6k
Forks
1.5k
Avg merge
1d 16h
Merged PRs (30d)
455

Description

Follow-up from #21973 (review thread: https://github.com/erigontech/erigon/pull/21973#discussion_r3499673639).

`findExecutedDiffsetAtHeight` (`execution/stagedsync/stage_execute.go`), extracted from `unwindExec3` in #21973, handles a height with no recorded canonical hash by reading the stored headers and:

- `len(headers) == 0` → returns `can't find diffsets for: `
- `len(headers) == 1` → uses that header's hash
- `len(headers) > 1` → returns `diffsets ambiguous for: , have headers`

### Logic improvement

The `len > 1` branch errors based purely on header count, but in reorg/fork scenarios it is normal to have multiple headers at a height while only the executed block has a stored diffset. The fallback should instead select the unique header whose diffset is present (`found=false` if none) and error only when more than one header actually carries a diffset. (This behavior was moved verbatim from the old inline `unwindExec3`, so it predates #21973.)

### Test coverage

`TestFindExecutedDiffsetAtHeight_FallsBackAfterCanonicalReorg` currently covers only the single-header fallback (plus the canonical-hit and no-diffset-stored cases). Add:

- **multiple headers, exactly one with a diffset**: clear the canonical hash, store two headers at the height with a diffset under only one → assert it is selected (the improvement above);
- **multiple headers, more than one with a diffset** → assert the `ambiguous` error;
- **no stored header** (`len == 0`) with the canonical hash cleared → assert the `can't find diffsets` error.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.