fix: validate tipsets in chain_exchange_full_tipset#6828
fix: validate tipsets in chain_exchange_full_tipset#6828hanabi1224 wants to merge 1 commit intomainfrom
chain_exchange_full_tipset#6828Conversation
WalkthroughA new Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/chain_sync/network_context.rs (1)
205-218:⚠️ Potential issue | 🟡 MinorApply validation to
chain_exchange_full_tipsetsmatchingchain_exchange_full_tipset.The batch method uses
|_| truewhile the singular method validates chain integrity viavalidate_network_tipsets(tipsets, tsk). This validation ensures:
- The first tipset matches the requested key
- All tipsets form a proper chain by parent references
Without validation, a malicious peer can return unchained or mismatched tipsets that get persisted directly to the blockstore. Both methods fetch and persist similar data; the singular method's validation should apply to the batch variant as well.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/chain_sync/network_context.rs` around lines 205 - 218, The batch method chain_exchange_full_tipsets currently passes |_| true to handle_chain_exchange_request allowing unvalidated tipsets; update it to perform the same validation used by chain_exchange_full_tipset by replacing the predicate closure with one that calls validate_network_tipsets(tipsets, tsk) and returns its boolean result. Locate chain_exchange_full_tipsets, change the predicate passed into handle_chain_exchange_request to run validate_network_tipsets on the fetched tipsets and the requested tsk (mirroring chain_exchange_full_tipset), and ensure any necessary imports or visibility for validate_network_tipsets are present so invalid or unchained tipsets are rejected before persisting.
🧹 Nitpick comments (1)
src/blocks/tipset.rs (1)
272-279: Consider adding documentation for the publicTipsetLiketrait.As a public trait that abstracts the common interface between
TipsetandFullTipset, a brief doc comment explaining its purpose would help consumers understand when to use it versus concrete types.📝 Suggested documentation
+/// A common read-only interface for tipset-like types. +/// +/// This trait abstracts over [`Tipset`] and [`FullTipset`], enabling generic +/// validation and processing of tipsets from network peers. pub trait TipsetLike { + /// Returns the epoch (height) of this tipset. fn epoch(&self) -> ChainEpoch; + /// Returns the key that uniquely identifies this tipset. fn key(&self) -> &TipsetKey; + /// Returns the key of the parent tipset. fn parents(&self) -> &TipsetKey; + /// Returns the parent state root CID. #[allow(dead_code)] fn parent_state(&self) -> &Cid; }As per coding guidelines: "Document public functions and structs with doc comments".
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/blocks/tipset.rs` around lines 272 - 279, Add a doc comment for the public trait TipsetLike explaining its purpose as an abstraction over Tipset and FullTipset, when to use it, and what each method represents; update the trait definition for TipsetLike to include a short summary line and brief descriptions for the methods epoch, key, parents, and parent_state so consumers know this trait exposes the canonical epoch, tipset key, parent key, and parent state CID for types like Tipset and FullTipset.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/chain_sync/network_context.rs`:
- Around line 205-218: The batch method chain_exchange_full_tipsets currently
passes |_| true to handle_chain_exchange_request allowing unvalidated tipsets;
update it to perform the same validation used by chain_exchange_full_tipset by
replacing the predicate closure with one that calls
validate_network_tipsets(tipsets, tsk) and returns its boolean result. Locate
chain_exchange_full_tipsets, change the predicate passed into
handle_chain_exchange_request to run validate_network_tipsets on the fetched
tipsets and the requested tsk (mirroring chain_exchange_full_tipset), and ensure
any necessary imports or visibility for validate_network_tipsets are present so
invalid or unchained tipsets are rejected before persisting.
---
Nitpick comments:
In `@src/blocks/tipset.rs`:
- Around line 272-279: Add a doc comment for the public trait TipsetLike
explaining its purpose as an abstraction over Tipset and FullTipset, when to use
it, and what each method represents; update the trait definition for TipsetLike
to include a short summary line and brief descriptions for the methods epoch,
key, parents, and parent_state so consumers know this trait exposes the
canonical epoch, tipset key, parent key, and parent state CID for types like
Tipset and FullTipset.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: f3c6ad36-0e45-467a-a450-d345d171e177
📒 Files selected for processing (3)
src/blocks/mod.rssrc/blocks/tipset.rssrc/chain_sync/network_context.rs
Summary of changes
Changes introduced in this pull request:
Reference issue to close (if applicable)
Closes
Other information and links
Change checklist
Outside contributions
Summary by CodeRabbit