Skip to content

refactor(spice): tidy chunk-certification endorsement bookkeeping (1/6)#15936

Open
darioush wants to merge 2 commits into
masterfrom
darioush/spice/all-stake-fallback-1
Open

refactor(spice): tidy chunk-certification endorsement bookkeeping (1/6)#15936
darioush wants to merge 2 commits into
masterfrom
darioush/spice/all-stake-fallback-1

Conversation

@darioush

@darioush darioush commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Two behavior-preserving refactors of the SPICE chunk-certification code.

Tally helper:

  • Extract the per-result endorsement-threshold tally shared by the live and on-chain certification paths into a single reaches_endorsement_threshold helper on SpiceCoreReader, replacing the duplicated inline assignment-lookup-and-tally in core_writer_actor.
  • Add is_endorsed on ChunkValidatorAssignments so callers read the verdict directly.

Block-validation endorsement state:

  • Collect the waiting_on_endorsements / known_endorsements maps in validate_core_statements_in_block into an AncestryEndorsements struct that owns the "endorsement state as of the previous block" bookkeeping.
  • Extract push_stored_endorsements and verify_endorsement_signature from core_statements_for_next_block / validate_core_statements_in_block.
  • Add an as-yet-unwritten present_fallback_endorsements field to SpiceUncertifiedChunkInfo, read through all_present_endorsements(), so later work can accumulate endorsements without re-touching the validation loop.

Note: Full change (non-stacked PRs) is available here: #15935

@darioush darioush changed the title refactor(spice): extract endorsement-threshold tally to shared helper refactor(spice): tidy chunk-certification endorsement bookkeeping Jun 17, 2026
@codecov

codecov Bot commented Jun 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 137 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.68%. Comparing base (cf425fe) to head (5c85509).

Files with missing lines Patch % Lines
chain/chain/src/spice/core.rs 0.00% 66 Missing ⚠️
chain/chain/src/spice/ancestry_endorsements.rs 0.00% 34 Missing ⚠️
chain/chain/src/spice/core_writer_actor.rs 0.00% 22 Missing ⚠️
...s/src/stateless_validation/validator_assignment.rs 0.00% 10 Missing ⚠️
core/primitives/src/types.rs 0.00% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #15936      +/-   ##
==========================================
- Coverage   69.70%   69.68%   -0.03%     
==========================================
  Files         946      947       +1     
  Lines      204272   204311      +39     
  Branches   204272   204311      +39     
==========================================
- Hits       142395   142381      -14     
- Misses      57124    57183      +59     
+ Partials     4753     4747       -6     
Flag Coverage Δ
pytests-nightly 1.10% <0.00%> (-0.01%) ⬇️
unittests 69.43% <0.00%> (-0.03%) ⬇️
unittests-nightly 69.38% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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 refactors SPICE chunk-certification endorsement bookkeeping by extracting duplicated endorsement-threshold logic and encapsulating “previous block endorsement state” into a dedicated helper struct, with a preparatory field added to track fallback endorsements.

Changes:

  • Adds SpiceCoreReader::reaches_endorsement_threshold and ChunkValidatorAssignments::is_endorsed to reuse the endorsement-threshold tally logic.
  • Introduces AncestryEndorsements to centralize “pending/known endorsements from previous uncertified chunks” handling during block core-statement validation.
  • Extends SpiceUncertifiedChunkInfo with present_fallback_endorsements and provides all_present_endorsements() for unified iteration.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
core/primitives/src/types.rs Adds fallback-endorsement storage + iterator helper on SpiceUncertifiedChunkInfo.
core/primitives/src/stateless_validation/validator_assignment.rs Adds is_endorsed stake-verdict helper to avoid materializing full endorsement state.
chain/chain/src/spice/tests/core.rs Updates test helper struct construction for new SpiceUncertifiedChunkInfo field.
chain/chain/src/spice/mod.rs Registers new ancestry_endorsements module.
chain/chain/src/spice/core.rs Uses AncestryEndorsements; extracts signature verification + stored-endorsement push; adds threshold helper.
chain/chain/src/spice/core_writer_actor.rs Replaces duplicated store-endorsement tally logic with reaches_endorsement_threshold.
chain/chain/src/spice/ancestry_endorsements.rs New struct encapsulating previous-block endorsement bookkeeping for validation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread core/primitives/src/types.rs
@darioush darioush changed the title refactor(spice): tidy chunk-certification endorsement bookkeeping (1/6) refactor(spice): tidy chunk-certification endorsement bookkeeping Jun 17, 2026
@darioush darioush changed the title (1/6) refactor(spice): tidy chunk-certification endorsement bookkeeping refactor(spice): tidy chunk-certification endorsement bookkeeping (1/6) Jun 17, 2026
@darioush darioush requested a review from pugachAG June 17, 2026 23:49
@darioush darioush marked this pull request as ready for review June 17, 2026 23:49
@darioush darioush requested a review from a team as a code owner June 17, 2026 23:49
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