[#606] Fix BlockHeight read from CompactBlockStore
This commit is contained in:
parent
280d0d2027
commit
1135353a84
|
@ -304,13 +304,15 @@ class CompactBlockProcessor internal constructor(
|
|||
ProcessorInfo(
|
||||
networkBlockHeight = downloader.getLatestBlockHeight(),
|
||||
lastScannedHeight = getLastScannedHeight(),
|
||||
lastDownloadedHeight = BlockHeight.new(
|
||||
network,
|
||||
max(
|
||||
getLastDownloadedHeight().value,
|
||||
lowerBoundHeight.value - 1
|
||||
lastDownloadedHeight = getLastDownloadedHeight()?.let {
|
||||
BlockHeight.new(
|
||||
network,
|
||||
max(
|
||||
it.value,
|
||||
lowerBoundHeight.value - 1
|
||||
)
|
||||
)
|
||||
),
|
||||
},
|
||||
lastDownloadRange = null,
|
||||
lastScanRange = null
|
||||
).let { initialInfo ->
|
||||
|
@ -574,7 +576,6 @@ class CompactBlockProcessor internal constructor(
|
|||
progress = (i / batches.toFloat() * 100).roundToInt()
|
||||
_progress.send(progress)
|
||||
val lastDownloadedHeight = downloader.getLastDownloadedHeight()
|
||||
.takeUnless { it < network.saplingActivationHeight }
|
||||
updateProgress(lastDownloadedHeight = lastDownloadedHeight)
|
||||
downloadedBlockHeight = end
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ import cash.z.ecc.android.sdk.model.BlockHeight
|
|||
import cash.z.ecc.android.sdk.type.ZcashNetwork
|
||||
import cash.z.wallet.sdk.rpc.CompactFormats
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlin.math.max
|
||||
|
||||
/**
|
||||
* 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()
|
||||
|
||||
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? =
|
||||
cacheDao.findCompactBlock(height.value)?.let { CompactFormats.CompactBlock.parseFrom(it) }
|
||||
|
|
|
@ -12,7 +12,7 @@ interface CompactBlockStore {
|
|||
*
|
||||
* @return the latest block height.
|
||||
*/
|
||||
suspend fun getLatestHeight(): BlockHeight
|
||||
suspend fun getLatestHeight(): BlockHeight?
|
||||
|
||||
/**
|
||||
* Fetch the compact block for the given height, if it exists.
|
||||
|
|
Loading…
Reference in New Issue