Skip to content

Commit 1569477

Browse files
authored
Merge pull request #74 from synonymdev/fix/channel-monitor-migration
fix: prevent channel data overwrite in FS→KV migration
2 parents d1d6fff + ffc0ec5 commit 1569477

10 files changed

Lines changed: 1006 additions & 480 deletions

File tree

AGENTS.md

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,56 @@ cargo build --profile=release-smaller
2121
```
2222

2323
### Testing
24+
25+
#### Unit tests (no external infrastructure needed)
26+
```bash
27+
cargo test --lib
28+
```
29+
30+
#### Standard integration tests
31+
Uses the `electrsd` crate to auto-download and spawn `bitcoind` + `electrs` binaries.
32+
To use pre-downloaded binaries, set `BITCOIND_EXE` and `ELECTRS_EXE` env vars.
33+
34+
On macOS, the default file descriptor limit (256) is too low for spawning `bitcoind` +
35+
`electrs`. Raise it before running integration tests:
36+
37+
Test files: `tests/integration_tests_rust.rs`, `tests/reorg_test.rs`,
38+
`tests/multi_address_types_tests.rs`
39+
2440
```bash
25-
# Run all tests
26-
cargo test
41+
ulimit -n 10240 && cargo test
42+
```
2743

28-
# Run a specific test
44+
#### Run a specific test
45+
```bash
2946
cargo test test_name
47+
```
3048

31-
# Run tests with specific features
49+
#### Run tests with UniFFI bindings feature
50+
```bash
3251
cargo test --features "uniffi"
52+
```
53+
54+
#### CLN integration tests
55+
Requires Docker and `socat` for RPC socket forwarding.
56+
```bash
57+
docker compose -f docker-compose-cln.yml up -d
58+
RUSTFLAGS="--cfg cln_test" cargo test --test integration_tests_cln
59+
```
3360

34-
# Integration tests with specific backends
35-
cargo test --cfg cln_test # Core Lightning tests
36-
cargo test --cfg lnd_test # LND tests
37-
cargo test --cfg vss_test # VSS (Versioned Storage Service) tests
61+
#### LND integration tests
62+
Requires Docker and CMake (>=3.5, <4.0) for `lnd_grpc_rust`.
63+
Set `LND_DATA_DIR`, `LND_CERT_PATH`, and `LND_MACAROON_PATH` env vars.
64+
```bash
65+
docker compose -f docker-compose-lnd.yml up -d
66+
RUSTFLAGS="--cfg lnd_test" cargo test --test integration_tests_lnd
67+
```
68+
69+
#### VSS integration tests
70+
Requires PostgreSQL and a running VSS server (from `lightningdevkit/vss-server`).
71+
Set `TEST_VSS_BASE_URL` env var.
72+
```bash
73+
RUSTFLAGS="--cfg vss_test" cargo test --test integration_tests_vss
3874
```
3975

4076
### Code Quality
@@ -200,6 +236,7 @@ marked as skipped for CI), you must fix it before declaring success.
200236
- NEVER suggest manually adding @Serializable annotations to generated Kotlin bindings
201237
- ALWAYS run `cargo fmt` before committing to ensure consistent code formatting
202238
- ALWAYS move imports to the top of the file when applicable (no inline imports in functions)
239+
- ALWAYS add unit tests for new business logic — untested code will be flagged in review
203240
- Run `./bindgen.sh` in the background when bindings need regeneration (it is long-running)
204241

205242
## Bindings Generation Command

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
- Switched from forked rust-lightning (`ovitrif/rust-lightning#0.2-electrum-fix`) back to official
2727
upstream crates.io releases. The Electrum sync fix (PR #4341) is now in upstream
2828
`lightning-transaction-sync` v0.2.1. Also picks up `lightning` v0.2.2 fixes.
29+
- Fixed FS→KV channel data migration blindly overwriting newer state. The migration now skips
30+
writing a channel monitor when the KV store already holds one with a newer or equal `update_id`,
31+
and skips the channel manager when one already exists. Read or deserialization failures fail-closed
32+
to prevent silent data loss.
2933

3034
## Synonym Fork Additions
3135

@@ -36,7 +40,6 @@
3640
255 and a warning is logged.
3741
**Breaking change:** existing struct-literal construction of `ElectrumSyncConfig` must add the
3842
new field or switch to `ElectrumSyncConfig { .., ..Default::default() }`.
39-
4043
- Added `OnchainPayment::calculate_send_all_fee()` to preview the fee for a drain / send-all
4144
transaction before broadcasting (fee-calculation counterpart of `send_all_to_address`)
4245
- Added runtime APIs for dynamic address type management:

0 commit comments

Comments
 (0)