Emit sync progress from `CBP.runSyncingAndEnhancingOnRange` after scan (#1361)

Downloading and scanning blocks are requirements for updating sync
progress, but block deletion from the cache is not. This change moves
block deletion into "the background" alongside transaction enhancement.

Co-authored-by: Honza <rychnovsky.honza@gmail.com>
This commit is contained in:
str4d 2024-03-06 14:10:56 +00:00 committed by GitHub
parent 41324da2d8
commit 41bb83cb5e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 27 additions and 8 deletions

View File

@ -1420,6 +1420,25 @@ class CompactBlockProcessor internal constructor(
}.map { scanResult ->
Twig.debug { "Scan stage done with result: $scanResult" }
val resultState =
when (scanResult.stageResult) {
is SyncingResult.ScanSuccess -> {
SyncingResult.AllSuccess
} else -> {
scanResult.stageResult
}
}
// We don't need to wait for the cached blocks to be deleted, or newly-discovered
// transactions to be enhanced, to report that a block range has been scanned.
emit(
BatchSyncProgress(
order = scanResult.batch.order,
range = scanResult.batch.range,
resultState = resultState
)
)
when (scanResult.stageResult) {
is SyncingResult.ScanSuccess -> {
// TODO [#1369]: Use the scan summary to trigger balance updates.
@ -1447,17 +1466,17 @@ class CompactBlockProcessor internal constructor(
if (continuousResult.stageResult == SyncingResult.DeleteSuccess) {
SyncingResult.AllSuccess
} else {
// Emitting the possible [SyncingResult.DeleteFailed] state here is necessary
emit(
BatchSyncProgress(
order = continuousResult.batch.order,
range = continuousResult.batch.range,
resultState = continuousResult.stageResult
)
)
continuousResult.stageResult
}
emit(
BatchSyncProgress(
order = continuousResult.batch.order,
range = continuousResult.batch.range,
resultState = resultState
)
)
// Increment and compare the range for triggering the enhancing
enhancingRange = enhancingRange.start..continuousResult.batch.range.endInclusive