Repository navigation
Commit 2d675c0
fix: iter_is_valid_for_type wrapper arms preserve cost (CodeRabbit)
CodeRabbit flagged that the three aggregate-wrapper arms in
`QueryItem::iter_is_valid_for_type` (AggregateCountOnRange,
AggregateSumOnRange, AggregateCountAndSumOnRange) early-return from
the inner match BEFORE the outer `cost` accumulator is folded into
the result, dropping the already-collected `iter.key()` cost AND
making the recursive call re-read the iterator.
Fix: short-circuit wrapper variants at the TOP of the function,
before any `iter.key()` read. The inner item does its own read +
cost accumulation, so the outer-level read becomes redundant. The
in-match arms for wrapper variants become `unreachable!()` since
the early return covers them all.
Skipped CodeRabbit findings (decline with reasons):
- `helpers.rs:99` `.unwrap()` on `CostResult` — false alarm. `.unwrap()`
on `CostContext<T>` (which is what `CostResult<T>` is — `CostContext`
is a wrapper struct, not `Result`) returns the inner `T` while
discarding the cost. No panic risk. The `Result` is then handled
by `.map_err(...)?`. Same idiom used by sibling
`aggregate_count/helpers.rs` and `aggregate_sum/helpers.rs`.
- V0 PCPS rejection at `generate.rs:815-823` — declining as
inconsistent with the established V0 pattern. The match arm groups
PCPS with `MmrTree`, `BulkAppendTree`, `DenseAppendOnlyFixedSizeTree`,
and the other `Provable*` variants as "tree-without-subquery"
emissions. CodeRabbit's suggestion would single-out PCPS for hard
rejection while leaving sibling new-Element-variants behaving as
tree-passthrough — that's the inconsistency. V0 already rejects
PCPS at descend-time via the leaf-merk-open guard at
`prove_subqueries:425`; the surface that remains (returning a
PCPS Element as a query result without descending) follows the
same passthrough pattern as MmrTree/BulkAppendTree and is
consistent with how V0 has historically dealt with new Element
variants it doesn't fully understand.
627 merk + 1791 grovedb tests pass; cargo fmt clean.
Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>1 parent 517f327 commit 2d675c0
1 file changed
Lines changed: 18 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1292 | 1292 | | |
1293 | 1293 | | |
1294 | 1294 | | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
1295 | 1309 | | |
1296 | 1310 | | |
1297 | 1311 | | |
| |||
1345 | 1359 | | |
1346 | 1360 | | |
1347 | 1361 | | |
1348 | | - | |
1349 | | - | |
1350 | | - | |
1351 | | - | |
1352 | | - | |
1353 | | - | |
1354 | | - | |
1355 | | - | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
1356 | 1366 | | |
1357 | 1367 | | |
1358 | 1368 | | |
| |||
0 commit comments