Repository navigation
Conversation
The SQLite store's tests only ever read databases they wrote themselves, and neither covered zero-length or multi-megabyte values, a schema migration failing halfway through, nor contention with a second connection. These are the paths most likely to change behavior when the underlying SQLite wrapper is touched. Add tests asserting that values of any length are stored as BLOBs, that a database written by LDK Node v0.7 is migrated and remains usable, that a failed migration leaves the database untouched, and that writes wait for a lock held by another connection. Co-Authored-By: HAL 9000
|
🎉 This PR is now ready for review! |
vincenzopalazzo
left a comment
There was a problem hiding this comment.
Concept ACK
I added a small comment on how to include the library!
As libsqlite3-sys may only be linked once per build and every rusqlite release pins a single version of it, LDK Node and any application using SQLite themselves had to agree on a rusqlite release. Our MSRV furthermore kept us from admitting recent releases, leaving downstream users unable to pick up newer bundled SQLite versions. Access SQLite through sqlite-thin instead, which declares the C API itself and hence accepts any libsqlite3-sys release from 0.28 on, leaving the choice to the application. It mirrors the subset of rusqlite's API we use, so the store's logic remains unchanged. As we no longer need to bundle SQLite on rusqlite's behalf, we move building it from source to a separate storage-sqlite-bundled feature, allowing users to link the system's SQLite via storage-sqlite alone. The default and uniffi-default feature sets keep bundling it, so their behavior remains unchanged. Co-Authored-By: HAL 9000
01b9284 to
59847b1
Compare
|
|
| storage-sqlite = ["dep:rusqlite"] | ||
| storage-sqlite = ["dep:sqlite-thin"] | ||
| storage-sqlite-bundled = ["storage-sqlite", "sqlite-thin/bundled"] |
There was a problem hiding this comment.
Here i'd prefer to have something like this:
storage-sqlite = ["storage-sqlite-system", "sqlite-thin/bundled"]
storage-sqlite-system = ["dep:sqlite-thin"]This keeps something like
cargo build --no-default-features --features storage-sqlite
the same across this PR. Otherwise a user building with this command gets a dynamic link of SQLite, which they never asked for.
| `storage-sqlite` links the SQLite library installed on the system, which hence needs to be | ||
| available at build time and at runtime. Enable `storage-sqlite-bundled` instead to build SQLite from | ||
| source and link it statically, which requires a C compiler. |
There was a problem hiding this comment.
Would be good to document here that with dynamic linking, database migrations requires at least SQLite 3.35.0. With 3.34.1, the v1 migration fails.
| LDK Node itself is written in [Rust][rust] and may therefore be natively added as a library dependency to any `std` Rust program. However, beyond its Rust API it also offers language bindings for [Swift][swift], [Kotlin][kotlin], and [Python][python] based on the [UniFFI](https://github.com/mozilla/uniffi-rs/). | ||
|
|
||
| ## MSRV | ||
| The Minimum Supported Rust Version (MSRV) is currently 1.85.0. |
There was a problem hiding this comment.
Note that downstream applications can fail to build on 1.85.0 if they depend on LDK-node because the version 2 resolver would select libsqlite3-sys 0.40.0, which requires 1.88.
Users could work around this with
[resolver]
incompatible-rust-versions = "fallback"or
CARGO_RESOLVER_INCOMPATIBLE_RUST_VERSIONS=fallback
| # Keep these endpoints in sync with the supported range in Cargo.toml. | ||
| # The oldest release sqlite-thin can share a libsqlite3-sys with, and the newest | ||
| # release line entirely compiling on our MSRV. | ||
| rusqlite: ["0.31.0", "0.39.0"] |
There was a problem hiding this comment.
Here we could test the fallback mentioned above against an application that only depends on SQLite ldk-node, and does not specify a rustqlite dependency itself. Without the fallback cargo selects libsqlite3-sys 0.40.0 which does not build on MSRV 1.85.
| # Keep these endpoints in sync with the supported range in Cargo.toml. | ||
| # The oldest release sqlite-thin can share a libsqlite3-sys with, and the newest | ||
| # release line entirely compiling on our MSRV. | ||
| rusqlite: ["0.31.0", "0.39.0"] |
There was a problem hiding this comment.
Also here we could also replace v0.39.0 with v0.40.2 to test the full range available on MSRV
| ("key_0", vec![42u8; 32]), | ||
| ("key_1", Vec::new()), | ||
| ("key_2", (0..=u8::MAX).collect()), | ||
| ("key_3", (0..1024 * 1024).map(|i| (i % 251) as u8).collect()), |
There was a problem hiding this comment.
nit: Here can we move the keys around such that the expected newest-first order asserted below is different from reverse alphabetical order ? For example insert key_2 before key_1.
| use crate::io::test_utils::{do_read_write_remove_list_persist, random_storage_path}; | ||
|
|
||
| #[tokio::test] | ||
| async fn rwrl_post_schema_1_migration() { |
There was a problem hiding this comment.
We could also cover this test in CI with system SQLite, for example such a test would fail with Debian 11’s SQLite 3.34.1.
libsqlite3-sysmay only be linked once per build and everyrusqliterelease pins exactly one version of it, so LDK Node and any application using
SQLite have to agree on a
rusqliterelease. Our MSRV additionally keeps usfrom admitting recent releases, which keeps downstream users from picking up
newer bundled SQLite versions.
This switches
SqliteStoretosqlite-thin, a small wrapper that declares theSQLite C API itself and accepts any
libsqlite3-sysrelease from 0.28 on,leaving the version choice to the application. It mirrors the subset of
rusqlite's API we use, so the change is an import rename and the on-diskformat is unchanged.
For downstream users this drops 6 crates from the tree (
rusqlite,hashlink,hashbrown,foldhash,fallible-iterator,fallible-streaming-iterator) andadds 1 (
sqlite-thin).The first commit adds tests for the paths most likely to be affected (empty and
large values, upgrading a database written by LDK Node v0.7, a failed migration
rolling back, and lock contention). They pass both before and after the switch.
Still open:
sqlite-thinneeds a crates.io release before this can be merged,and since it doesn't cap
libsqlite3-sys, a downstream build without its ownrusqliteresolves to 0.40.0, which requires Rust 1.88 (our MSRV is 1.85).