feat: validate chunk cache content#16081
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #16081 +/- ##
==========================================
+ Coverage 73.19% 73.33% +0.13%
==========================================
Files 856 857 +1
Lines 188394 189410 +1016
Branches 188394 189410 +1016
==========================================
+ Hits 137904 138902 +998
+ Misses 46070 46066 -4
- Partials 4420 4442 +22
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Pull request overviewAdds a Changes:
Reviewed changesPer-file summary
FindingsBlocking (must fix before merge):
Non-blocking (nits, follow-ups, suggestions):
|
Verify a partial encoded chunk's header producer signature at arrival, without waiting for the parent block to be processed. Today, a chunk's signature can only be checked once its parent block is available (the parent is needed to resolve the chunk producer). Near the tip, parts routinely beat their block, so the pipeline caches and gossips chunks on a header whose authenticity is still unproven.
This PR carries a grandparent anchor (
prev_prev_block_hash+epoch_id) in a newPartialEncodedChunkV3wire message. The anchor is enough to resolve the producer for any chunk withinhead+2even when the parent is not yet processed, so the header signature can be verified immediately. Gated behindProtocolFeature::EarlyKickout.Changes
core/primitives/src/sharding.rs— newPartialEncodedChunkV3variant (= 2) carryingprev_prev_block_hashandepoch_id, all enum accessor arms,prev_prev_block_hash()/epoch_id()accessors, and theFrom<PartialEncodedChunkWithArcReceipts>impl that emits V3 when the anchor is present.chain/chunks/src/shards_manager_actor.rs— producer emits V3 underEarlyKickout(anchor viagrandparent_anchor); arrival path captures the anchor before the V2 collapse and threads it intovalidate_chunk_header_preliminary, which now resolves the producer from the anchor and verifies the signature. An anchorless V2 message on anEarlyKickoutepoch is dropped.chain/chain/src/signature_verification.rs— shared, carrier-agnostic anchored helpers (resolve_anchored_producer,verify_anchored_chunk_key,resolve_and_verify_anchored_producer), factored out and reused by both chunk-header and state-witness verification.chain/client/src/stateless_validation/validate.rs— witness verification now calls the shared helpers instead of its own copies.ANCHORED_CHUNK_PRODUCER_LOOKUP_TOTALmoved from the client crate tochain/chain, now labeled bymessage_type(chunk/witness/contract_accesses/contract_deploys) andresult.Testing
chain/chunks(shards_manager_actor.rs,test_utils.rs) — arrival-time unit tests: a valid V3 chunk beating its parent is verified and cached; a forged header (bad signature, or valid signature but height/epoch mismatched against the anchor) is rejected and not cached; an anchorless V2 message on anEarlyKickoutepoch is dropped; V3 borsh round-trip.chain/client/src/stateless_validation/validate_tests.rs— shared-helper edge cases (genesis / genesis+1 default anchor, skipped heights, parent-present vs parent-absent) run against the extracted helpers.test-loop-tests—test_early_kickout_version_upgrade(early_kickout_boundary.rs): a live chain upgrading intoEarlyKickoutreaches post-feature epochs with no skipped blocks and no missing chunks (a dropped valid V3 chunk would surface as a missing chunk).