shardtree: discard stale cap roots on truncation#147
Conversation
727f7e8 to
5e0a34b
Compare
|
@gustavovalverde this looks like it now conflicts with |
5e0a34b to
ffcb132
Compare
|
@nuttycom rebased |
This sounds to me like a problem in the pruning logic, not one that we should work around by truncating to a different point than the one that was requested. It should always be possible to truncate to exactly any checkpoint leaf; if that invariant isn't preserved by some paths, then the correct option is to find that bug rather than try to work around it. |
nuttycom
left a comment
There was a problem hiding this comment.
Blocking on figuring out how it's possible to get into the described failure state in the first place. Checkpoints should be allowed to be aggregated up the tree only in the case that a checkpoint corresponds to the right-hand leaf of some filled subtree. If there is a path to a checkpoint being constructed (or retained after pruning) for a pruned leaf, that's definitely a bug.
ffcb132 to
af93c7c
Compare
af93c7c to
48b5297
Compare
|
@nuttycom the fix is now more targeted. The PR body was updated alongside the changelog to represent the latest code |
48b5297 to
ce08286
Compare
|
Thanks, you were right: the earlier tests manufactured invalid checkpoints and did not establish a real path to that state. I removed that behavior and narrowed the PR to the stale cap cache issue. The regression now uses only a valid checkpoint and public operations: import 2 shard roots, cache their combined hash, scan the first shard, truncate at its checkpoint, then insert a replacement second shard. On main, the final root incorrectly remains The fix does not change shard or checkpoint truncation semantics. It only discards cap nodes and annotations that commit beyond a successful truncation boundary, so later roots recompute from authoritative shard data. |
Checkpoint truncation could retain a cached cap hash covering positions after the target checkpoint. After inserting replacement commitments, root queries could return the pre-truncation root.
The cap is non-authoritative: shard data remains the source of truth. This change retains cache nodes wholly before the checkpoint and discards cached leaves and parent annotations that cross its boundary, forcing later root queries to recompute from the retained and replacement shards.
Shard and checkpoint truncation semantics are unchanged. The regression reproduces the relevant wallet sequence through public
ShardTreeoperations: insert subtree roots, cache their combined root, scan to a valid checkpoint, truncate, and insert replacement commitments.