Skip to content

Commit

Permalink
Migrate to zcash_client_sqlite 0.12 (#1613)
Browse files Browse the repository at this point in the history
* rust: Raise MSRV to 1.82

* rust: Fix clippy lints after MSRV bump

* rust: Migrate to `#[unsafe(no_mangle)]`

* rust: Remove superfluous generated file

The PoC was added to the codebase in 01efabe.
It was removed in 5f90675 but the generated
bindings were missed.

* Migrate to `zcash_client_sqlite 0.12`

* Remove incorrect javadoc

* Use `zcash_client_sqlite 0.12.2` to avoid a bug

* Remove `quickRewind `

- Changelog updated
- Demo app use of the quick rewind action replaced

---------

Co-authored-by: Honza <[email protected]>
  • Loading branch information
str4d and HonzaR authored Oct 22, 2024
1 parent bc92362 commit 6f9ab06
Show file tree
Hide file tree
Showing 18 changed files with 294 additions and 1,043 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ and this library adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
the given ZIP-321 Uri, and then creating transactions from it.

### Changed
- Migrated to Rust 1.82.0.
- `Synchronizer.rewindToNearestHeight` now returns the block height that was
actually rewound to, or `null` if no rewind was performed.
- `Synchronizer.proposeTransfer` throws `TransactionEncoderException.ProposalFromParametersException`
- `Synchronizer.proposeShielding` throws `TransactionEncoderException.ProposalShieldingException`
- `Synchronizer.createProposedTransactions` throws `TransactionEncoderException.TransactionNotCreatedException` and `TransactionEncoderException.TransactionNotFoundException`
Expand All @@ -22,6 +25,12 @@ and this library adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `FailedSynchronizationException` reported using `Synchronizer.onProcessorErrorHandler` now contains the full
stacktrace history

### Removed
- `Synchronizer.getNearestRewindHeight` (its function is now handled internally
by `Synchronizer.rewindToNearestHeight`).
- `Synchronizer.quickRewind` and `CompactBlockProcessor.quickRewind` have been removed as they triggered the block
rewind action at an invalid height. Use `Synchronizer.rewindToNearestHeight` instead.

## [2.2.4] - 2024-09-16

### Added
Expand Down
61 changes: 28 additions & 33 deletions backend-lib/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions backend-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@ authors = [
description = "JNI backend for the Android wallet SDK"
publish = false
edition = "2018"
rust-version = "1.80"
rust-version = "1.82"

[dependencies]
# Zcash dependencies
orchard = "0.9"
sapling = { package = "sapling-crypto", version = "0.2", default-features = false }
zcash_address = "0.4"
zcash_client_backend = { version = "0.13", features = ["orchard", "tor", "transparent-inputs", "unstable"] }
zcash_client_sqlite = { version = "0.11.2", features = ["orchard", "transparent-inputs", "unstable"] }
zcash_primitives = "0.16"
zcash_proofs = "0.16"
orchard = "0.10"
sapling = { package = "sapling-crypto", version = "0.3", default-features = false }
zcash_address = "0.6"
zcash_client_backend = { version = "0.14", features = ["orchard", "tor", "transparent-inputs", "unstable"] }
zcash_client_sqlite = { version = "0.12.2", features = ["orchard", "transparent-inputs", "unstable"] }
zcash_primitives = "0.19"
zcash_proofs = "0.19"

# Infrastructure
prost = "0.13"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cash.z.ecc.android.sdk.internal

import cash.z.ecc.android.sdk.internal.model.JniBlockMeta
import cash.z.ecc.android.sdk.internal.model.JniRewindResult
import cash.z.ecc.android.sdk.internal.model.JniScanRange
import cash.z.ecc.android.sdk.internal.model.JniScanSummary
import cash.z.ecc.android.sdk.internal.model.JniSubtreeRoot
Expand Down Expand Up @@ -121,13 +122,11 @@ interface Backend {
outputIndex: Int
): String?

suspend fun getNearestRewindHeight(height: Long): Long

/**
* @throws RuntimeException as a common indicator of the operation failure
*/
@Throws(RuntimeException::class)
suspend fun rewindToHeight(height: Long)
suspend fun rewindToHeight(height: Long): JniRewindResult

/**
* @throws RuntimeException as a common indicator of the operation failure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import cash.z.ecc.android.sdk.internal.SdkDispatchers
import cash.z.ecc.android.sdk.internal.ext.deleteRecursivelySuspend
import cash.z.ecc.android.sdk.internal.ext.deleteSuspend
import cash.z.ecc.android.sdk.internal.model.JniBlockMeta
import cash.z.ecc.android.sdk.internal.model.JniRewindResult
import cash.z.ecc.android.sdk.internal.model.JniScanRange
import cash.z.ecc.android.sdk.internal.model.JniScanSummary
import cash.z.ecc.android.sdk.internal.model.JniSubtreeRoot
Expand Down Expand Up @@ -184,21 +185,10 @@ class RustBackend private constructor(
)
}

override suspend fun getNearestRewindHeight(height: Long): Long =
withContext(SdkDispatchers.DATABASE_IO) {
getNearestRewindHeight(
dataDbFile.absolutePath,
height,
networkId = networkId
)
}

/**
* Deletes data for all blocks above the given height. Boils down to:
*
* DELETE FROM blocks WHERE height > ?
* Rewinds the data database to at most the given height.
*/
override suspend fun rewindToHeight(height: Long) =
override suspend fun rewindToHeight(height: Long): JniRewindResult =
withContext(SdkDispatchers.DATABASE_IO) {
rewindToHeight(
dataDbFile.absolutePath,
Expand Down Expand Up @@ -580,19 +570,12 @@ class RustBackend private constructor(
height: Long
)

@JvmStatic
private external fun getNearestRewindHeight(
dbDataPath: String,
height: Long,
networkId: Int
): Long

@JvmStatic
private external fun rewindToHeight(
dbDataPath: String,
height: Long,
networkId: Int
)
): JniRewindResult

@JvmStatic
@Suppress("LongParameterList")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package cash.z.ecc.android.sdk.internal.model

import androidx.annotation.Keep
import cash.z.ecc.android.sdk.internal.ext.isInUIntRange

/**
* Serves as cross layer (Kotlin, Rust) communication class.
*/
@Keep
sealed class JniRewindResult {
/**
* A rewind was successful.
*
* `height` is the height to which the data store was actually truncated.
*/
@Keep
class Success(val height: Long) : JniRewindResult() {
init {
require(height.isInUIntRange()) {
"Height $height is outside of allowed UInt range"
}
}
}

/**
* A requested rewind would violate invariants of the storage layer.
*
* If no safe rewind height can be determined, the safe rewind height member will be -1.
*/
@Keep
class Invalid(val safeRewindHeight: Long, val requestedHeight: Long) : JniRewindResult() {
init {
if (safeRewindHeight != -1L) {
require(safeRewindHeight.isInUIntRange()) {
"Height $safeRewindHeight is outside of allowed UInt range and is not -1"
}
}
require(requestedHeight.isInUIntRange()) {
"Height $requestedHeight is outside of allowed UInt range"
}
}
}
}
Loading

0 comments on commit 6f9ab06

Please sign in to comment.