perf(history): band the full sent-sweep so it doesn't hold cs_main for minutes
A full z_listsentbyaddress holds the daemon's cs_main for the whole sweep -- ~140 s on a large wallet on a daemon without the sent-history decrypt cache -- which starves block connection and makes every other RPC (getinfo, balances) wait, so the node looks "busy". This runs the full sweep in depth bands so no single call holds the lock for long. - The full case now covers [0, tip] in bands: z_listsentbyaddress(z, minconf=a, filter-2, maxDepth=b) returns exactly depth [a, b]. Newest band first (its minconf=0 includes the mempool); results dedupe by txid across the overlap. - Each band is a separate call, so cs_main is held only ~5 s at a time and the node stays responsive between bands (block connection isn't starved, the busy canary answers). Total CPU is unchanged -- just not in one long lock. - sentSweepNextBandSize adapts the next band toward ~5 s: grows up to 4x in sparse depth (empty regions covered fast), shrinks to 1/2x in dense depth. - W advances only after every band succeeds; a mid-sweep failure re-sweeps rather than marking a partial result. The windowed sweep is unchanged. - Each band also fits the 120 s timeout on its own, so the seed completes even on a daemon where the single whole-wallet call used to time out. This removes the ~2.5 min hang on the first-run seed, the weekly safety-net re-sweep, and any invalidation. Multi-band + band-sizing covered by tests. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -70,6 +70,15 @@ bool sentSweepSafetyNetDue(std::int64_t nowSec, std::int64_t lastFullSec)
|
||||
return lastFullSec > 0 && (nowSec - lastFullSec) > kSentSweepSafetyNetSec;
|
||||
}
|
||||
|
||||
int sentSweepNextBandSize(int prevSize, double prevMs)
|
||||
{
|
||||
if (!(prevMs > 0.0)) return std::clamp(prevSize, kSentSweepBandMinBlocks, kSentSweepBandMaxBlocks);
|
||||
double scale = static_cast<double>(kSentSweepBandTargetMs) / prevMs;
|
||||
scale = std::clamp(scale, 0.5, 4.0); // don't swing more than 2x smaller / 4x larger per step
|
||||
int next = static_cast<int>(std::lround(prevSize * scale));
|
||||
return std::clamp(next, kSentSweepBandMinBlocks, kSentSweepBandMaxBlocks);
|
||||
}
|
||||
|
||||
long fullSentSweepRetryDelaySec(int consecutiveFailures)
|
||||
{
|
||||
if (consecutiveFailures <= 0) return 0;
|
||||
|
||||
Reference in New Issue
Block a user