feat(proposals): say how far a proposal has got, not just what it is waiting for
A row said "waiting for 2 of 3 members to take part" on the day a proposal was made and on the day before it completed. That is the rule, not the progress. Now it says "1 of 3 members have offered to sign", and on the next stage "2 of 3 signatures are in" -- the fractions that actually move. Nothing is counted once it has ended, which is both endings and not only the happy one. A signed session has nothing left to gather; an abandoned one has counts frozen where they stopped, and "2 of 3" beside a failure invites the reader to wait for a third that is never coming. The failure reason is what that row has to say. The denominators are the ones the protocol gates on. `orderedNonces` returns nothing until `threshold` nonces have arrived and then takes the first `threshold` of them, so the threshold is both what is needed and what is used -- the room's size is a bigger number nothing waits for. Once the signer set exists it is the set being waited on, which is the same count from the other side. The numerator is the part that had to be got right. A nonce or a partial signature is recorded with no check on who sent it, unlike a refusal, and `orderedNonces` drops the ones from members holding no share when it aggregates. So the tally joins `DkgParticipantMessage` on HOST_KEY and counts members rather than rows: a count including strangers would have a row read ahead of the coordinator, saying the group has what it needs while the session sits still. That is the one direction a progress figure must never be wrong in, and there is a DAO test for it. A count that still runs ahead -- a nonce landing before this device runs `advance` -- is clamped, because a fraction over one reads as a bug rather than as a session about to move. The counts travel as their own `GROUP BY` flow, combined with the sessions in the view model. They change far more often than the rows do, and carrying the messages themselves would carry every nonce payload the room has ever exchanged to a screen that only wants to count them. The progress is its own line rather than a clause, so a reader scanning for the one that is nearly there does not have to read a sentence to find out. That left `statusOf` saying only who the reader is in the proposal, and since this adds user-facing text its remaining literals moved to the catalogue with it -- nine strings that had been raw in the screen since before the catalogue rule. 1367 jvm tests pass, the Android target compiles, all audit budgets met. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
13ae0a1def
commit
7c6e9b0a84
12 files changed
+821
-28
No files matched your search
@@ -21,6 +21,7 @@
|
||||
"XML file ... is not valid. Check the file content."
|
||||
-->
|
||||
<string name="abandoned">Abandoned</string>
|
||||
<string name="abandoned_nothing_was_signed">Abandoned. Nothing was signed.</string>
|
||||
<string name="filter_all">All</string>
|
||||
<string name="app_name">Curare</string>
|
||||
<string name="add_a_dialect_the_group_can_translate_into">Add a dialect the group can translate into</string>
|
||||
@@ -91,6 +92,7 @@
|
||||
<string name="emergency_kit">Emergency kit</string>
|
||||
<string name="ended">ENDED</string>
|
||||
<string name="encrypt_and_back_your_recovery_information">Encrypt and back your recovery information up to your Google Drive or iCloud.</string>
|
||||
<string name="enough_members_took_part_without_you">Enough members took part without you.</string>
|
||||
<string name="enter_the_name_you_want_to_use_for_your">Enter the name you want to use for your group</string>
|
||||
<string name="enter_the_name_you_want_to_use_for_your_2">Enter the name you want to use for your profile</string>
|
||||
<string name="enter_the_translation_for_this_chunk">Enter the translation for this chunk</string>
|
||||
@@ -155,6 +157,7 @@
|
||||
<string name="name_eg_group_discussions">Name (eg. Group Discussions)</string>
|
||||
<string name="name_of_artifact">Name of artifact</string>
|
||||
<string name="needs_you">Needs you</string>
|
||||
<string name="needs_your_review">Needs your review.</string>
|
||||
<string name="network_relays">Network relays</string>
|
||||
<string name="no_proposal_is_being_signed">No proposal is being signed.</string>
|
||||
<string name="no_proposal_is_waiting_on_members">No proposal is waiting on members.</string>
|
||||
@@ -240,6 +243,7 @@
|
||||
<string name="the_signed_event">The signed event</string>
|
||||
<string name="copy_the_signed_event">Copy the signed event</string>
|
||||
<string name="copied_the_signed_event">Copied the signed event</string>
|
||||
<string name="signed_by_the_group">Signed by the group.</string>
|
||||
<string name="this_device_does_not_hold_the_event">This device holds the group's reading of this, but not the signed event itself. Nothing here can be checked against a signature.</string>
|
||||
<string name="sign">Sign</string>
|
||||
<string name="sign_in">Sign in</string>
|
||||
@@ -324,9 +328,12 @@
|
||||
<string name="write_down_and_secure_the_12_word_phrase">Write down and secure the 12 word phrase that this profile and its wallet are derived from.</string>
|
||||
<string name="who_will_you_be_passing_the_aux_to">Who will you be passing the aux to?</string>
|
||||
<string name="you">You</string>
|
||||
<string name="you_agreed">You agreed.</string>
|
||||
<string name="you_and_1_other">You and 1 other</string>
|
||||
<string name="you_are_about_to_create_a_nostr_profile">You are about to create a NOSTR profile.</string>
|
||||
<string name="you_are_signing">You are signing.</string>
|
||||
<string name="you_can_still_carry_on_and_invite_people">You can still carry on and invite people later.</string>
|
||||
<string name="you_declined">You declined.</string>
|
||||
<string name="you_have_not_backed_up_your_recovery_phrase">You have not backed up your recovery phrase</string>
|
||||
<string name="you_only_live_once_lose_this_phone_and_the">You only live once. Lose this phone and the profile goes with it, along with anything it holds.</string>
|
||||
<string name="you_said_you_wrote_it_down">You said you wrote it down</string>
|
||||
@@ -400,6 +407,8 @@
|
||||
<string name="anyone_in_this_group_can_run_a_subgroup">Anyone in this group can run a subgroup, whether or not they administer this one.</string>
|
||||
<string name="has_no_key_package_yet">Has no key package yet</string>
|
||||
<string name="admin_of_this_group">Admin of this group</string>
|
||||
<string name="of_members_have_offered_to_sign">%1$s of %2$s members have offered to sign</string>
|
||||
<string name="of_signatures_are_in">%1$s of %2$s signatures are in</string>
|
||||
<string name="you_coordinate_this_subgroup">You coordinate this subgroup</string>
|
||||
<string name="start_the_key_ceremony">Start the key ceremony</string>
|
||||
<string name="checking_who_can_be_added">Checking who can be added…</string>
|
||||
|
||||
+43
@@ -10,6 +10,7 @@ import kotlinx.coroutines.flow.Flow
|
||||
import to.curare.compose.database.model.FrostSignerMessage
|
||||
import to.curare.compose.database.model.FrostSigningItem
|
||||
import to.curare.compose.database.model.FrostSigningSession
|
||||
import to.curare.compose.database.model.intermdiate.FrostSignerTally
|
||||
import to.curare.compose.database.model.intermdiate.LocalFrostSigningSession
|
||||
|
||||
@Dao
|
||||
@@ -33,6 +34,48 @@ interface FrostSigningSessionDao {
|
||||
@Query("SELECT * FROM FrostSigningSession WHERE chatRoomId = :chatRoomId ORDER BY createdAt DESC")
|
||||
fun observeSessionsForChatRoom(chatRoomId: String): Flow<List<LocalFrostSigningSession>>
|
||||
|
||||
/**
|
||||
* How many members have sent each kind of message, for every session in a
|
||||
* room, in one query.
|
||||
*
|
||||
* The list shows each proposal's progress -- three of the four nonces it
|
||||
* needs, two of the three signatures -- and a query per row would be one per
|
||||
* proposal on a screen whose whole point is that a room has several.
|
||||
*
|
||||
* The join to `DkgParticipantMessage` is what makes the figure honest rather
|
||||
* than merely available. A nonce or a partial signature is recorded without
|
||||
* any check on who sent it, unlike a refusal; `FrostSigningManager`'s
|
||||
* `orderedNonces` then drops the ones from members who hold no share when it
|
||||
* aggregates. Counting those here would have a row read ahead of the session
|
||||
* it describes -- saying the group has what it needs while the coordinator
|
||||
* is still waiting -- which is the one direction a progress figure must
|
||||
* never be wrong in. `HOST_KEY` is the message that makes somebody a share
|
||||
* holder, and the entity's primary key makes it at most one row per member,
|
||||
* so the join cannot multiply a count either.
|
||||
*
|
||||
* @param hostKeyKind `DkgRitualEvents.HOST_KEY`; passed rather than written
|
||||
* in, because a kind inlined into SQL is a kind nothing would renumber.
|
||||
*/
|
||||
@Query(
|
||||
"""
|
||||
SELECT m.sessionId AS sessionId,
|
||||
m.kind AS kind,
|
||||
COUNT(DISTINCT m.signerPublicKey) AS members
|
||||
FROM FrostSignerMessage m
|
||||
JOIN FrostSigningSession s ON s.id = m.sessionId
|
||||
JOIN DkgParticipantMessage d ON d.sessionId = s.dkgSessionId
|
||||
AND d.participantPublicKey = m.signerPublicKey
|
||||
AND d.kind = :hostKeyKind
|
||||
WHERE s.chatRoomId = :chatRoomId AND m.kind IN (:kinds)
|
||||
GROUP BY m.sessionId, m.kind
|
||||
"""
|
||||
)
|
||||
fun observeSignerTalliesForChatRoom(
|
||||
chatRoomId: String,
|
||||
kinds: List<Kind>,
|
||||
hostKeyKind: Kind,
|
||||
): Flow<List<FrostSignerTally>>
|
||||
|
||||
@Query("SELECT * FROM FrostSigningSession WHERE chatRoomId = :chatRoomId ORDER BY createdAt DESC LIMIT 1")
|
||||
suspend fun getLatestSessionForChatRoom(chatRoomId: String): FrostSigningSession?
|
||||
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package to.curare.compose.database.model.intermdiate
|
||||
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Kind
|
||||
|
||||
/**
|
||||
* How many members have sent one kind of message to one signing session.
|
||||
*
|
||||
* A projection rather than an entity: there is no table of these, only a count
|
||||
* over `FrostSignerMessage` grouped by session and kind. It exists so a list of
|
||||
* a room's proposals can say how far each has got without one query per row --
|
||||
* the same reason `LocalFrostSigningSession` joins the items.
|
||||
*
|
||||
* [members] counts members and not rows, and counts only the ones who hold a
|
||||
* share of the key being signed with. Both matter: `FrostSigningManager` records
|
||||
* a nonce or a partial signature without checking who sent it -- unlike a
|
||||
* refusal, which it filters -- so the table may hold messages from members who
|
||||
* are not in the ceremony at all, and `orderedNonces` drops exactly those when
|
||||
* it aggregates. A count that included them would read ahead of the session it
|
||||
* describes, which is the one way a progress figure must never be wrong: it
|
||||
* would say the group is ready while the coordinator is still waiting.
|
||||
*/
|
||||
data class FrostSignerTally(
|
||||
val sessionId: String,
|
||||
val kind: Kind,
|
||||
val members: Int,
|
||||
)
|
||||
+13
@@ -12,10 +12,12 @@ import to.curare.compose.database.CurareDatabase
|
||||
import to.curare.compose.database.model.FrostSignerMessage
|
||||
import to.curare.compose.database.model.FrostSigningItem
|
||||
import to.curare.compose.database.model.FrostSigningSession
|
||||
import to.curare.compose.database.model.intermdiate.FrostSignerTally
|
||||
import to.curare.compose.database.model.intermdiate.LocalChatRoom
|
||||
import to.curare.compose.database.model.intermdiate.LocalFrostSigningSession
|
||||
import to.curare.compose.managers.FrostSigningManager
|
||||
import to.curare.compose.nostr.dkg.DkgRitualEvents
|
||||
import to.curare.compose.nostr.frost.FrostSigningEvents
|
||||
import to.curare.compose.repository.FrostSigningRepository
|
||||
|
||||
class DatabaseFrostSigningRepository(
|
||||
@@ -30,6 +32,17 @@ class DatabaseFrostSigningRepository(
|
||||
override fun observeSessionsForChatRoom(chatRoomId: String): Flow<List<LocalFrostSigningSession>> =
|
||||
database.frostSigningSessionDao().observeSessionsForChatRoom(chatRoomId)
|
||||
|
||||
override fun observeSignerTalliesForChatRoom(
|
||||
chatRoomId: String
|
||||
): Flow<List<FrostSignerTally>> =
|
||||
database.frostSigningSessionDao().observeSignerTalliesForChatRoom(
|
||||
chatRoomId = chatRoomId,
|
||||
// The two kinds a proposal's progress is counted in. Asked for by
|
||||
// name so the query carries no opinion about which kinds exist.
|
||||
kinds = listOf(FrostSigningEvents.NONCE, FrostSigningEvents.PARTIAL_SIGNATURE),
|
||||
hostKeyKind = DkgRitualEvents.HOST_KEY,
|
||||
)
|
||||
|
||||
override fun observeMessages(sessionId: String): Flow<List<FrostSignerMessage>> =
|
||||
database.frostSigningSessionDao().observeMessages(sessionId)
|
||||
|
||||
|
||||
+20
@@ -10,6 +10,7 @@ import to.curare.compose.database.model.FrostSignerMessage
|
||||
import to.curare.compose.database.model.FrostSigningItem
|
||||
import to.curare.compose.database.model.FrostSigningSession
|
||||
import to.curare.compose.database.model.intermdiate.LocalChatRoom
|
||||
import to.curare.compose.database.model.intermdiate.FrostSignerTally
|
||||
import to.curare.compose.database.model.intermdiate.LocalFrostSigningSession
|
||||
|
||||
/**
|
||||
@@ -30,6 +31,21 @@ interface FrostSigningRepository {
|
||||
*/
|
||||
fun observeSessionsForChatRoom(chatRoomId: String): Flow<List<LocalFrostSigningSession>>
|
||||
|
||||
/**
|
||||
* How far each of a room's sessions has got at gathering what it needs, as
|
||||
* a count of members per session per kind of message.
|
||||
*
|
||||
* A companion to [observeSessionsForChatRoom] rather than part of it: the
|
||||
* session rows say which stage a proposal is in, and this says how far
|
||||
* through that stage it is. Kept apart because the counts change far more
|
||||
* often than the rows do -- every member's nonce moves one -- and because
|
||||
* carrying the messages themselves would carry every nonce payload the room
|
||||
* has ever exchanged to a screen that only wants to count them.
|
||||
*
|
||||
* Only members holding a share of the key are counted; see the query.
|
||||
*/
|
||||
fun observeSignerTalliesForChatRoom(chatRoomId: String): Flow<List<FrostSignerTally>>
|
||||
|
||||
fun observeMessages(sessionId: String): Flow<List<FrostSignerMessage>>
|
||||
|
||||
/**
|
||||
@@ -177,6 +193,10 @@ interface FrostSigningRepository {
|
||||
override fun observeSessionsForChatRoom(chatRoomId: String): Flow<List<LocalFrostSigningSession>> =
|
||||
flowOf(emptyList())
|
||||
|
||||
override fun observeSignerTalliesForChatRoom(
|
||||
chatRoomId: String
|
||||
): Flow<List<FrostSignerTally>> = flowOf(emptyList())
|
||||
|
||||
override fun observeMessages(sessionId: String): Flow<List<FrostSignerMessage>> =
|
||||
flowOf(emptyList())
|
||||
|
||||
|
||||
+71
-16
@@ -59,6 +59,15 @@ import to.curare.compose.ui.theme.spacing
|
||||
import curare.composeapp.generated.resources.Res
|
||||
import org.jetbrains.compose.resources.stringResource
|
||||
import curare.composeapp.generated.resources.abandoned
|
||||
import curare.composeapp.generated.resources.you_declined
|
||||
import curare.composeapp.generated.resources.you_are_signing
|
||||
import curare.composeapp.generated.resources.you_agreed
|
||||
import curare.composeapp.generated.resources.signed_by_the_group
|
||||
import curare.composeapp.generated.resources.of_signatures_are_in
|
||||
import curare.composeapp.generated.resources.of_members_have_offered_to_sign
|
||||
import curare.composeapp.generated.resources.needs_your_review
|
||||
import curare.composeapp.generated.resources.enough_members_took_part_without_you
|
||||
import curare.composeapp.generated.resources.abandoned_nothing_was_signed
|
||||
import curare.composeapp.generated.resources.everything_else
|
||||
import curare.composeapp.generated.resources.filter_all
|
||||
import curare.composeapp.generated.resources.filter_and_count
|
||||
@@ -508,7 +517,11 @@ private fun ProposalCard(
|
||||
)
|
||||
}
|
||||
|
||||
Text(text = statusOf(proposal))
|
||||
Text(text = statusOf(proposal), color = cardContentColor)
|
||||
|
||||
proposal.progress?.let { progress ->
|
||||
ProgressLine(progress = progress, color = cardContentColor)
|
||||
}
|
||||
|
||||
Text(
|
||||
text = "${proposal.proposerName} · " +
|
||||
@@ -523,13 +536,19 @@ private fun ProposalCard(
|
||||
}
|
||||
|
||||
/**
|
||||
* Where a proposal has got to, in a line.
|
||||
* Who the reader is in this proposal, in a line.
|
||||
*
|
||||
* Shorter than the signing screen's version of the same question, and it has to
|
||||
* be: this is one row of a list somebody is scanning, not the page they are
|
||||
* deciding on. What it must never do is call a session finished when it is not,
|
||||
* or waiting when the decision has gone.
|
||||
*
|
||||
* It no longer carries any numbers. It used to say "waiting for 2 of 3 members
|
||||
* to take part", which is the rule rather than the progress -- a row said the
|
||||
* same thing on the day a proposal was made and on the day before it completed.
|
||||
* The fraction that does move is [ProgressLine]'s, and two fractions on one row
|
||||
* meaning different things would be worse than the one that said nothing.
|
||||
*
|
||||
* Still switches on the stage rather than on `Proposal.state`, and still has to,
|
||||
* though for less than it used to. What is left collapsed inside a state is who
|
||||
* the reader was in it: whether they agreed or declined, under
|
||||
@@ -538,39 +557,75 @@ private fun ProposalCard(
|
||||
* than about the proposal, which is why they are a sentence on the row and not a
|
||||
* chip above it.
|
||||
*/
|
||||
@Composable
|
||||
private fun statusOf(proposal: ProposalListUIState.Proposal): String {
|
||||
val session = proposal.session
|
||||
|
||||
if (proposal.state == ProposalState.NEEDS_YOU) return "Needs your review"
|
||||
if (proposal.state == ProposalState.NEEDS_YOU) {
|
||||
return stringResource(Res.string.needs_your_review)
|
||||
}
|
||||
|
||||
return when (session.stage) {
|
||||
// Not awaiting the reader and still collecting means they answered, one
|
||||
// way or the other. A refusal leaves the session open -- a t-of-n key
|
||||
// can do without this member -- so it is still a session in progress,
|
||||
// and the row has to say which answer was given.
|
||||
FrostSigningStage.COLLECTING_NONCES ->
|
||||
(if (session.signDeclinedAt != null) "You declined. " else "You agreed. ") +
|
||||
"Waiting for ${session.threshold} of " +
|
||||
"${session.participantCount} members to take part."
|
||||
FrostSigningStage.COLLECTING_NONCES -> when (session.signDeclinedAt) {
|
||||
null -> stringResource(Res.string.you_agreed)
|
||||
else -> stringResource(Res.string.you_declined)
|
||||
}
|
||||
|
||||
FrostSigningStage.COLLECTING_PARTIAL_SIGNATURES ->
|
||||
if (session.isSigner()) {
|
||||
"You are signing. Waiting on the rest of the signers."
|
||||
} else {
|
||||
"Enough members took part without you. Waiting on them to sign."
|
||||
}
|
||||
FrostSigningStage.COLLECTING_PARTIAL_SIGNATURES -> when {
|
||||
session.isSigner() -> stringResource(Res.string.you_are_signing)
|
||||
else -> stringResource(Res.string.enough_members_took_part_without_you)
|
||||
}
|
||||
|
||||
FrostSigningStage.COMPLETE -> "Signed by the group."
|
||||
FrostSigningStage.COMPLETE -> stringResource(Res.string.signed_by_the_group)
|
||||
|
||||
// The reason is the whole content of a failure -- "declined on this
|
||||
// device" and "the group could not agree" are different things to
|
||||
// have happened -- so it stands in for the word "abandoned" whenever
|
||||
// there is one.
|
||||
FrostSigningStage.FAILED ->
|
||||
session.failureReason ?: "Abandoned. Nothing was signed."
|
||||
FrostSigningStage.FAILED -> session.failureReason
|
||||
?: stringResource(Res.string.abandoned_nothing_was_signed)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* How much of what the proposal is waiting for has arrived.
|
||||
*
|
||||
* A line of its own rather than a clause of the status line, because it is the
|
||||
* only thing on the row that moves while the reader is looking at it -- a
|
||||
* member's nonce landing changes this and nothing else -- and because a reader
|
||||
* scanning a list for the one that is nearly there should not have to read a
|
||||
* sentence to find out.
|
||||
*
|
||||
* Drawn only while something is being gathered: see
|
||||
* `ProposalListUIState.Proposal.progress`, which is null for both endings.
|
||||
*/
|
||||
@Composable
|
||||
private fun ProgressLine(
|
||||
progress: ProposalListUIState.Progress,
|
||||
color: Color,
|
||||
) {
|
||||
Text(
|
||||
text = when (progress.of) {
|
||||
ProposalListUIState.Progress.Of.MEMBERS -> stringResource(
|
||||
Res.string.of_members_have_offered_to_sign,
|
||||
progress.have,
|
||||
progress.need
|
||||
)
|
||||
|
||||
ProposalListUIState.Progress.Of.SIGNATURES -> stringResource(
|
||||
Res.string.of_signatures_are_in,
|
||||
progress.have,
|
||||
progress.need
|
||||
)
|
||||
},
|
||||
color = color
|
||||
)
|
||||
}
|
||||
|
||||
@ConformancePreviews
|
||||
@Composable
|
||||
private fun ProposalListScreenPreview() {
|
||||
|
||||
+29
-4
@@ -10,12 +10,16 @@ import androidx.lifecycle.viewmodel.initializer
|
||||
import androidx.lifecycle.viewmodel.viewModelFactory
|
||||
import co.touchlab.kermit.Logger
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Kind
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.IO
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.launch
|
||||
import to.curare.compose.database.model.intermdiate.FrostSignerTally
|
||||
import to.curare.compose.database.model.intermdiate.LocalFrostSigningSession
|
||||
import to.curare.compose.extensions.shortened
|
||||
import to.curare.compose.managers.FrostSigningManager
|
||||
import to.curare.compose.nostr.frost.FrostSigningEvents
|
||||
import to.curare.compose.repository.ChatRepository
|
||||
import to.curare.compose.repository.FrostSigningRepository
|
||||
import to.curare.compose.text.ProposedEvent
|
||||
@@ -82,12 +86,24 @@ class ProposalListViewModel(
|
||||
return@launch
|
||||
}
|
||||
|
||||
frostSigningRepository.observeSessionsForChatRoom(chatRoomId).collect { sessions ->
|
||||
// Two flows rather than one, combined here. The rows and the counts
|
||||
// move on different things -- a row changes when a session advances,
|
||||
// a count every time any member's message lands -- and the counts
|
||||
// are a `GROUP BY` that would carry every nonce payload the room has
|
||||
// ever exchanged if it travelled as the messages themselves.
|
||||
combine(
|
||||
frostSigningRepository.observeSessionsForChatRoom(chatRoomId),
|
||||
frostSigningRepository.observeSignerTalliesForChatRoom(chatRoomId),
|
||||
) { sessions, tallies ->
|
||||
sessions to tallies.groupBy { it.sessionId }
|
||||
}.collect { (sessions, talliesBySession) ->
|
||||
logger.d("${sessions.size} proposals in $chatRoomId")
|
||||
|
||||
proposalListUIState = ProposalListUIState.Loaded(
|
||||
localChatRoom = localChatRoom,
|
||||
proposals = sessions.map { asProposal(it) },
|
||||
proposals = sessions.map {
|
||||
asProposal(it, talliesBySession[it.session.id].orEmpty())
|
||||
},
|
||||
filter = filter
|
||||
)
|
||||
}
|
||||
@@ -119,10 +135,17 @@ class ProposalListViewModel(
|
||||
* worked out here, so the list and the signing screen cannot disagree about
|
||||
* which proposals still have a decision in them.
|
||||
*/
|
||||
private fun asProposal(local: LocalFrostSigningSession): ProposalListUIState.Proposal {
|
||||
private fun asProposal(
|
||||
local: LocalFrostSigningSession,
|
||||
tallies: List<FrostSignerTally>,
|
||||
): ProposalListUIState.Proposal {
|
||||
val items = local.items
|
||||
val events = items.mapNotNull { Event.fromJsonOrNull(it.unsignedEventJson) }
|
||||
|
||||
// A session nobody has answered has no row in the tally at all, which is
|
||||
// a count of zero rather than a missing one.
|
||||
fun counted(kind: Kind) = tallies.firstOrNull { it.kind == kind }?.members ?: 0
|
||||
|
||||
return ProposalListUIState.Proposal(
|
||||
session = local.session,
|
||||
proposerName = when {
|
||||
@@ -132,7 +155,9 @@ class ProposalListViewModel(
|
||||
},
|
||||
signs = events.map { ProposedEvent.summarize(it) },
|
||||
unreadable = items.size - events.size,
|
||||
awaitsYou = FrostSigningManager.isAwaitingApproval(local.session, items)
|
||||
awaitsYou = FrostSigningManager.isAwaitingApproval(local.session, items),
|
||||
noncesOffered = counted(FrostSigningEvents.NONCE),
|
||||
partialSignatures = counted(FrostSigningEvents.PARTIAL_SIGNATURE)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+66
@@ -93,6 +93,17 @@ sealed interface ProposalListUIState {
|
||||
|
||||
/** Whether the session is still waiting on this device's owner. */
|
||||
val awaitsYou: Boolean = false,
|
||||
|
||||
/**
|
||||
* How many share-holding members have offered a nonce, and how many
|
||||
* have published their part of the signature.
|
||||
*
|
||||
* Counts of members, not of messages, and only of members who hold a
|
||||
* share -- see `FrostSignerTally`, which is where both restrictions are
|
||||
* imposed and explained.
|
||||
*/
|
||||
val noncesOffered: Int = 0,
|
||||
val partialSignatures: Int = 0,
|
||||
) {
|
||||
/** The batch's size, readable or not. */
|
||||
val eventCount: Int get() = signs.size + unreadable
|
||||
@@ -126,6 +137,61 @@ sealed interface ProposalListUIState {
|
||||
FrostSigningStage.FAILED -> ProposalState.ABANDONED
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* How far the thing it is currently gathering has got, or null when it
|
||||
* is gathering nothing.
|
||||
*
|
||||
* Keyed on the stage rather than on [state], because the stage is what
|
||||
* decides *which* count is the live one and [ProposalState.NEEDS_YOU]
|
||||
* overlays both of the gathering stages. A proposal can need the
|
||||
* reader's answer while the group is on either, and in both cases the
|
||||
* figure it wants is the one for the stage it is actually in.
|
||||
*
|
||||
* Null once it has ended, which is both of the endings and not only the
|
||||
* happy one. A signed session has nothing left to gather; an abandoned
|
||||
* one has counts frozen where they stopped, and "2 of 3" beside a
|
||||
* failure invites the reader to wait for a third that is never coming.
|
||||
* The failure reason is what that row has to say.
|
||||
*/
|
||||
val progress: Progress? get() = when (session.stage) {
|
||||
// Enough to aggregate is the threshold, not the whole room --
|
||||
// `orderedNonces` gates on exactly this and takes the first t of
|
||||
// them, so t is both what is needed and what will be used.
|
||||
FrostSigningStage.COLLECTING_NONCES ->
|
||||
Progress(noncesOffered, session.threshold, Progress.Of.MEMBERS)
|
||||
|
||||
// The signer set once it exists, and the threshold until it does --
|
||||
// they are the same number, since the set is the first t offers, but
|
||||
// the set is the one this stage is actually waiting on.
|
||||
FrostSigningStage.COLLECTING_PARTIAL_SIGNATURES -> Progress(
|
||||
partialSignatures,
|
||||
session.signerIdList()?.size ?: session.threshold,
|
||||
Progress.Of.SIGNATURES
|
||||
)
|
||||
|
||||
FrostSigningStage.COMPLETE, FrostSigningStage.FAILED -> null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* How much of what a proposal is waiting for has arrived.
|
||||
*
|
||||
* [have] can exceed [need] for a moment: a member's nonce lands locally
|
||||
* before this device has run `advance` and moved the session on, so a row
|
||||
* can read "3 of 2" between a delivery and the pass that acts on it. Clamped
|
||||
* rather than shown, because a fraction over one reads as a bug in the app
|
||||
* rather than as a session about to advance.
|
||||
*/
|
||||
data class Progress(
|
||||
private val arrived: Int,
|
||||
val need: Int,
|
||||
val of: Of,
|
||||
) {
|
||||
val have: Int = arrived.coerceIn(0, need)
|
||||
|
||||
/** What is being counted, which decides the word the row uses. */
|
||||
enum class Of { MEMBERS, SIGNATURES }
|
||||
}
|
||||
|
||||
data class Error(
|
||||
|
||||
Reference in new issue
Block a user