fix(commitment-tree): reject negative sqlite positions#746
fix(commitment-tree): reject negative sqlite positions#746thepastaclaw wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis PR strengthens SQLite data integrity by validating that shard indices and checkpoint positions are non-negative. It introduces a validation helper, applies CHECK constraints to database schemas, updates retrieval methods to use validation, and verifies the changes with schema-level and integration tests. ChangesNegative Value Validation for Shard and Checkpoint Operations
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@grovedb-commitment-tree/src/client/sqlite_store/sql_helpers.rs`:
- Around line 128-134: Wrap rusqlite errors from both stmt.query_map calls and
their row iterations with contextual mapping using .map_err(|e|
Error::CorruptedData(format!("...: {}", e))) so callers get operation-specific
context; specifically, update the first loop around stmt.query_map(...) that
constructs Address::from_parts(Level::from(SHARD_HEIGHT),
non_negative_i64_to_u64("shard_index", index?)?) to map any query_map/row error
into Error::CorruptedData with a message like "querying shard indices" and do
the same for the second query_map loop at the other location (lines ~393-399)
with a descriptive message for that operation.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d0757e2e-a0d6-4211-9377-70c0dca97249
📒 Files selected for processing (2)
grovedb-commitment-tree/src/client/sqlite_store/sql_helpers.rsgrovedb-commitment-tree/src/client/sqlite_store_tests.rs
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #746 +/- ##
========================================
Coverage 91.43% 91.43%
========================================
Files 236 236
Lines 67111 67120 +9
========================================
+ Hits 61364 61373 +9
Misses 5747 5747
🚀 New features to boost your workflow:
|
cd1aafd to
5ca122d
Compare
|
✅ Review complete (commit 851f1da) |
thepastaclaw
left a comment
There was a problem hiding this comment.
Code Review
Small, well-scoped defensive PR for the SQLite commitment-tree store: adds CHECK constraints to freshly created tables and validates legacy i64 rows on read before converting to u64. Read coverage spans the natural enumeration paths (sql_last_shard, sql_get_shard_roots, checkpoint loads, mark loads) and the test suite exercises both schema-level rejection and legacy-row rejection. No in-scope blockers or suggestions found.
Note: GitHub does not allow PastaClaw to approve their own PR, so this clean review is posted as a comment review rather than an approval.
Out-of-scope follow-up noted
- Write-side
u64 as i64casts and directsql_get_shardindex cast remain unchecked — Multiple write paths (sql_put_shard:114,sql_truncate_shards:146,sql_add_checkpoint:213,224,sql_update_checkpoint_with:323,333) and the targeted read pathsql_get_shard:57still use uncheckedas i64casts onu64values. On the new schema the added CHECK constraints reject these defensively at write time; on legacy schemas a wrapped negative could be written. Pre-existing pattern, not introduced by this PR. The PR's read-side guarantee is enforced where shards/checkpoints are enumerated, which is the realistic legacy-data exposure path. A directget_shard(addr)whose index wraps to a negative would require a contrived caller. Worth tracking separately to applyi64::try_from(u64)symmetrically at the write boundary and the index-bind insql_get_shard.- Follow-up: Open a follow-up issue to use
i64::try_from(u64)for shard_index and position values at the write boundary and thesql_get_shardquery bind ingrovedb-commitment-tree/src/client/sqlite_store/sql_helpers.rs.
- Follow-up: Open a follow-up issue to use
PR Body
Summary
shard_indexandpositionvalues when readinglegacy commitment tree rows.
CHECKconstraints for newly-created SQLite commitmenttree tables.
checkpoints, and marks-removed positions.
Validation
cargo fmt --allgit diff --checkcargo check --offline -p grovedb-commitment-tree --features sqlitecargo test --offline -p grovedb-commitment-tree --features sqlite \ client::sqlite_store_tests -- --nocapture— 32 passedshipSummary by CodeRabbit