Add logic to validate processor setup.
This commit is contained in:
parent
dd18a13b47
commit
4d655b0f04
|
@ -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()) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue