Skip to content

[#2193] Add Android voting JNI round lifecycle#5

Closed
greg0x wants to merge 3 commits into
greg/voting-rust-foundationfrom
greg/voting-jni-db-rounds
Closed

[#2193] Add Android voting JNI round lifecycle#5
greg0x wants to merge 3 commits into
greg/voting-rust-foundationfrom
greg/voting-jni-db-rounds

Conversation

@greg0x

@greg0x greg0x commented May 8, 2026

Copy link
Copy Markdown

Part of zodl-inc/zodl-android#2193.
Slice of zcash#1924 (umbrella draft PR being split into reviewable pieces).
Depends on zcash#1934 (first slice — zcash_voting dependency foundation).

Why

Second slice of the Android shielded-voting integration. zcash#1934 wires the zcash_voting crate 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, setWalletId
  • rounds.rsinitRound, getRoundState, listRoundsJson, getVotesJson, clearRound, deleteSkippedBundles
  • share_tracking.rs — existing computeShareNullifier, lifted out of the monolithic module
  • helpers.rs — shared JNI helpers: fixed-width byte validation (PROTOCOL_FIELD_BYTES = 32), jint/jlong widening, RoundStateFfiRoundState construction
  • json.rs — round summary / vote record serialization, RoundPhaseu32 mapping
  • voting.rs — reduced to module roots + shared imports

Kotlin (sdk-lib/.../internal/):

  • jni/VotingRustBackend.kt — external declarations for the new surface
  • TypesafeVotingBackend.kt + impl — suspend wrappers, IO dispatcher, error checks, JSON → VoteRecord parsing
  • model/voting/FfiVotingModels.ktFfiRoundState, FfiRoundPhase

Not included

  • hotkey generation
  • bundle setup/count
  • proving cache warmup
  • delegation proving/submission
  • vote commitment or share payloads
  • recovery/share tracking
  • public Synchronizer voting API

Review focus

Primary review track: core-dev. Please look at:

  • native handle lifecycle (Box::into_raw / Box::from_raw across openVotingDb/closeVotingDb, Arc<VotingDb> usage)
  • JNI boundary error semantics (panic-safe via catch_unwind, exception conversion)
  • byte-array validation (java_bytes_exact on 32-byte protocol fields)
  • RoundState / RoundSummary JSON and FFI mapping
  • Kotlin surface is intentionally internal and minimal — just enough to compile and exercise the JNI

Swift counterparts:

Validation

  • cargo check --manifest-path backend-lib/Cargo.toml --locked
  • cargo fmt --manifest-path backend-lib/Cargo.toml --check
  • ./gradlew :backend-lib:compileReleaseKotlin :sdk-lib:compileReleaseKotlin
  • ./gradlew ktlint detektAll
  • ./gradlew checkProperties
  • git diff --check

Author

  • Self-review your own code in GitHub web interface
  • Add automated tests as appropriate
  • Update the manual tests as appropriate
  • Check the code coverage report for the automated tests
  • Update documentation as appropriate
  • Run the demo app and try the changes
  • Pull in the latest changes from the main branch and squash your commits before assigning a reviewer

Reviewer

  • Check the code with the Code Review Guidelines checklist
  • Perform an ad hoc review
  • Review the automated tests
  • Review the manual tests
  • Review the documentation as appropriate
  • Run the demo app and try the changes

@greg0x

greg0x commented May 8, 2026

Copy link
Copy Markdown
Author

zcash#1938

@greg0x greg0x closed this May 8, 2026
@greg0x greg0x deleted the greg/voting-jni-db-rounds branch May 8, 2026 18:08
@greg0x greg0x restored the greg/voting-jni-db-rounds branch May 9, 2026 12:43
greg0x added a commit that referenced this pull request May 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant