[#606] Fix BlockHeight read from CompactBlockStore

This commit is contained in:
Carter Jernigan 2022-07-15 07:09:00 -04:00 committed by GitHub
parent 280d0d2027
commit 1135353a84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 10 deletions

View File

@ -304,13 +304,15 @@ class CompactBlockProcessor internal constructor(
ProcessorInfo( ProcessorInfo(
networkBlockHeight = downloader.getLatestBlockHeight(), networkBlockHeight = downloader.getLatestBlockHeight(),
lastScannedHeight = getLastScannedHeight(), lastScannedHeight = getLastScannedHeight(),
lastDownloadedHeight = BlockHeight.new( lastDownloadedHeight = getLastDownloadedHeight()?.let {
BlockHeight.new(
network, network,
max( max(
getLastDownloadedHeight().value, it.value,
lowerBoundHeight.value - 1 lowerBoundHeight.value - 1
) )
), )
},
lastDownloadRange = null, lastDownloadRange = null,
lastScanRange = null lastScanRange = null
).let { initialInfo -> ).let { initialInfo ->
@ -574,7 +576,6 @@ class CompactBlockProcessor internal constructor(
progress = (i / batches.toFloat() * 100).roundToInt() progress = (i / batches.toFloat() * 100).roundToInt()
_progress.send(progress) _progress.send(progress)
val lastDownloadedHeight = downloader.getLastDownloadedHeight() val lastDownloadedHeight = downloader.getLastDownloadedHeight()
.takeUnless { it < network.saplingActivationHeight }
updateProgress(lastDownloadedHeight = lastDownloadedHeight) updateProgress(lastDownloadedHeight = lastDownloadedHeight)
downloadedBlockHeight = end downloadedBlockHeight = end
} }

View File

@ -11,7 +11,6 @@ import cash.z.ecc.android.sdk.model.BlockHeight
import cash.z.ecc.android.sdk.type.ZcashNetwork import cash.z.ecc.android.sdk.type.ZcashNetwork
import cash.z.wallet.sdk.rpc.CompactFormats import cash.z.wallet.sdk.rpc.CompactFormats
import kotlinx.coroutines.withContext import kotlinx.coroutines.withContext
import kotlin.math.max
/** /**
* An implementation of CompactBlockStore that persists information to a database in the given * An implementation of CompactBlockStore that persists information to a database in the given
@ -24,7 +23,9 @@ class CompactBlockDbStore private constructor(
private val cacheDao = cacheDb.compactBlockDao() private val cacheDao = cacheDb.compactBlockDao()
override suspend fun getLatestHeight(): BlockHeight = BlockHeight.new(network, max(0L, cacheDao.latestBlockHeight())) override suspend fun getLatestHeight(): BlockHeight? = runCatching {
BlockHeight.new(network, cacheDao.latestBlockHeight())
}.getOrNull()
override suspend fun findCompactBlock(height: BlockHeight): CompactFormats.CompactBlock? = override suspend fun findCompactBlock(height: BlockHeight): CompactFormats.CompactBlock? =
cacheDao.findCompactBlock(height.value)?.let { CompactFormats.CompactBlock.parseFrom(it) } cacheDao.findCompactBlock(height.value)?.let { CompactFormats.CompactBlock.parseFrom(it) }

View File

@ -12,7 +12,7 @@ interface CompactBlockStore {
* *
* @return the latest block height. * @return the latest block height.
*/ */
suspend fun getLatestHeight(): BlockHeight suspend fun getLatestHeight(): BlockHeight?
/** /**
* Fetch the compact block for the given height, if it exists. * Fetch the compact block for the given height, if it exists.