diff --git a/composeApp/src/commonMain/composeResources/values/strings.xml b/composeApp/src/commonMain/composeResources/values/strings.xml index ec0f66f1..969837e7 100644 --- a/composeApp/src/commonMain/composeResources/values/strings.xml +++ b/composeApp/src/commonMain/composeResources/values/strings.xml @@ -457,7 +457,6 @@ %1$s hasn't set up messaging on Bennu yet. Try again later, or ask them to open Bennu. Group onchain wallet - Group onchain wallet on %1$s %1$s onchain wallet Open a group onchain wallet @@ -561,7 +560,7 @@ While the wallet is new, a spend on mainnet can send at most %1$s sats. Lightning wallet key This group has no key for a Lightning wallet yet. - A Lightning wallet closes to the group's onchain wallet. Open one on %1$s first. + A Lightning wallet closes to the group's onchain wallet. Open that first. A Lightning wallet needs at least four members who hold the onchain wallet's key. The key is made by everyone who holds the onchain wallet's key. Every payment will need %1$s of their devices online. Start a key ceremony @@ -584,7 +583,7 @@ Make a key See the key ceremony Open a Lightning wallet - Opening a Lightning wallet asks the group to sign for its node, its LSP and how much can be in flight at once. The scheme behind its key has not been reviewed outside the project, so it is offered on %1$s only. + Opening a Lightning wallet asks the group to sign for its node, its LSP and how much can be in flight at once. The scheme behind its key has not been reviewed outside the project, so for now a channel holds at most %1$s sats: keep in it only what the group can afford to lose. Node %1$s LSP %1$s At most %1$s sats in flight diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/GroupLightningCoSigner.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/GroupLightningCoSigner.kt index 59ed6fb1..abb155a9 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/GroupLightningCoSigner.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/managers/GroupLightningCoSigner.kt @@ -12,6 +12,7 @@ import com.machankura.bennu.compose.extensions.toHex import com.machankura.bennu.compose.network.serialization.CommonJson import com.machankura.bennu.compose.nostr.lightning.GroupLightningEvents import com.machankura.bennu.compose.nostr.wallet.GroupWalletStatementEvent +import com.machankura.bennu.compose.wallet.GroupLightningRollout import com.machankura.bennu.compose.wallet.lightning.CoSignerPolicy import com.machankura.bennu.compose.wallet.lightning.CoSigningWire import com.vitorpamplona.quartz.nip01Core.core.Event @@ -33,8 +34,9 @@ import fr.acinq.lightning.channel.Commitments import fr.acinq.lightning.crypto.LocalKeyManager import fr.acinq.lightning.transactions.Scripts import fr.acinq.lightning.transactions.Transactions -import kotlinx.serialization.Serializable +import fr.acinq.phoenixd.conf.LSP import kotlin.time.Clock +import kotlinx.serialization.Serializable /** * The co-signer every Iceberg participant runs: it answers the operator's node for the group, without a @@ -62,9 +64,17 @@ object GroupLightningCoSigner { /** The most a single provision request makes a co-signer publish. */ const val MAX_BATCH: Long = 128 - /** A swap-in xpub for [LocalKeyManager], which wants one; a group node never swaps in, so any valid one does. */ + /** + * A swap-in xpub for [LocalKeyManager], which wants one; a group node never swaps in, so any valid one + * does -- for the network. lightning-kmp checks the prefix: a tpub on mainnet throws, and so would the + * first key manager every co-signer and the operator's node built. So mainnet takes the mainnet LSP's + * published one, and every other network this tpub. Nothing derives from either: the node id and + * every channel key come from the seed. + */ internal const val UNUSED_SWAP_IN_TPUB = "tpubDAmCFB21J9ExKBRPDcVxSvGs9jtcf8U1wWWbS1xTYmnUsuUHPCoFdCnEGxLE3THSWcQE48GHJnyz8XPbYUivBMbLSMBifFd3G9KmafkM9og" + private fun unusedSwapInXpub(chain: Chain): String = if (chain.isMainnet()) LSP.from(Chain.Mainnet).swapInXpub else UNUSED_SWAP_IN_TPUB + fun walletKey(chatRoomId: String, chain: Chain, wallet: Long): String = "$chatRoomId:${GroupWalletStatementEvent.chainName(chain)}:$wallet" /** The label of pool counter [counter] for the group key [icebergKey]: every member computes the same. */ @@ -72,7 +82,7 @@ object GroupLightningCoSigner { Crypto.taggedHash(ByteVector(icebergKey).toByteArray() + Pack.writeInt64BE(counter), "bennu/iceberg/pool/v1") /** The key manager a group node runs, and a co-signer rebuilds commitments with. */ - fun keyManagerOf(seed: ByteVector, chain: Chain): LocalKeyManager = LocalKeyManager(seed, chain, UNUSED_SWAP_IN_TPUB) + fun keyManagerOf(seed: ByteVector, chain: Chain): LocalKeyManager = LocalKeyManager(seed, chain, unusedSwapInXpub(chain)) /** What a co-signer stores of a channel's ledger, in JSON. */ @Serializable @@ -359,6 +369,12 @@ object GroupLightningCoSigner { pinned: IcebergChannelLedger?, ): String? { val seed = wallet.seed ?: return "this device does not hold the node's seed, and cannot rebuild the commitment" + // On mainnet a channel holds at most the rollout's cap. Refusing its commitments means a bigger + // channel never opens; one that opened smaller cannot grow, since splices are refused. + GroupLightningRollout.channelCapFor(wallet.statement.chain)?.let { cap -> + val capacity = CoSigningWire.inputInfo(request.input).txOut.amount + if (capacity > cap) return "the channel holds ${capacity.sat} sats, over the ${cap.sat} a channel may hold on mainnet for now" + } val commitParams = CoSigningWire.commit(context.commit ?: return "no commitment parameters") val commitIndex = context.commitIndex ?: return "no commitment number" val perCommitmentPoint = PublicKey.fromHex(context.remotePerCommitmentPoint ?: return "no per-commitment point") diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/ChatRoomDetailScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/ChatRoomDetailScreen.kt index 845c0b71..3d78b8e5 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/ChatRoomDetailScreen.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/ChatRoomDetailScreen.kt @@ -4,8 +4,6 @@ import androidx.compose.material.icons.filled.Bolt import bennu.composeapp.generated.resources.lightning_wallet import bennu.composeapp.generated.resources.member_removal_requested_lightning import com.machankura.bennu.compose.ui.composable.navigation.routes.GroupLightningWalletRoute -import bennu.composeapp.generated.resources.group_wallet_on_s -import fr.acinq.phoenix.managers.NodeParamsManager import com.machankura.bennu.compose.wallet.GroupLightningRollout import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Box @@ -403,7 +401,7 @@ fun ChatRoomDetailScreen( } // The group's Lightning wallet, which closes to the onchain - // wallet on its own network -- the row above this one. + // wallet -- the row above this one, on the same network. if (GroupLightningRollout.ENABLED) item { SignedWorkRow( icon = Icons.Default.Bolt, @@ -420,29 +418,6 @@ fun ChatRoomDetailScreen( ) } - // The same wallet on the network the Lightning wallet is - // tried on, which it closes to: a Lightning wallet cannot - // be opened without one there (docs/group-lightning-wallet.md). - if (GroupWalletRollout.ENABLED && GroupLightningRollout.ENABLED && GroupLightningRollout.NETWORK != NodeParamsManager.chain) item { - val network = GroupWalletStatementEvent.chainName(GroupLightningRollout.NETWORK) - SignedWorkRow( - icon = Icons.Default.AccountBalanceWallet, - headline = stringResource(Res.string.group_wallet_on_s, network), - supporting = chatRoomDetailUIState.testNetworkWallet?.let { stringResource(Res.string.open_on_s, network) } - ?: stringResource(Res.string.not_opened_yet), - onOpen = { - onNavigateToRoute.invoke( - GroupWalletRoute( - activeUserPublicKey = activeUserPublicKey, - chatRoomId = chatRoomId, - relayHint = relayHint, - chain = network - ) - ) - } - ) - } - item { HorizontalDivider() } diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupLightningWalletScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupLightningWalletScreen.kt index 19947ce6..4083df4e 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupLightningWalletScreen.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupLightningWalletScreen.kt @@ -59,7 +59,7 @@ import bennu.composeapp.generated.resources.couldn_t_propose_this import bennu.composeapp.generated.resources.couldn_t_send_s_sats import bennu.composeapp.generated.resources.earlier_wallet_s import bennu.composeapp.generated.resources.force_close -import bennu.composeapp.generated.resources.group_wallet_on_s +import bennu.composeapp.generated.resources.group_wallet import bennu.composeapp.generated.resources.lightning_wallet import bennu.composeapp.generated.resources.lsp_s import bennu.composeapp.generated.resources.make_a_key @@ -70,7 +70,7 @@ import bennu.composeapp.generated.resources.nobody_runs_this_wallet_s_node import bennu.composeapp.generated.resources.node_s import bennu.composeapp.generated.resources.open_a_lightning_wallet import bennu.composeapp.generated.resources.open_a_new_lightning_wallet -import bennu.composeapp.generated.resources.open_an_onchain_wallet_on_s_first +import bennu.composeapp.generated.resources.open_the_group_s_onchain_wallet_first import bennu.composeapp.generated.resources.opening_a_lightning_wallet_asks import bennu.composeapp.generated.resources.payments import bennu.composeapp.generated.resources.receive @@ -160,7 +160,6 @@ fun GroupLightningWalletScreen( val notify = rememberNotifier(rememberCoroutineScope()) val couldNotPropose = stringResource(Res.string.couldn_t_propose_this) - val network = GroupWalletStatementEvent.chainName(GroupLightningRollout.NETWORK) val toSession = { sessionId: String -> onNavigateToRoute(FrostSigningRoute(activeUserPublicKey = activeUserPublicKey, chatRoomId = chatRoomId, sessionId = sessionId)) } val toCeremony = { sessionId: String? -> onNavigateToRoute(IcebergCeremonyRoute(activeUserPublicKey = activeUserPublicKey, chatRoomId = chatRoomId, sessionId = sessionId)) } @@ -181,11 +180,11 @@ fun GroupLightningWalletScreen( is GroupLightningWalletUIState.NeedsOnchainWallet -> EmptyState( modifier = Modifier.padding(padding).readableContent(), - message = stringResource(Res.string.open_an_onchain_wallet_on_s_first, network), + message = stringResource(Res.string.open_the_group_s_onchain_wallet_first), icon = Icons.Default.AccountBalanceWallet, action = { - Button(onClick = { onNavigateToRoute(GroupWalletRoute(activeUserPublicKey = activeUserPublicKey, chatRoomId = chatRoomId, relayHint = null, chain = network)) }) { - Text(stringResource(Res.string.group_wallet_on_s, network)) + Button(onClick = { onNavigateToRoute(GroupWalletRoute(activeUserPublicKey = activeUserPublicKey, chatRoomId = chatRoomId, relayHint = null)) }) { + Text(stringResource(Res.string.group_wallet)) } } ) @@ -209,7 +208,7 @@ fun GroupLightningWalletScreen( is GroupLightningWalletUIState.NotOpened -> EmptyState( modifier = Modifier.padding(padding).readableContent(), - message = stringResource(Res.string.opening_a_lightning_wallet_asks, network), + message = stringResource(Res.string.opening_a_lightning_wallet_asks, GroupLightningRollout.channelCapFor(GroupLightningRollout.NETWORK)?.grouped() ?: ""), icon = Icons.Default.Bolt, action = if (state.canPropose) { { diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/IcebergCeremonyScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/IcebergCeremonyScreen.kt index 8aedb389..6d4c2974 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/IcebergCeremonyScreen.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/IcebergCeremonyScreen.kt @@ -42,7 +42,7 @@ import bennu.composeapp.generated.resources.hasn_t_answered_the_proposal_yet import bennu.composeapp.generated.resources.join_the_ceremony import bennu.composeapp.generated.resources.joining_publishes_commitments import bennu.composeapp.generated.resources.lightning_wallet_key -import bennu.composeapp.generated.resources.open_an_onchain_wallet_on_s_first +import bennu.composeapp.generated.resources.open_the_group_s_onchain_wallet_first import bennu.composeapp.generated.resources.s_of_3_steps import bennu.composeapp.generated.resources.send_your_contributions import bennu.composeapp.generated.resources.sending_contributions_encrypts_each @@ -129,7 +129,7 @@ fun IcebergCeremonyScreen( EmptyState( modifier = Modifier.padding(padding).readableContent(), message = when { - !state.hasOnchainWallet -> stringResource(Res.string.open_an_onchain_wallet_on_s_first, GroupWalletStatementEvent.chainName(GroupLightningRollout.NETWORK)) + !state.hasOnchainWallet -> stringResource(Res.string.open_the_group_s_onchain_wallet_first) state.thresholds.isEmpty() -> stringResource(Res.string.a_lightning_wallet_needs_four_signers) else -> stringResource(Res.string.this_group_has_no_lightning_wallet_key_yet) }, diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/ChatRoomDetailViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/ChatRoomDetailViewModel.kt index 68bb49af..f5adb022 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/ChatRoomDetailViewModel.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/ChatRoomDetailViewModel.kt @@ -106,9 +106,6 @@ class ChatRoomDetailViewModel( walletPolicy = chatRepository.walletPolicyOf(chatRoomId), guardianDelay = chatRepository.guardiansOf(chatRoomId)?.firstOrNull()?.delay, groupWallet = chatRepository.groupWallet(chatRoomId, NodeParamsManager.chain), - testNetworkWallet = if (GroupLightningRollout.ENABLED && GroupLightningRollout.NETWORK != NodeParamsManager.chain) { - chatRepository.groupWallet(chatRoomId, GroupLightningRollout.NETWORK) - } else null, lightningParticipants = if (GroupLightningRollout.ENABLED) chatRepository.lightningParticipants(chatRoomId, GroupLightningRollout.NETWORK) else emptySet(), canAddSubgroup = canSign, canGovern = canGovern, diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/ChatRoomDetailUIState.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/ChatRoomDetailUIState.kt index 070c1081..e6ae8cd7 100755 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/ChatRoomDetailUIState.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/state/ChatRoomDetailUIState.kt @@ -67,12 +67,6 @@ sealed interface ChatRoomDetailUIState { * `GroupWalletScreen`. */ val groupWallet: GroupWallet? = null, - /** - * The wallet this group has opened on the Lightning wallet's test network, which is not the app's - * own network while the Lightning wallet is tried there. Null when it has not, or when the - * Lightning wallet is not offered on this build (`GroupLightningRollout`). - */ - val testNetworkWallet: GroupWallet? = null, /** Who holds a share of the group's Lightning wallet key, so removing one of them can say what it leaves. */ val lightningParticipants: Set = emptySet(), /** diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/wallet/GroupLightningRollout.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/wallet/GroupLightningRollout.kt index 90970c55..de2f3a70 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/wallet/GroupLightningRollout.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/wallet/GroupLightningRollout.kt @@ -1,35 +1,48 @@ package com.machankura.bennu.compose.wallet import fr.acinq.bitcoin.Chain +import fr.acinq.bitcoin.Satoshi +import fr.acinq.phoenix.managers.NodeParamsManager /** * The gates the group Lightning wallet ships behind -- `docs/group-lightning-wallet.md`, Phase 15 -- * in one place, each with the condition that lifts it. * * As with [GroupWalletRollout], these decide what this device offers, never what it accepts: a device - * with a gate closed still verifies and co-signs for a wallet another member opened. + * with a gate closed still verifies and co-signs for a wallet another member opened -- except the + * channel cap, which every co-signer holds to, since it is the one gate that bounds what can be lost. */ object GroupLightningRollout { /** - * Whether the group's screen offers a Lightning wallet, and the test-network on-chain wallet it closes - * to, and whether this device runs the group nodes it is elected to. On, on testnet3 only: the phases - * are in, the JVM suite passes and the regtest end-to-end run passes. Phase 0's measurement of how - * long the LSP waits for a signature was still to be made on testnet3 when it was lifted, so the - * signing deadline is a guess until the first groups run there. + * Whether the group's screen offers a Lightning wallet, and whether this device runs the group nodes + * it is elected to. On: the phases are in, the JVM suite passes and the regtest end-to-end run passes. */ const val ENABLED: Boolean = true /** - * The only network a Lightning wallet may be opened on. Iceberg says not to put money behind it, so - * mainnet is refused in code rather than hidden; this lifts only when the scheme and the DKG have - * been reviewed outside the project and a testnet3 group has run for a month without a refused label - * or a lost channel. + * The network a Lightning wallet is opened on: the node's own, mainnet, where the group's onchain + * wallet already is. Lifted to mainnet by decision, ahead of what the plan named for it -- a review + * of the Iceberg scheme and the DKG outside the project, and a month of a testnet3 group with no + * refused label and no lost channel. The Iceberg library itself says not to put money behind it. + * What bounds the loss meanwhile is [MAINNET_CHANNEL_CAP], the statement's in-flight cap, and + * every co-signer's checks. */ - val NETWORK: Chain = Chain.Testnet3 + val NETWORK: Chain = NodeParamsManager.chain /** - * Whether a Lightning wallet may be opened on [chain] at all. [NETWORK], and regtest for tests and - * development; never mainnet, whatever a screen offers. + * The most one channel may hold on mainnet. Every co-signer refuses to sign the first commitment of a + * bigger channel, so it never opens, and a channel never grows: the co-signers refuse splices. Lifts + * on the same condition as [GroupWalletRollout.MAINNET_CAP]: a release that has run real channels, + * payments and closes with no refused label and no lost channel. + */ + val MAINNET_CHANNEL_CAP: Satoshi = Satoshi(1_000_000) + + /** The most a channel on [chain] may hold, or null where there is no cap. */ + fun channelCapFor(chain: Chain): Satoshi? = MAINNET_CHANNEL_CAP.takeIf { chain.isMainnet() } + + /** + * Whether a Lightning wallet may be opened on [chain] at all: [NETWORK], and regtest for tests and + * development. */ fun allows(chain: Chain): Boolean = chain == NETWORK || chain == Chain.Regtest } diff --git a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/managers/GroupLightningCoSigningJvmTest.kt b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/managers/GroupLightningCoSigningJvmTest.kt index 3e52f390..2ccfa302 100644 --- a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/managers/GroupLightningCoSigningJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/managers/GroupLightningCoSigningJvmTest.kt @@ -2,10 +2,12 @@ package com.machankura.bennu.compose.managers import com.machankura.bennu.compose.nostr.lightning.GroupLightningAuthorisationEvent import com.machankura.bennu.compose.nostr.lightning.GroupLightningEvents +import com.machankura.bennu.compose.wallet.GroupLightningRollout import com.vitorpamplona.quartz.nip01Core.core.toHexKey import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair import fr.acinq.bitcoin.ByteVector import fr.acinq.bitcoin.ByteVector32 +import fr.acinq.bitcoin.Chain import fr.acinq.bitcoin.PrivateKey import fr.acinq.bitcoin.PublicKey import fr.acinq.bitcoin.Satoshi @@ -65,8 +67,8 @@ import kotlinx.coroutines.withTimeout * that every member rebuilds the same transaction from the same context and signs it only if it leaves * the group what the group agreed to. */ -class GroupLightningCoSigningJvmTest { - private val fixture = GroupLightningFixture() +abstract class GroupLightningCoSigningCases(chain: Chain) { + private val fixture = GroupLightningFixture(chain = chain) private val lspKey = PrivateKey(Random.nextBytes(32).byteVector32()) private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Default) @@ -98,13 +100,13 @@ class GroupLightningCoSigningJvmTest { } /** A channel with the LSP, as the operator's node would hold it. */ - private inner class Channel(group: Group, ours: Long, theirs: Long) { + private inner class Channel(group: Group, ours: Long, theirs: Long, capacity: Satoshi = Satoshi(1_000_000)) { val seed = ByteVector(group.wallet.seed!!.seed) val keyManager = GroupLightningCoSigner.keyManagerOf(seed, fixture.chain) val groupKey = PublicKey.fromHex(group.wallet.statement.icebergKey) val remoteFundingKey = PrivateKey(Random.nextBytes(32).byteVector32()) val fundingTxId = TxId(Random.nextBytes(32).byteVector32()) - val input = Transactions.makeFundingInputInfo(fundingTxId, 0, Satoshi(1_000_000), groupKey, remoteFundingKey.publicKey(), Transactions.CommitmentFormat.SimpleTaprootChannels) + val input = Transactions.makeFundingInputInfo(fundingTxId, 0, capacity, groupKey, remoteFundingKey.publicKey(), Transactions.CommitmentFormat.SimpleTaprootChannels) val onchain = fixture.account val params = ChannelParams( channelId = Random.nextBytes(32).byteVector32(), @@ -220,6 +222,19 @@ class GroupLightningCoSigningJvmTest { Transaction.correctlySpends(signedNext, mapOf(channel.input.outPoint to channel.input.txOut), ScriptFlags.STANDARD_SCRIPT_VERIFY_FLAGS) } + @Test + fun `on mainnet no member signs for a channel over the rollout's cap`() = runBlocking { + val cap = GroupLightningRollout.channelCapFor(fixture.chain) ?: return@runBlocking + val group = group() + val (signer, _) = operatorSigner(group, deadline = 3.seconds) + val atCap = Channel(group, ours = 400_000_000, theirs = cap.sat * 1000 - 400_000_000, capacity = cap) + val (fits, fitsContext) = atCap.commitment(0, atCap.spec) + assertIs>(groupSigns(group, signer, atCap, fits, fitsContext), "a channel of exactly the cap opens") + val over = Channel(group, ours = 400_000_000, theirs = cap.sat * 1000, capacity = cap + Satoshi(400_000)) + val (big, bigContext) = over.commitment(0, over.spec) + assertIs(assertIs>(groupSigns(group, signer, over, big, bigContext)).value, "a bigger one never gets a signature") + } + @Test fun `a transaction its context does not rebuild to is refused by every member`() = runBlocking { val group = group() @@ -303,3 +318,6 @@ class GroupLightningCoSigningJvmTest { assertIs>(groupSigns(group, again, channel, other, otherContext)) } } + +/** The cases on regtest, the network every other four-device test runs on. */ +class GroupLightningCoSigningJvmTest : GroupLightningCoSigningCases(Chain.Regtest) diff --git a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/managers/GroupLightningCoSigningMainnetJvmTest.kt b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/managers/GroupLightningCoSigningMainnetJvmTest.kt new file mode 100644 index 00000000..80df3da7 --- /dev/null +++ b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/managers/GroupLightningCoSigningMainnetJvmTest.kt @@ -0,0 +1,9 @@ +package com.machankura.bennu.compose.managers + +import fr.acinq.bitcoin.Chain + +/** + * Every co-signing test again, on mainnet: the network the Lightning wallet is opened on, and the one + * where every co-signer holds a channel to the rollout's cap. + */ +class GroupLightningCoSigningMainnetJvmTest : GroupLightningCoSigningCases(Chain.Mainnet) diff --git a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/managers/GroupLightningWalletJvmTest.kt b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/managers/GroupLightningWalletJvmTest.kt index c9cb4528..cf3fc6ed 100644 --- a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/managers/GroupLightningWalletJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/managers/GroupLightningWalletJvmTest.kt @@ -5,15 +5,13 @@ import com.machankura.bennu.compose.network.serialization.CommonJson import com.machankura.bennu.compose.nostr.lightning.GroupLightningEvents import com.machankura.bennu.compose.nostr.lightning.GroupLightningOperatorStatementEvent import com.machankura.bennu.compose.nostr.lightning.GroupLightningWalletStatementEvent -import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair +import com.machankura.bennu.compose.wallet.GroupLightningRollout import com.vitorpamplona.quartz.nip01Core.core.toHexKey +import com.vitorpamplona.quartz.nip01Core.crypto.KeyPair import fr.acinq.bitcoin.ByteVector import fr.acinq.bitcoin.Chain +import fr.acinq.bitcoin.Satoshi import fr.acinq.lightning.crypto.LocalKeyManager -import kotlinx.coroutines.runBlocking -import kotlinx.serialization.json.JsonObject -import kotlinx.serialization.json.JsonPrimitive -import kotlinx.serialization.json.jsonObject import kotlin.random.Random import kotlin.test.AfterTest import kotlin.test.Test @@ -24,6 +22,10 @@ import kotlin.test.assertNull import kotlin.test.assertTrue import kotlin.time.Clock import kotlin.time.Duration.Companion.minutes +import kotlinx.coroutines.runBlocking +import kotlinx.serialization.json.JsonObject +import kotlinx.serialization.json.JsonPrimitive +import kotlinx.serialization.json.jsonObject /** * Opening a group's Lightning wallet and choosing who runs it, between four devices @@ -94,12 +96,16 @@ class GroupLightningWalletJvmTest { } @Test - // That no statement leaves the group needs no test of its own: nothing in the app sends a - // group-signed event to a relay any more. - fun `there is no Lightning wallet on mainnet`() = runBlocking { + fun `a Lightning wallet is opened on the node's network, and nowhere else`() = runBlocking { + assertEquals(Chain.Mainnet, GroupLightningRollout.NETWORK) + assertTrue(GroupLightningRollout.allows(Chain.Mainnet)) + assertTrue(GroupLightningRollout.allows(Chain.Regtest), "regtest, for tests and development") + assertTrue(!GroupLightningRollout.allows(Chain.Testnet3) && !GroupLightningRollout.allows(Chain.Signet)) + assertEquals(Satoshi(1_000_000), GroupLightningRollout.channelCapFor(Chain.Mainnet)) + assertEquals(null, GroupLightningRollout.channelCapFor(Chain.Regtest)) val all = fixture.group() fixture.runCeremony(all) - val refused = runCatching { GroupLightningWalletManager.proposeWallet(all[0].db, all[0].room, all[0].publicKey, all[0].privateKey, Chain.Mainnet, lsp) } + val refused = runCatching { GroupLightningWalletManager.proposeWallet(all[0].db, all[0].room, all[0].publicKey, all[0].privateKey, Chain.Testnet3, lsp) } assertTrue(refused.isFailure) } diff --git a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/composable/GroupSignedWorkRowsJvmTest.kt b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/composable/GroupSignedWorkRowsJvmTest.kt index 0a076d28..154fe0aa 100644 --- a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/composable/GroupSignedWorkRowsJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/composable/GroupSignedWorkRowsJvmTest.kt @@ -57,7 +57,6 @@ class GroupSignedWorkRowsJvmTest { var opened: Route? = null render(state(), onNavigateToRoute = { opened = it }) { - // This row's own status: the testnet3 wallet's row, below it, says the same of its wallet. onNode(hasText(WALLET_ROW) and hasText("Not opened yet")).assertIsDisplayed() onNodeWithText(WALLET_ROW).performClick() } @@ -66,25 +65,17 @@ class GroupSignedWorkRowsJvmTest { } @Test - fun `the Lightning wallet's rows open it, and the testnet3 wallet it closes to`() { + fun `the Lightning wallet's row opens it, and there is no second onchain wallet`() { if (!GroupWalletRollout.ENABLED || !GroupLightningRollout.ENABLED) return - val network = GroupWalletStatementEvent.chainName(GroupLightningRollout.NETWORK) - val opened = mutableListOf() + var opened: Route? = null - render(state(), onNavigateToRoute = { opened += it }) { - onNode(hasText("Lightning wallet") and hasText(network)).assertIsDisplayed() - onNode(hasText("Group onchain wallet on $network") and hasText("Not opened yet")).assertIsDisplayed() + render(state(), onNavigateToRoute = { opened = it }) { + onNode(hasText("Lightning wallet") and hasText(GroupWalletStatementEvent.chainName(GroupLightningRollout.NETWORK))).assertIsDisplayed() + onNodeWithText("Group onchain wallet on", substring = true).assertDoesNotExist() onNodeWithText("Lightning wallet").performClick() - onNodeWithText("Group onchain wallet on $network").performClick() } - assertEquals( - listOf( - GroupLightningWalletRoute(activeUserPublicKey, chatRoomId), - GroupWalletRoute(activeUserPublicKey, chatRoomId, relayHint = null, chain = network), - ), - opened, - ) + assertEquals(GroupLightningWalletRoute(activeUserPublicKey, chatRoomId), opened) } @Test diff --git a/docs/group-lightning-wallet.md b/docs/group-lightning-wallet.md index f8cc79b2..8b1de5fb 100644 --- a/docs/group-lightning-wallet.md +++ b/docs/group-lightning-wallet.md @@ -33,7 +33,7 @@ build chose differently, this table says so. | 1 | done: `IcebergDkg`, 11 tests, among them a byte-for-byte match against the library's dealer and a signature from every 2-of-4 and 3-of-7 quorum | | 2 | done, in the fork (`4bc973df`): the three signing methods suspend, `RemoteIcebergFundingSigner`, pings answered outside the channel loop. lightning-kmp's JVM suite, 985 tests, passes | | 3 | done: in the fork (`e15e31ba`), `withGroupBasepoints`, `GroupHeldOutputs` and `KeyManager.defaultFinalScriptPubKey`, 991 tests passing. In the app, `GroupLightningDerivation`, pinned, with a FROST quorum spending `to_remote` and `to_local` | -| 4 | done: `GroupChainClients`, one Electrum connection per network for the wallets and the watcher; the wallet routes carry a chain; a second wallet row for testnet3 behind `GroupLightningRollout`, which is off | +| 4 | done, then taken out again: `GroupChainClients`, one Electrum connection per network, and the wallet routes carry a chain. The second wallet row for testnet3 is gone since the Lightning wallet moved to mainnet (Phase 15): it now closes to the group's own onchain wallet, on the node's network. The per-network plumbing stays; nothing but regtest uses a second network now | | 5 | done: `IcebergRitualManager`, schema 27, now part of 32 (`IcebergKeySession`, `IcebergParticipantMessage`), the ceremony screen and its transcript lines. Seven four-device tests, and the app's 1,391 JVM tests pass | | 6, 7 | done together, as their screen and summaries are one piece: the wallet and operator statements, the node seed (schema 28, now part of 32), `GroupLightningWalletManager`, `GroupLightningOperatorManager` and the Lightning wallet screen. Twelve new tests; the app's 1,403 JVM tests pass | | 9 | done before 8, because the node's transport is half of it: `GroupLightningCoSigner`, `CoSignerPolicy`, `GroupIcebergTransport`, schema 29, now part of 32, and the fork's `SigningContext` (`bd78ed62`). A four-device test co-signs a real commitment that spends its funding output beside a stock counterparty, and five refusals hold. The app's 1,415 JVM tests and the fork's 993 pass | @@ -43,7 +43,7 @@ build chose differently, this table says so. | 12 | done: `GroupLightningAuthorisationEvent` (kind 30363, `pay`), budgets read from the signed authorisations, the node paying each once, its summary and transcript line, and the send screen (`GroupLightningSendScreen`). The co-signers now hold offered HTLCs under the statement's in-flight cap. Seven new tests | | 13 | done, except splicing out. `close` and `force-close` authorisations, the node acting on each once, the co-signers signing our own commitment only under a force-close authorisation and only after rebuilding it, and the channel menu on the wallet screen. Sweeps: the snapshot lists what closed channels left the group, any member proposes a sweep (`GroupSweep`, a new FROST subject), every member checks it against its own basepoints and the onchain wallet, and the watcher sends it. Five new tests: a force close and a two-input sweep both pass the script interpreter | | 14 | done: a room can have several Lightning wallets on a network, the highest-numbered current. A member who leaves is named on the wallet screen until a new wallet replaces it; the new key is made over the onchain key's holders who are still in the room; the old wallet keeps its operator and node until its channels are closed, in one decision for all of them; and removing a share holder says what it leaves. A five-device test re-keys after a removal | -| 15 | **on, on testnet3.** `GroupLightningRollout.ENABLED` is `true`: the group's screen offers the Lightning wallet and the testnet3 onchain wallet it closes to, and devices run the group nodes they are elected to. It was lifted with Phase 0's testnet3 measurement of how long the LSP waits for a signature still to make, so the 60-second signing deadline is a guess until the first groups run there. Mainnet is still refused by `GroupLightningRollout.allows`, whatever a screen offers, until the scheme and the DKG are reviewed outside the project and a testnet3 group has run a month cleanly. The ceremony screen names every participant who has not answered | +| 15 | **on, on mainnet.** `GroupLightningRollout.ENABLED` is `true` and `NETWORK` is the node's own, mainnet, lifted there by decision ahead of what the plan named for it: a review of the Iceberg scheme and the DKG outside the project, and a month of a testnet3 group with no refused label and no lost channel. Neither happened, and Phase 0's measurement of how long the LSP waits for a signature was never made, so the 60-second signing deadline is a guess. What bounds the loss meanwhile: `MAINNET_CHANNEL_CAP`, 1,000,000 sats a channel, which every co-signer holds to (a bigger channel's first commitment is never signed, and splices are refused, so none grows); the statement's in-flight cap; and every co-signer's checks. The opening screen says the scheme is unreviewed and the cap is there. Testnet3 is no longer offered | | what the plan said | what it turned out to be | |---|---| @@ -113,6 +113,8 @@ build chose differently, this table says so. | the member-removal flow says so, as it already does for the onchain wallet | the removal flow said nothing about either wallet. It now says what a removal leaves when the member holds a share of the Lightning wallet's key. The onchain wallet's own sentence is left to that wallet's plan | | one schema version per phase, 27 to 30 | **one, 32.** The main branch used 27 to 31 meanwhile. The four versions this branch made were never on an installed database, so at the merge they became one migration, 31 to 32, that adds every Lightning table | | the operator's node needs a profile with a node of its own | it never did in substance -- a group's node is its own `Peer` -- only in the wiring, which took the context and logger from the identity's Phoenix business. Once the main branch gave profiles with no node an Electrum client (`IdentityElectrum`), the wiring takes them from the app instead, so an nsec or npub profile that holds a share can be elected and run the group's node | +| D8: testnet3 first, mainnet refused in code | **mainnet only**, by decision, with a cap of 1,000,000 sats a channel held by every co-signer (`GroupLightningRollout.MAINNET_CHANNEL_CAP`). The Lightning wallet now closes to the onchain wallet the group already has, so the testnet3 onchain wallet and its row are gone. The co-signing suite also runs whole on mainnet (`GroupLightningCoSigningMainnetJvmTest`) | +| any swap-in xpub will do, since a group node never swaps in | any xpub *of the network*: lightning-kmp checks the prefix, and the testnet tpub every key manager was built with would have thrown on mainnet, in every co-signer and in the operator's node, before any channel. The mainnet run of the co-signing suite found it. Mainnet now takes the mainnet LSP's published xpub; nothing derives from it | | the kinds are taken from 30333 | from **30350**: the guarded-wallet family took 30333-30337 on the main branch meanwhile, and nothing failed when the two met, since each reads the other's events by kind. The family moved at the merge, which costs nothing for rumor kinds that never shipped, and the test now also asserts that it starts past every kind the app uses | | the kinds are reserved | in code: `GroupLightningEvents`, 30350-30366, with a test asserting the run is unbroken and touches no kind the app already dispatches on | | library phases land in the forks' `threshold` branches | on a new branch, `claude/group-lightning-wallet`, in `lightning-kmp-app` and in `experimental/lightning-kmp`. It is local and not pushed. The app's submodule pointer follows it, so a checkout of this branch needs those commits from the same machine until they are pushed |