Skip to content

Add support for esplora backend#10538

Open
niteshbalusu11 wants to merge 56 commits intolightningnetwork:masterfrom
niteshbalusu11:esplora-support
Open

Add support for esplora backend#10538
niteshbalusu11 wants to merge 56 commits intolightningnetwork:masterfrom
niteshbalusu11:esplora-support

Conversation

@niteshbalusu11
Copy link

Change Description

Description of change / link to associated issue.

Disclaimer: This PR was heavily written by AI but I spent a lot of time code reviewing and testing it

Motivation

I have been working on Blixt Wallet with @hsjoberg for a long time now and we have been using Neutrino as our backend, although neutrino is great for privacy, the UX of it with syncing issues has been a pain for a lot of our users especially for users in countries where internet connectivity is not very good. We even deployed btcd nodes in 4 continents to reduce latency for users but that hasn't helped either.

The PR introduces a new backend for LND based on esplora so you can connect to any public esplora endpoint such as mempool.space or blockstream.info. However, it is recommended that wallet devs run their own instance of esplora because the public endpoints are heavily rate limited.

Details

The core components of this PR are:

  • esplora/client.go: HTTP client for Esplora REST API with automatic retries and block polling for new blocks.
  • esplora/chainclient.go: Implements chain.Interface for btcwallet integration, handling address watching, transaction notifications, and block processing
  • esplora/fee_estimator.go: Implements chainfee.Estimator interface with cached fee estimates and automatic background updates
  • chainntnfs/esploranotify/: Chain notifier implementation for confirmation and spend notifications
  • routing/chainview/esplora.go: Filtered chain view for UTXO tracking

Wallet recovery:

  • When it comes to wallet recovery, neutrino is efficient with sending data across the wire with compact blocks but esplora doesn't do that. To get around this, Evan had the idea of adding a Gap limit which I implemented which significantly improves the performance during recoveries.
  • Configurable gap limit (default: 20) and address batch size (default: 10) for concurrent queries
  • For large address sets, automatically switches to block-based scanning which fetches block transactions and scans them locally which is much more efficient than per-address API queries

Block notification handling:

  • Since esplora is HTTP only, we use polling at configurable intervals (default 10s)

Configuration

[esplora]
esplora.url              - API endpoint URL
esplora.requesttimeout   - HTTP request timeout (default: 30s)
esplora.maxretries       - Retry count for failed requests (default: 3)
esplora.pollinterval     - Block polling interval (default: 10s)
esplora.usegaplimit      - Enable gap limit optimization (default: true)
esplora.gaplimit         - Consecutive unused addresses before stopping (default: 20)
esplora.addressbatchsize - Concurrent address queries (default: 10)

Steps to Test

  • I have made a repo for end to end testing of various important scenarios that you can run for testing the backend:
    https://github.com/niteshbalusu11/lnd-esplora-testing
  • The Readme of the repo should have all the details needed for testing.
  • There are unit tests in the esplora directory for important components.
    Also, @kaloudis helped a lot with testing this with Zeus on testnet.

Pull Request Checklist

Testing

  • Your PR passes all CI checks.
  • Tests covering the positive and negative (error paths) are included.
  • Bug fixes contain tests triggering the bug to prevent regressions.

Code Style and Documentation

📝 Please see our Contribution Guidelines for further guidance.

Refactor `handleNewHeader` to sequentially process blocks, ensuring
complete block notification and watched address tracking. Key changes:
- Process blocks from last known height to current
- Fetch and validate each block header
- Separate reorg detection from block processing
- Improve logging and error handling
- Ensure consistent block caching and notifications
This change adds REST API capabilities to the Electrum backend,
enabling:
- Fetching full block information
- Retrieving transaction details
- Finding transaction indices within blocks
- Validating channel-related transactions

Key changes include:
- Added RESTClient to electrum package
- Updated ElectrumNotifier and ChainClient to support REST URL
- Modified configuration to require REST URL in Electrum mode
- Implemented methods for block and transaction retrieval
This change adds support for fetching the actual pkScript for Taproot
outputs when the script cannot be derived directly from the witness. It
retrieves the full funding transaction to extract the correct output
script for historical spend detection.
Ensure proper synchronization and order of operations when updating
transaction notifier during block connected events. The height is now
updated first, and confirmation/spend checks run concurrently to prevent
potential race conditions.
This commit improves the fee estimation logic by:
- Adding a method to find the most appropriate cached fee
- Implementing fee clamping to ensure minimum fee thresholds
- Handling edge cases like missing targets and exceeding max block
  target
Improve block transaction scanning by:
- Increasing max concurrent block fetches
- Using /block/:hash/txs endpoint for more efficient pre-fetching
- Reducing API calls by processing addresses directly from API response
- Minimizing duplicate transaction processing
- Fetching only matched raw transactions at the end
The commit introduces an advanced gap limit scanning method for more
efficient wallet recovery in the Esplora chain client. Key improvements
include:

- Configurable gap limit optimization
- Ability to control address batch size
- Dramatically faster wallet recovery by stopping scan after consecutive
  unused addresses
- Parallel address querying for improved performance
@gemini-code-assist
Copy link

Summary of Changes

Hello @niteshbalusu11, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request integrates a new Esplora backend for LND, providing a robust and efficient alternative to the existing Neutrino backend. The primary motivation is to enhance the user experience, particularly for users facing unreliable internet connections, by leveraging Esplora's HTTP-based API for blockchain interactions. The implementation covers essential services like block and transaction notifications, fee estimation, and wallet synchronization, with specific optimizations for faster and more reliable wallet recovery processes.

Highlights

  • New Esplora Backend Integration: Introduces Esplora as a new, lightweight HTTP-based blockchain backend for LND, offering an alternative to Neutrino for improved user experience, especially in environments with poor internet connectivity.
  • Comprehensive Chain Interaction: Implements core blockchain functionalities including an Esplora HTTP client, a chain notifier for confirmation and spend notifications, a fee estimator with cached updates, and a chain client for btcwallet integration.
  • Optimized Wallet Recovery: Features a configurable 'Gap Limit' (default: 20) and address batching (default: 10) to significantly enhance wallet recovery performance. For large address sets, it automatically switches to more efficient block-based scanning.
  • HTTP-Based Block Notifications: Addresses the HTTP-only nature of Esplora by implementing a polling mechanism (default: 10s interval) for new block notifications, ensuring timely updates.
  • Configuration Options: Provides a dedicated [esplora] section in the configuration for customizing URL, request timeouts, retry counts, polling intervals, and wallet recovery parameters.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@lightninglabs-deploy
Copy link
Collaborator

🔴 PR Severity: CRITICAL

Add support for esplora backend | 18 files | 6,297 lines changed

🔴 Critical (2 files)
  • lnwallet/btcwallet/blockchain.go - Wallet blockchain interface operations
  • lnwallet/btcwallet/btcwallet.go - Core wallet implementation and signing
🟠 High (5 files)
  • chainntnfs/esploranotify/driver.go - Chain notification driver registration
  • chainntnfs/esploranotify/esplora.go - Esplora chain notification implementation (884 lines)
  • chainntnfs/esploranotify/log.go - Logging setup
  • chainntnfs/txnotifier.go - Transaction notifier modifications
  • routing/chainview/esplora.go - Routing chain view for Esplora (561 lines)
🟡 Medium (8 files)
  • chainreg/chainregistry.go - Chain registry integration
  • lncfg/chain.go - Chain configuration
  • lncfg/esplora.go - Esplora-specific configuration
  • esplora/chainclient.go - Esplora chain client implementation (1,746 lines)
  • esplora/client.go - Esplora HTTP client (900 lines)
  • esplora/fee_estimator.go - Fee estimation logic (299 lines)
  • esplora/log.go - Logging setup
  • esplora/scripthash.go - Script hash utilities
🟢 Low (3 files)
  • config.go - Top-level configuration
  • config_builder.go - Configuration builder
  • log.go - Logger registration
  • sample-lnd.conf - Configuration example

Analysis

This PR introduces Esplora backend support, enabling lnd to operate with Esplora blockchain data sources as an alternative to btcd/bitcoind. The CRITICAL severity is assigned due to:

  1. Critical Package Impact: Changes to lnwallet/btcwallet/* touch core wallet operations including blockchain interface implementations and wallet signing logic. These components handle channel funding, commitment transactions, and key material.

  2. Scale: With 6,297 lines added across 18 non-test files, this is a substantial change that introduces an entirely new blockchain backend. The sheer size increases risk of subtle bugs.

  3. Chain Notification Changes: Modifications to chainntnfs/* affect the critical system that detects on-chain events (channel opens/closes, HTLC settlements, breach attempts). Any bugs here could lead to missed transactions or incorrect channel state.

  4. New Subsystem: The new esplora/* package (4,000+ lines) implements chain client interfaces, fee estimation, and transaction broadcasting. While tested, this is greenfield code that needs thorough review.

Key Review Areas:

  • Wallet blockchain interface compatibility in lnwallet/btcwallet/blockchain.go
  • Chain notification reliability in chainntnfs/esploranotify/esplora.go
  • Proper transaction indexing and confirmation tracking
  • Fee estimation accuracy vs existing backends
  • Race conditions in HTTP client polling logic
  • Error handling for Esplora API failures

To override, add a severity-override-{critical,high,medium,low} label.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces significant new functionality by adding support for Esplora as a chain backend. This is a valuable addition, allowing lnd to operate in a lightweight mode without a local full node. The implementation is comprehensive, touching configuration, chain notification, chain view, and wallet logic, and includes thoughtful optimizations like gap-limit scanning for wallet recovery. My review focuses on potential bugs related to error handling, performance optimizations for sorting and data fetching, and adherence to the project's coding style. Overall, this is a great contribution.

Comment on lines +12 to +13
// createNewNotifier creates a new instance of the EsploraNotifier from a
// config.

Choose a reason for hiding this comment

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

medium

According to the repository's style guide, function comments should start with the function's name. This comment should be updated to // CreateNewNotifier....

Suggested change
// createNewNotifier creates a new instance of the EsploraNotifier from a
// config.
// CreateNewNotifier creates a new instance of the EsploraNotifier from a
// config.
References
  1. Function comments must begin with the function name. (link)

Comment on lines 272 to 348
func (e *EsploraFilteredChainView) filterBlockTransactions(
blockHeight uint32) []*wire.MsgTx {

e.filterMtx.RLock()
if len(e.chainFilter) == 0 {
e.filterMtx.RUnlock()
return nil
}

// Copy the current filter to avoid holding the lock during API calls.
watchedOutpoints := make(map[wire.OutPoint][]byte)
for op, script := range e.chainFilter {
watchedOutpoints[op] = script
}
e.filterMtx.RUnlock()

var filteredTxns []*wire.MsgTx
spentOutpoints := make([]wire.OutPoint, 0)

ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
defer cancel()

// For each watched outpoint, check if it was spent using the outspend
// endpoint.
for outpoint := range watchedOutpoints {
outSpend, err := e.client.GetTxOutSpend(
ctx, outpoint.Hash.String(), outpoint.Index,
)
if err != nil {
log.Debugf("Failed to check outspend for %v: %v",
outpoint, err)
continue
}

if !outSpend.Spent {
continue
}

// Check if the spend is confirmed and at this block height.
if !outSpend.Status.Confirmed {
continue
}

if uint32(outSpend.Status.BlockHeight) != blockHeight {
continue
}

// Fetch the spending transaction.
tx, err := e.client.GetRawTransactionMsgTx(ctx, outSpend.TxID)
if err != nil {
log.Debugf("Failed to get spending tx %s: %v",
outSpend.TxID, err)
continue
}

filteredTxns = append(filteredTxns, tx)
spentOutpoints = append(spentOutpoints, outpoint)
}

// Remove spent outpoints from the filter.
if len(spentOutpoints) > 0 {
e.filterMtx.Lock()
for _, op := range spentOutpoints {
pkScript := e.chainFilter[op]
delete(e.chainFilter, op)

// Also remove from scripthash mapping.
if pkScript != nil {
sh := esplora.ScripthashFromScript(pkScript)
delete(e.scripthashToOutpoint, sh)
}
}
e.filterMtx.Unlock()
}

return filteredTxns
}

Choose a reason for hiding this comment

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

medium

The current implementation of filterBlockTransactions iterates over all watched outpoints and makes a separate API call (GetTxOutSpend) for each one. For a node with many channels, this can result in a very large number of API calls per block, which is inefficient and may lead to being rate-limited by public Esplora servers.

A more efficient approach would be to fetch all transactions in the block with a single client.GetBlockTxs call (which handles pagination internally) and then iterate through the transactions and their inputs locally to check for spends of watched outpoints. This would significantly reduce the number of API requests.

Copy link
Author

Choose a reason for hiding this comment

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

Made this more efficient.

@lightninglabs-deploy
Copy link
Collaborator

🔴 PR Severity: CRITICAL

Add support for esplora backend | 24 files | ~6,200 lines changed

🔴 Critical (2 files)
  • lnwallet/btcwallet/blockchain.go - Wallet operations and blockchain interface
  • lnwallet/btcwallet/btcwallet.go - Core wallet implementation
🟠 High (6 files)
  • chainntnfs/esploranotify/driver.go - New chain notification driver
  • chainntnfs/esploranotify/esplora.go - Chain notification implementation for Esplora
  • chainntnfs/esploranotify/log.go - Logging setup
  • chainntnfs/txnotifier.go - Transaction notifier modifications
  • chainreg/chainregistry.go - Chain registry modifications
  • routing/chainview/esplora.go - Routing chain view for Esplora
🟡 Medium (2 files)
  • lncfg/chain.go - Chain configuration
  • lncfg/esplora.go - Esplora-specific configuration
🟢 Low (1 file)
  • sample-lnd.conf - Configuration sample file
📦 New Infrastructure (13 files)
  • esplora/chainclient.go - New chain client implementation (1,746 lines)
  • esplora/client.go - Esplora HTTP client (900 lines)
  • esplora/fee_estimator.go - Fee estimation for Esplora
  • esplora/scripthash.go - Script hash utilities
  • esplora/log.go - Logging setup
  • config.go, config_builder.go, log.go - Core configuration changes
  • Test files: esplora/chainclient_test.go, esplora/client_test.go, esplora/fee_estimator_test.go, esplora/scripthash_test.go, lnwallet/btcwallet/btcwallet_test.go

Analysis

This PR introduces a complete new backend implementation for Esplora, which is a significant architectural addition. The severity has been classified as CRITICAL for the following reasons:

  1. Critical Package Impact: Modifies lnwallet/btcwallet/* which handles core wallet operations and blockchain interactions

  2. Scale: 24 files changed with ~6,200 lines added (excluding tests: 22 files, ~5,500 lines)

  3. Multi-Package Impact: Affects multiple high-severity packages:

    • lnwallet/* (wallet operations)
    • chainntnfs/* (chain notifications)
    • routing/* (routing chain view)
    • chainreg/* (chain registry)
  4. New Backend Integration: Introduces an entirely new blockchain backend alongside existing bitcoind and btcd support, requiring:

    • New chain client implementation
    • Chain notification system integration
    • Fee estimation logic
    • Routing chain view adapter
    • Wallet blockchain interface modifications

This PR requires expert review from engineers familiar with lnd's chain backend architecture, wallet operations, and notification systems to ensure the Esplora integration is safe, correct, and maintains compatibility with existing backends.


To override, add a severity-override-{critical,high,medium,low} label.

@yyforyongyu
Copy link
Member

Approved CI run

@lightninglabs-deploy
Copy link
Collaborator

🔴 PR Severity: CRITICAL

Add support for esplora backend | 24 files | ~4,856 lines changed (excluding tests)

🔴 Critical (3 files)
  • lnwallet/btcwallet/blockchain.go - Wallet blockchain interface integration
  • lnwallet/btcwallet/btcwallet.go - Core wallet implementation modifications
  • lnwallet/btcwallet/btcwallet_test.go - Wallet test updates
🟠 High (5 files)
  • chainntnfs/esploranotify/driver.go - New chain notification driver
  • chainntnfs/esploranotify/esplora.go - Esplora chain notifier implementation (886 lines)
  • chainntnfs/esploranotify/log.go - Notification logging
  • chainntnfs/txnotifier.go - Transaction notifier modifications
  • routing/chainview/esplora.go - Routing chain view for esplora (561 lines)
🟡 Medium (11 files)
  • esplora/chainclient.go - New esplora chain client (1,746 lines)
  • esplora/client.go - Core esplora client (900 lines)
  • esplora/fee_estimator.go - Fee estimation via esplora (299 lines)
  • esplora/scripthash.go - Script hash utilities
  • esplora/log.go - Esplora logging
  • chainreg/chainregistry.go - Chain registry integration
  • config.go - Main configuration updates
  • config_builder.go - Config builder
  • lncfg/chain.go - Chain config
  • lncfg/esplora.go - Esplora config (80 lines)
  • log.go - Main logging
🟢 Low (5 files)
  • esplora/chainclient_test.go - Test file (481 lines)
  • esplora/client_test.go - Test file (395 lines)
  • esplora/fee_estimator_test.go - Test file (330 lines)
  • esplora/scripthash_test.go - Test file (170 lines)
  • sample-lnd.conf - Configuration sample

Analysis

This PR adds comprehensive support for Esplora as a blockchain backend, which is a significant architectural addition. The classification as CRITICAL is based on:

  1. Wallet Integration Changes: Modifications to lnwallet/btcwallet/* files directly impact wallet operations, which are always critical-tier components handling channel funding, commitment transactions, and signing operations.

  2. Large Scope: ~4,856 lines of new/changed code (excluding tests) across 19 non-test files introduces substantial new functionality that requires thorough expert review.

  3. Core Infrastructure: The PR touches critical infrastructure layers:

    • Chain notifications (chainntnfs) - essential for detecting on-chain events
    • Routing chain view - impacts payment pathfinding
    • Wallet blockchain interface - affects all wallet operations
  4. New Backend Integration: Adding a new blockchain backend is inherently high-risk as it affects:

    • Transaction broadcasting and confirmation detection
    • Fee estimation
    • UTXO management
    • Block and transaction monitoring

Key Review Areas:

  • Verify esplora API error handling and retry logic
  • Confirm transaction and block notification reliability
  • Validate fee estimation accuracy
  • Ensure proper handling of chain reorganizations
  • Review wallet integration for correct UTXO tracking

To override, add a severity-override-{critical,high,medium,low} label.

@lightninglabs-deploy
Copy link
Collaborator

🔴 PR Severity: CRITICAL

New Esplora backend implementation | 24 files | 6,237 lines changed

🔴 Critical (2 files)
  • lnwallet/btcwallet/blockchain.go - Wallet blockchain interface modifications
  • lnwallet/btcwallet/btcwallet.go - Core wallet operations integration with new backend
🟠 High (5 files)
  • chainntnfs/esploranotify/driver.go - New chain notifier driver for Esplora
  • chainntnfs/esploranotify/esplora.go - Chain notifier implementation (886 lines)
  • chainntnfs/esploranotify/log.go - Chain notifier logging setup
  • chainntnfs/txnotifier.go - Transaction notifier modifications
  • routing/chainview/esplora.go - Filtered chain view implementation (561 lines)
🟡 Medium (16 files)
  • esplora/chainclient.go - New chain client implementation (1,746 lines)
  • esplora/client.go - HTTP client for Esplora REST API (900 lines)
  • esplora/fee_estimator.go - Fee estimation implementation (301 lines)
  • esplora/scripthash.go - Script hash utilities
  • esplora/log.go - Esplora subsystem logging
  • chainreg/chainregistry.go - Chain registry integration
  • lncfg/esplora.go - Esplora configuration options
  • lncfg/chain.go - Chain configuration updates
  • config.go - Main configuration integration
  • config_builder.go - Configuration builder updates
  • log.go - Logging subsystem registration
  • Test files: esplora/*_test.go, lnwallet/btcwallet/btcwallet_test.go
🟢 Low (1 file)
  • sample-lnd.conf - Configuration documentation

Analysis

This PR receives a CRITICAL severity classification for the following reasons:

  1. Wallet Integration: Modifies core wallet components in lnwallet/btcwallet/*, which handle critical operations including transaction signing, channel funding, and wallet state management.

  2. Multiple Critical Subsystems: Touches three major subsystems:

    • lnwallet (critical tier) - Direct wallet operations
    • chainntnfs (high tier) - Chain notification infrastructure
    • routing (high tier) - Payment routing chain view
  3. Large-Scale Addition: 6,237 lines added across 24 files (~4,858 non-test lines), introducing an entirely new backend implementation. This scale of change requires thorough expert review.

  4. Core Infrastructure Change: Adds a completely new chain backend option alongside Neutrino/bitcoind. This is fundamental infrastructure that affects:

    • Block synchronization and notification delivery
    • UTXO tracking and transaction confirmation
    • Fee estimation for commitment transactions
    • Wallet recovery mechanisms

Key Review Areas:

  • Wallet integration points must preserve existing security guarantees
  • Chain notification reliability (HTTP polling vs. ZMQ push notifications)
  • Race conditions in async block polling
  • Fee estimation accuracy and fallback behavior
  • Gap limit optimization correctness during wallet recovery
  • Error handling for network failures and rate limiting

Recommendation: Requires review from engineers with deep knowledge of LND's wallet architecture and chain backend abstractions.


To override, add a severity-override-{critical,high,medium,low} label.

@lightninglabs-deploy
Copy link
Collaborator

🔴 PR Severity: CRITICAL

New Esplora backend integration | 20 non-test files | ~4,644 lines changed

🔴 Critical (2 files)
  • lnwallet/btcwallet/blockchain.go (+17) - Wallet blockchain interface integration
  • lnwallet/btcwallet/btcwallet.go (+11/-3) - Core wallet operations modified
🟠 High (6 files)
  • chainntnfs/esploranotify/driver.go (+60) - New chain notification driver
  • chainntnfs/esploranotify/esplora.go (+886) - Chain notification implementation
  • chainntnfs/esploranotify/log.go (+23) - Chain notification logging
  • chainntnfs/txnotifier.go (+28) - Transaction notifier modifications
  • routing/chainview/esplora.go (+561) - Routing chain view for Esplora
  • chainreg/chainregistry.go (+79) - Chain registry integration
🟡 Medium (8 files)
  • esplora/chainclient.go (+1,735) - New chain client implementation
  • esplora/client.go (+900) - New Esplora API client
  • esplora/fee_estimator.go (+301) - Fee estimation for Esplora
  • esplora/scripthash.go (+86) - Script hash utilities
  • lncfg/chain.go (+1/-1) - Chain config modification
  • lncfg/esplora.go (+80) - New Esplora configuration
  • config.go (+13/-2) - Configuration changes
  • config_builder.go (+1) - Config builder update
🟢 Low (4 files)
  • sample-lnd.conf (+38) - Configuration documentation
  • log.go (+4) - Logging setup
🧪 Test Files (5 files, excluded from severity calculation)
  • esplora/chainclient_test.go (+481)
  • esplora/client_test.go (+395)
  • esplora/fee_estimator_test.go (+330)
  • esplora/scripthash_test.go (+170)
  • lnwallet/btcwallet/btcwallet_test.go (+3)

Analysis

This PR introduces a complete new blockchain backend (Esplora) as an alternative to btcd/bitcoind. The severity is CRITICAL because:

  1. Wallet Operations Modified: Changes to lnwallet/btcwallet/* directly affect wallet operations and blockchain interface integration, which is classified as critical infrastructure

  2. Large-Scale Integration: 20+ non-test files with ~4,644 lines of production code across multiple critical subsystems

  3. Multiple Critical Subsystems Affected:

    • lnwallet: Wallet blockchain interface
    • chainntnfs: Chain notification system (block/tx confirmations)
    • routing: Chain view for pathfinding
    • chainreg: Chain backend registry
  4. New Backend Architecture: Introducing an entirely new chain backend requires expert review to ensure:

    • Correct handling of chain reorganizations
    • Proper transaction and block notification delivery
    • Fee estimation accuracy
    • Wallet state consistency
    • No regressions in existing btcd/bitcoind backends

Recommendation: This PR requires thorough review by engineers with deep knowledge of LND's chain backend architecture, wallet operations, and chain notification systems. Consider splitting test coverage review separately from the core implementation review.


To override, add a severity-override-{critical,high,medium,low} label.

Optimize scanning watched outpoints by fetching entire block
transactions instead of making individual API calls.
@lightninglabs-deploy
Copy link
Collaborator

🔴 PR Severity: CRITICAL

Add support for esplora backend | 24 files | 6,250 lines changed

🔴 Critical (2 files)
  • lnwallet/btcwallet/blockchain.go - Wallet blockchain interface modifications
  • lnwallet/btcwallet/btcwallet.go - Core wallet operations changes
🟠 High (6 files)
  • chainntnfs/esploranotify/driver.go - New chain notification driver
  • chainntnfs/esploranotify/esplora.go - Esplora chain notification implementation (886 lines)
  • chainntnfs/esploranotify/log.go - Notification logging
  • chainntnfs/txnotifier.go - Transaction notifier modifications
  • chainreg/chainregistry.go - Chain registry updates
  • routing/chainview/esplora.go - Routing chain view for Esplora (585 lines)
🟡 Medium (8 files)
  • esplora/chainclient.go - New Esplora chain client (1,735 lines)
  • esplora/client.go - New Esplora client (900 lines)
  • esplora/fee_estimator.go - Fee estimation (301 lines)
  • esplora/scripthash.go - Script hash utilities (86 lines)
  • lncfg/chain.go - Chain configuration
  • lncfg/esplora.go - Esplora configuration (80 lines)
  • config.go - Main configuration updates
  • config_builder.go, log.go - Minor supporting changes
🟢 Low (1 file)
  • sample-lnd.conf - Configuration example updates
🧪 Test files (7 files)
  • lnwallet/btcwallet/btcwallet_test.go
  • esplora/chainclient_test.go (481 lines)
  • esplora/client_test.go (395 lines)
  • esplora/fee_estimator_test.go (330 lines)
  • esplora/scripthash_test.go (170 lines)

Analysis

This PR is classified as CRITICAL for the following reasons:

  1. Critical Package Modifications: Changes to lnwallet/btcwallet/* files which handle core wallet operations and blockchain interface - these are inherently critical components.

  2. New Blockchain Backend: Adds complete support for Esplora as an alternative blockchain backend, introducing a new subsystem (esplora/* package with ~3,100 lines of new code excluding tests).

  3. Multiple Critical Subsystems Affected:

    • Wallet layer (lnwallet/*)
    • Chain notifications (chainntnfs/*)
    • Routing chain view (routing/chainview/*)
    • Chain registry coordination
  4. Large Scale Change:

    • 20 non-test files modified/added
    • ~5,400 lines of production code (excluding tests)
    • Both metrics exceed the threshold for severity bump
  5. Integration Complexity: This change requires deep integration across multiple critical subsystems to provide an alternative way to interact with the Bitcoin blockchain.

Review Recommendations:

  • Expert review required for wallet integration points
  • Careful examination of chain notification event handling
  • Verification of blockchain data consistency with existing backends
  • Thorough testing of fee estimation logic
  • Review of error handling and edge cases in the new backend

To override, add a severity-override-{critical,high,medium,low} label.

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.

3 participants