wallet.py: add sync barriers to fix flaky wallet-scan race#106
Closed
oxarbitrage wants to merge 1 commit into
Closed
wallet.py: add sync barriers to fix flaky wallet-scan race#106oxarbitrage wants to merge 1 commit into
oxarbitrage wants to merge 1 commit into
Conversation
wallet.py read z_gettotalbalance / z_listtransactions immediately after mining, before the wallet had scanned and committed the new blocks, causing a flaky transparent-balance assertion (0 vs 6.25). Poll for the expected wallet view (no synchronous wallet-sync RPC yet, zcash/wallet#316) before the wallet-side assertions. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
oxarbitrage
added a commit
that referenced
this pull request
Jun 5, 2026
…s in wallet.py The getwalletstatus sync barrier indexed `wallet_tip` unconditionally, but the RPC omits that field (Option + skip_serializing_if) until the wallet has a committed tip — which happens transiently right after blocks are mined. The barrier therefore raised `KeyError: 'wallet_tip'` ~1 run in 4, exactly during the window it is meant to poll through. Treat an absent wallet_tip as "not synced yet" and keep polling, in sync_blocks, sync_mempools, and rebuild_cache. Also make wallet.py use the now wallet-aware self.sync_all() instead of an immediate read and a fixed time.sleep(1), removing the remaining flaky wallet-scan race (and the unused `import time`). This supersedes the bespoke pollers in #106. Validated 10/10 green locally against a zallet carrying zcash/wallet#367 (getwalletstatus) + zcash/wallet#455 (empty shielded tree fix). Closes #105 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Author
|
Superseded by #56. Now that zcash/wallet#367 adds Branch |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #105
Motivation
wallet.pyreads wallet state (z_gettotalbalance/z_listtransactions)immediately after mining, before the embedded wallet has scanned and committed
the newly mined blocks. The transparent-balance assertion races the asynchronous
wallet scan and intermittently fails with
0instead of the expected6.25.There is no synchronous "wallet has synced to height N" RPC to await yet
(tracked upstream in zcash/wallet#316), so the test must poll for the expected
wallet view rather than assuming immediate consistency after mining.
Solution
Add poll-barriers before the wallet-side assertions:
wait_for_wallet_transparent— wait until the transparent balance reflects thematured coinbase.
wait_for_wallet_txcount— wait until the wallet observes the expected numberof transactions.
This mirrors the sync-barrier idiom already used in the migrated tests. No test
logic or coverage is changed — only the ordering guarantee that the wallet has
scanned before we assert on its view.
Test evidence
Run locally against zebrad + zainod + zallet (the zallet built with the
zcash/wallet#455 fix so sync reaches the wallet-scan stage):
wallet.pypasses 3/3 consecutive runs (~7-8s each, exit 0,"Missing Orchard tree state" = 0). Without the barriers the transparent-balance
assertion fails intermittently (0 vs 6.25).
Notes
main(the Make wallet_z_shieldcoinbase_multi_taddr.py executable #100 merge).sync: Treat an absent shielded tree state as an empty note commitment tree wallet#455 (Closes wallet sync task crashes with "Missing Orchard tree state" when a shielded pool is active but its tree is still empty wallet#454) — independent of this change.