Commit Graph

32 Commits

Author SHA1 Message Date
Kgothatso Ngako
f5eb744ca7 test: cover the long-running sync, and open the seams needed to do it
The six commits that built the live chat sync added no tests. Everything they
touch fails silently by nature — a filter that drops messages, a subscription
that stops being replayed, a group whose id never reaches the `#h` tag — so the
symptom is always "some messages didn't arrive", days later, on someone else's
phone. 46 tests, in four files.

**What is covered**

RelayPoolSubscriptionTest (13) — the pool's half of surviving a dropped socket.
A query is retained and replayed on reconnect; a closed one is forgotten and
stops the socket reconnecting for it; closing one of two leaves the other alone;
a negentropy exchange is never replayed (its rounds are stateful, so resuming
one reconciles against a conversation the relay is no longer having); an update
to a live subscription replaces what gets replayed, including when the send
itself fails; dropping a relay or closing the pool forgets what they carried;
replay is scoped to the relay that reconnected. Plus the semantic the whole
change rests on, asserted in both directions: a live subscription keeps
delivering after EOSE, a one-shot query still ends at it.

LiveSubscriptionReconcileTest (12) — the requirement this all exists for: the
group filter follows group membership with nobody calling a subscribe function.
Joining widens the filter *in place* rather than reopening (a reopen would drop
the live tail of every other group in that chunk); leaving drops one; leaving
everything closes the subscription; churn inside the debounce window collapses
to one update; a NIP-17 room never becomes a group subscription. Then the
collect loop: events stored against the relay they came from, an event after
EOSE still stored, a CLOSED reopened once the back-off elapses and not before,
and a rate-limited CLOSED waiting far longer — but still coming back.
Backgrounding closes and foregrounding rebuilds, reconnects, and queues the
catch-up.

LiveSubscriptionPlanTest (11) — the filter and planning rules, led by the one
most likely to be "tidied up" later: the gift wrap filter carries no `since`,
because NIP-59 randomizes created_at into the past and a `since` near the
present silently drops new messages.

RelayBackPressureTest (4) and ReconnectBackoffTest (6) — the two pure decisions.
Which CLOSED reasons mean "ease off", and the backoff arithmetic including the
exponent clamp: 2.0.pow(4000) is Infinity and Duration * Double throws on it, so
without it a socket failing long enough turned its reconnect loop into a crash
loop, at the point the network was least likely to recover unaided.

**Seams opened to get there**, each a readability win on its own terms:

  - NostrSocketClientFactory becomes an interface with DefaultNostrSocketClientFactory
    behind it, so the pool can be driven by a fake socket.
  - RelayPool takes its CoroutineScope, so the replay a reconnect triggers can be
    observed rather than raced.
  - LiveSubscriptionManager depends on a new LiveSubscriptionTransport (4
    methods) rather than RelaysSocketManager, which observes the active wallet in
    its init and cannot be stood up in a test at all.
  - Its pure planning helpers move to the companion as `internal`, and its
    launches inherit the caller's dispatcher instead of pinning Dispatchers.IO.
    SynchronizationViewModel already launches observe() on IO, so nothing moves —
    but a coroutine that picks its own dispatcher cannot be driven by a test
    scheduler.
  - reconnectDelay is extracted to ReconnectBackoff.kt with jitter as a
    parameter, so the arithmetic can be pinned without randomness.
  - endsLiveSubscription names the live-subscription termination rule next to
    isTerminalFor, which is the one-shot rule. Having both named makes the
    difference between them reviewable rather than implicit.

kotlinx-coroutines-test is added to commonTest: the pool's bookkeeping is all
suspend functions and there is no runBlocking in a common source set.

The tests were checked by mutation, not just by passing — reintroducing a
`since`, making EOSE terminal, dropping the leftGroupAt filter and removing
retention from query() each produce failures.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-05 23:31:11 +02:00
Kgothatso Ngako
a611277d5d build: drop six unused dependencies and their catalog entries
None of these are imported by any source file in composeApp, generated sources
included, and none is the kind of dependency that gets used without an import.

  androidx.paging:paging-common    no androidx.paging import anywhere; no DAO
  androidx.paging:paging-compose   returns PagingSource and nothing calls
                                   collectAsLazyPagingItems, so the Room-Paging
                                   integration that would need it is not in use
  androidx.work:work-runtime-ktx   no Worker, CoroutineWorker or WorkManager
                                   reference, and no provider or initializer entry
                                   in AndroidManifest.xml
  okhttp3:okhttp-coroutines        redundant rather than unused: quartz-android
                                   1.14.0 depends on it and at 5.5.0, which was
                                   already upgrading this declaration's 5.4.0. It
                                   stays on the runtime classpath either way
  com.ionspin.kotlin:bignum        no com.ionspin import. Arrived in a10dc1a with
                                   lightning-mobile support, not with
                                   secp256k1-frost-kmp, though frost was the last
                                   thing in the tree that used bignum at all
  no.synth:kmp-zip                 no no.synth import
  no.synth:kmp-zip-okio

The catalog entries and the pagingCommon, workRuntimeKtx and okhttp version refs
go with them, since each was referenced exactly once and nothing else in this
build points at them. lightning-kmp-app also declares work-runtime-ktx, but reads
it from its own catalog, so it is unaffected.

Deliberately kept:

app.cash.sqldelight looks unused by the same test -- no .kt file under
composeApp/src imports it -- but composeApp holds .sq schemas for three databases
(ChannelsDatabase, PaymentsDatabase, AppDatabase) and the generated sources import
it in 29 files. The runtime, the coroutines extensions and the platform drivers
all stay.

compose.desktop.currentOs and kotlinx-coroutines-swing in jvmMain are untouched,
but worth flagging: the `jvm()` target is commented out, so that source set and the
files under composeApp/src/jvmMain are not built. Whether they are dead or waiting
for the desktop target to come back is a decision about the target, not about a
dependency, so this commit leaves both alone.

Commented-out declarations elsewhere in the file -- room vs room3, kspIosX64,
kspJvm -- are left as the migration markers they are.

`:composeApp:assembleDebug` passes and the APK still packages libsecp256k1-jni.so
for all four ABIs.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 23:26:24 +02:00
Kgothatso Ngako
546095b026 build: unify the composite on AGP 9.4.0 so Android Studio can sync
Android Studio refused to sync the project after the lightning-kmp-app bump in 4e939c4:

    Using multiple versions of the Android Gradle Plugin [9.1.1, 9.4.0] across Gradle builds is
    not allowed.
    Affected builds: [:, :lightning-kmp-app:lightning-kmp:bitcoin-kmp:secp256k1-kmp]

A composite build has to settle on a single AGP version across every build that applies the
plugin. Four builds in this tree do:

    :                                                        9.1.1  version catalog
    :lightning-kmp-app                                       9.1.1  version catalog
    :secp256k1-frost-kmp                                     9.1.1  version catalog
    :lightning-kmp-app:lightning-kmp:bitcoin-kmp:secp256k1-kmp  9.4.0  hardcoded

lightning-kmp and bitcoin-kmp apply no android plugin at all, which is why the message names
only the two ends of the chain rather than everything between them.

secp256k1-kmp pins 9.4.0 twice -- a buildscript classpath entry, and a pluginManagement
resolutionStrategy that rewrites every requested com.android plugin to that version -- so it
cannot be talked out of it from here. The three catalogs move up to meet it. Pinning it down to
9.1.1 instead would mean editing a build four submodules deep and then committing in bitcoin-kmp
and lightning-kmp purely to carry the pointer, for no gain. Moving up is also the direction the
chain already set: bbba08b's f22c30a moved every build in it onto Gradle 9.7.1 for the same
reason, and 4e939c4 followed.

Submodule commits carried here:

  lightning-kmp-app  bbba08b -> ce1ed01  build: move to AGP 9.4.0, matching the version the
                                         submodule chain pins
  secp256k1-frost-kmp  d3b294d -> 80a55b7  build: move to AGP 9.4.0 to match the rest of
                                           mantra-kmp's composite

Both sit on branches (build/agp-9.4.0 and build/gate-ios-targets-on-macos) rather than their
masters, and neither is pushed yet, so a fresh clone cannot resolve these two pointers until
they are.

9.4.0 is a minor bump inside the AGP 9.x line, so the DSL is unchanged and every android.* flag
in gradle.properties -- newDsl, builtInKotlin, the r8 settings -- keeps its meaning.
`:composeApp:compileDebugKotlinAndroid` passes clean.

Note that this is only what the IDE needs to sync, not everything worth knowing about the
chain. bitcoin-kmp's settings.gradle.kts substitutes secp256k1-kmp, -jni-jvm and the three
-jni-jvm-{linux,darwin,mingw} coordinates, but not -jni-android. So the android app still
resolves secp256k1-kmp-jni-android from maven central at stock 0.24.0, without the
FROST/prefractal native modules the threshold branch exists to provide, and a call into those
from android would fail with UnsatisfiedLinkError. Fixing that needs a substitution rule in
bitcoin-kmp. Untouched here because it is a runtime concern, not a sync one.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 22:58:32 +02:00
Kgothatso Ngako
4e939c4570 build: bump lightning-kmp-app to bbba08b, building lightning-kmp from source
lightning-kmp-app moves 6745d88 -> bbba08b, four commits:

  57353cf Minor updates
  9f3cd72 Build lightning-kmp from the experimental submodule via a composite build
  f22c30a Follow the submodule chain onto Gradle 9.7.1
  bbba08b Declare the ios targets only on a mac, so the IDE can import the project

9f3cd72 is the substantive one. lightning-kmp no longer comes from maven central: the
submodule now carries its own experimental/lightning-kmp submodule on branch `threshold`
-- the branch with the FROST/prefractal signers -- and substitutes
fr.acinq.lightning:lightning-kmp-core for that build's project. That build includes
bitcoin-kmp, which includes secp256k1-kmp, which compiles the C library from a secp256k1-zkp
fork. So this repo's build tree is now four levels deep and compiles native code.

Cloning therefore needs `git submodule update --init --recursive`, and because each included
build resolves the android SDK from its own local.properties rather than inheriting the
root's, the three new nested builds each need a (gitignored) local.properties with sdk.dir.

57353cf changed two signatures that MantraApplication implements -- LightningApplication
gained getApplicationContext(), and BusinessManager.initialize now takes the application
rather than a Context. Neither needed a source change: MantraApplication extends
android.app.Application, which already supplies getApplicationContext(), and it was already
passing `this`, which satisfies the narrowed parameter type.

The rest of this commit is what the update forces on the outer build.

gradle-wrapper.properties, 9.3.1 -> 9.7.1: f22c30a moved every build in the chain onto
9.7.1. An included build does not use its own wrapper -- the root build's gradle version runs
the whole tree -- so this repo has to follow for the chain to build at all.

gradle.properties, configuration cache off: secp256k1-kmp's `:jni:generateHeaders` and
`:native:buildSecp256k1<target>` both hold gradle script object references and cannot be
serialized. The configuration cache covers a whole build tree and has no per-build opt-out,
so an included build's incompatibility is this build's problem. The comment records how to
undo this once those tasks are fixed upstream.

composeApp/build.gradle.kts, ios targets gated on the host: secp256k1-kmp declares a
libsecp256k1 cinterop, which makes gradle switch off klib cross compilation for apple
targets. On linux nothing in the tree then offers an ios variant of
fr.acinq.phoenix:lightning-kmp-app, and the ios compilations failed with "No matching variant
of project ':lightning-kmp-app:library'" -- not a warning, a build failure. The gate covers
the target declarations, the iosMain dependencies (the source set only exists when the
targets do) and the kspIos* configurations (likewise). This mirrors bbba08b, which applied
the same gate inside the submodule for the same reason.

secp256k1-frost-kmp d3b294d applies that gate there too. Substitution rules apply across a
whole build tree, so that project's own lightning-kmp-core coordinate started resolving to
the source project without it asking, and every apple source set stopped resolving. The
android build masked it -- ios compilations are not in its task graph -- but
kmpPartiallyResolvedDependenciesChecker reported it and compileAppleMainKotlinMetadata failed
outright, which would have broken IDE import.

Note that `:composeApp:compileCommonMainKotlinMetadata` no longer exists on a linux host.
With ios gated off, androidTarget is the only declared target (jvm() is still commented out),
and KMP does not generate a commonMain metadata compilation for a single-target project.
`:composeApp:compileDebugKotlinAndroid` is the check now; it passes clean, with none of the
resolution errors above.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-04 22:50:59 +02:00
Kgothatso Ngako
f21b13da07 Update quarts 2026-08-29 16:22:56 +02:00
Kgothatso Ngako
539babbfce build: consume secp256k1-frost-kmp and lightning-kmp-app as composite-build submodules
Add both libraries as git submodules and resolve them through Gradle
composite builds instead of remote publications, so local changes to
either library are picked up by the app build directly.

Submodules:
* secp256k1-frost-kmp (github.com/ac-cord-ac/secp256k1-frost-kmp) at
  2478403 -- BIP-327 FROTH/FROST signing over secp256k1, KMP.
* lightning-kmp-app (github.com/kngako/lightning-kmp-app) at 6745d88 --
  phoenix business logic on top of lightning-kmp-core. Both submodules
  carry a local commit aligning them with this build's AGP 9.1.1 /
  Kotlin 2.4.10 (AGP version must match across a composite build or the
  android variants fail attribute matching).

settings.gradle.kts:
* includeBuild() both submodule checkouts.
* lightning-kmp-app's project stays named ':library' (compose-resources
  derives its Res package from the project name), so an explicit
  dependencySubstitution maps the coordinate the app declares,
  fr.acinq.phoenix:lightning-kmp-app, onto that project.
* Drop the jitpack.io repository: it only served com.github.kngako,
  which is no longer consumed as a binary.

composeApp/build.gradle.kts:
* commonMain gains ac.cord.auxiliary:library:1.0.0 (secp256k1-frost-kmp,
  substituted by the composite build).
* commonMain replaces com.github.kngako.lightning-kmp-app:library (via
  JitPack) with fr.acinq.phoenix:lightning-kmp-app:1.0.0 (substituted by
  the composite build). lightning-kmp-core still comes from Maven
  Central.
* Remove the RestoreJitPackClassifier component-metadata rule and the
  javax.inject import: it only existed to repair the artifact
  classifiers JitPack drops from the apple metadata variants, which no
  longer applies.

gradle/libs.versions.toml:
* Remove the now-unused lightningKmpApp version and the
  com.github.kngako lightning-kmp-app catalog entry.

Verified:
  ./gradlew :composeApp:compileCommonMainKotlinMetadata             :composeApp:compileDebugKotlinAndroid
2026-08-15 17:07:31 +02:00
Kgothatso Ngako
086b2f4e70 Update dependencies 2026-08-15 15:42:34 +02:00
Kgothatso Ngako
b17901973c Add lightning-kmp-app as a commonMain dependency via JitPack
The shared lightning/phoenix logic now lives in kngako/lightning-kmp-app,
which publishes a single `:library` module. JitPack serves a repository's
submodules under <GROUP>.<ARTIFACT>, hence the
com.github.kngako.lightning-kmp-app:library coordinate. The repository is
content-filtered to com.github.kngako so it is not consulted for anything
else -- an unfiltered jitpack.io entry gets asked about every dependency
that misses in mavenCentral, and each miss is a remote round trip.

The version is a commit rather than master-SNAPSHOT. For a -SNAPSHOT
version JitPack advertises a unique-snapshot maven-metadata.xml
(timestamp=<sha>, buildNumber=1) while serving the files under their
literal -SNAPSHOT names, so gradle derives library-<target>-master-<sha>-1
and gets a 404 on every artifact. Pinning a commit sidesteps the snapshot
machinery entirely and is reproducible; it needs bumping when the fork
moves.

That leaves the classifier. JitPack rewrites the version inside a
published .module file and drops the classifier while doing so, so both
the sources and the host-specific metadata variants of each apple target
come back naming library-<target>-<ver>.jar -- a file that does not
exist, next to the -sources.jar and -metadata.jar that do. The klib and
the aar are named without a classifier and so survive the rewrite, which
is why the android compilation resolves this dependency perfectly well
and only the metadata compilations fail. Every shared ios source set
resolves through those, so a component metadata rule puts the -metadata
classifier back. It is scoped to the two apple modules and to their
metadata variant by name, so it cannot disturb the klib artifacts.

Verified: :composeApp:compileCommonMainKotlinMetadata and
:composeApp:compileDebugKotlinAndroid both pass.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-02 18:46:00 +02:00
Kgothatso Ngako
aad97bdd9e Add deterministic id on MLS related models 2026-07-01 20:27:05 +02:00
Kgothatso Ngako
124856ce2d Add active profile screens 2026-07-01 15:11:31 +02:00
Kgothatso Ngako
a10dc1a6f8 Add lightning-mobile support 2026-06-15 14:39:46 +02:00
Kgothatso Ngako
66852835f8 Update dependencies 2026-06-05 23:55:44 +02:00
Kgothatso Ngako
7dca669d66 Update compose hot reload 2026-05-23 13:09:13 +02:00
Kgothatso Ngako
b501529a58 Remove unused libraries 2026-05-20 21:17:47 +02:00
Kgothatso Ngako
e09eb664c0 Update every other dependencies 2026-05-17 23:12:49 +02:00
Kgothatso Ngako
f9f7e5f242 Update compile sdk and kotlin version 2026-05-17 23:06:12 +02:00
Kgothatso Ngako
9fa4acc1b1 Update dependencies to get new quarts 2026-05-17 23:02:42 +02:00
Kgothatso Ngako
e8a42b0123 Introduce foundation for negentropy logic. 2026-05-04 18:12:11 +02:00
Kgothatso Ngako
0531248457 Update to android room3 2026-05-02 00:05:38 +02:00
Kgothatso Ngako
f92ece5b66 Add lightning-kmp to libs.versions.toml 2026-04-21 23:50:54 +02:00
Kgothatso Ngako
42c76c1a36 Add coil to libs.versions.toml 2026-04-21 23:49:54 +02:00
Kgothatso Ngako
403b245880 Sync using the new logic. 2026-04-19 04:30:29 +02:00
Kgothatso Ngako
87bd722960 Add Primal like NostrPublisher 2026-04-18 21:58:32 +02:00
Kgothatso Ngako
76858f9cf0 Add primal RelaySocketManager 2026-04-18 02:41:31 +02:00
Kgothatso Ngako
29953d2c20 Use the CIO engine for ktor
All platforms will use the same http engine.
2026-03-30 13:25:19 +02:00
Kgothatso Ngako
a45acbce8a Update dependencies 2026-03-30 13:21:14 +02:00
Kgothatso Ngako
19d87e6f12 Ordering dependencies 2026-03-30 13:14:37 +02:00
Kgothatso Ngako
4cce9bc3d4 Format time 2026-03-30 13:09:49 +02:00
Kgothatso Ngako
f4cd036f51 Broadcast the things 2026-03-27 13:35:29 +02:00
Kgothatso Ngako
23033b0b47 Make room for a database. 2026-03-24 04:47:19 +02:00
Kgothatso Ngako
7a64c519e4 Initial run 2026-03-23 02:21:18 +02:00
Kgothatso Ngako
0652c6add4 Pass the torch... initial commit. 2026-03-23 01:41:39 +02:00