[#1040] Implement ClearAlreadyScannedBlocksAction

Closes #1040
This commit is contained in:
Michal Fousek 2023-05-12 11:14:42 +02:00
parent 687abff8d0
commit d068851af7
1 changed files with 8 additions and 2 deletions

View File

@ -8,14 +8,20 @@
import Foundation
class ClearAlreadyScannedBlocksAction {
init(container: DIContainer) { }
let storage: CompactBlockRepository
let transactionRepository: TransactionRepository
init(container: DIContainer) {
storage = container.resolve(CompactBlockRepository.self)
transactionRepository = container.resolve(TransactionRepository.self)
}
}
extension ClearAlreadyScannedBlocksAction: Action {
var removeBlocksCacheWhenFailed: Bool { false }
func run(with context: ActionContext, didUpdate: @escaping (CompactBlockProcessorNG.Event) async -> Void) async throws -> ActionContext {
// clear storage but delete only blocks that were already scanned, when doing parallel download all blocks can't be deleted
let lastScannedHeight = try await transactionRepository.lastScannedHeight()
try await storage.clear(upTo: lastScannedHeight)
await context.update(state: .enhance)
return context