Documentation ¶
Index ¶
- Constants
- Variables
- func CurrentRPCProtocolVersion() looprpc.ProtocolVersion
- func EnableExperimentalProtocol()
- func MarshalKeyLocator(keyLocator keychain.KeyLocator) ([]byte, error)
- func MarshalProtocolVersion(version ProtocolVersion) []byte
- func NewBoltSwapStore(dbPath string, chainParams *chaincfg.Params) (*boltSwapStore, error)
- func ResetCurrentProtocolVersion()
- func UnmarshalKeyLocator(data []byte) (keychain.KeyLocator, error)
- func UseLogger(logger btclog.Logger)
- type ChannelSet
- type HtlcKeys
- type Loop
- type LoopEvent
- type LoopIn
- type LoopInContract
- type LoopOut
- type LoopOutContract
- type ProtocolVersion
- type SwapContract
- type SwapCost
- type SwapState
- type SwapStateData
- type SwapStateType
- type SwapStore
Constants ¶
const ( // DefaultLoopOutHtlcConfirmations is the default number of // confirmations we set for a loop out htlc. DefaultLoopOutHtlcConfirmations uint32 = 1 // DefaultLoopDBTimeout is the default maximum time we wait for the // Loop bbolt database to be opened. If the database is already opened // by another process, the unique lock cannot be obtained. With the // timeout we error out after the given time instead of just blocking // for forever. DefaultLoopDBTimeout = 5 * time.Second )
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 CurrentRPCProtocolVersion ¶
func CurrentRPCProtocolVersion() looprpc.ProtocolVersion
CurrentRPCProtocolVersion returns the RPC protocol version selected to be used for new swaps.
func EnableExperimentalProtocol ¶
func EnableExperimentalProtocol()
EnableExperimentalProtocol sets the current protocol version to include all experimental features. Do not call this function directly: used in loopd and unit tests only.
func MarshalKeyLocator ¶
func MarshalKeyLocator(keyLocator keychain.KeyLocator) ([]byte, error)
MarshalKeyLocator marshals a keychain.KeyLocator to a byte slice.
func MarshalProtocolVersion ¶
func MarshalProtocolVersion(version ProtocolVersion) []byte
MarshalProtocolVersion marshals a ProtocolVersion value to a byte slice.
func NewBoltSwapStore ¶
NewBoltSwapStore creates a new client swap store.
func ResetCurrentProtocolVersion ¶
func ResetCurrentProtocolVersion()
ResetCurrentProtocolVersion resets the current protocol version to the stable protocol. Note: used in integration tests only!
func UnmarshalKeyLocator ¶
func UnmarshalKeyLocator(data []byte) (keychain.KeyLocator, error)
UnmarshalKeyLocator unmarshals a keychain.KeyLocator from a byte slice.
Types ¶
type ChannelSet ¶
type ChannelSet []uint64
ChannelSet stores a set of channels.
func NewChannelSet ¶
func NewChannelSet(set []uint64) (ChannelSet, error)
NewChannelSet instantiates a new channel set and verifies that there are no duplicates present.
func (ChannelSet) String ¶
func (c ChannelSet) String() string
String returns the human-readable representation of a channel set.
type HtlcKeys ¶
type HtlcKeys struct { // SenderScriptKey is the sender's public key that is used in the HTLC, // specifically when constructing the script spend scripts. SenderScriptKey [33]byte // SenderInternalPubKey is the sender's internal pubkey that is used in // taproot HTLCs as part of the aggregate internal key. SenderInternalPubKey [33]byte // ReceiverScriptKey is the receiver's public key that is used in the // HTLC, specifically when constructing the script spend scripts. ReceiverScriptKey [33]byte // ReceiverInternalPubKey is the sender's internal pubkey that is used // in taproot HTLCs as part of the aggregate internal key. ReceiverInternalPubKey [33]byte // ClientScriptKeyLocator is the client's key locator for the key used // in the HTLC script spend scripts. ClientScriptKeyLocator keychain.KeyLocator }
HtlcKeys is a holder of all keys used when constructing the swap HTLC. Since it's used for both loop in and loop out swaps it may hold partial information about the sender or receiver depending on the swap type.
type Loop ¶
Loop contains fields shared between LoopIn and LoopOut.
func (*Loop) LastUpdate ¶
LastUpdate returns the most recent update of this swap.
func (*Loop) State ¶
func (s *Loop) State() SwapStateData
State returns the most recent state of this swap.
type LoopEvent ¶
type LoopEvent struct { SwapStateData // 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 // LastHop is the last hop to use for the loop in swap (optional). LastHop *route.Vertex // 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 // HtlcConfirmations is the number of confirmations we require the on // chain htlc to have before proceeding with the swap. HtlcConfirmations uint32 // OutgoingChanSet is the set of short ids of channels that may be used. // If empty, any channel may be used. OutgoingChanSet ChannelSet // 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 // SwapPublicationDeadline is a timestamp that the server commits to // have the on-chain swap published by. It is set by the client to // allow the server to delay the publication in exchange for possibly // lower fees. SwapPublicationDeadline time.Time }
LoopOutContract contains the data that is serialized to persistent storage for pending swaps.
type ProtocolVersion ¶
type ProtocolVersion uint32
ProtocolVersion represents the protocol version (declared on rpc level) that the client declared to us.
const ( // ProtocolVersionLegacy indicates that the client is a legacy version // that did not report its protocol version. ProtocolVersionLegacy ProtocolVersion = 0 // ProtocolVersionMultiLoopOut indicates that the client supports multi // loop out. ProtocolVersionMultiLoopOut ProtocolVersion = 1 // ProtocolVersionSegwitLoopIn indicates that the client supports segwit // loop in. ProtocolVersionSegwitLoopIn ProtocolVersion = 2 // ProtocolVersionPreimagePush indicates that the client will push loop // out preimages to the sever to speed up claim. ProtocolVersionPreimagePush ProtocolVersion = 3 // ProtocolVersionUserExpiryLoopOut indicates that the client will // propose a cltv expiry height for loop out. ProtocolVersionUserExpiryLoopOut ProtocolVersion = 4 // ProtocolVersionHtlcV2 indicates that the client will use the new // HTLC v2 scrips for swaps. ProtocolVersionHtlcV2 ProtocolVersion = 5 // ProtocolVersionMultiLoopIn indicates that the client creates a probe // invoice so that the server can perform a multi-path probe. ProtocolVersionMultiLoopIn ProtocolVersion = 6 // ProtocolVersionLoopOutCancel indicates that the client supports // canceling loop out swaps. ProtocolVersionLoopOutCancel = 7 // ProtocolVerionProbe indicates that the client is able to request // the server to perform a probe to test inbound liquidty. ProtocolVersionProbe ProtocolVersion = 8 // The client may ask the server to use a custom routing helper plugin // in order to enhance off-chain payments corresponding to a swap. ProtocolVersionRoutingPlugin = 9 // ProtocolVersionHtlcV3 indicates that the client will now use the new // HTLC v3 (P2TR) script for swaps. ProtocolVersionHtlcV3 = 10 // ProtocolVersionMuSig2 will enable MuSig2 signature scheme for loops. ProtocolVersionMuSig2 ProtocolVersion = 11 // ProtocolVersionUnrecorded is set for swaps were created before we // started saving protocol version with swaps. ProtocolVersionUnrecorded ProtocolVersion = math.MaxUint32 )
func CurrentProtocolVersion ¶
func CurrentProtocolVersion() ProtocolVersion
CurrentProtocolVersion returns the internal protocol version selected to be used for new swaps.
func UnmarshalProtocolVersion ¶
func UnmarshalProtocolVersion(b []byte) (ProtocolVersion, error)
UnmarshalProtocolVersion attempts to unmarshal a byte slice to a ProtocolVersion value. If the unmarshal fails, ProtocolVersionUnrecorded is returned along with an error.
func (ProtocolVersion) String ¶
func (p ProtocolVersion) String() string
String returns the string representation of a protocol version.
func (ProtocolVersion) Valid ¶
func (p ProtocolVersion) Valid() bool
Valid returns true if the value of the ProtocolVersion is valid.
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 // HtlcKeys holds all keys used in the swap HTLC construction. HtlcKeys HtlcKeys // 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 // Label contains an optional label for the swap. Label string // ProtocolVersion stores the protocol version when the swap was // created. ProtocolVersion ProtocolVersion }
SwapContract contains the base data that is serialized to persistent storage for pending swaps.
type SwapCost ¶
type SwapCost struct { // Swap is the amount paid to the server. Server btcutil.Amount // Onchain is the amount paid to miners for the onchain tx. Onchain btcutil.Amount // Offchain is the amount paid in routing fees. Offchain btcutil.Amount }
SwapCost is a breakdown of the final swap costs.
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.
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 SwapState = 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 SwapState = 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 SwapState = 3 // StateFailTimeout indicates that the on-chain htlc wasn't confirmed // before its expiry or confirmed too late (MinPreimageRevealDelta // violated). StateFailTimeout SwapState = 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 SwapState = 5 // StateFailInsufficientValue indicates that the published on-chain htlc // had a value lower than the requested amount. StateFailInsufficientValue SwapState = 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 SwapState = 7 // StateHtlcPublished means that the client published the on-chain htlc. StateHtlcPublished SwapState = 8 // StateInvoiceSettled means that the swap invoice has been paid by the // server. StateInvoiceSettled SwapState = 9 // StateFailIncorrectHtlcAmt indicates that the amount of an externally // published loop in htlc didn't match the swap amount. StateFailIncorrectHtlcAmt SwapState = 10 )
func (SwapState) Type ¶
func (s SwapState) Type() SwapStateType
Type returns the type of the SwapState it is called on.
type SwapStateData ¶
type SwapStateData struct { // SwapState is the state the swap is in. State SwapState // Cost are the accrued (final) costs so far. Cost SwapCost // HtlcTxHash is the tx id of the confirmed htlc. HtlcTxHash *chainhash.Hash }
SwapStateData is all persistent data to describe the current swap state.
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) // FetchLoopOutSwap returns the loop out swap with the given hash. FetchLoopOutSwap(hash lntypes.Hash) (*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 SwapStateData) 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 SwapStateData) error // PutLiquidityParams writes the serialized `manager.Parameters` bytes // into the bucket. // // NOTE: it's the caller's responsibility to encode the param. Atm, // it's encoding using the proto package's `Marshal` method. PutLiquidityParams(params []byte) error // FetchLiquidityParams reads the serialized `manager.Parameters` bytes // from the bucket. // // NOTE: it's the caller's responsibility to decode the param. Atm, // it's decoding using the proto package's `Unmarshal` method. FetchLiquidityParams() ([]byte, 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.