Skip to content

zcash_client_sqlite: Allow truncate_to_chain_state to truncate to an unscanned block height.#2248

Merged
nuttycom merged 7 commits into
mainfrom
bug/rewind_to_chain_state
Mar 30, 2026
Merged

zcash_client_sqlite: Allow truncate_to_chain_state to truncate to an unscanned block height.#2248
nuttycom merged 7 commits into
mainfrom
bug/rewind_to_chain_state

Conversation

@nuttycom
Copy link
Copy Markdown
Collaborator

Previously, the computation of the block height to which we would truncate to allow room for the rewind-to checkpoint would fail if the truncation height didn't have an entry in the blocks table. This fixes that problem.

Fixes #2247

@nuttycom nuttycom marked this pull request as ready for review March 27, 2026 19:43
@nuttycom nuttycom force-pushed the bug/rewind_to_chain_state branch 2 times, most recently from b44e7eb to 3842361 Compare March 27, 2026 19:45
@nuttycom nuttycom requested review from nullcopy and schell March 27, 2026 19:45
daira
daira previously approved these changes Mar 27, 2026
Copy link
Copy Markdown
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

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

utACK

str4d
str4d previously approved these changes Mar 27, 2026
Copy link
Copy Markdown
Contributor

@str4d str4d left a comment

Choose a reason for hiding this comment

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

utACK 3842361

Comment thread zcash_client_sqlite/src/wallet.rs Outdated
Comment thread zcash_client_sqlite/src/wallet.rs
nullcopy
nullcopy previously approved these changes Mar 27, 2026
Copy link
Copy Markdown
Contributor

@nullcopy nullcopy left a comment

Choose a reason for hiding this comment

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

Comment thread zcash_client_sqlite/src/wallet.rs
@nuttycom nuttycom dismissed stale reviews from nullcopy, str4d, and daira via 4e88d15 March 28, 2026 22:29
@nuttycom nuttycom force-pushed the bug/rewind_to_chain_state branch from 5122160 to d4e3e1d Compare March 29, 2026 02:15
SqliteShardStore::<_, ::sapling::Node, SAPLING_SHARD_HEIGHT>::from_connection(
conn,
crate::SAPLING_TABLES_PREFIX,
// If a birthday frontiers are available and the birthday height is less than or equal to the
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// If a birthday frontiers are available and the birthday height is less than or equal to the
// If birthday frontiers are available and the birthday height is less than or equal to the

Non-blocking.

Comment thread zcash_client_sqlite/src/wallet.rs Outdated
Comment thread zcash_client_sqlite/src/wallet.rs Outdated
Copy link
Copy Markdown
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

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

Reviewed with suggestions.

Copy link
Copy Markdown
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

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

The suggestion about the target_height comparison is blocking because the code doesn't currently match the comment. (If the comment is wrong, please change that instead.)

@schell
Copy link
Copy Markdown
Contributor

schell commented Mar 30, 2026

Not my wheelhouse but these changes look sound to me.

nuttycom and others added 4 commits March 30, 2026 08:27
…below wallet birthday

Tests that truncate_to_chain_state succeeds when the target height is
below the wallet birthday (i.e., there is no entry in the blocks table
at that height). This exercises the case where a wallet needs to rewind
to a height it has never scanned.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…oint intersection

The previous query computed MAX(MIN(sapling), MIN(orchard)), which
returns a lower bound on where both trees have started checkpointing
but does not guarantee that a checkpoint at that specific height exists
in both tables. This caused incorrect safe rewind height reporting and
incorrect truncation targets in truncate_to_chain_state.

The fix queries for the actual minimum checkpoint height that exists in
the intersection of both checkpoint tables, matching the semantics used
by select_truncation_height.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…canned heights.

Previously, truncate_to_chain_state could fail if no entry existed in
the `blocks` table at the given height. This change repeals that
restriction.
@nuttycom nuttycom marked this pull request as draft March 30, 2026 14:41
@nuttycom
Copy link
Copy Markdown
Collaborator Author

Moved back to draft because I discovered another failure mode in the same vein.

@nuttycom nuttycom force-pushed the bug/rewind_to_chain_state branch from d4e3e1d to ad7b729 Compare March 30, 2026 16:02
…canned.

This tests the scenario where the wallet has been truncated to an
earlier chain state (for example, when adding an account with an earlier
birthday) and then truncate_to_chain_state is called again with a
*greater* height, such that a discontinuity would be introduced in the
subtree roots by the chain state insertion.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nuttycom nuttycom force-pushed the bug/rewind_to_chain_state branch from ad7b729 to 76913b5 Compare March 30, 2026 16:34
…anned height.

`Shardtree` will return an error if insertion results in a discontinuity
in subtree roots. When adding an account after truncation, this can
cause the insertion to fail.
@nuttycom nuttycom force-pushed the bug/rewind_to_chain_state branch from 76913b5 to eb3ea65 Compare March 30, 2026 16:36
@nuttycom nuttycom requested review from daira and nullcopy March 30, 2026 16:36
@daira daira marked this pull request as ready for review March 30, 2026 17:59
Comment thread zcash_client_sqlite/src/wallet.rs Outdated
Comment thread zcash_client_sqlite/src/wallet.rs Outdated
Comment thread zcash_client_sqlite/src/wallet.rs Outdated
daira
daira previously approved these changes Mar 30, 2026
Copy link
Copy Markdown
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

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

Inaccurate comment which should be fixed, but I will unblock this now.

@nuttycom nuttycom merged commit 438657c into main Mar 30, 2026
48 checks passed
@nuttycom nuttycom deleted the bug/rewind_to_chain_state branch March 30, 2026 19:23
Copy link
Copy Markdown
Contributor

@daira daira left a comment

Choose a reason for hiding this comment

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

Post-hoc ACK.

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.

zcash_client_sqlite: truncate_to_chain_state fails when rewinding to a block that has not been scanned.

5 participants