diff --git a/composeApp/src/commonMain/composeResources/values/strings.xml b/composeApp/src/commonMain/composeResources/values/strings.xml index 64106570..422243c2 100644 --- a/composeApp/src/commonMain/composeResources/values/strings.xml +++ b/composeApp/src/commonMain/composeResources/values/strings.xml @@ -672,6 +672,5 @@ Bump the fee Sent again Couldn't bump the fee: there isn't enough left over to pay it. - For now, a spend sends everything the group has confirmed to one address, less the fee. While the wallet is new, a spend on mainnet can send at most %1$s sats. diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupSendScreen.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupSendScreen.kt index 934c81ae..839919be 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupSendScreen.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/composable/GroupSendScreen.kt @@ -1,7 +1,5 @@ package com.machankura.bennu.compose.ui.composable -import com.machankura.bennu.compose.wallet.GroupWalletRollout -import bennu.composeapp.generated.resources.for_now_a_spend_sends_everything import bennu.composeapp.generated.resources.while_the_wallet_is_new_at_most_s_sats import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column @@ -169,29 +167,19 @@ fun GroupSendScreen( label = { Text(stringResource(Res.string.address)) }, ) - // Send-all only while the wallet is new: no switch, no amount, - // and a sentence saying everything confirmed is what goes. - if (GroupWalletRollout.SEND_AN_AMOUNT) { - Row( - modifier = Modifier.fillMaxWidth(), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.SpaceBetween, - ) { - Text(stringResource(Res.string.send_everything)) - Switch( - checked = groupSendViewModel.sendEverything.value, - onCheckedChange = { groupSendViewModel.sendEverything.value = it }, - ) - } - } else { - Text( - text = stringResource(Res.string.for_now_a_spend_sends_everything), - style = MaterialTheme.typography.bodyMedium, - color = MaterialTheme.colorScheme.onSurfaceVariant, + Row( + modifier = Modifier.fillMaxWidth(), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.SpaceBetween, + ) { + Text(stringResource(Res.string.send_everything)) + Switch( + checked = groupSendViewModel.sendEverything.value, + onCheckedChange = { groupSendViewModel.sendEverything.value = it }, ) } - if (GroupWalletRollout.SEND_AN_AMOUNT && !groupSendViewModel.sendEverything.value) { + if (!groupSendViewModel.sendEverything.value) { OutlinedTextField( modifier = Modifier.fillMaxWidth(), state = groupSendViewModel.amountField, diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/GroupSendViewModel.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/GroupSendViewModel.kt index 8ea223bd..9f1a4acc 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/GroupSendViewModel.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/ui/view/model/GroupSendViewModel.kt @@ -108,7 +108,7 @@ class GroupSendViewModel( val state = groupSendUIState as? GroupSendUIState.Ready ?: return null val walletState = state.walletState ?: return null - val amount = if (sendEverything.value || !GroupWalletRollout.SEND_AN_AMOUNT) { + val amount = if (sendEverything.value) { null } else { when (val input = amount()) { diff --git a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/wallet/GroupWalletRollout.kt b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/wallet/GroupWalletRollout.kt index 352ac80a..94020bed 100644 --- a/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/wallet/GroupWalletRollout.kt +++ b/composeApp/src/commonMain/kotlin/com/machankura/bennu/compose/wallet/GroupWalletRollout.kt @@ -19,14 +19,9 @@ object GroupWalletRollout { const val ENABLED: Boolean = true /** - * Whether a member can send a chosen amount, with change, or only everything - * to one address. Send-all only until send-an-amount has had a release with - * nobody reporting a mislabelled change output. - */ - const val SEND_AN_AMOUNT: Boolean = false - - /** - * The most one spend proposed from this device may send on mainnet. Lifts + * The most one spend proposed from this device may send on mainnet -- and, + * since a member can send an amount with change on every network, the + * bound on what a builder bug in that change could put at risk. Lifts * when a release has run real spends end to end with no session that failed * to aggregate and no transaction that failed to confirm. Test networks have * no cap: nothing on them is worth one. diff --git a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/GroupSendViewModelJvmTest.kt b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/GroupSendViewModelJvmTest.kt index 4d21377c..868502b9 100644 --- a/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/GroupSendViewModelJvmTest.kt +++ b/composeApp/src/jvmTest/kotlin/com/machankura/bennu/compose/ui/view/model/GroupSendViewModelJvmTest.kt @@ -43,7 +43,6 @@ import kotlin.test.BeforeTest import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertIs -import kotlin.test.assertNotEquals import kotlin.test.assertNotNull import kotlin.test.assertNull import kotlin.time.Instant @@ -64,9 +63,10 @@ class GroupSendViewModelJvmTest { private val localChatRoom = LocalChatRoom( chatRoom = ChatRoom(id = chatRoomId, userPublicKey = "a".repeat(64), subject = "Treasury", description = null, initialGiftWrapPayloadId = "p", mlsGroupState = "state") ) - private val account = GroupWalletDerivation.account( - PrivateKey(ByteVector32(Hex.decode("1c0ffee".padStart(64, '0')))).publicKey().toString(), Chain.Regtest, + private fun accountOn(chain: Chain): GroupWalletDerivation.Account = GroupWalletDerivation.account( + PrivateKey(ByteVector32(Hex.decode("1c0ffee".padStart(64, '0')))).publicKey().toString(), chain, ) + private val account: GroupWalletDerivation.Account = accountOn(Chain.Regtest) private val wallet = GroupWallet( GroupSignedEvent( id = "e".repeat(64), chatRoomId = chatRoomId, publicKey = chatRoomId, kind = GroupWalletStatementEvent.KIND, @@ -76,19 +76,23 @@ class GroupSendViewModelJvmTest { account, ) - private val walletState: GroupWalletState = run { + /** One confirmed coin of [sats] under [account], and one unused change address. */ + private fun walletStateOf(account: GroupWalletDerivation.Account, sats: Long): GroupWalletState { + val chain = account.chain val derived = GroupWalletDerivation.derive(account, GroupWalletDerivation.RECEIVE, 0) - val tx = Transaction(2, listOf(TxIn(OutPoint(TxId(ByteVector32(ByteArray(32) { 1 })), 0), ByteVector.empty, 0xffffffffL)), listOf(TxOut(Satoshi(100_000), derived.pubkeyScript)), 0) + val tx = Transaction(2, listOf(TxIn(OutPoint(TxId(ByteVector32(ByteArray(32) { 1 })), 0), ByteVector.empty, 0xffffffffL)), listOf(TxOut(Satoshi(sats), derived.pubkeyScript)), 0) val meta = WalletState.AddressMeta.Derived(0) val change = GroupWalletDerivation.derive(account, GroupWalletDerivation.CHANGE, 0) - GroupWalletState( + return GroupWalletState( account, - WalletState(mapOf(derived.address(Chain.Regtest) to WalletState.AddressState(meta, true, listOf(WalletState.Utxo(tx.txid, 0, 100, tx, meta))))), - WalletState(mapOf(change.address(Chain.Regtest) to WalletState.AddressState(WalletState.AddressMeta.Derived(0), false, emptyList()))), + WalletState(mapOf(derived.address(chain) to WalletState.AddressState(meta, true, listOf(WalletState.Utxo(tx.txid, 0, 100, tx, meta))))), + WalletState(mapOf(change.address(chain) to WalletState.AddressState(WalletState.AddressMeta.Derived(0), false, emptyList()))), tipHeight = 110, ) } + private val walletState: GroupWalletState = walletStateOf(account, 100_000) + private class RecordingSigning : FrostSigningRepository by FrostSigningRepository.NO_OP_FROST_SIGNING_REPOSITORY { var proposed: Psbt? = null override suspend fun proposeSpend(localChatRoom: LocalChatRoom, userPublicKey: HexKey, psbt: Psbt, chain: Chain): FrostSigningSession? { @@ -97,8 +101,12 @@ class GroupSendViewModelJvmTest { } } - private fun viewModel(initial: GroupSendUIState, chat: ChatRepository = ChatRepository.NO_OP_CHAT_REPOSITORY, signing: FrostSigningRepository = RecordingSigning()) = - GroupSendViewModel("a".repeat(64), chatRoomId, Chain.Regtest, initial, chat, signing, wallets = null) + private fun viewModel( + initial: GroupSendUIState, + chat: ChatRepository = ChatRepository.NO_OP_CHAT_REPOSITORY, + signing: FrostSigningRepository = RecordingSigning(), + chain: Chain = Chain.Regtest, + ) = GroupSendViewModel("a".repeat(64), chatRoomId, chain, initial, chat, signing, wallets = null) @Test fun `a profile with no node is not offered the form`() { @@ -124,14 +132,8 @@ class GroupSendViewModelJvmTest { model.feerateField.setTextAndPlaceCursorAtEnd("4") model.amountField.setTextAndPlaceCursorAtEnd("40,000") val built = assertIs(model.preview()) - if (GroupWalletRollout.SEND_AN_AMOUNT) { - assertEquals(Satoshi(40_000), built.amount) - assertNotNull(built.change) - } else { - // Gated to send-all: the amount typed is not what is sent. - assertEquals(Satoshi(100_000), built.amount + built.fee) - assertNull(built.change) - } + assertEquals(Satoshi(40_000), built.amount) + assertEquals(Satoshi(100_000), built.amount + built.fee + assertNotNull(built.change), "the rest comes back") model.propose(onSuccess = {}, onFailure = {}) runBlocking { withTimeout(5_000) { while (signing.proposed == null) delay(10) } } @@ -147,11 +149,26 @@ class GroupSendViewModelJvmTest { model.amountField.setTextAndPlaceCursorAtEnd("21000.5") assertEquals(SatsInput.NotWhole, model.amount()) - val preview = model.preview() - assertNotEquals(Satoshi(210_005), (preview as? GroupSpendBuilder.Result.Built)?.amount) - if (GroupWalletRollout.SEND_AN_AMOUNT) { - assertEquals(GroupSpendBuilder.Result.InvalidAmount(SatsInput.NotWhole), preview) - } + assertEquals(GroupSpendBuilder.Result.InvalidAmount(SatsInput.NotWhole), model.preview()) + } + + @Test + fun `on mainnet the cap holds an amount, as it holds sending everything`() { + val mainnet = accountOn(Chain.Mainnet) + val model = viewModel( + GroupSendUIState.Ready(localChatRoom, wallet, walletStateOf(mainnet, 300_000), reserved = emptySet()), + chain = Chain.Mainnet, + ) + model.addressField.setTextAndPlaceCursorAtEnd("bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4") + model.feerateField.setTextAndPlaceCursorAtEnd("4") + + model.amountField.setTextAndPlaceCursorAtEnd("150,000") + assertEquals(GroupSpendBuilder.Result.OverCap(GroupWalletRollout.MAINNET_CAP), model.preview()) + + model.amountField.setTextAndPlaceCursorAtEnd("100,000") + val built = assertIs(model.preview(), "the cap itself is allowed") + assertNotNull(built.change) + assertIs(GroupSpend.check(built.psbt, mainnet)) } @Test diff --git a/docs/group-chain-wallet.md b/docs/group-chain-wallet.md index 62bd0c68..b5d8c0b3 100644 --- a/docs/group-chain-wallet.md +++ b/docs/group-chain-wallet.md @@ -50,7 +50,7 @@ kept as written; where the build chose differently the table below says so. | a conflicting spend is noticed when a reserved coin is spent by a different transaction | when one of the group's spends *confirms*: only the group can spend its coins, so the only other transaction that can take one is another of its own spends, and the confirmation is the moment the question is settled. Settled by the confirmed spend's own row, so every device decides the same way | | a fee bump is proposed at a feerate the member chooses | at twice the spend's feerate, from a *Bump the fee* button on the spend's row — comfortably over BIP125's increment, and one decision rather than a form | | `GroupTransaction` rows are kept by the screen that shows them | `GroupTransactionWatcher`, one per identity beside the wallets, started with the identity's node whether or not anybody opens the wallet. It found a real bug before it shipped: following each spend from the list a pass began with wrote a settled row back from its stale copy | -| a feature flag, off, until Phases 1-9 are in | `GroupWalletRollout.ENABLED`, on: its own lift condition — Phases 1-9 in, the JVM suite passing — was met when it landed. The other two gates hold: `SEND_AN_AMOUNT` is false, so the form sends everything, and `MAINNET_CAP` is 100,000 sats per spend proposed from this device | +| a feature flag, off, until Phases 1-9 are in | `GroupWalletRollout.ENABLED`, on: its own lift condition — Phases 1-9 in, the JVM suite passing — was met when it landed. `MAINNET_CAP` holds, at 100,000 sats per spend proposed from this device. `SEND_AN_AMOUNT` was removed: its lift condition, a release with no mislabelled change, could not be met while it kept every network on send-all. A member sends an amount on every network, with the cap as the bound on mainnet — [group-send-an-amount.md](./group-send-an-amount.md) | | the gates are on the composer | and on nothing else, on purpose: a device with a gate closed still accepts, shows and signs what another member proposes, through every check `GroupSpend` makes. A gate decides what this device offers, never what a quorum may decide | The headline: **the best path is BIP86's own unhardened tail, `//`, @@ -796,7 +796,6 @@ that a function returned early. |---|---| | the wallet is behind a feature flag, off | Phases 1-9 are in and the jvm suite passes | | on mainnet, a statement can be signed and a spend proposed, but the composer refuses to move more than a small fixed amount | a release has run real spends end to end with no session that failed to aggregate or a transaction that failed to confirm | -| send-all only | send-an-amount has had a release with nobody reporting a mislabelled change output | If a testnet build exists by then, the cap is unnecessary there and the first two rows run on it instead. diff --git a/docs/group-send-an-amount.md b/docs/group-send-an-amount.md index b31c6e0b..d26f9157 100644 --- a/docs/group-send-an-amount.md +++ b/docs/group-send-an-amount.md @@ -9,7 +9,7 @@ Read [group-chain-wallet.md](./group-chain-wallet.md) first, Phases 8 and 10 in particular. This plan is that note's third rollout gate, and it starts from the code as it stands at `96055da5`. -**Phases 1 and 3 built; 2 and 4-7 not.** Written against `GroupSendScreen`, `GroupSendViewModel`, +**Phases 1-3 built; 4-7 not.** Written against `GroupSendScreen`, `GroupSendViewModel`, `GroupSpendBuilder`, `GroupSpend` and `GroupWalletRollout` as they are at that commit. @@ -150,7 +150,7 @@ and what `GroupedSats` shows. In `GroupSendViewModelJvmTest`, typing ## Phase 2: the gate comes out -**Half a day.** Phase 0 opened the gate on every network, so what is left is +**Half a day. Built.** Phase 0 opened the gate on every network, so what is left is removing it, not turning it into a per-network switch. A `const` that is always true is a branch the compiler keeps and a reader still has to follow. @@ -180,9 +180,10 @@ always true is a branch the compiler keeps and a reader still has to follow. needs to be in the same release. Phases 1 and 3 can land behind the closed gate in any order. This phase is the one that makes them reachable. -The wallet note's Phase 10 table loses its *send-all only* row, and its "built" -table's `SEND_AN_AMOUNT` row says the gate was removed, why, and which commit -removed it (Phase 6). +The wallet note's Phase 10 table has lost its *send-all only* row, and its +"built" table says the gate was removed and why. That was done in this phase +rather than Phase 6, so the note never describes a gate the code no longer +has. ---