Skip to content

Commit

Permalink
Rewind action continues to the processScanRanges
Browse files Browse the repository at this point in the history
- the diagram png + puml updated
- rewind action continues to the process scan ranges
  • Loading branch information
LukasKorba committed Sep 13, 2023
1 parent 95c9746 commit 5600e77
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class RewindAction {
}

private func update(context: ActionContext) async -> ActionContext {
await context.update(state: .download)
await context.update(state: .processSuggestedScanRanges)
return context
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class RewindActionTests: ZcashTestCase {
"downloader.rewind(latestDownloadedBlockHeight:) is not expected to be called."
)

let acResult = nextContext.checkStateIs(.download)
let acResult = nextContext.checkStateIs(.processSuggestedScanRanges)
XCTAssertTrue(acResult == .true, "Check of state failed with '\(acResult)'")
} catch {
XCTFail("testRewindAction_requestedRewindHeightNil is not expected to fail. \(error)")
Expand Down Expand Up @@ -80,7 +80,7 @@ final class RewindActionTests: ZcashTestCase {
"downloaderService.rewind(to:) is expected to be called."
)

let acResult = nextContext.checkStateIs(.download)
let acResult = nextContext.checkStateIs(.processSuggestedScanRanges)
XCTAssertTrue(acResult == .true, "Check of state failed with '\(acResult)'")
} catch {
XCTFail("testRewindAction_FullPass is not expected to fail. \(error)")
Expand Down
56 changes: 9 additions & 47 deletions docs/cbp_state_machine.puml
Original file line number Diff line number Diff line change
@@ -1,82 +1,49 @@
@startuml
hide empty description

note as Lines
Green lines are happy paths.
Red lines are error paths.
Blue lines are stop paths.

In general any action for any state can produce error.
And the sync process can be stopped during any action.
end note


[*] -> idle

idle -[#green,bold]-> migrateLegacyCacheDB

migrateLegacyCacheDB : MigrateLegacyCacheDBAction
migrateLegacyCacheDB -[#green,bold]-> validateServer
migrateLegacyCacheDB -[#red]-> failed : Error occured.
migrateLegacyCacheDB -[#blue]-> stopped : Sync was stopped.

validateServer : ValidateServerAction
validateServer -[#green,bold]-> fetchUTXO
validateServer -[#red]-> failed : Error occured.
validateServer -[#blue]-> stopped : Sync was stopped.

fetchUTXO : FetchUTXOAction
fetchUTXO -[#green,bold]-> handleSaplingParams
fetchUTXO -[#red]-> failed : Error occured.
fetchUTXO -[#blue]-> stopped : Sync was stopped.

handleSaplingParams : SaplingParamsAction
handleSaplingParams -[#green,bold]-> updateSubtreeRoots
handleSaplingParams -[#red]-> failed : Error occured.
handleSaplingParams -[#blue]-> stopped : Sync was stopped.

updateSubtreeRoots : UpdateSubtreeRootsAction
updateSubtreeRoots -[#green,bold]-> updateChainTip
updateSubtreeRoots -[#red]-> failed : Error occured.
updateSubtreeRoots -[#blue]-> stopped : Sync was stopped.

updateChainTip : UpdateChainTipAction
updateChainTip -[#green,bold]-> clearCache : Every 10mins or after updateSubtreeRoots
updateChainTip -[#green,bold]-> download : Processing of scan range continues
updateChainTip -[#red]-> failed : Error occured.
updateChainTip -[#blue]-> stopped : Sync was stopped.

processSuggestedScanRanges : ProcessSuggestedScanRangesAction
processSuggestedScanRanges -[#green,bold]-> download : Scan range available to process
processSuggestedScanRanges -[#green,bold]-> finished : Scan ranges processed
processSuggestedScanRanges -[#red]-> failed : Error occured.
processSuggestedScanRanges -[#blue]-> stopped : Sync was stopped.
processSuggestedScanRanges -[#green,bold]-> finished : Scan ranges FULLY processed

download : DownloadAction
download -[#green,bold]-> validate
download -[#red]-> failed : Error occured.
download -[#blue]-> stopped : Sync was stopped.

validate : ValidateAction
validate -[#green,bold]-> scan
validate -[#red]-> failed : Error occured.
validate -[#blue]-> stopped : Sync was stopped.
download -[#green,bold]-> scan

scan : ScanAction
scan -[#green,bold]-> clearAlreadyScannedBlocks
scan -[#red]-> failed : Error occured.
scan -[#blue]-> stopped : Sync was stopped.
scan -[#green,bold]-> clearAlreadyScannedBlocks : All ok
scan -[#green,bold]-> rewind : continuity error

rewind : RewindAction
rewind -[#green,bold]-> processSuggestedScanRanges

clearAlreadyScannedBlocks : ClearAlreadyScannedBlocksAction
clearAlreadyScannedBlocks -[#green,bold]-> enhance
clearAlreadyScannedBlocks -[#red]-> failed : Error occured.
clearAlreadyScannedBlocks -[#blue]-> stopped : Sync was stopped.

enhance : EnhanceAction
enhance -[#green,bold]-> updateChainTip : Not all blocks in the\nsync range are downloaded\nand scanned yet.
enhance -[#green,bold]-> clearCache : Clear cache and check the scan ranges
enhance -[#red]-> failed : Error occured.
enhance -[#blue]-> stopped : Sync was stopped.
enhance -[#green,bold]-> updateChainTip : Range NOT finished
enhance -[#green,bold]-> clearCache : Range finished, clear cache and check the scan ranges

note right of enhance
Enhance transactions in batches of 1000
Expand All @@ -86,11 +53,6 @@ end note

clearCache : ClearCacheAction
clearCache -[#green,bold]-> processSuggestedScanRanges
clearCache -[#red]-> failed : Error occured.
clearCache -[#blue]-> stopped : Sync was stopped.

finished --> [*]
failed --> [*]
stopped --> [*]

@enduml
Binary file modified docs/images/cbp_state_machine.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5600e77

Please sign in to comment.