Make bitcoind optional: add transaction-sync as an alternative chain backend - #126
Conversation
0e5ad71 to
9500239
Compare
zoedberg
left a comment
There was a problem hiding this comment.
Please check my comment #125 (comment), I explained why we should not replace the block-sync with the transaction-sync but add it instead as an alternative sync mode. Please update this PR accordingly
|
Hi @bitwalt, here #125 (comment) you said you agreed in updating this PR to add this as an alternative sync mode. Are you still willing to complete this PR? |
|
Hi Zoe, sure I'll try to complete this |
…backend Adds `lightning-transaction-sync` (electrum/esplora) as an alternative to the existing `lightning-block-sync` (bitcoind) chain backend, rather than replacing it (addresses the review on RGB-Tools#126 / RGB-Tools#125). The sync mode is selected explicitly at unlock time via a new `sync_mode` tag on the unlock request: - `block_sync` (default): consume full blocks from a trusted/local bitcoind over JSON-RPC. The bitcoind RPC parameters now live inside this variant, so they are required exactly when this mode is selected and rejected otherwise, with no manual "all or none" validation. - `transaction_sync`: sync through the configured electrum/esplora `indexer_url` only; no bitcoind required. Each backend is gated behind a Cargo feature (`block-sync`, `transaction-sync`), both enabled by default, so a user can build with only the sync dependency they need. A single mode is still fully functional on its own. LDK is wired against trait objects for the fee estimator, broadcaster and gossip UTXO lookup so one set of type aliases serves both backends. Because `lightning-block-sync`'s `GossipVerifier` requires the `P2PGossipSync` to be typed with `Arc<Self>`, a `BlockSyncGossipVerifier` provides the block-sync gossip UTXO lookup against the shared trait-object gossip sync. Adds an integration test for the transaction-sync backend: two nodes are unlocked in transaction-sync mode, an RGB asset channel is opened, a node is restarted (re-establishing the channel after syncing via the indexer) and the channel is cooperatively closed. Closes RGB-Tools#125 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
9500239 to
536b29f
Compare
|
Thanks @zoedberg — I've reworked the PR along the lines you suggested. Rather than replacing block-sync, it now keeps
Both are behind Cargo features ( I added the integration test you described (unlock 2 nodes, open a channel, restart a node, close the channel) exercising the transaction-sync path, and the existing block-sync tests still pass. Two notes for review:
|
536b29f to
cf5f6ea
Compare
|
Thanks for the thorough review @zoedberg — reworked and squashed into a single signed commit. Rundown per thread:
|
cf5f6ea to
92cefca
Compare
|
Thanks again @zoedberg — went through this round and pushed an updated (still signed) commit. Per thread:
|
…backend
Adds `lightning-transaction-sync` (electrum/esplora) as an alternative to the
existing `lightning-block-sync` (bitcoind) chain backend, rather than replacing
it.
The chain backend is selected explicitly at unlock time via the `ldk_chain_sync`
field of the `/unlock` request, an adjacently-tagged `{ "mode", "config" }`
object:
- `BlockSync`: consume full blocks from a trusted/local bitcoind over JSON-RPC.
The `bitcoind_rpc_*` parameters live in this mode's `config`, so they are
required exactly when this mode is selected.
- `TransactionSync`: sync through an electrum/esplora indexer, so no bitcoind
is required. By default it reuses the wallet's `indexer_url`; a dedicated LN
indexer can be set in this mode's `config`.
Each backend is gated behind a Cargo feature (`block-sync`, `transaction-sync`),
both enabled by default and composing with the existing `electrum`/`esplora`
features, so a user can build with only the sync dependency they need. The mode
variants and their wiring are feature-gated accordingly, a build with neither
feature fails with a `compile_error!`, and the single-feature builds are covered
in the build and lint workflows.
The backends live in a new `ldk_chain_backend` module (`block_sync`,
`transaction_sync` and a shared `mod.rs` holding the chain-backend types and the
common fee-estimate logic). LDK is wired against trait objects for the fee
estimator, broadcaster and gossip UTXO lookup so one set of type aliases serves
both backends. Because `lightning-block-sync`'s `GossipVerifier` requires the
`P2PGossipSync` to be typed with `Arc<Self>`, a `BlockSyncGossipVerifier`
provides the block-sync gossip UTXO lookup against the shared trait-object
gossip sync, mirroring upstream's block cache. The transaction-sync gossip
lookup enforces the same six-confirmation depth as the block-sync path.
For the electrum backend, transactions registered via `Filter::register_tx` are
confirmed with a supplementary pass against the electrum server (without holding
its lock across network calls), as `ElectrumSyncClient::sync` alone does not
notify the confirmables about them in this setup.
Adds an integration test for the transaction-sync backend against both electrum
and esplora indexers (an esplora service is added to the regtest compose file):
three nodes are unlocked in transaction-sync mode, two announced RGB asset
channels are opened and node1 makes a multihop RGB payment to node3 (exercising
the indexer gossip lookup), the nodes are restarted (re-establishing the
channels after syncing via the indexer) and a channel is cooperatively closed.
Closes RGB-Tools#125
92cefca to
45d951b
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #126 +/- ##
==========================================
- Coverage 87.96% 87.82% -0.15%
==========================================
Files 14 16 +2
Lines 7829 8394 +565
==========================================
+ Hits 6887 7372 +485
- Misses 942 1022 +80
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
* drop workaround for note indexed transactions in electrum transaction sync * verify the funding output is unspent in the indexer gossip lookup as the block-sync path already did * require indexer_url in the transaction-sync config, following the default indexer removal * lint all 9 feature combinations in CI * test suite no longer needs block-sync; wait for esplora when mining * minor improvements/changes
|
Thanks for sticking with this. I pushed a commit on top of yours instead of sending another round of comments, because most of it needed digging that was quicker to just do. I found out why So the fix belongs in Other changes:
None of this changes the design you landed on, it all sits on top. @bitwalt please have a look and let me know if it looks good to you. |
|
Hi Zoe, thanks for the clarification and for completing this. LGTM |
Implements #125.
Reworked per @zoedberg's review: instead of replacing
lightning-block-syncwithlightning-transaction-sync, this adds transaction-sync as an alternative chain backend and keeps block-sync intact. The sync mode is chosen explicitly at unlock time.Sync modes
The
/unlockpayload gains async_modetag:block_sync(default): consume full blocks from a trusted/local bitcoind over JSON-RPC (lightning-block-sync). Thebitcoind_rpc_*parameters live inside this variant, so they are required exactly when this mode is selected and rejected otherwise — no manual "all or none" validation. This is the more trust-minimized / local-first option.transaction_sync: sync through the configured electrum/esploraindexer_url(lightning-transaction-sync). No bitcoind required — lighter to deploy for indexer-based setups.Cargo features
Each backend is gated behind a feature (
block-sync,transaction-sync), both enabled by default, so a user who wants only one sync type can build with only the dependency they need. Both single-feature builds compile cleanly, and requesting a mode that wasn't compiled in returns a clear error.Implementation notes
lightning-block-sync'sGossipVerifierrequires theP2PGossipSyncto be typed withArc<Self>, a smallBlockSyncGossipVerifierprovides the block-sync gossip UTXO lookup against the shared trait-object gossip sync (mirroring the transaction-syncIndexerGossipVerifier).Tests
Adds an integration test for the transaction-sync backend (as suggested): two nodes are unlocked in transaction-sync mode, an RGB asset channel is opened, a node is restarted (re-establishing the channel after syncing via the indexer) and the channel is cooperatively closed. The existing block-sync tests continue to pass unchanged.