[#2193] Add Android voting JNI round lifecycle#1938
Conversation
75a95d7 to
350e2b1
Compare
7171d4a to
f0106ae
Compare
| VOTE_READY(FFI_ROUND_PHASE_VOTE_READY); | ||
|
|
||
| companion object { | ||
| fun fromInt(value: Int) = |
There was a problem hiding this comment.
Forward compatibility risk
This throws if Rust adds a new RoundPhase variant before Kotlin is updated — a library update alone can crash the app. For an internal sdk-lib boundary it is defensible, but consider an UNKNOWN(-1) fallback or returning null until the phase set is stable.
There was a problem hiding this comment.
This is an internal api contract between rust and kotlin. For this it's better to fail as soon as possible so the issue comes out during dev, failing silently.
The phase set can also be considered stable.
p.s.: I wish we could enjoy the comfort of UniFFI which solves this problem at generation time.
There was a problem hiding this comment.
p.s.: I wish we could enjoy the comfort of UniFFI which solves this problem at generation time.
@noop-sk Is this something we should track as a future improvement?
|
|
||
| fn next_handle() -> anyhow::Result<jlong> { | ||
| NEXT_DB_HANDLE | ||
| .fetch_update(Ordering::Relaxed, Ordering::Relaxed, |id| { |
There was a problem hiding this comment.
@nuttycom — Ordering::Relaxed on both the success and failure orderings of fetch_update is correct for a monotone uniqueness counter on its own, since the registry Mutex provides the necessary acquire/release barriers around the actual map insert. Just flagging for a second pair of eyes given the subtle interaction between the two synchronization primitives.
There was a problem hiding this comment.
Confirm, that the above is correct.
| VOTE_READY(FFI_ROUND_PHASE_VOTE_READY); | ||
|
|
||
| companion object { | ||
| fun fromInt(value: Int) = |
There was a problem hiding this comment.
p.s.: I wish we could enjoy the comfort of UniFFI which solves this problem at generation time.
@noop-sk Is this something we should track as a future improvement?
30a2201 to
450fe29
Compare
Part of zodl-inc/zodl-android#2193.
Slice of #1924 (umbrella draft PR being split into reviewable pieces).
Depends on #1934 (first slice —
zcash_votingdependency foundation).Resolves MOB-1109
Why
Second slice of the Android shielded-voting integration. #1934 wires the
zcash_votingcrate into backend-lib; this PR adds the voting DB handle and round lifecycle so the round-keyed surface (init / state / list / get-votes / clear / delete-skipped) compiles end-to-end from Rust through JNI to Kotlin.Foundation for the Coinholder Polling flow tracked in zodl-inc/zodl-android#2193 — no user-visible behavior on its own.
What's in
Rust / JNI (
backend-lib/src/main/rust/voting/):db.rs— open/close native handle,setWalletIdrounds.rs—initRound,getRoundState,listRoundsJson,getVotesJson,clearRound,deleteSkippedBundlesshare_tracking.rs— existingcomputeShareNullifier, lifted out of the monolithic modulehelpers.rs— shared JNI helpers: fixed-width byte validation (PROTOCOL_FIELD_BYTES = 32),jint/jlongwidening,RoundState→FfiRoundStateconstructionjson.rs— round summary / vote record serialization,RoundPhase↔u32mappingvoting.rs— reduced to module roots + shared importsKotlin (
sdk-lib/.../internal/):jni/VotingRustBackend.kt— external declarations for the new surfaceTypesafeVotingBackend.kt+ impl —suspendwrappers, IO dispatcher, error checks, JSON →VoteRecordparsingmodel/voting/FfiVotingModels.kt—FfiRoundState,FfiRoundPhaseNot included
Review focus
Primary review track: core-dev. Please look at:
Box::into_raw/Box::from_rawacrossopenVotingDb/closeVotingDb,Arc<VotingDb>usage)catch_unwind, exception conversion)java_bytes_exacton 32-byte protocol fields)RoundState/RoundSummaryJSON and FFI mappinginternaland minimal — just enough to compile and exercise the JNISwift counterparts:
Validation
cargo check --manifest-path backend-lib/Cargo.toml --lockedcargo fmt --manifest-path backend-lib/Cargo.toml --check./gradlew :backend-lib:compileReleaseKotlin :sdk-lib:compileReleaseKotlin./gradlew ktlint detektAll./gradlew checkPropertiesgit diff --checkAuthor
Reviewer