Add ldk-watchtower-client crate - #277
Draft
vincenzopalazzo wants to merge 1 commit into
Draft
Conversation
Workspace crate that polls an ldk-server WatchtowerStateExport endpoint and ships teos (Eye of Satoshi) appointments to a tower over Tor. - Local prost definitions of the WatchtowerStateExport API (no git deps on ldk-server repos) - HMAC-SHA256 x-auth header mirroring ldk-server's validate_auth - Blocking teos tower client with Tor SOCKS5 proxy support, receipt signature verification and misbehavior proofs - SQLite-backed tracking of commitment states (pending queue survives restarts), registration/appointment receipt persistence - structopt CLI + optional TOML config file - Pins rust-toolchain.toml to 1.81; bumps async-stream 0.3.2 -> 0.3.6 (0.3.2 does not compile on newer rustc, breaking tonic 0.11)
There was a problem hiding this comment.
Pull request overview
This PR adds a new workspace crate, ldk-watchtower-client, implementing a blocking client that polls an ldk-server WatchtowerStateExport endpoint and submits TEOS appointments (optionally via Tor for onion towers). It also pins the Rust toolchain and updates the lockfile to restore workspace compatibility with newer compilers.
Changes:
- Introduce
ldk-watchtower-clientcrate with polling, appointment building/encryption, tower interaction, retry/backoff, and SQLite persistence. - Add
rust-toolchain.tomlpinning Rust 1.81 for consistent builds. - Update workspace membership and
Cargo.lock(incl.async-streambump) to keep the workspace compiling.
Reviewed changes
Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| rust-toolchain.toml | Pins Rust toolchain to 1.81 for reproducible builds. |
| Cargo.toml | Adds ldk-watchtower-client to workspace members. |
| Cargo.lock | Updates dependencies and adds the new crate to the lockfile. |
| ldk-watchtower-client/Cargo.toml | Defines the new crate, dependencies, and binary target. |
| ldk-watchtower-client/src/lib.rs | Exposes the crate modules (poller, tower, dbm, etc.). |
| ldk-watchtower-client/src/main.rs | Binary entrypoint and polling loop. |
| ldk-watchtower-client/src/config.rs | CLI + TOML configuration resolution. |
| ldk-watchtower-client/src/proto.rs | Local prost message definitions for the export API + tests. |
| ldk-watchtower-client/src/ldk_client.rs | Protobuf-over-HTTP client for ldk-server export endpoint + HMAC auth + tests. |
| ldk-watchtower-client/src/appointments.rs | Builds TEOS appointments from justice transactions + tests. |
| ldk-watchtower-client/src/dbm.rs | SQLite persistence/state machine for exported justice states + tests. |
| ldk-watchtower-client/src/retrier.rs | Bounded exponential backoff retry wrapper for tower submissions. |
| ldk-watchtower-client/src/poller.rs | Main polling/tick logic: export state, persist, deliver appointments. |
| ldk-watchtower-client/src/tower.rs | Blocking TEOS tower HTTP client (register/add_appointment) + receipt handling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+245
to
+247
| let recovered_id = TowerId( | ||
| cryptography::recover_pk(&receipt.to_vec(), &receipt.signature().unwrap()).unwrap(), | ||
| ); |
Comment on lines
+29
to
+52
| let (_trigger, listener) = triggered::trigger(); | ||
| log::info!( | ||
| "ldk-watchtower-client started. Polling {} every {}s", | ||
| cfg.ldk_server_url, | ||
| cfg.poll_interval_secs | ||
| ); | ||
|
|
||
| loop { | ||
| client.tick(); | ||
| // Sleep until the next tick, waking up periodically to check for | ||
| // Ctrl-C / SIGTERM (triggered 0.1 has no timed wait on `Listener`). | ||
| let mut slept = Duration::ZERO; | ||
| while slept < poll_interval && !listener.is_triggered() { | ||
| let step = poll_interval | ||
| .checked_sub(slept) | ||
| .unwrap_or_default() | ||
| .min(Duration::from_secs(1)); | ||
| std::thread::sleep(step); | ||
| slept += step; | ||
| } | ||
| if listener.is_triggered() { | ||
| log::info!("Shutting down"); | ||
| break; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ldk-watchtower-client(~1.8k LOC): the ldk-server analogue of the CLN watchtower-plugin - polls an ldk-server node'sWatchtowerStateExportendpoint and ships appointments to a teos tower (Tor viasocks5h://when the tower address is onion)Appointment(locator = txid[..16], ChaCha20-Poly1305 blob keyed by sha256(dispute_txid)) -> sign + send with bounded backoff -> verify receipt signature, persistMisbehaviorProofon mismatchseen -> pending -> sent/invalid) survives restarts; v1 skipssigned=false/empty entries but tracks their txids so the transition to signed entries is detected as new state--ldk-server-url,--api-key(HMACx-authheader as the server expects),--tower-id,--tower-net-addr,--tor-proxy,--data-dir,--poll-interval-secs, repeatable--watch-channel)Test plan
seen->pending, no downgrade fromsent), HMAC determinismNotes: depends on the (draft) ldk-server export endpoint (lightningdevkit/ldk-server#254) and ldk-node watchtower APIs (lightningdevkit/ldk-node#1031). Adds
rust-toolchain.tomlpinning 1.81 (was absent). Bumpsasync-stream0.3.2->0.3.6 in the lockfile: the pinned version fails to compile on rustc >=1.76 - pre-existing workspace breakage.