Final changes before beta release.

This commit is contained in:
Kevin Gorham 2020-01-15 07:10:22 -05:00
parent 08f95d505d
commit 38f20c696e
No known key found for this signature in database
GPG Key ID: CCA55602DF49FC38
5 changed files with 46 additions and 12 deletions

View File

@ -99,6 +99,7 @@ class Initializer(
* the most common use case for the initializer--reopening a wallet that was previously created.
*/
fun open(birthday: WalletBirthday): Initializer {
twig("Opening wallet with birthday ${birthday.height}")
initRustLibrary()
rustBackend.birthdayHeight = birthday.height
return this
@ -121,7 +122,7 @@ class Initializer(
overwrite: Boolean = false
): Array<String> {
this.birthday = birthday
twig("Initializing accounts with birthday ${birthday.height}")
try {
if (overwrite) rustBackend.clear()
// only creates tables, if they don't exist
@ -278,9 +279,12 @@ class Initializer(
override fun hasImportedBirthday(): Boolean = importedBirthdayHeight != null
override fun getBirthday() = loadBirthdayFromPrefs(prefs) ?: saplingBirthday
override fun getBirthday(): Initializer.WalletBirthday {
return loadBirthdayFromPrefs(prefs).apply { twig("Loaded birthday from prefs: ${this?.height}") } ?: saplingBirthday.apply { twig("returning sapling birthday") }
}
override fun setBirthday(value: WalletBirthday) {
twig("Setting birthday to ${value.height}")
saveBirthdayToPrefs(prefs, value)
}
@ -362,7 +366,13 @@ class Initializer(
): WalletBirthday {
twig("loading birthday from assets: $birthdayHeight")
val treeFiles =
context.assets.list(BIRTHDAY_DIRECTORY)?.apply { sortDescending() }
context.assets.list(BIRTHDAY_DIRECTORY)?.apply { sortByDescending { fileName ->
try {
fileName.split('.').first().toInt()
} catch (t: Throwable) {
ZcashSdk.SAPLING_ACTIVATION_HEIGHT
}
} }
if (treeFiles.isNullOrEmpty()) throw BirthdayException.MissingBirthdayFilesException(
BIRTHDAY_DIRECTORY
)

View File

@ -185,12 +185,15 @@ class SdkSynchronizer internal constructor(
processor.state.onEach {
when (it) {
is Scanned -> {
// do a bit of housekeeping and then report synced status
onScanComplete(it.scannedRange)
SYNCED
}
is Stopped -> STOPPED
is Disconnected -> DISCONNECTED
else -> SYNCING
is Downloading, Initialized -> DOWNLOADING
is Validating -> VALIDATING
is Scanning -> SCANNING
}.let { synchronizerStatus ->
_status.send(synchronizerStatus)
}

View File

@ -200,15 +200,26 @@ interface Synchronizer {
DISCONNECTED,
/**
* Indicates that this Synchronizer is not yet synced and therefore should not broadcast
* transactions because it does not have the latest data. When set, a UI element may want
* to turn yellow.
* Indicates that this Synchronizer is actively downloading new blocks from the server.
*/
SYNCING,
DOWNLOADING,
/**
* Indicates that this Synchronizer is actively validating new blocks that were downloaded
* from the server. Blocks need to be verified before they are scanned. This confirms that
* each block is chain-sequential, thereby detecting missing blocks and reorgs.
*/
VALIDATING,
/**
* Indicates that this Synchronizer is actively decrypting new blocks that were downloaded
* from the server.
*/
SCANNING,
/**
* Indicates that this Synchronizer is fully up to date and ready for all wallet functions.
* When set, a UI element may want to turn green.
* When set, a UI element may want to turn green. In this state, the balance can be trusted.
*/
SYNCED
}

View File

@ -13,6 +13,7 @@ import cash.z.wallet.sdk.ext.ZcashSdk.POLL_INTERVAL
import cash.z.wallet.sdk.ext.ZcashSdk.RETRIES
import cash.z.wallet.sdk.ext.ZcashSdk.REWIND_DISTANCE
import cash.z.wallet.sdk.ext.ZcashSdk.SAPLING_ACTIVATION_HEIGHT
import cash.z.wallet.sdk.ext.ZcashSdk.SCAN_BATCH_SIZE
import cash.z.wallet.sdk.jni.RustBackend
import cash.z.wallet.sdk.jni.RustBackendWelding
import cash.z.wallet.sdk.transaction.TransactionRepository
@ -215,7 +216,7 @@ class CompactBlockProcessor(
if (failedAttempts > 0) twig("retrying the scan after $failedAttempts failure(s)...")
do {
var scannedNewBlocks = false
result = rustBackend.scanBlocks(500)
result = rustBackend.scanBlocks(SCAN_BATCH_SIZE)
val lastScannedHeight = getLastScannedHeight()
twig("batch scan complete. Last scanned height: $lastScannedHeight target height: ${range.last}")
if (currentInfo.lastScannedHeight != lastScannedHeight) {
@ -271,7 +272,10 @@ class CompactBlockProcessor(
private fun determineLowerBound(errorHeight: Int): Int {
val offset = Math.min(MAX_REORG_SIZE, REWIND_DISTANCE * (consecutiveChainErrors.get() + 1))
return Math.max(errorHeight - offset, lowerBoundHeight)
return Math.max(errorHeight - offset, lowerBoundHeight).also {
twig("offset = min($MAX_REORG_SIZE, $REWIND_DISTANCE * (${consecutiveChainErrors.get() + 1})) = $offset")
twig("lowerBound = max($errorHeight - $offset, $lowerBoundHeight) = $it")
}
}
suspend fun getLastDownloadedHeight() = withContext(IO) {

View File

@ -40,11 +40,17 @@ open class ZcashSdkCommon {
*/
val DOWNLOAD_BATCH_SIZE = 100
/**
* Default size of batches of blocks to scan via librustzcash. The smaller this number the more granular information
* can be provided about scan state. Unfortunately, it may also lead to a lot of overhead during scanning.
*/
val SCAN_BATCH_SIZE = 150
/**
* Default amount of time, in milliseconds, to poll for new blocks. Typically, this should be about half the average
* block time.
*/
val POLL_INTERVAL = 75_000L
val POLL_INTERVAL = 20_000L
/**
* Default attempts at retrying.