Repository navigation
fix(replication): refuse a peer-chosen tree type of another family when serving chunks - #989
Conversation
…en serving chunks `GroveDb::fetch_chunk` opened the subtree a state-sync peer addressed with the tree type from the peer's global chunk id, as-is. Naming a Provable* type for a plain, sum or count subtree (plain chunk route), or an indexed type with a header request (indexed header route), hashed nodes under a type of another aggregate family and reached the fail-closed panic in `TreeNode::hash_for_link`: any peer could crash a serving node at will. Every Merk the source opens for a peer (the generic chunk path, the indexed primary and each indexed secondary) now passes `ensure_served_merk_family`, which compares the root node's family with the opened type and returns `Error::CorruptedData` on a mismatch before anything is hashed. `hash_for_link` is unchanged. Serving is not consensus and an honest target always names the type its restored element carries, so the check is not version-gated. Tests: a black-box reproduction in grovedb/tests, a matrix that replays every honest global chunk id of a grove holding every subtree kind with every tree-type byte, root key kept or dropped and every local-id shape (latest and GROVE_V3), and a fetch_chunk proptest in the replication fuzz tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Warning Review limit reachedNext included review available in 59 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (8)
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. Comment |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
🕓 Queued for automated review — 9th in line, estimated start in ~2.4 h (commit bf04e8e)
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #989 +/- ##
===========================================
+ Coverage 92.95% 92.98% +0.02%
===========================================
Files 331 331
Lines 104500 104518 +18
===========================================
+ Hits 97138 97183 +45
+ Misses 7362 7335 -27
🚀 New features to boost your workflow:
|
Issue being fixed or feature implemented
GroveDb::fetch_chunkis the entry point that untrusted state-sync peers call. It decodes aTreeTypefrom a byte of the peer's global chunk id (it accepts0..=16) and opens the addressed subtree with that type as-is. It never checks the type against the aggregate family of the nodes on disk. Hashing nodes under a type from another family breaks the invariant thatTreeNode::hash_for_linkenforces with a deliberatepanic!, so one request from any peer crashes the serving handler. Two routes reach it:ProvableCount,ProvableCountSum,ProvableSumorProvableCountProvableSum(bytes 5, 6, 11, 12) for a Normal, Sum or Count subtree deep enough to haveHashboundaries in its root chunk. Chunk generation (to_hash_node_for_tree_type) then hits the panic ("got NoAggregateData").[0xFE, 1, 0, 0, 0].serve_indexed_header_pagecallsmerk.root_hash()on any non-provable subtree with a root key and hits the same panic.This was reproduced before the fix: 7 panics under both the latest version and
GROVE_V3. There is no state or consensus effect, but the panic is deterministic and a peer can repeat it at will. No released Platform build serves snapshots yet. On the unmergedfeat/state-sync-v15branch, drive-abci's panic hook would shut the node down. The restore side already has the matching check (Restorer::write_chunk); the serving side lacked one.What was done?
This change is on the serving side only.
hash_for_linkis untouched: it is consensus-critical and its panic is an intentional invariant.replication::ensure_served_merk_familycompares the root node'snode_type()withmerk.tree_type.inner_node_type(). On a mismatch it returnsError::CorruptedData, with the named type, the subtree prefix and the stored family, before anything is hashed. An empty Merk passes because it has nothing to hash.fetch_chunk;serve_indexed_header_page;GroveVersiongate, because serving is not consensus.fetch_chunkruns onlycheck_grovedb_v0.open_transactional_merk_by_prefixopens through the secondary's persisted base root with a forcedNormalTree. The source used to hash the provable secondary under that type. This did not panic (NormalTreehashing falls through to the plain hash), but it produced a hash the target would reject. The family check now refuses it.fetch_chunk_rejects_malformed_indexed_header_requestsnow passes the real secondary root key in its "primary root key opens nothing" case, so that case still exercises the primary, and it pins this refusal as a separate case.How Has This Been Tested?
grovedb/tests/state_sync_serving_tree_type.rsis a black-box test that uses only the public API, like a remote peer. It is the audit reproduction: bytes 5, 6, 11 and 12 on the plain route and 13, 14 and 15 on the header route, all against a 100-itemNormalTree. Every request is now refused with the family error, and the node keeps serving the honest request. It runs under the latest version andGROVE_V3.grovedb/src/tests/replication_serving_tree_type_tests.rs:The full matrix builds a grove with one populated subtree of every kind: Normal, Sum, BigSum, Count, CountSum, PC, PCS, PS, PCPS, empty, PCIT, PSIT, PCPSIT (with their secondaries), CommitmentTree, MMR, BulkAppend, Dense and PrivateDocumentStore. It records every global chunk id an honest sync sends, then replays each target with:
0..=16plus the unknown bytes 17, 128 and 255;The matrix asserts that no request panics, that honest requests are still served, that a Merk subtree named with a type from another family is refused with the family error, and that unknown bytes are refused. It runs under the latest version and
GROVE_V3.The grove root and an empty grove get every tree-type byte, with the root key kept or dropped.
replication_fuzz_tests.rsadds a proptest (fetch_chunk_survives_peer_chosen_tree_types_and_ids) that drivesfetch_chunkon the same fixture. Each case uses a random target, a peer-chosen type byte, a root key that may be dropped, and mutated local ids or a mutated whole request. It asserts there is never a panic and that a mismatched family is never served.With the check disabled, all four new
src/teststests fail.Local runs:
cargo fmt --checkpasses.cargo clippy -p grovedb --all-targets -- -D warningsis clean.replication_serving_tree_type_tests, the new fuzz property, and--test state_sync_serving_tree_type.cargo test -p grovedbrun passes: 3494 lib tests plus every integration binary and the doctests, 0 failures. An earlier run showedfetch_chunk_rejects_malformed_indexed_header_requestsfailing; that test was adjusted as described above.Breaking Changes
None. The change is serving-side only and not version-gated. Honest requests are unaffected; only requests that name a tree type from another family than the addressed Merk's nodes are now refused with
Error::CorruptedData.Checklist:
For repository code-owners and collaborators only
🤖 Generated with Claude Code
PR Hygiene ·
bf04e8e/skip-botsproceeds without the ones not yet reported/self-reviewedonce the bots are doneWhen every box is checked the
PR Hygienecheck passes and this can merge.