`grant(..., delay)`, `BlockDuration` and `delayText` are the entry points. The
phases below are kept as written, line references included, which have since
moved; where the build chose differently the table says so.
| what the plan said | what it turned out to be |
|---|---|
| Phase 2: one jvmTest | two. The script edges are in `GuardianSpendRoundTest` (commonTest), beside the 12-block test they generalise; the builder and the check are in `GuardianSigningJvmTest`, where the funded-state fixture is |
| Phase 3: `BlockDuration` in `wallet/` | in `text/`, beside `Sats.kt`, with `groupedBlocks()`. `delayText` and `approximateDuration` are in `ui/composable/widgets/DelayText.kt`. `BlockDuration.describe` says the same in fixed English for `ProposedEvent`, which is not a composable |
| Phase 4: a migration test | none, as for the policy's v29: the nullable auto-migrations have none, and every jvmTest's in-memory database runs at v30 |
| Phase 5: `setGuardianDelay` stores what was typed | two calls: `setGuardianDelay(blocks)` for a preset and `setGuardianDelayInput(text)` for the field, which drops anything but digits and stops at seven, enough to say *at most 65,535* about a number past it. The presets are `SelectSubgroupAdminsViewModel.DELAY_PRESETS`, as `FilterChip`s in a `FlowRow`. A retry comes back on its preset when it was one, and in the field when it was not |
| Phase 5: tests of `confirm` | not written, as for the policy: `confirm` needs an `Identity` with a private key and settled key packages |
| Phase 6: the summary's own-leaf line | a separate element, *this group after 144 blocks, about 1 day*, after the existing reach line |
| Phase 7: the guarded section's title says the shortest delay | not built. Each guardian is listed nearest first with its own delay, named by the room this device holds for it — `GroupWalletUIState.guardianNames` — and otherwise *a group above this one* |
| Phase 7: `withinReach` reads `wallet.account.guardians[position].delay` | `GuardianManager.GuardedWallet.delay`, the same thing named once |
| Phase 4: schema 29 → 30 | **30 → 31.** The default branch took 30 for the member-wallet tables (`docs/member-guarded-wallets.md`) while this was being built, so `DkgSession.guardianDelay` is v31 |
| nothing about member wallets or funding | both landed on the default branch meanwhile, quoting 12. On merging: `GuardedWalletRow.arriving` counts by this group's own leaf like `withinReach`; the funding form says that leaf's delay; a member wallet's screens and its proposal summary say each guardian's delay, through `MemberWalletManager.delaysOf` -- the group's own leaf at the default, every group above at the delay it chose. A group could not then choose the delay on its own leaf in a member's wallet; since [member-wallet-delay.md](./member-wallet-delay.md) it does, in a policy it signs, and a group that signs none does not guard members' wallets at all |
| `GuardianDerivation.Guardian.delay` | a field, defaulting to `ANCESTOR_DELAY` |
| `GuardianDerivation.leafScript` | already writes 1 to 16 as `OP_1`…`OP_16` and anything above as a minimal number push, and refuses anything outside 1 to 65,535 |
| `grantedTo` | `copy(...)` of the guardian, so an inherited key already keeps its delay one step down |
| `descriptorTree` | `older(${guardian.delay})` |
| `GroupSpend.check` | reads the spender's own leaf's delay and requires every input's sequence to equal it |
| `GroupSpendBuilder.lockOf` | per leaf: offers a guardian only coins at least that deep, and puts that sequence on every input |
| fee sizing, `GroupSpend.kt:390` | built from the real leaf script, so a longer number push is already counted |
| `GuardianManager.takenIn` | rebuilds each leaf from its own delay |
What still assumes 12:
| piece | where |
|---|---|
| `grant()` | the parent's own new entry takes the default, `ANCESTOR_DELAY` |
| `refuseCertificate` | compares the proposal to `grant()`, so any own delay other than 12 is refused |
| every string that quotes a delay | the picker (`SelectSubgroupAdminsScreen.kt:395`), the join gate (`DkgJoinApprovalScreen.kt:78`), the wallet screen (`GroupWalletScreen.kt:386`, `:408`, `:461`, `:672`), and six strings in `strings.xml` that say `%1$d confirmations` as if there were one number |
| the guardians note | *Why 12, and why for everybody* |
So the work is three things: let the parent choose, carry the choice to
everybody who signs it, and stop every screen from saying "12".
---
## The limits
### The floor: 6 blocks
About an hour. It keeps the property the guardians note gives as the reason for
a delay at all: **the child's own spends always go first.** A guardian cannot
race the child for a payment that has only just arrived, nor take the change
from a spend the child made a few minutes ago. Below about six blocks, one block
found quickly or a short reorg can put a fresh coin within a guardian's reach
before the child has had a chance to act on it.
### The ceiling: 65,535 blocks
BIP68 gives a relative lock 16 bits of `nSequence`. With the type flag (bit 22)
clear, the value counts blocks: 1 to 65,535, which is about 455 days, or a
little over 15 months. That is the most the protocol can express **for a lock
that counts from the coin's own confirmation**, which is the kind the guardian
leaf has to be.
Two other locks look longer and are not the same thing:
- **BIP68 in time units** (bit 22 set) counts 512-second steps, also 16 bits.
Its ceiling is 65,535 × 512 s, about 388 days, so it is *shorter* than the
block form. It also measures median time past rather than blocks. Not used.
- **An absolute lock** (`OP_CHECKLOCKTIMEVERIFY`) can name any height or date,
but it counts from a fixed point rather than from the coin. A leaf with one
would become spendable by the guardian for every coin at once, on one day,
however recently each arrived. That is a different promise, and it is listed
under [what this does not do](#what-this-does-not-do).
Staying at or below 65,535 also keeps two other things true without extra
checks:
- **bit 22 is never set**, so the number is always read as blocks;
- **the sequence stays far below `GroupSpend.MAX_SEQUENCE`** (`0xfffffffd`), so
a guardian spend still signals replaceability and *Bump the fee* still works.
### The encoding, at its edges
Script numbers are little-endian, sign-and-magnitude, minimally encoded.
`Script.encodeNumber` in bitcoin-kmp already does this, including the zero byte
a positive number needs when its top byte has the high bit set. The cases a test
has to pin, because each is where the encoding changes length:
| delay | `<delay>` in the leaf | leaf script |
|---|---|---|
| 6 | `OP_6` | 36 bytes |
| 16 | `OP_16` | 36 bytes |
| 17 | `0x01 0x11` | 37 bytes |
| 127 | `0x01 0x7f` | 37 bytes |
| 128 | `0x02 0x80 0x00` | 38 bytes |
| 32,767 | `0x02 0xff 0x7f` | 38 bytes |
| 32,768 | `0x03 0x00 0x80 0x00` | 39 bytes |
| 65,535 | `0x03 0xff 0xff 0x00` | 39 bytes |
A guardian input therefore costs at most three weight units more than it does
today. That is under one vbyte, and it is paid only when a guardian spends.
---
## What a longer delay changes, said plainly
The guardians note is candid that two hours is not autonomy: "two hours is not
long enough for a child to notice a coin coming within reach and move it."
That stops being true as the delay grows, and the picker has to say so.
**The clock is per coin, and spending resets it.** A coin moved by the child is
a new coin, confirmed afresh. So a child that spends, or merely moves, each coin
before it is `d` blocks old keeps every coin out of every guardian's reach for
as long as it keeps doing that. With `d = 12` that would mean a transaction
every two hours, which is not practical. With `d = 4,320`, about a month, it
means one consolidation a month, which is cheap.
So the choice is a real trade, and the picker's description says both halves:
| delay | the guardian is | the child is |
|---|---|---|
| short (hours) | an override: in practice it can take any coin the child has not just received | under the guardian's control |
| long (months) | a backstop: it reaches coins the child has left alone for that long, such as a dormant wallet or a group that has stopped meeting | able to keep its coins out of reach by moving them before the lock runs out |
A long delay is the right choice for a parent that wants a recovery path for a
subgroup that falls silent, and the wrong one for a parent that wants to be able
to take funds back from a subgroup that is still active.