Skip to content

Release shardtree v0.7.1#198

Merged
nuttycom merged 9 commits into
maint/shardtree-0.7.xfrom
release/shardtree-0.7.1
Jul 17, 2026
Merged

Release shardtree v0.7.1#198
nuttycom merged 9 commits into
maint/shardtree-0.7.xfrom
release/shardtree-0.7.1

Conversation

@nuttycom

Copy link
Copy Markdown
Contributor

No description provided.

nuttycom and others added 8 commits July 9, 2026 11:07
`LocatedPrunableTree::truncate_to_position` and its callers mishandle
two situations in which the tree's pruned representation interacts
badly with the truncation position:

1. The parent nodes reconstructed along the truncation path retain
   their cached root annotations. Such an annotation is a hash over
   the parent's complete subtree — including the data being truncated
   away — so a stale annotation later causes a spurious
   `Insert(Conflict(..))` (or a silently incorrect root) when the
   truncated region is refilled with different data, as happens when a
   wallet re-scans a divergent chain after a reorg. Annotations of
   this shape are routinely written by `insert_frontier`, which is
   invoked with the chain state at the start of every scanned batch.

2. When the truncation position falls in the interior of a pruned
   subtree (a merged hash node), `truncate_to_position` returns `None`
   — correctly, since truncating there would have to discard retained
   data along with the requested suffix — but `truncate_to_checkpoint`
   reacts to the refusal by silently skipping the truncation while
   still reporting success, leaving all post-checkpoint state in
   place. (Before the preceding cap-truncation fix, the cap had
   already been modified at that point, additionally leaving the
   store internally inconsistent.)

The annotation tests and the `truncate_to_checkpoint` coherence test
are RED at this commit; `truncate_to_position_fails_inside_pruned_subtree`
passes, pinning the refusal contract that the fix must preserve. The
fix follows in the next commit.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
`LocatedPrunableTree::truncate_to_position` now guarantees that nothing
derived from the discarded suffix of the tree survives a truncation
that it performs, and refuses truncation at any position the tree does
not individually represent:

- A subtree lying entirely at or below the truncation position is
  retained unmodified (including any cached root annotation). This
  check is now made once at the top of the recursion, generalizing the
  check previously made only for pruned leaf nodes.
- Parent nodes whose subtrees lose data in the truncation are
  reconstructed without their cached root annotations: such an
  annotation is a hash over the parent's complete subtree, which by
  construction of the truncation path includes discarded data.
- Truncation at a position in the interior of a pruned subtree (or at
  which the tree holds no data) is refused, as before; it is the
  caller's responsibility to select a position at which truncation is
  possible.

`ShardTree::truncate_to_checkpoint{_depth}` now handle the refusal by
failing with `QueryError::CheckpointPruned`, leaving the store
unmodified, instead of silently skipping the truncation while still
reporting success.

The cap remains truncated with `truncate_cache_to_position`,
introduced by the preceding cap-truncation fix: the cap is a cache —
every node in it is a hash recomputable from the shards below — so a
cached entry spanning the truncation boundary is discarded rather
than making the position unusable. With refusal now handled up front,
the cap, shard, and checkpoint updates are performed unconditionally.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
shardtree: discard stale state when truncating

@nuttycom nuttycom left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self-utACK

@pacu pacu left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@nuttycom
nuttycom merged commit cc96695 into maint/shardtree-0.7.x Jul 17, 2026
17 checks passed
@nuttycom
nuttycom deleted the release/shardtree-0.7.1 branch July 17, 2026 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants