Skip to content

refactor(network): validate aligned header range payloads#298

Merged
p0mvn merged 5 commits into
mainfrom
refactor/header-sync-checked-ranges
Jul 20, 2026
Merged

refactor(network): validate aligned header range payloads#298
p0mvn merged 5 commits into
mainfrom
refactor/header-sync-checked-ranges

Conversation

@p0mvn

@p0mvn p0mvn commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Motivation

Header-sync range geometry is currently represented by loose start_height and count fields, while headers, body-size hints, and tree-aux roots cross asynchronous boundaries as independent vectors. The upcoming root-authentication lane will reuse one response for operations with different prefixes, making unchecked arithmetic and independent slicing unsafe.

PR #246 answered: “Which request and operation produced this completion?”

This PR answers: “Exactly which heights and per-height data belong to that operation?”

Why this matters:

  • Root authentication requests [F+1 … E+1] but authenticates only [F+1 … E]; the last header is a successor witness.
  • Short peer responses change the actual endpoint.
  • Existing block progress can trim a buffered range.
  • One response will eventually feed both header commit and root authentication.
  • CheckedHeaderRange prevents zero-length, reversed, or overflowing range geometry and supplies checked prefix/suffix operations.

HeaderRangePayload binds headers, body-size hints, and optional roots together. Trimming a prefix now slices all three atomically, preventing roots or counts from becoming associated with the wrong header.

This is prerequisite scaffolding only. It does not yet:

  • authenticate roots;
  • change the wire protocol;
  • change persistence;
  • add the authentication frontier;
  • add overlapping root scheduling.

The next design step can therefore implement state-owned root persistence knowing that network responses have exact identities, checked heights, and structurally aligned data.

Solution

  • add CheckedHeaderRange for non-empty, overflow-safe inclusive geometry and checked prefix/suffix operations
  • add HeaderRangePayload to validate and atomically slice headers, body sizes, and optional all-or-nothing roots
  • carry the aligned payload through buffering, commit actions, tracing, the testkit, and the node state driver
  • keep the wire encoding, protocol version, state request, and scheduling behavior unchanged

Specifications & References

@v12-auditor

v12-auditor Bot commented Jul 20, 2026

Copy link
Copy Markdown

Note

Complete: Audit complete. V12 did not find any issues that need review.

Open the full results here.

Analyzed 13 files, diff fa490f3...38f1e85.

Base automatically changed from refactor/header-sync-operation-identity to main July 20, 2026 19:09
p0mvn added 2 commits July 20, 2026 13:13
Make request geometry and delivered per-height data structurally checked before overlap and root-authentication scheduling reuse them.
Keep checked range failures fallible through the optional suffix path and satisfy the strict unwrap-in-result lint.
@p0mvn
p0mvn force-pushed the refactor/header-sync-checked-ranges branch from 004361b to 975730a Compare July 20, 2026 19:13
@p0mvn
p0mvn marked this pull request as ready for review July 20, 2026 19:34

@evan-forbes evan-forbes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're free to make breaks atm

therefore if its easier to just stick everything in a struct and have a single vector then I'm down

we can even include the request ids in the message

generally not against so I don't want to block, but I think we could also still find a better solution

#[error(
"Zakura header-sync range starting at {start:?} has invalid or overflowing count {count}"
)]
InvalidRangeGeometry {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personally find the name geometry here unconventional and not intuitive

perhaps we could just say, invalid range

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this was an initial AI choice. I thought I renamed everything, but it looks like this one remained. Changing

@p0mvn

p0mvn commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator Author

I am making a follow-up PR to address the comments

@p0mvn
p0mvn merged commit a0a9f59 into main Jul 20, 2026
47 checks passed
@p0mvn
p0mvn deleted the refactor/header-sync-checked-ranges branch July 20, 2026 20:39
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