feat(lightning): the group Lightning wallet on mainnet only

The Lightning wallet now opens on the node's own network, mainnet,
where the group's onchain wallet already is, so the separate testnet3
onchain wallet and its row on the group's screen are gone.
GroupLightningRollout.allows takes mainnet and regtest, nothing else.

This lifts the plan's mainnet gate by decision, ahead of its condition:
an outside review of the Iceberg scheme and the DKG, and a month on
testnet3. The LSP's signing deadline was never measured either.
Meanwhile:

- Every co-signer refuses to sign for a mainnet channel over
  MAINNET_CHANNEL_CAP, 1,000,000 sats, so a bigger one never opens; none
  grows, since splices are refused.
- The opening screen says the scheme is unreviewed and names the cap.

Running the co-signing suite on mainnet (now a second test class) found a
bug that would have stopped everything there: every key manager was built
with a testnet swap-in tpub, which lightning-kmp rejects on mainnet. That
covers every co-signer and the operator's node. Mainnet now takes the
mainnet LSP's published xpub; nothing derives from it.

The full JVM suite (1,578 tests) and the regtest run pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kgothatso NgakoandClaude Opus 5.5 committed 2026-10-26 21:45:57 +02:00
1 parent 5ff9380b03
commit cf8ae0200e
13 files changed
+112 -93

No files matched your search

@@ -457,7 +457,6 @@
<string name="s_hasn_t_set_up_messaging_on_bennu_yet">%1$s hasn't set up messaging on Bennu yet. Try again later, or ask them to open Bennu.</string>
<!-- The group's on-chain wallet. -->
<string name="group_wallet">Group onchain wallet</string>
<string name="group_wallet_on_s">Group onchain wallet on %1$s</string>
<!-- The group's on-chain wallet, named for its group: "Treasury onchain wallet". -->
<string name="s_onchain_wallet">%1$s onchain wallet</string>
<string name="open_a_group_wallet">Open a group onchain wallet</string>
@@ -561,7 +560,7 @@
<string name="while_the_wallet_is_new_at_most_s_sats">While the wallet is new, a spend on mainnet can send at most %1$s sats.</string>
<string name="lightning_wallet_key">Lightning wallet key</string>
<string name="this_group_has_no_lightning_wallet_key_yet">This group has no key for a Lightning wallet yet.</string>
<string name="open_an_onchain_wallet_on_s_first">A Lightning wallet closes to the group's onchain wallet. Open one on %1$s first.</string>
<string name="open_the_group_s_onchain_wallet_first">A Lightning wallet closes to the group's onchain wallet. Open that first.</string>
<string name="a_lightning_wallet_needs_four_signers">A Lightning wallet needs at least four members who hold the onchain wallet's key.</string>
<string name="the_lightning_wallet_key_is_made_by_everyone">The key is made by everyone who holds the onchain wallet's key. Every payment will need %1$s of their devices online.</string>
<string name="start_a_key_ceremony">Start a key ceremony</string>
@@ -584,7 +583,7 @@
<string name="make_a_key">Make a key</string>
<string name="see_the_key_ceremony">See the key ceremony</string>
<string name="open_a_lightning_wallet">Open a Lightning wallet</string>
<string name="opening_a_lightning_wallet_asks">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.</string>
<string name="opening_a_lightning_wallet_asks">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.</string>
<string name="node_s">Node %1$s</string>
<string name="lsp_s">LSP %1$s</string>
<string name="at_most_s_sats_in_flight">At most %1$s sats in flight</string>
@@ -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")
@@ -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()
}
@@ -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) {
{
@@ -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)
},
@@ -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,
@@ -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<HexKey> = emptySet(),
/**
@@ -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
}