Builder's Guide
  • Welcome to the Builder's Guide to the LND Galaxy!
  • The Lightning Network
    • Overview
    • Payment Channels
      • Lifecycle of a Payment Channel
      • Watchtowers
      • Understanding Sweeping
      • Etymology
    • The Gossip Network
      • Identifying Good Peers on the Lightning Network
    • Pathfinding
      • Finding routes in the Lightning Network
      • Channel Fees
      • Multipath Payments (MPP)
    • Lightning Network Invoices
      • Understanding Lightning Invoices
    • Making Payments
      • The Payment Cycle
      • Timelocks
      • ⭐Hashed Timelock Contract (HTLC)
      • Payment Etymology
      • ⭐What Makes a Good Routing Node
      • Understanding Submarine Swaps
      • Instant Submarine Swaps
    • Liquidity
      • ⭐Understanding Liquidity
      • Managing Liquidity on the Lightning Network
      • Liquidity Management for Lightning Merchants
      • How to Get Inbound Capacity on the Lightning Network
      • Lightning Service Provider
    • L402: Lightning HTTP 402 Protocol
      • Macaroons
      • L402
      • 📋Protocol Specification
      • Implementations and Links
    • Taproot Assets
      • Taproot Assets Protocol
      • Taproot Assets on Lightning
      • Edge Nodes
      • Taproot Assets Trustless Swap
      • FAQ
      • Glossary
  • Lightning Network Tools
    • LND
      • 🛠️Get Started
      • lnd.conf
      • First Steps With LND
      • Wallet Management
      • Sending Payments
      • Atomic Multi-path Payments (AMP)
      • Receiving Payments
      • Unconfirmed Bitcoin Transactions
      • Channel Fees
      • Inbound Channel Fees
      • Macaroons
      • Configuring Watchtowers
      • Pathfinding
      • Blinded Paths
      • Key Import
      • Secure Your Lightning Network Node
      • Configuration of a Routing Node
      • Quick Tor Setup
      • Configuring Tor
      • Enable ‘Neutrino mode’ in Bitcoin Core
      • Send Messages With Keysend
      • Partially Signed Bitcoin Transactions
      • Bulk onchain actions with PSBTs
      • Sweeper
      • Debugging LND
      • Fuzzing LND
      • LND API documentation
      • Channel Acceptor
      • RPC Middleware Interceptor
      • HTLC Interceptor
      • NAT Traversal
      • Recovery: Planning for Failure
      • Migrating LND
      • Disaster recovery
      • Contribute to LND
    • Lightning Terminal
      • What is Lightning Terminal?
      • 🛠️Get litd
      • Run litd
      • Integrating litd
      • Demo: Litd Speed Run
      • Connect to Terminal
      • Recommended Channels
      • Rankings
      • Health Checks
      • Liquidity Report
      • Opening Lightning Network Channels
      • Managing Channel Liquidity
      • Autofees
      • AutoOpen
      • LND Accounts
      • Loop and Lightning Terminal
      • Loop Fees
      • Pool and Lightning Terminal
      • Command Line Interface
      • Troubleshooting
      • Lightning Node Connect: Under the hood
      • LNC Node Package
      • LITD API Documentation
      • Privacy and Security
      • Privacy Policy
      • Terms of Use
    • Loop
      • 🛠️Get Started
      • The Loop CLI
      • Autoloop
      • Static Loop In Addresses
      • Instant Loop Outs
      • Peer with Loop
      • Loop API Documentation
    • Pool
      • Overview
      • Quickstart
      • 🛠️Installation
      • First Steps
      • Accounts
      • Orders and Asks
      • Sidecar Channels
      • Zero-confirmation Channels
      • Channel Leases
      • Batch Execution
      • Account Recovery
      • Pool API Documentation
      • FAQs
    • Taproot Assets
      • Get Started
      • First Steps
      • Taproot Assets Channels
      • Asset Decimal Display
      • Become an Edge Node
      • RFQ
      • Collectibles
      • Universes
      • Asset Loop
      • Debugging Tapd
      • Multisignature
      • Minting Assets With an External Signer
      • Lightning Polar
      • Operational Safety Guidelines
      • Taproot Assets API Documentation
    • Aperture
      • ⚒️Get Aperture
      • LNC Backend
      • LNC Mailbox
      • Pricing
    • Faraday
      • 🛠️Get Started
      • The Faraday CLI
      • Faraday API Documentation
  • LAPPs
    • Guides
      • Use Polar to Build Your First LAPP
        • Setup: Local Cluster with Polar
        • Setup: Run the Completed App
        • Setup: Run the App Without LND
      • Add Features
        • Feature 1: Connect to LND
        • Feature 2: Display Node Alias and Balance
        • Feature 3: Sign and Verify Posts
        • Feature 4: Modify Upvote Action
      • Make Your own LNC-powered Application
    • Next Steps
  • Community Resources
    • Resource List
    • Lightning Bulb 💡
    • Glossary
    • FAQ
Powered by GitBook
On this page
  • Types of funds that need to be swept
  • Local force closure
  • Remote force closure
  • Anchors
  • Incoming HTLCs
  • Outgoing HTLCs
  • Loop In
  • Loop Out
  • Batch sweeping
  • LNCLI

Was this helpful?

  1. The Lightning Network
  2. Payment Channels

Understanding Sweeping

Sweeps are transactions from specialized scripts back into your main wallet. They are used in various contexts throughout the Lightning Network.

PreviousWatchtowersNextEtymology

Last updated 1 year ago

Was this helpful?

In the context of running a Lightning Network node, the term Sweeping refers to transferring Bitcoin from specialized scripts into the node’s main on-chain wallet.

The primary need for sweeping arises from timeouts in scripts used in the Lightning Network. Funds have to be moved within a certain amount of time, or else they may be sweeped by the channel peer.

Additionally there is also the limitation that not all addresses are hierarchically generated, meaning not all addresses can be recovered using the node’s seed phrase alone. To prevent funds from being unrecoverable in the event of data loss, they are swept to an address that can be recovered purely from the seed phrase.

Types of funds that need to be swept

There are several distinct situations in which funds have to be swept.

Local force closure

When your node publishes the commitment transaction for a channel, the local balance is sent to an arbitration contract, from where your node is able to sweep the funds after a minimum amount of time has passed.

This sweep requires your node’s signature.

Remote force closure

When a peer force closes on you, your funds can be swept after the force closure transaction is included in a block.

This sweep requires your node’s signature.

In the event in which your peer publishes an invalid commitment transaction, you are able to sweep their balance into your wallet within the pre-defined arbitration period using a revocation key.

This sweep requires your node’s signature and the revocation key.

Anchors

When an anchor channel is force-closed, for each channel party that has a non-dust balance an anchor of 330 satoshis is created. These anchors can be swept within 16 blocks by you, or by anyone else after to prevent the UTXO set from bloating. The main purpose of these anchors is to give either party an opportunity to increase the fee of the commitment transaction using CPFP (Child Pays for Parent).

Before 16 blocks, this sweep requires your node’s signature. After 16 blocks, the sweep does not require any signature, meaning others can sweep your anchors, too.

Incoming HTLCs

When your peer force closes your channel, and this closure transaction contains an HTLC paid to you for which you have the preimage, you will need to claim these funds by sweeping the HTLC within a predefined arbitration period.

This sweep requires your node’s signature and the preimage of the HTLC.

Outgoing HTLCs

If your node closes a channel by publishing a commitment transaction that contains an outgoing HTLC, your peer has the opportunity to claim this HTLC using the preimage.

If the peer does not possess the preimage, or does not respond within the CLTV time limit, your node uses a pre-signed transaction to move HTLC into another address, from where your peer gets the opportunity to claim the funds using the revocation key in case your node is publishing a breaching force closure transaction.

After this “second stage” (CLTV) expires, your node can finally sweep the funds back into its main wallet.

This sweep requires your node’s signature.

Loop In

If a Loop In were to fail, for example because the off-chain funds couldn’t be delivered to the destination node, the funds have to be swept back into your on-chain wallet after a timeout.

This sweep requires your node’s signature.

Loop Out

When performing a Loop Out, meaning to swap off-chain funds into your on-chain wallet, the swap contract has to be swept by the recipient of the on-chain funds using the preimage of the off-chain payment.

This sweep requires your node’s signature and the preimage of the offchain payment.

Batch sweeping

Sweeps can be batched to save on on-chain fees. If your node needs to frequently perform sweeps you may increase the following setting to something higher, for instance an hour.

sweeper.batchwindowduration=10m

LNCLI

Pending sweeps can be inspected with the command:

lncli wallet pendingsweeps

All performed sweeps can be inspected with:

lncli wallet listsweeps

Not all sweeps are economical. In cases where the sweep amount is smaller than the sweep fees, LND will not attempt the sweep right away, and instead wait for fees to go down.

Read also: Timelocks
Read also: Hashed Timelock Contracts
Read also: Understanding Submarine swaps