Skip to content

Add ldk-watchtower-client crate - #277

Draft
vincenzopalazzo wants to merge 1 commit into
talaia-labs:masterfrom
vincenzopalazzo:feat/ldk-watchtower-client
Draft

Add ldk-watchtower-client crate#277
vincenzopalazzo wants to merge 1 commit into
talaia-labs:masterfrom
vincenzopalazzo:feat/ldk-watchtower-client

Conversation

@vincenzopalazzo

Copy link
Copy Markdown
Contributor

Summary

  • New workspace crate ldk-watchtower-client (~1.8k LOC): the ldk-server analogue of the CLN watchtower-plugin - polls an ldk-server node's WatchtowerStateExport endpoint and ships appointments to a teos tower (Tor via socks5h:// when the tower address is onion)
  • Self-contained: local prost defs of the export messages (field numbers match the canonical ldk-server proto), zero new crates beyond the workspace lock, no git deps on ldk-server repos
  • Full pipeline: tower registration with persisted receipt -> poll/track per commitment txid -> build Appointment (locator = txid[..16], ChaCha20-Poly1305 blob keyed by sha256(dispute_txid)) -> sign + send with bounded backoff -> verify receipt signature, persist MisbehaviorProof on mismatch
  • SQLite-backed pending queue (seen -> pending -> sent/invalid) survives restarts; v1 skips signed=false/empty entries but tracks their txids so the transition to signed entries is detected as new state
  • Config mirrors teos: structopt CLI + optional TOML (--ldk-server-url, --api-key (HMAC x-auth header as the server expects), --tower-id, --tower-net-addr, --tor-proxy, --data-dir, --poll-interval-secs, repeatable --watch-channel)

Test plan

  • 9 unit tests on the pinned 1.81 toolchain: encrypt/decrypt round-trip against the teos test vector, locator derivation byte-order, protobuf round-trip incl. v1 unsigned entries, skip/filter logic, DBM state transitions (seen->pending, no downgrade from sent), HMAC determinism
  • No network tests by design; integration against a live tower + ldk-server is follow-up

Notes: depends on the (draft) ldk-server export endpoint (lightningdevkit/ldk-server#254) and ldk-node watchtower APIs (lightningdevkit/ldk-node#1031). Adds rust-toolchain.toml pinning 1.81 (was absent). Bumps async-stream 0.3.2->0.3.6 in the lockfile: the pinned version fails to compile on rustc >=1.76 - pre-existing workspace breakage.

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)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-client crate with polling, appointment building/encryption, tower interaction, retry/backoff, and SQLite persistence.
  • Add rust-toolchain.toml pinning Rust 1.81 for consistent builds.
  • Update workspace membership and Cargo.lock (incl. async-stream bump) 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants