Compare commits

...

2 Commits

Author SHA1 Message Date
Lukas Korba 83702731a0
Merge pull request #1414 from LukasKorba/1412-Review-wipe-function-and-in-memory-values
[#1412] Review wipe function and in memory values
2024-04-17 12:36:08 +02:00
Lukas Korba ffc7fd1be9 [#1412] Review wipe function and in memory values
- The wipe() is now resetting local in memory values of latestBlocksDataProvider. In some case this could cause a reset of CBP's state machine context sooner than it was supposed to, resulting in corrupted sync.
2024-04-16 16:48:20 +02:00
4 changed files with 30 additions and 1 deletions

View File

@ -6,6 +6,12 @@ and this library adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
# Unreleased
## Changed
- The database locking mechanism has been changed to use async/await concurrency approach - the DBActor.
## Fixed
- Call of wipe() resets local (in memory) values.
# 2.1.3 - 2024-03-28
## Fixed

View File

@ -386,6 +386,8 @@ extension CompactBlockProcessor {
try await rewindDownloadBlockAction(to: nil)
await latestBlocksDataProvider.reset()
await context.completion(nil)
} catch {
await context.completion(error)

View File

@ -12,7 +12,8 @@ protocol LatestBlocksDataProvider {
var maxScannedHeight: BlockHeight { get async }
var latestBlockHeight: BlockHeight { get async }
var walletBirthday: BlockHeight { get async }
func reset() async
func updateScannedData() async
func updateBlockData() async
func updateWalletBirthday(_ walletBirthday: BlockHeight) async
@ -36,6 +37,13 @@ actor LatestBlocksDataProviderImpl: LatestBlocksDataProvider {
self.rustBackend = rustBackend
}
func reset() async {
fullyScannedHeight = .zero
maxScannedHeight = .zero
latestBlockHeight = .zero
walletBirthday = .zero
}
func updateScannedData() async {
fullyScannedHeight = (try? await rustBackend.fullyScannedHeight()) ?? walletBirthday
maxScannedHeight = (try? await rustBackend.maxScannedHeight()) ?? walletBirthday

View File

@ -671,6 +671,19 @@ class LatestBlocksDataProviderMock: LatestBlocksDataProvider {
}
var underlyingWalletBirthday: BlockHeight!
// MARK: - reset
var resetCallsCount = 0
var resetCalled: Bool {
return resetCallsCount > 0
}
var resetClosure: (() async -> Void)?
func reset() async {
resetCallsCount += 1
await resetClosure!()
}
// MARK: - updateScannedData
var updateScannedDataCallsCount = 0