wallet: fix consolidation-scheduler wedge (ran every block; dead mutual-exclusion)

The Sapling auto-consolidation scheduler never advanced nextConsolidation after
init and never set fConsolidationRunning, so once the tip passed the init
threshold `-consolidation` dispatched a consolidation op every block instead of
once per -consolidationinterval, and every guard that reads fConsolidationRunning
(in RunSaplingSweep, and in the new autoshield driver) was dead.

Mirror the intended scheduler model:
- RunSaplingConsolidation sets fConsolidationRunning=true before dispatch and
  self-guards with `if (fConsolidationRunning) return;`.
- The consolidation op advances nextConsolidation = consolidationInterval +
  tipHeight and clears fConsolidationRunning on every terminal state
  (success/failure/exception/cancel), guarded by op id so only the current op
  mutates scheduler state.
- saplingConsolidationOperationId moved to public so the op can read it.

Restores the documented once-per-interval cadence and makes the
sweep/consolidation/autoshield mutual-exclusion guards effective.

Note: the sweep op has the same latent wedge (fSweepRunning/nextSweep are
cleared only on the sweepComplete success path, so a cancelled or throwing
sweep leaves fSweepRunning stuck true) - left for a follow-up; this commit is
the template to port.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-08-21 18:28:17 -05:00
co-authored by Claude Opus 4.8
parent 2ebbbc777c
commit ca730a5d98
3 changed files with 35 additions and 5 deletions
+3 -1
View File
@@ -784,7 +784,6 @@ private:
TxNullifiers mapTxSaplingNullifiers;
std::vector<CTransaction> pendingSaplingConsolidationTxs;
AsyncRPCOperationId saplingConsolidationOperationId;
std::vector<CTransaction> pendingSaplingSweepTxs;
AsyncRPCOperationId saplingSweepOperationId;
@@ -802,6 +801,9 @@ public:
int64_t nWitnessCacheSize;
bool needsRescan = false;
int nextConsolidation = 0;
// Id of the in-flight consolidation op; read by the op to confirm it is
// still the current one before mutating scheduler state.
AsyncRPCOperationId saplingConsolidationOperationId;
bool fSaplingConsolidationEnabled = false;
bool fConsolidationRunning = false;