-
Notifications
You must be signed in to change notification settings - Fork 27
[#2193] Add Android voting JNI round lifecycle #1938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f81ebb0
Split voting share nullifier JNI module
greg0x af36d96
Add voting DB round lifecycle JNI
greg0x f0106ae
Add internal voting round lifecycle wrappers
greg0x 662a871
fix: Document FfiRoundState JNI constructor
greg0x 2098c32
fix: Narrow missing round state handling
greg0x 4447de6
fix: Document round phase FFI constants
greg0x 7cd088b
fix: Remove Keep from JSON round summary
greg0x fe73e0f
fix: Remove redundant deleted rows guard
greg0x e730711
fix: Move VoteRecord into voting models
greg0x 3c8bd28
fix: Reuse voting Rust backend instance
greg0x c07f8e7
fix: Use typed JNI for voting round lists
greg0x dad02c3
fix: Use zcash_voting round helper
greg0x 450fe29
fix: Rename voting JNI models
greg0x File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
backend-lib/src/main/java/cash/z/ecc/android/sdk/internal/model/voting/JniVotingModels.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package cash.z.ecc.android.sdk.internal.model.voting | ||
|
|
||
| import androidx.annotation.Keep | ||
|
|
||
| // Must match PHASE_* constants in backend-lib/src/main/rust/voting/helpers.rs. | ||
| internal const val JNI_ROUND_PHASE_INITIALIZED = 0 | ||
| internal const val JNI_ROUND_PHASE_HOTKEY_GENERATED = 1 | ||
| internal const val JNI_ROUND_PHASE_DELEGATION_CONSTRUCTED = 2 | ||
| internal const val JNI_ROUND_PHASE_DELEGATION_PROVED = 3 | ||
| internal const val JNI_ROUND_PHASE_VOTE_READY = 4 | ||
|
|
||
| @Keep | ||
| data class JniRoundState( | ||
| val roundId: String, | ||
| val phase: Int, | ||
| val snapshotHeight: Long, | ||
| val hotkeyAddress: String?, | ||
| val delegatedWeight: Long?, | ||
| val proofGenerated: Boolean | ||
| ) { | ||
| val roundPhase = JniRoundPhase.fromInt(phase) | ||
| } | ||
|
|
||
| @Keep | ||
| enum class JniRoundPhase( | ||
| val value: Int | ||
| ) { | ||
| INITIALIZED(JNI_ROUND_PHASE_INITIALIZED), | ||
| HOTKEY_GENERATED(JNI_ROUND_PHASE_HOTKEY_GENERATED), | ||
| DELEGATION_CONSTRUCTED(JNI_ROUND_PHASE_DELEGATION_CONSTRUCTED), | ||
| DELEGATION_PROVED(JNI_ROUND_PHASE_DELEGATION_PROVED), | ||
| VOTE_READY(JNI_ROUND_PHASE_VOTE_READY); | ||
|
|
||
| companion object { | ||
| fun fromInt(value: Int) = | ||
| entries.firstOrNull { it.value == value } | ||
| ?: error("Unknown round phase: $value") | ||
| } | ||
| } | ||
|
|
||
| @Keep | ||
| data class JniRoundSummary( | ||
| val roundId: String, | ||
| val phase: Int, | ||
| val snapshotHeight: Long, | ||
| val createdAt: Long | ||
| ) { | ||
| val roundPhase = JniRoundPhase.fromInt(phase) | ||
| } | ||
|
|
||
| @Keep | ||
| data class JniVoteRecord( | ||
| val proposalId: Int, | ||
| val bundleIndex: Int, | ||
| val choice: Int, | ||
| val submitted: Boolean | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forward compatibility risk
This throws if Rust adds a new
RoundPhasevariant before Kotlin is updated — a library update alone can crash the app. For an internalsdk-libboundary it is defensible, but consider anUNKNOWN(-1)fallback or returningnulluntil the phase set is stable.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@noop-sk Is this something we should track as a future improvement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree