build(marmot): quartz 1.15.2, with the two things it broke (v2 Phase 0)

The bump to 1.15.2 -- the release that carries the Marmot current profile --
breaks the compile in exactly two places, and the rest of the ~130 quartz
symbols the app imports are untouched.

CommitOrdering is gone from the library. Its inbound processor now settles
same-epoch commits through a convergence engine and calls the old rule
superseded "and deliberately": created_at and the event id are both transport
metadata the sender chooses and MLS never authenticates, so a member could win
every race by backdating. The app's pipeline does not go through that
processor -- it drives MlsGroup itself -- so the rule is vendored unchanged into
managers/CommitOrdering.kt, with a header saying why the library dropped it,
until Phase 5 of docs/marmot-v2.md replaces the pipeline. NostrDao and
MarmotInboundManager only change their import.

GroupEventResult gained AppMessageOnCandidateBranch and RefusedByLifecycle, so
the exhaustive when in ChatMessage.fromGroupEventResult needs both. Neither is a
delivery -- the first is a payload that decrypted only on a losing fork, which
the library is explicit must not be rendered, the second is input a disbanded
or unrecoverable group refuses -- so both get no chat line, the same as a
duplicate. The app never constructs either today.

Verified rather than assumed: the two sources jars were diffed file by file
against the app's imports; all 1,128 JVM tests pass on 1.15.2; the rewritten
Curve25519 field arithmetic matches the RFC 8032 and RFC 7748 vectors bit for
bit (the app persists raw MLS private keys, so this mattered); the app's own
KeyPackages sit inside the new 84-day lifetime ceiling at 30 days; no new
EventFactory kind collides with the app's.

One-way door: MlsGroupState's blob goes from version 2 to version 4 and 1.14.0
has `require(version in 1..2)`, so a room re-persisted under this build cannot
be opened by the previous one again.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Kgothatso NgakoandClaude Opus 5 committed 2026-09-13 22:04:41 +02:00
1 parent f304e7d642
commit 96a0c81341
5 files changed
+128 -3

No files matched your search

@@ -45,7 +45,7 @@ import com.vitorpamplona.quartz.marmot.GroupEventResult
import com.vitorpamplona.quartz.marmot.mip00KeyPackages.KeyPackageEvent
import com.vitorpamplona.quartz.marmot.mip00KeyPackages.KeyPackageRelayListEvent
import com.vitorpamplona.quartz.marmot.mip02Welcome.WelcomeEvent
import com.vitorpamplona.quartz.marmot.mip03GroupMessages.CommitOrdering
import to.curare.compose.managers.CommitOrdering
import com.vitorpamplona.quartz.marmot.mip03GroupMessages.GroupEvent
import com.vitorpamplona.quartz.marmot.mls.codec.TlsReader
import com.vitorpamplona.quartz.marmot.mls.group.MlsGroup
@@ -982,6 +982,15 @@ data class ChatMessage(
content = "Undecryptable Message", // TODO: Figure out what to do here...
)
}
// Neither is a delivery. quartz 1.15.2's inbound processor produces both
// from its convergence engine: the first is a payload that decrypted only
// on a losing fork, which the library is explicit must not be rendered,
// and the second is input a disbanded or unrecoverable group refuses
// outright. [MarmotInboundManager] drives MlsGroup itself and never
// constructs either, so today these are unreachable; if it adopts the
// engine they get no chat line, the same as a duplicate.
is GroupEventResult.AppMessageOnCandidateBranch -> null
is GroupEventResult.RefusedByLifecycle -> null
}
}
@@ -0,0 +1,117 @@
package to.curare.compose.managers
import com.vitorpamplona.quartz.marmot.mip03GroupMessages.GroupEvent
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
/**
* Deterministic commit conflict resolution for MLS over Nostr (MIP-03), carried over
* from quartz 1.14.0's `com.vitorpamplona.quartz.marmot.mip03GroupMessages.CommitOrdering`
* (MIT, Copyright (c) 2025 Vitor Pamplona).
*
* quartz 1.15.2 removed it: its inbound processor resolves same-epoch commits through
* `protocolCore.MarmotConvergenceEngine` instead, and its changelog calls this rule
* superseded "and deliberately: both [created_at and event id] are transport metadata
* the sender chooses and MLS does not authenticate, so a member could win every race by
* backdating". The app's inbound pipeline does not go through that processor -- it
* drives [com.vitorpamplona.quartz.marmot.mls.group.MlsGroup] itself -- so the rule is
* kept here, unchanged, until the pipeline adopts the convergence engine.
*
* When multiple members submit Commits for the same epoch, exactly one must win:
* 1. Lowest created_at timestamp wins
* 2. If timestamps are equal, lexicographically smallest event id wins
* 3. All other competing Commits for that epoch are discarded
*/
object CommitOrdering {
/**
* Comparator for ordering GroupEvents deterministically.
* The "winner" (lowest value) should be applied; all others are discarded.
*/
val comparator: Comparator<GroupEvent> =
compareBy<GroupEvent> { it.createdAt }
.thenBy { it.id }
/**
* Selects the winning Commit from a set of competing Commits for the same epoch.
*/
fun selectWinner(commits: List<GroupEvent>): GroupEvent? {
if (commits.isEmpty()) return null
return commits.minWithOrNull(comparator)
}
/**
* Key for tracking pending commits: must be unique per (group, epoch) pair
* since epoch numbers are not globally unique across different groups.
*/
data class GroupEpochKey(
val groupId: String,
val epoch: Long,
)
/**
* Tracks pending commits per (group, epoch) and resolves conflicts.
*/
class EpochCommitTracker {
private val mutex = Mutex()
private val pendingByGroupEpoch = mutableMapOf<GroupEpochKey, MutableList<GroupEvent>>()
companion object {
/** Maximum number of (group, epoch) entries to track before evicting oldest. */
const val MAX_TRACKED_EPOCHS = 1000
}
suspend fun addCommit(
groupId: String,
epoch: Long,
commit: GroupEvent,
) = mutex.withLock {
val key = GroupEpochKey(groupId, epoch)
pendingByGroupEpoch.getOrPut(key) { mutableListOf() }.add(commit)
// Evict oldest entries if the tracker grows too large
if (pendingByGroupEpoch.size > MAX_TRACKED_EPOCHS) {
val oldestKeys =
pendingByGroupEpoch.keys
.sortedBy { it.epoch }
.take(pendingByGroupEpoch.size - MAX_TRACKED_EPOCHS)
for (oldKey in oldestKeys) {
pendingByGroupEpoch.remove(oldKey)
}
}
}
suspend fun pendingForEpoch(
groupId: String,
epoch: Long,
): List<GroupEvent> =
mutex.withLock {
pendingByGroupEpoch[GroupEpochKey(groupId, epoch)]?.toList() ?: emptyList()
}
suspend fun resolve(
groupId: String,
epoch: Long,
): GroupEvent? =
mutex.withLock {
selectWinner(pendingByGroupEpoch[GroupEpochKey(groupId, epoch)] ?: emptyList())
}
suspend fun clearEpoch(
groupId: String,
epoch: Long,
) = mutex.withLock {
pendingByGroupEpoch.remove(GroupEpochKey(groupId, epoch))
Unit
}
suspend fun pendingGroupEpochs(): Set<GroupEpochKey> =
mutex.withLock {
pendingByGroupEpoch.keys.toSet()
}
suspend fun clear() =
mutex.withLock {
pendingByGroupEpoch.clear()
}
}
}
@@ -11,7 +11,6 @@ import co.touchlab.kermit.Logger
import com.vitorpamplona.quartz.marmot.GroupEventResult
import com.vitorpamplona.quartz.marmot.mip00KeyPackages.KeyPackageEvent
import com.vitorpamplona.quartz.marmot.mip00KeyPackages.KeyPackageRelayListEvent
import com.vitorpamplona.quartz.marmot.mip03GroupMessages.CommitOrdering
import com.vitorpamplona.quartz.marmot.mip03GroupMessages.GroupEvent
import com.vitorpamplona.quartz.marmot.mip03GroupMessages.GroupEventEncryption
import com.vitorpamplona.quartz.marmot.mls.codec.TlsReader
+1 -1
View File
@@ -34,7 +34,7 @@ materialIconsExtended = "1.7.3"
navigationCompose = "2.9.2"
okio = "3.18.1"
qrose = "1.1.2"
quartz = "1.14.0"
quartz = "1.15.2"
room3 = "3.0.1"
sqldelight = "2.3.2"
sqlite = "2.7.0"