lnd: github.com/lightningnetwork/lnd Index | Files | Directories

package lnd

import "github.com/lightningnetwork/lnd"

Index

Package Files

breacharbiter.go chainparams.go chainregistry.go chancloser.go channel_notifier.go chanrestore.go config.go doc.go fundingmanager.go lnd.go log.go mock.go nursery_store.go peer.go pilot.go rpcserver.go server.go subrpcserver_config.go test_utils.go utxonursery.go witness_beacon.go

Constants

const (

    // DefaultBitcoinBaseFeeMSat is the default forwarding base fee.
    DefaultBitcoinBaseFeeMSat = lnwire.MilliSatoshi(1000)

    // DefaultBitcoinFeeRate is the default forwarding fee rate.
    DefaultBitcoinFeeRate = lnwire.MilliSatoshi(1)

    // DefaultBitcoinTimeLockDelta is the default forwarding time lock
    // delta.
    DefaultBitcoinTimeLockDelta = 40
)
const (

    // DefaultMaxPendingChannels is the default maximum number of incoming
    // pending channels permitted per peer.
    DefaultMaxPendingChannels = 1

    // DefaultIncomingBroadcastDelta defines the number of blocks before the
    // expiry of an incoming htlc at which we force close the channel. We
    // only go to chain if we also have the preimage to actually pull in the
    // htlc. BOLT #2 suggests 7 blocks. We use a few more for extra safety.
    // Within this window we need to get our sweep or 2nd level success tx
    // confirmed, because after that the remote party is also able to claim
    // the htlc using the timeout path.
    DefaultIncomingBroadcastDelta = 10

    // DefaultOutgoingBroadcastDelta defines the number of blocks before the
    // expiry of an outgoing htlc at which we force close the channel. We
    // are not in a hurry to force close, because there is nothing to claim
    // for us. We do need to time the htlc out, because there may be an
    // incoming htlc that will time out too (albeit later). Bolt #2 suggests
    // a value of -1 here, but we allow one block less to prevent potential
    // confusion around the negative value. It means we force close the
    // channel at exactly the htlc expiry height.
    DefaultOutgoingBroadcastDelta = 0
)
const (

    // MaxBtcFundingAmount is a soft-limit of the maximum channel size
    // currently accepted on the Bitcoin chain within the Lightning
    // Protocol. This limit is defined in BOLT-0002, and serves as an
    // initial precautionary limit while implementations are battle tested
    // in the real world.
    MaxBtcFundingAmount = btcutil.Amount(1<<24) - 1
)
const UnassignedConnID uint64 = 0

UnassignedConnID is the default connection ID that a request can have before it actually is submitted to the connmgr. TODO(conner): move into connmgr package, or better, add connmgr method for generating atomic IDs

Variables

var (
    // ErrChanAlreadyClosing is returned when a channel shutdown is
    // attempted more than once.
    ErrChanAlreadyClosing = fmt.Errorf("channel shutdown already initiated")

    // ErrChanCloseNotFinished is returned when a caller attempts to access
    // a field or function that is contingent on the channel closure
    // negotiation already being completed.
    ErrChanCloseNotFinished = fmt.Errorf("close negotiation not finished")

    // ErrInvalidState is returned when the closing state machine receives
    // a message while it is in an unknown state.
    ErrInvalidState = fmt.Errorf("invalid state")
)
var (
    // MaxFundingAmount is a soft-limit of the maximum channel size
    // currently accepted within the Lightning Protocol. This limit is
    // defined in BOLT-0002, and serves as an initial precautionary limit
    // while implementations are battle tested in the real world.
    //
    // At the moment, this value depends on which chain is active. It is set
    // to the value under the Bitcoin chain as default.
    //
    // TODO(roasbeef): add command line param to modify
    MaxFundingAmount = MaxBtcFundingAmount

    // ErrFundingManagerShuttingDown is an error returned when attempting to
    // process a funding request/message but the funding manager has already
    // been signaled to shut down.
    ErrFundingManagerShuttingDown = errors.New("funding manager shutting " +
        "down")

    // ErrConfirmationTimeout is an error returned when we as a responder
    // are waiting for a funding transaction to confirm, but too many
    // blocks pass without confirmation.
    ErrConfirmationTimeout = errors.New("timeout waiting for funding " +
        "confirmation")
)
var (
    // ErrPeerNotConnected signals that the server has no connection to the
    // given peer.
    ErrPeerNotConnected = errors.New("peer is not connected")

    // ErrServerNotActive indicates that the server has started but hasn't
    // fully finished the startup process.
    ErrServerNotActive = errors.New("server is still in the process of " +
        "starting")

    // ErrServerShuttingDown indicates that the server is in the process of
    // gracefully exiting.
    ErrServerShuttingDown = errors.New("server is shutting down")
)
var (

    // ErrChannelNotFound is an error returned when a channel is not known
    // to us. In this case of the fundingManager, this error is returned
    // when the channel in question is not considered being in an opening
    // state.
    ErrChannelNotFound = fmt.Errorf("channel not found")
)
var (
    // ErrContractNotFound is returned when the nursery is unable to
    // retrieve information about a queried contract.
    ErrContractNotFound = fmt.Errorf("unable to locate contract")
)
var ErrImmatureChannel = errors.New("cannot remove immature channel, " +
    "still has ungraduated outputs")

ErrImmatureChannel signals a channel cannot be removed because not all of its outputs have graduated.

var (
    // MaxPaymentMSat is the maximum allowed payment currently permitted as
    // defined in BOLT-002. This value depends on which chain is active.
    // It is set to the value under the Bitcoin chain as default.
    MaxPaymentMSat = maxBtcPaymentMSat
)

func GetChanPointFundingTxid Uses

func GetChanPointFundingTxid(chanPoint *lnrpc.ChannelPoint) (*chainhash.Hash, error)

GetChanPointFundingTxid returns the given channel point's funding txid in raw bytes.

func Main Uses

func Main(lisCfg ListenerCfg) error

Main is the true entry point for lnd. This function is required since defers created in the top-level scope of a main method aren't executed if os.Exit() is called.

type BreachConfig Uses

type BreachConfig struct {
    // CloseLink allows the breach arbiter to shutdown any channel links for
    // which it detects a breach, ensuring now further activity will
    // continue across the link. The method accepts link's channel point and
    // a close type to be included in the channel close summary.
    CloseLink func(*wire.OutPoint, htlcswitch.ChannelCloseType)

    // DB provides access to the user's channels, allowing the breach
    // arbiter to determine the current state of a user's channels, and how
    // it should respond to channel closure.
    DB  *channeldb.DB

    // Estimator is used by the breach arbiter to determine an appropriate
    // fee level when generating, signing, and broadcasting sweep
    // transactions.
    Estimator chainfee.Estimator

    // GenSweepScript generates the receiving scripts for swept outputs.
    GenSweepScript func() ([]byte, error)

    // Notifier provides a publish/subscribe interface for event driven
    // notifications regarding the confirmation of txids.
    Notifier chainntnfs.ChainNotifier

    // PublishTransaction facilitates the process of broadcasting a
    // transaction to the network.
    PublishTransaction func(*wire.MsgTx) error

    // ContractBreaches is a channel where the breachArbiter will receive
    // notifications in the event of a contract breach being observed. A
    // ContractBreachEvent must be ACKed by the breachArbiter, such that
    // the sending subsystem knows that the event is properly handed off.
    ContractBreaches <-chan *ContractBreachEvent

    // Signer is used by the breach arbiter to generate sweep transactions,
    // which move coins from previously open channels back to the user's
    // wallet.
    Signer input.Signer

    // Store is a persistent resource that maintains information regarding
    // breached channels. This is used in conjunction with DB to recover
    // from crashes, restarts, or other failures.
    Store RetributionStore
}

BreachConfig bundles the required subsystems used by the breach arbiter. An instance of BreachConfig is passed to newBreachArbiter during instantiation.

type ContractBreachEvent Uses

type ContractBreachEvent struct {
    // ChanPoint is the channel point of the breached channel.
    ChanPoint wire.OutPoint

    // ProcessACK is an error channel where a nil error should be sent
    // iff the breach retribution info is safely stored in the retribution
    // store. In case storing the information to the store fails, a non-nil
    // error should be sent.
    ProcessACK chan error

    // BreachRetribution is the information needed to act on this contract
    // breach.
    BreachRetribution *lnwallet.BreachRetribution
}

ContractBreachEvent is an event the breachArbiter will receive in case a contract breach is observed on-chain. It contains the necessary information to handle the breach, and a ProcessACK channel we will use to ACK the event when we have safely stored all the necessary information.

type LinkUpdater Uses

type LinkUpdater interface {
    // TargetChanID returns the channel id of the link for which this
    // message is intended.
    TargetChanID() lnwire.ChannelID
}

LinkUpdater is an interface implemented by most messages in BOLT 2 that are allowed to update the channel state.

type ListenerCfg Uses

type ListenerCfg struct {
    // WalletUnlocker can be set to the listener to use for the wallet
    // unlocker. If nil a regular network listener will be created.
    WalletUnlocker net.Listener

    // RPCListener can be set to the listener to use for the RPC server. If
    // nil a regular network listener will be created.
    RPCListener net.Listener
}

ListenerCfg is a wrapper around custom listeners that can be passed to lnd when calling its main method.

type NurseryConfig Uses

type NurseryConfig struct {
    // ChainIO is used by the utxo nursery to determine the current block
    // height, which drives the incubation of the nursery's outputs.
    ChainIO lnwallet.BlockChainIO

    // ConfDepth is the number of blocks the nursery store waits before
    // determining outputs in the chain as confirmed.
    ConfDepth uint32

    // FetchClosedChannels provides access to a user's channels, such that
    // they can be marked fully closed after incubation has concluded.
    FetchClosedChannels func(pendingOnly bool) (
        []*channeldb.ChannelCloseSummary, error)

    // FetchClosedChannel provides access to the close summary to extract a
    // height hint from.
    FetchClosedChannel func(chanID *wire.OutPoint) (
        *channeldb.ChannelCloseSummary, error)

    // Notifier provides the utxo nursery the ability to subscribe to
    // transaction confirmation events, which advance outputs through their
    // persistence state transitions.
    Notifier chainntnfs.ChainNotifier

    // PublishTransaction facilitates the process of broadcasting a signed
    // transaction to the appropriate network.
    PublishTransaction func(*wire.MsgTx) error

    // Store provides access to and modification of the persistent state
    // maintained about the utxo nursery's incubating outputs.
    Store NurseryStore

    // Sweep sweeps an input back to the wallet.
    SweepInput func(input.Input, sweep.FeePreference) (chan sweep.Result, error)
}

NurseryConfig abstracts the required subsystems used by the utxo nursery. An instance of NurseryConfig is passed to newUtxoNursery during instantiation.

type NurseryStore Uses

type NurseryStore interface {
    // Incubate registers a set of CSV delayed outputs (incoming HTLC's on
    // our commitment transaction, or a commitment output), and a slice of
    // outgoing htlc outputs to be swept back into the user's wallet. The
    // event is persisted to disk, such that the nursery can resume the
    // incubation process after a potential crash.
    Incubate([]kidOutput, []babyOutput) error

    // CribToKinder atomically moves a babyOutput in the crib bucket to the
    // kindergarten bucket. Baby outputs are outgoing HTLC's which require
    // us to go to the second-layer to claim. The now mature kidOutput
    // contained in the babyOutput will be stored as it waits out the
    // kidOutput's CSV delay.
    CribToKinder(*babyOutput) error

    // PreschoolToKinder atomically moves a kidOutput from the preschool
    // bucket to the kindergarten bucket. This transition should be executed
    // after receiving confirmation of the preschool output. Incoming HTLC's
    // we need to go to the second-layer to claim, and also our commitment
    // outputs fall into this class.
    //
    // An additional parameter specifies the last graduated height. This is
    // used in case of late registration. It schedules the output for sweep
    // at the next epoch even though it has already expired earlier.
    PreschoolToKinder(kid *kidOutput, lastGradHeight uint32) error

    // GraduateKinder atomically moves an output at the provided height into
    // the graduated status. This involves removing the kindergarten entries
    // from both the height and channel indexes. The height bucket will be
    // opportunistically pruned from the height index as outputs are
    // removed.
    GraduateKinder(height uint32, output *kidOutput) error

    // FetchPreschools returns a list of all outputs currently stored in
    // the preschool bucket.
    FetchPreschools() ([]kidOutput, error)

    // FetchClass returns a list of kindergarten and crib outputs whose
    // timelocks expire at the given height.
    FetchClass(height uint32) ([]kidOutput, []babyOutput, error)

    // HeightsBelowOrEqual returns the lowest non-empty heights in the
    // height index, that exist at or below the provided upper bound.
    HeightsBelowOrEqual(height uint32) ([]uint32, error)

    // ForChanOutputs iterates over all outputs being incubated for a
    // particular channel point. This method accepts a callback that allows
    // the caller to process each key-value pair. The key will be a prefixed
    // outpoint, and the value will be the serialized bytes for an output,
    // whose type should be inferred from the key's prefix.
    ForChanOutputs(*wire.OutPoint, func([]byte, []byte) error) error

    // ListChannels returns all channels the nursery is currently tracking.
    ListChannels() ([]wire.OutPoint, error)

    // IsMatureChannel determines the whether or not all of the outputs in a
    // particular channel bucket have been marked as graduated.
    IsMatureChannel(*wire.OutPoint) (bool, error)

    // RemoveChannel channel erases all entries from the channel bucket for
    // the provided channel point, this method should only be called if
    // IsMatureChannel indicates the channel is ready for removal.
    RemoveChannel(*wire.OutPoint) error
}

NurseryStore abstracts the persistent storage layer for the utxo nursery. Concretely, it stores commitment and htlc outputs until any time-bounded constraints have fully matured. The store exposes methods for enumerating its contents, and persisting state transitions detected by the utxo nursery.

type RetributionStore Uses

type RetributionStore interface {
    // Add persists the retributionInfo to disk, using the information's
    // chanPoint as the key. This method should overwrite any existing
    // entries found under the same key, and an error should be raised if
    // the addition fails.
    Add(retInfo *retributionInfo) error

    // IsBreached queries the retribution store to see if the breach arbiter
    // is aware of any breaches for the provided channel point.
    IsBreached(chanPoint *wire.OutPoint) (bool, error)

    // Finalize persists the finalized justice transaction for a particular
    // channel.
    Finalize(chanPoint *wire.OutPoint, finalTx *wire.MsgTx) error

    // GetFinalizedTxn loads the finalized justice transaction, if any, from
    // the retribution store. The finalized transaction will be nil if
    // Finalize has not yet been called for this channel point.
    GetFinalizedTxn(chanPoint *wire.OutPoint) (*wire.MsgTx, error)

    // Remove deletes the retributionInfo from disk, if any exists, under
    // the given key. An error should be re raised if the removal fails.
    Remove(key *wire.OutPoint) error

    // ForAll iterates over the existing on-disk contents and applies a
    // chosen, read-only callback to each. This method should ensure that it
    // immediately propagate any errors generated by the callback.
    ForAll(cb func(*retributionInfo) error) error
}

RetributionStore provides an interface for managing a persistent map from wire.OutPoint -> retributionInfo. Upon learning of a breach, a BreachArbiter should record the retributionInfo for the breached channel, which serves a checkpoint in the event that retribution needs to be resumed after failure. A RetributionStore provides an interface for managing the persisted set, as well as mapping user defined functions over the entire on-disk contents.

Calls to RetributionStore may occur concurrently. A concrete instance of RetributionStore should use appropriate synchronization primitives, or be otherwise safe for concurrent access.

type WalletUnlockParams Uses

type WalletUnlockParams struct {
    // Password is the public and private wallet passphrase.
    Password []byte

    // Birthday specifies the approximate time that this wallet was created.
    // This is used to bound any rescans on startup.
    Birthday time.Time

    // RecoveryWindow specifies the address lookahead when entering recovery
    // mode. A recovery will be attempted if this value is non-zero.
    RecoveryWindow uint32

    // Wallet is the loaded and unlocked Wallet. This is returned
    // from the unlocker service to avoid it being unlocked twice (once in
    // the unlocker service to check if the password is correct and again
    // later when lnd actually uses it). Because unlocking involves scrypt
    // which is resource intensive, we want to avoid doing it twice.
    Wallet *wallet.Wallet

    // ChansToRestore a set of static channel backups that should be
    // restored before the main server instance starts up.
    ChansToRestore walletunlocker.ChannelsToRecover
}

WalletUnlockParams holds the variables used to parameterize the unlocking of lnd's wallet after it has already been created.

Directories

PathSynopsis
aezeed
autopilot
brontide
buffer
build
cert
chainntnfs
chainntnfs/bitcoindnotify
chainntnfs/btcdnotify
chainntnfs/neutrinonotify
chanacceptor
chanbackup
chanfitnessPackage chanfitness monitors the behaviour of channels to provide insight into the health and performance of a channel.
channeldb
channeldb/migration_01_to_11
channeldb/migration12
channeldb/migtest
channelnotifier
contractcourt
discovery
feature
htlcswitch
htlcswitch/hodl
htlcswitch/hop
input
invoices
keychain
lncfg
lnpeer
lnrpcPackage lnrpc is a reverse proxy.
lnrpc/autopilotrpc
lnrpc/chainrpc
lnrpc/invoicesrpc
lnrpc/routerrpc
lnrpc/signrpc
lnrpc/walletrpc
lnrpc/watchtowerrpc
lnrpc/wtclientrpc
lntestPackage lntest provides testing utilities for the lnd repository.
lntest/wait
lntypes
lnwallet
lnwallet/btcwallet
lnwallet/chainfee
lnwallet/chanfunding
lnwallet/chanvalidate
lnwire
macaroons
monitoring
multimutex
nat
netann
peernotifier
pool
queue
record
routing
routing/chainview
routing/localchans
routing/route
shachain
signal
subscribe
sweep
ticker
tlv
tor
walletunlocker
watchtower
watchtower/blob
watchtower/lookout
watchtower/wtclient
watchtower/wtdb
watchtower/wtmock
watchtower/wtpolicy
watchtower/wtserver
watchtower/wtwire
zpay32

Package lnd imports 123 packages (graph) and is imported by 4 packages. Updated 2019-12-06. Refresh now. Tools for package owners.