Add logic to validate processor setup.

This commit is contained in:
Kevin Gorham 2020-02-11 20:00:35 -05:00
parent dd18a13b47
commit 4d655b0f04
No known key found for this signature in database
GPG Key ID: CCA55602DF49FC38
2 changed files with 10 additions and 3 deletions

View File

@ -113,8 +113,8 @@ class CompactBlockProcessor(
* return the block height where an error was found.
*/
private suspend fun processNewBlocks(): Int = withContext(IO) {
verifySetup()
twig("beginning to process new blocks (with lower bound: $lowerBoundHeight)...")
// Get the latest info (but don't transmit it on the channel) and then use that to update the scan/download ranges
ProcessorInfo(
networkBlockHeight = downloader.getLatestBlockHeight(),
@ -158,6 +158,10 @@ class CompactBlockProcessor(
}
private fun verifySetup() {
if (!repository.isInitialized()) throw CompactBlockProcessorException.Uninitialized
}
@VisibleForTesting //allow mocks to verify how this is called, rather than the downloader, which is more complex
internal suspend fun downloadNewBlocks(range: IntRange) = withContext<Unit>(IO) {
if (range.isEmpty()) {

View File

@ -41,6 +41,9 @@ sealed class CompactBlockProcessorException(message: String, cause: Throwable? =
class FailedReorgRepair(message: String) : CompactBlockProcessorException(message)
object FailedScan : CompactBlockProcessorException("Error while scanning blocks. This most " +
"likely means a block is missing or a reorg was mishandled. See Rust logs for details.")
object Uninitialized : CompactBlockProcessorException("Cannot process blocks because the wallet has not been" +
" initialized. Verify that the seed phrase was properly created or imported. If so, then this problem" +
" can be fixed by re-importing the wallet.")
}
sealed class CompactBlockStreamException(message: String, cause: Throwable? = null) : SdkException(message, cause) {
@ -77,8 +80,8 @@ sealed class InitializerException(message: String, cause: Throwable? = null) :
" because it already exists in $dbPath", cause)
object DatabasePathException :
InitializerException("Critical failure to locate path for storing databases. Perhaps this" +
" device prevents apps from storing data? We cannot manage initialize the wallet" +
" unless we can store data.")
" device prevents apps from storing data? We cannot initialize the wallet unless" +
" we can store data.")
}
sealed class LightwalletException(message: String, cause: Throwable? = null) : SdkException(message, cause) {