From 67fe01dd5b0e9a162cb0444a529fe456362760a7 Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Fri, 23 Oct 2026 20:51:38 +0200 Subject: [PATCH] fix(groups): a grandchild's wallet reaches every guardian in one share Sharing a guarded statement wrote one notice per guardian room, each hashed from the same sharer, second, kind, tags and content -- so every notice had the same id, and the last room's upsert took the row. A grandchild told its parent and grandparent at once reached only the grandparent. Each notice now names its room in an `h` tag, which gives it an id of its own. Co-Authored-By: Claude Opus 5.5 --- .../bennu/compose/managers/GuardianManager.kt | 6 +++++- .../compose/managers/GuardianSigningJvmTest.kt | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/GuardianManager.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/GuardianManager.kt index fdd64988..cc09f6d8 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/GuardianManager.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/GuardianManager.kt @@ -210,6 +210,10 @@ object GuardianManager { * Tells every room in [rooms] about [statement], as [userPublicKey]: one * notice each, queued for the outbound pipeline the way every inner event * is. Returns how many were queued. + * + * Each notice names its room in an `h` tag. Without it, one statement told + * to a grandchild's parent and grandparent in the same second is one id -- + * and one row, the last room's -- so the parent was never told. */ suspend fun share( database: BennuDatabase, @@ -219,9 +223,9 @@ object GuardianManager { createdAt: Long = Clock.System.now().epochSeconds, ): Int { val content = statement.toJson() - val tags = emptyArray>() rooms.forEach { room -> + val tags = arrayOf(arrayOf("h", room.chatRoom.id)) val id = EventHasher.hashId(userPublicKey, createdAt, GuardedWalletNoticeEvent.KIND, tags, content) database.marmotInnerEventDao().upsert( MarmotInnerEvent( diff --git a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/managers/GuardianSigningJvmTest.kt b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/managers/GuardianSigningJvmTest.kt index bffa294e..f0a984e3 100644 --- a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/managers/GuardianSigningJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/managers/GuardianSigningJvmTest.kt @@ -369,6 +369,23 @@ class GuardianSigningJvmTest { assertEquals(listOf(statement.id), GuardianManager.guardedWalletsOf(member.db, roomId).map { it.statement.id }) } + @Test + fun `a grandchild's statement told to its parent and grandparent at once reaches both`(): Unit = runBlocking { + val member = device(members[0], signerIndex = 0) + val grandparentRoomId = "9".repeat(64) + member.db.chatRoomDao().upsert(ChatRoom(id = grandparentRoomId, userPublicKey = member.publicKey, subject = "Assembly", description = null, mlsGroupState = "00")) + val rooms = listOf(roomId, grandparentRoomId).map { assertNotNull(member.db.chatRoomDao().findChatRoomById(it)) } + + // One statement, one sharer, one second: only the room tells the two notices apart. + assertEquals(2, GuardianManager.share(member.db, guardedStatement(), rooms, member.publicKey, createdAt = 1_700_000_100)) + + val told = listOf(roomId, grandparentRoomId).associateWith { room -> + member.db.marmotInnerEventDao().getByChatRoomAndKinds(room, listOf(GuardedWalletNoticeEvent.KIND)).single() + } + told.forEach { (room, notice) -> assertEquals(listOf(listOf("h", room)), notice.tags.map { it.toList() }) } + assertEquals(2, told.values.map { it.id }.toSet().size) + } + // ---- Spending from a guarded wallet ------------------------------------ private val chain = Chain.Regtest