Repository navigation
feat: async - #1923
feat: async#1923
Conversation
…XMTP fork Base: e125674 (insipx/bincode-fixes — the rev libxmtp pins). Merged: 18a7243 (upstream raphael/async tip, main merged through 2026-05-15). Storage traits become async-by-default via maybe-async 0.2.11 (AFIT mode); the sync feature (maybe-async/is_sync) collapses everything back to the existing synchronous shape, which is what libxmtp consumes today. The branch also carries openmls_sqlx_storage — an async StorageProvider over sqlx whose schema is relational (openmls_group_data keyed by (group_id, data_type)) rather than an opaque KV, which is what makes batched group loads possible. Conflict resolutions: - message_secrets.rs: keep the fork's 5-field persisted MessageSecrets with #[serde(skip)] added_at (upstream's #[serde(default)] 6th field corrupts stored MessageSecretsStore blobs mid-VecDeque under bincode). - config.rs / past_secrets.rs / lifetime.rs / past_secrets tests: web-time import convergence (fork carry vs upstream openmls#2016) — upstream form kept. - membership.rs: annotate the fork's update_group_membership with #[maybe_async::maybe_async] and await load_psks/stage_commit/ write_group_state. Fix an upstream defect that made the async path unbuildable: openmls_memory_storage hardcoded openmls_traits/sync, and openmls_rust_crypto depends on it unconditionally. Because maybe-async/is_sync is a global switch on a proc-macro crate, any graph reaching rust_crypto was forced to compile every trait in sync shape — which broke openmls_sqlx_storage's async impls with 53 signature-mismatch errors. Neither sqlx_storage nor openmls_async_tests is a workspace member, so nothing in CI ever compiled them and the rot went unnoticed. MemoryStorage's StorageProvider impl is now maybe_async(AFIT) like the rest, and both crates expose sync/async passthrough features. Verified: cargo check -p openmls in both modes; full cargo test -p openmls --features sync,test-utils green (23 suites, incl. the serde variant-index lock tests); openmls_async_tests now compiles AND runs its end-to-end two-member async group flow (credential -> add_members -> create_message -> process_message) against SqliteStorageProvider over sqlx. Known gap: sqlx_storage is SQLite-only (SqliteStorageProvider, sqlx feature "sqlite"); Postgres needs a second provider plus a Migrate impl twin, since migrator.rs copies sqlx's SqliteConnection Migrate impl to rename the migrations table.
…ostgres sqlx provider Base: e125674 (insipx/bincode-fixes — the rev libxmtp pins). Merged: 18a7243 (upstream raphael/async tip, main merged through 2026-05-15). Storage traits become async-by-default via maybe-async 0.2.11 (AFIT mode); the sync feature (maybe-async/is_sync) collapses everything back to the existing synchronous shape, which is what libxmtp's wasm and mobile targets consume. Merge conflict resolutions: - message_secrets.rs: keep the fork's 5-field persisted MessageSecrets with #[serde(skip)] added_at. Upstream's #[serde(default)] 6th field corrupts stored MessageSecretsStore blobs mid-VecDeque under bincode. - config.rs / past_secrets.rs / lifetime.rs / past_secrets tests: web-time import convergence (fork carry vs upstream openmls#2016) — upstream form kept. - membership.rs: annotate update_group_membership with maybe_async and await load_psks/stage_commit/write_group_state. Fix an upstream defect that made the async path unbuildable: memory_storage hardcoded openmls_traits/sync and openmls_rust_crypto depends on it unconditionally. maybe-async/is_sync is a global switch on a proc-macro crate, so every graph reaching rust_crypto compiled the traits in sync shape, breaking openmls_sqlx_storage with 53 signature mismatches. Neither sqlx_storage nor openmls_async_tests is a workspace member, so CI never compiled them and the rot went unnoticed. MemoryStorage's impl is now maybe_async(AFIT) and both crates expose sync/async passthrough features. Teach openmls_sqlx_storage PostgreSQL alongside SQLite, behind (default) and features that may be enabled together: - storage_provider.rs used the compile-time query!/query_scalar! macros with a checked-in .sqlx offline cache, which bakes one driver in at compile time. Converted to the runtime API so a second dialect is expressible and no live database is needed to build; .sqlx/ and .env are deleted as dead. - One impl_storage_provider! macro emits a whole module per backend. Emitting a module (rather than sharing types) is required because the Storable* newtypes carry inherent methods over an executor, and inherent impls are crate-global. It also leaves call sites byte-identical to upstream, which matters for a fork that has to rebase. - The 26 statements live once in a statement_set! macro rendered per dialect; 18 of them differ only in ?N vs $N, and silent drift between dialects in crypto-key storage is the failure worth engineering against. - Postgres needs its own Migrate impl: sqlx's is copied per-backend solely to rename the migrations table, and the Postgres one takes a pg_advisory_lock. - leaf_index binds as i64 on both backends since Postgres has no unsigned types. Verified backward-compatible against existing SQLite data: rows written with the old u32 binding are still found, and upserts still collapse onto the same primary key. SQLite's migrations/ are byte-unchanged, so deployed migration checksums still match. Verified: openmls builds in both modes; full sync suite green (23 suites); openmls_async_tests runs its end-to-end two-member async group flow; sqlx_storage green on sqlite, postgres, and all-features, with the Postgres round-trip suite (tests/postgres.rs, opt-in via OPENMLS_SQLX_POSTGRES_URL, schema-isolated) passing against a live postgres:16. Known gap: CI compile-checks Postgres but does not run its tests — that needs a service container the macos matrix leg cannot host. No sqlx TLS feature is wired; a deployment wanting encrypted connections enables sqlx/tls-rustls downstream.
…ostgres sqlx provider Base: e125674 (insipx/bincode-fixes — the rev libxmtp pins). Merged: 18a7243 (upstream raphael/async tip, main merged through 2026-05-15). Storage traits become async-by-default via maybe-async 0.2.11 (AFIT mode); the sync feature (maybe-async/is_sync) collapses everything back to the existing synchronous shape, which is what libxmtp's wasm and mobile targets consume. Merge conflict resolutions: - message_secrets.rs: keep the fork's 5-field persisted MessageSecrets with #[serde(skip)] added_at. Upstream's #[serde(default)] 6th field corrupts stored MessageSecretsStore blobs mid-VecDeque under bincode. - config.rs / past_secrets.rs / lifetime.rs / past_secrets tests: web-time import convergence (fork carry vs upstream openmls#2016) — upstream form kept. - membership.rs: annotate update_group_membership with maybe_async and await load_psks/stage_commit/write_group_state. Fix an upstream defect that made the async path unbuildable: memory_storage hardcoded openmls_traits/sync and openmls_rust_crypto depends on it unconditionally. maybe-async/is_sync is a global switch on a proc-macro crate, so every graph reaching rust_crypto compiled the traits in sync shape, breaking openmls_sqlx_storage with 53 signature mismatches. Neither sqlx_storage nor openmls_async_tests is a workspace member, so CI never compiled them and the rot went unnoticed. MemoryStorage's impl is now maybe_async(AFIT) and both crates expose sync/async passthrough features. Teach openmls_sqlx_storage PostgreSQL alongside SQLite, behind `sqlite` (default) and `postgres` features that may be enabled together: - storage_provider.rs used the compile-time query!/query_scalar! macros with a checked-in .sqlx offline cache, which bakes one driver in at compile time. Converted to the runtime API so a second dialect is expressible and no live database is needed to build; .sqlx/ and .env are deleted as dead. - One impl_storage_provider! macro emits a whole module per backend. Emitting a module (rather than sharing types) is required because the Storable* newtypes carry inherent methods over an executor, and inherent impls are crate-global. It also leaves call sites byte-identical to upstream, which matters for a fork that has to rebase. - The 26 statements live once in a statement_set! macro rendered per dialect; 18 of them differ only in ?N vs $N, and silent drift between dialects in crypto-key storage is the failure worth engineering against. - Postgres needs its own Migrate impl: sqlx's is copied per-backend solely to rename the migrations table, and the Postgres one takes a pg_advisory_lock. - leaf_index binds as i64 on both backends since Postgres has no unsigned types. Verified backward-compatible against existing SQLite data: rows written with the old u32 binding are still found, and upserts still collapse onto the same primary key. SQLite's migrations/ are byte-unchanged, so deployed migration checksums still match. Verified: openmls builds in both modes; full sync suite green (23 suites); openmls_async_tests runs its end-to-end two-member async group flow; sqlx_storage green on sqlite, postgres, and all-features, with the Postgres round-trip suite (tests/postgres.rs, opt-in via OPENMLS_SQLX_POSTGRES_URL, schema-isolated) passing against a live postgres:16. Known gap: CI compile-checks Postgres but does not run its tests — that needs a service container the macos matrix leg cannot host. No sqlx TLS feature is wired; a deployment wanting encrypted connections enables sqlx/tls-rustls downstream.
|
@raphaelrobert We're evaluating this branch for XMTP and merged it onto our fork. We hit three bugs, then prototyped the two receiver shapes that would prevent the third. Everything below reproduces on
|
|
Thanks for the feedback. Note that this is still in an early stage and should not be expected to work flawlessly. It's out of sync with the main branch and will likely see substantial changes. We'll resume work on this after v0.9 is published. |
Thanks for reporting the issues, they should all be addressed in the refactoring now. |
# Conflicts: # openmls/src/group/mls_group/creation.rs # openmls/src/group/mls_group/updates.rs # openmls/src/key_packages/vc.rs # openmls/src/treesync/node/leaf_node.rs
boxdot
left a comment
There was a problem hiding this comment.
Looks good to me!
I checked that the code is basically the same (except for several replacements of iterators by loops) in sync mode.
The Send+Sync requirement on futures in the provider traits is a tradeoff, which won't allow to implement those traits in a non-send context. However on the other hand, the requirement for futures to be able to be spawned on different threads is more important for us.
* introduce maybe_async * follow-up to merging main branch * refactoring * make reinit async as well * include reinit & fork resolution in async tests * one feature mode
This PR introduces maybe_async for the storage provider. A few things to note: