Skip to content

fix(light,statesync): format light-provider height errors and document chunk-ID integrity - #1358

Merged
lklimek merged 1 commit into
v1.6-devfrom
fix/light-height-fmt-statesync-chunk-doc
Jun 19, 2026
Merged

lklimek merged 1 commit into
v1.6-devfrom
fix/light-height-fmt-statesync-chunk-doc

Conversation

@lklimek

@lklimek lklimek commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

Two low-severity production fixes, no logic changes:

  • Fix 1 (LOW) — light/provider/http: validatorSet() formatted height (a *int64) with %d, which printed the pointer's decimal memory address (e.g. 824636669952) instead of the actual block height. Added a fmtHeight(*int64) string helper and replaced %d + height with %s + fmtHeight(height) in all three ErrBadLightBlock error messages ('validator set is empty', 'total number of vals is <= 0', 'missing threshold public key or quorum hash').

  • Fix 2 (LOW / SEC-016 accept-risk) — internal/statesync/chunks.go: added a concise doc comment on chunkQueue.Add recording that individual chunk IDs and content are not cryptographically verified at this layer — integrity is delegated to (a) the ABCI application that reassembles/applies the snapshot, and (b) the post-restore app-hash comparison against the trusted light block. Documentation-only; zero logic change.

Test plan

  • go build ./light/... ./internal/statesync/... — clean
  • gofmt -w -s — no formatting changes needed
  • golangci-lint run on both packages — all findings are pre-existing in untouched files
  • Unit tests: go test ./light/provider/http/... ./internal/statesync/... fails to link in this environment due to missing native BLS library (-lmimalloc-secure); unrelated to these changes — same failure on base branch

🤖 Generated with Claude Code

…t chunk-ID integrity

- light/provider/http: validatorSet() was formatting height (*int64) with
  %d, printing the pointer address instead of the value; add fmtHeight()
  helper and use %s in all three ErrBadLightBlock messages (LOW severity)
- internal/statesync: add SEC-016 accept-risk doc comment on chunkQueue.Add
  documenting that chunk-ID integrity is delegated to the ABCI app and the
  post-restore app-hash check against the trusted light block (LOW severity)

Co-authored-by: Lukasz Klimek <[email protected]>
@lklimek
lklimek requested a review from QuantumExplorer as a code owner June 19, 2026 09:12
@coderabbitai

coderabbitai Bot commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 491ef289-8822-4851-add3-d66f98dc5152

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/light-height-fmt-statesync-chunk-doc

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@thepastaclaw

thepastaclaw commented Jun 19, 2026 •

Copy link
Copy Markdown

✅ Review complete (commit 738706d)

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

Tightly scoped PR with two safe changes: a fmtHeight helper fixing %d-on-*int64 bugs in three light-provider error messages, and a documentation-only comment on chunkQueue.Add describing the SEC-016 trust model. Both changes verified against the source — fmtHeight is correct (nil→"latest", else deref), and the chunk-integrity claim matches the actual flow (post-restore app-hash comparison in syncer.verifyApp). No blockers; one in-scope test-coverage suggestion from Codex.

🟡 1 suggestion(s)

🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `light/provider/http/http.go`:
- [SUGGESTION] light/provider/http/http.go:360-367: Add a test that locks in the fmtHeight fix
  The whole point of this PR is to stop `%d` from formatting `*int64` as a pointer address, but there is no test exercising `fmtHeight` or asserting on the resulting `ErrBadLightBlock.Reason` string. A future refactor could silently reintroduce `%d`/pointer formatting and existing tests would still pass. A small table-driven test on `fmtHeight` covering nil and a concrete height — or an assertion on one of the three affected error strings — would lock the fix in.

Comment on lines +360 to +367
// fmtHeight formats a nullable height pointer for use in error messages.
// A nil pointer means "latest" (height was not specified by the caller).
func fmtHeight(h *int64) string {
if h == nil {
return "latest"
}
return fmt.Sprintf("%d", *h)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Suggestion: Add a test that locks in the fmtHeight fix

The whole point of this PR is to stop %d from formatting *int64 as a pointer address, but there is no test exercising fmtHeight or asserting on the resulting ErrBadLightBlock.Reason string. A future refactor could silently reintroduce %d/pointer formatting and existing tests would still pass. A small table-driven test on fmtHeight covering nil and a concrete height — or an assertion on one of the three affected error strings — would lock the fix in.

source: ['codex']

Copilot AI 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.

Pull request overview

This PR applies two low-severity production-facing improvements: it fixes incorrect block-height formatting in light-provider error messages (previously printing a pointer address), and it documents the intended integrity boundary for state-sync chunk handling.

Changes:

  • Fix light/provider/http error messages to render *int64 heights correctly via a small fmtHeight(*int64) string helper (nil → "latest").
  • Add a doc comment to chunkQueue.Add clarifying that chunk IDs/content are not cryptographically verified at the queue layer, and where end-to-end integrity is enforced instead.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
light/provider/http/http.go Replaces %d formatting of a *int64 height with %s + fmtHeight(height) to avoid printing pointer addresses in ErrBadLightBlock reasons.
internal/statesync/chunks.go Documents the integrity assumptions/guarantees for chunk handling at the chunkQueue.Add boundary (documentation-only).

@lklimek
lklimek merged commit 895f3f6 into v1.6-dev Jun 19, 2026
17 checks passed
@lklimek
lklimek deleted the fix/light-height-fmt-statesync-chunk-doc branch June 19, 2026 09:29
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.

3 participants