Documentation
¶
Index ¶
- Constants
- Variables
- func DisableLog()
- func NewBoltSwapStore(dbPath string, chainParams *chaincfg.Params) (*boltSwapStore, error)
- func UseLogger(logger btclog.Logger)
- type Loop
- type LoopEvent
- type LoopIn
- type LoopInContract
- type LoopOut
- type LoopOutContract
- type SwapContract
- type SwapState
- type SwapStateType
- type SwapStore
Constants ¶
const ( // StateInitiated is the initial state of a swap. At that point, the // initiation call to the server has been made and the payment process // has been started for the swap and prepayment invoices. StateInitiated SwapState = 0 // StatePreimageRevealed is reached when the sweep tx publication is // first attempted. From that point on, we should consider the preimage // to no longer be secret and we need to do all we can to get the sweep // confirmed. This state will mostly coalesce with StateHtlcConfirmed, // except in the case where we wait for fees to come down before we // sweep. StatePreimageRevealed = 1 // StateSuccess is the final swap state that is reached when the sweep // tx has the required confirmation depth (SweepConfDepth) and the // server pulled the off-chain htlc. StateSuccess = 2 // StateFailOffchainPayments indicates that it wasn't possible to find // routes for one or both of the off-chain payments to the server that // satisfied the payment restrictions (fee and timelock limits). StateFailOffchainPayments = 3 // StateFailTimeout indicates that the on-chain htlc wasn't confirmed // before its expiry or confirmed too late (MinPreimageRevealDelta // violated). StateFailTimeout = 4 // StateFailSweepTimeout indicates that the on-chain htlc wasn't swept // before the server revoked the htlc. The server didn't pull the // off-chain htlc (even though it could have) and we timed out the // off-chain htlc ourselves. No funds lost. StateFailSweepTimeout = 5 // StateFailInsufficientValue indicates that the published on-chain htlc // had a value lower than the requested amount. StateFailInsufficientValue = 6 // StateFailTemporary indicates that the swap cannot progress because // of an internal error. This is not a final state. Manual intervention // (like a restart) is required to solve this problem. StateFailTemporary = 7 // StateHtlcPublished means that the client published the on-chain htlc. StateHtlcPublished = 8 // StateInvoiceSettled means that the swap invoice has been paid by the // server. StateInvoiceSettled = 9 )
const ( // StateTypePending indicates that the swap is still pending. StateTypePending SwapStateType = 0 // StateTypeSuccess indicates that the swap has completed successfully. StateTypeSuccess = 1 // StateTypeFail indicates that the swap has failed. StateTypeFail = 2 )
Variables ¶
var ( // ErrDBReversion is returned when detecting an attempt to revert to a // prior database version. ErrDBReversion = fmt.Errorf("channel db cannot revert to prior version") )
Functions ¶
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.
func NewBoltSwapStore ¶
NewBoltSwapStore creates a new client swap store.
Types ¶
type Loop ¶
Loop contains fields shared between LoopIn and LoopOut
func (*Loop) LastUpdate ¶
LastUpdate returns the most recent update of this swap.
type LoopEvent ¶
type LoopEvent struct {
// State is the new state for this swap as a result of this event.
State SwapState
// Time is the time that this swap had its state changed.
Time time.Time
}
LoopEvent contains the dynamic data of a swap.
type LoopIn ¶
type LoopIn struct {
Loop
Contract *LoopInContract
}
LoopIn is a combination of the contract and the updates.
func (*LoopIn) LastUpdateTime ¶
LastUpdateTime returns the last update time of this swap.
type LoopInContract ¶
type LoopInContract struct {
SwapContract
// SweepConfTarget specifies the targeted confirmation target for the
// client sweep tx.
HtlcConfTarget int32
// LoopInChannel is the channel to charge. If zero, any channel may
// be used.
LoopInChannel *uint64
// ExternalHtlc specifies whether the htlc is published by an external
// source.
ExternalHtlc bool
}
LoopInContract contains the data that is serialized to persistent storage for pending loop in swaps.
type LoopOut ¶
type LoopOut struct {
Loop
// Contract is the active contract for this swap. It describes the
// precise details of the swap including the final fee, CLTV value,
// etc.
Contract *LoopOutContract
}
LoopOut is a combination of the contract and the updates.
func (*LoopOut) LastUpdateTime ¶
LastUpdateTime returns the last update time of this swap.
type LoopOutContract ¶
type LoopOutContract struct {
// SwapContract contains basic information pertaining to this swap.
// Each swap type has a base contract, then swap specific information
// on top of it.
SwapContract
// DestAddr is the destination address of the loop out swap.
DestAddr btcutil.Address
// SwapInvoice is the invoice that is to be paid by the client to
// initiate the loop out swap.
SwapInvoice string
// MaxSwapRoutingFee is the maximum off-chain fee in msat that may be
// paid for the swap payment to the server.
MaxSwapRoutingFee btcutil.Amount
// SweepConfTarget specifies the targeted confirmation target for the
// client sweep tx.
SweepConfTarget int32
// TargetChannel is the channel to loop out. If zero, any channel may
// be used.
UnchargeChannel *uint64
// PrepayInvoice is the invoice that the client should pay to the
// server that will be returned if the swap is complete.
PrepayInvoice string
// MaxPrepayRoutingFee is the maximum off-chain fee in msat that may be
// paid for the prepayment to the server.
MaxPrepayRoutingFee btcutil.Amount
}
LoopOutContract contains the data that is serialized to persistent storage for pending swaps.
type SwapContract ¶
type SwapContract struct {
// Preimage is the preimage for the swap.
Preimage lntypes.Preimage
// AmountRequested is the total amount of the swap.
AmountRequested btcutil.Amount
// SenderKey is the key of the sender that will be used in the on-chain
// HTLC.
SenderKey [33]byte
// ReceiverKey is the of the receiver that will be used in the on-chain
// HTLC.
ReceiverKey [33]byte
// CltvExpiry is the total absolute CLTV expiry of the swap.
CltvExpiry int32
// MaxSwapFee is the maximum we are willing to pay the server for the
// swap.
MaxSwapFee btcutil.Amount
// MaxMinerFee is the maximum in on-chain fees that we are willing to
// spend.
MaxMinerFee btcutil.Amount
// InitiationHeight is the block height at which the swap was
// initiated.
InitiationHeight int32
// InitiationTime is the time at which the swap was initiated.
InitiationTime time.Time
}
SwapContract contains the base data that is serialized to persistent storage for pending swaps.
type SwapState ¶
type SwapState uint8
SwapState indicates the current state of a swap. This enumeration is the union of loop in and loop out states. A single type is used for both swap types to be able to reduce code duplication that would otherwise be required.
func (SwapState) Type ¶
func (s SwapState) Type() SwapStateType
Type returns the type of the SwapState it is called on.
type SwapStateType ¶
type SwapStateType uint8
SwapStateType defines the types of swap states that exist. Every swap state defined as type SwapState above, falls into one of these SwapStateType categories.
type SwapStore ¶
type SwapStore interface {
// FetchLoopOutSwaps returns all swaps currently in the store.
FetchLoopOutSwaps() ([]*LoopOut, error)
// CreateLoopOut adds an initiated swap to the store.
CreateLoopOut(hash lntypes.Hash, swap *LoopOutContract) error
// UpdateLoopOut stores a new event for a target loop out swap. This
// appends to the event log for a particular swap as it goes through
// the various stages in its lifetime.
UpdateLoopOut(hash lntypes.Hash, time time.Time, state SwapState) error
// FetchLoopInSwaps returns all swaps currently in the store.
FetchLoopInSwaps() ([]*LoopIn, error)
// CreateLoopIn adds an initiated swap to the store.
CreateLoopIn(hash lntypes.Hash, swap *LoopInContract) error
// UpdateLoopIn stores a new event for a target loop in swap. This
// appends to the event log for a particular swap as it goes through
// the various stages in its lifetime.
UpdateLoopIn(hash lntypes.Hash, time time.Time, state SwapState) error
// Close closes the underlying database.
Close() error
}
SwapStore is the primary database interface used by the loopd system. It houses information for all pending completed/failed swaps.