Documentation ¶
Index ¶
- Constants
- Variables
- type AcceptCallback
- type FailResolutionResult
- type HtlcFailResolution
- type HtlcResolution
- type HtlcSettleResolution
- type Invoice
- type InvoiceCallback
- type InvoiceCreator
- func (c *InvoiceCreator) Create(amtMSat int64, expiry time.Duration, memo string, descHash *lntypes.Hash, ...) (*Invoice, lntypes.Preimage, error)
- func (c *InvoiceCreator) Network() *chaincfg.Params
- func (c *InvoiceCreator) NodePubKeys() []*btcec.PublicKey
- func (c *InvoiceCreator) PubKey() *btcec.PublicKey
- type InvoiceCreatorConfig
- type InvoiceRegistry
- func (i *InvoiceRegistry) AutoSettle() bool
- func (i *InvoiceRegistry) CancelInvoice(hash lntypes.Hash, setID SetID) error
- func (i *InvoiceRegistry) NotifyExitHopHtlc(h *registryHtlc)
- func (i *InvoiceRegistry) RequestSettle(hash lntypes.Hash, setID SetID) error
- func (i *InvoiceRegistry) Run(ctx context.Context) error
- func (i *InvoiceRegistry) SubscribeAccept(callback AcceptCallback) (func(), error)
- type InvoiceUpdate
- type KeyRing
- func (b *KeyRing) DeriveKey(keyLoc keychain.KeyLocator) (keychain.KeyDescriptor, error)
- func (b *KeyRing) DeriveNextKey(keyFam keychain.KeyFamily) (keychain.KeyDescriptor, error)
- func (b *KeyRing) DerivePrivKey(keyDesc keychain.KeyDescriptor) (*btcec.PrivateKey, error)
- func (b *KeyRing) ECDH(keyDesc keychain.KeyDescriptor, pub *btcec.PublicKey) ([32]byte, error)
- func (b *KeyRing) SignMessage(keyLoc keychain.KeyLocator, msg []byte, doubleHash bool) (*ecdsa.Signature, error)
- func (b *KeyRing) SignMessageCompact(keyLoc keychain.KeyLocator, msg []byte, doubleHash bool) ([]byte, error)
- type Mux
- type MuxConfig
- type Payload
- type RegistryConfig
- type RoutingPolicy
- type SetID
- type SettleResolutionResult
- type SettledHandler
- type SettledHandlerConfig
Constants ¶
const DefaultGracePeriodWithoutSubscribers = 30 * time.Second
DefaultGracePeriodWithoutSubscribers is the default period during which the subscriberManager is waiting for a subscriber to reconnect.
const ( // DefaultHtlcHoldDuration defines the default for how long mpp htlcs // are held while waiting for the other set members to arrive. DefaultHtlcHoldDuration = 120 * time.Second )
Variables ¶
var ( // ErrInvoiceAlreadyCanceled is returned when the invoice is already // canceled. ErrInvoiceAlreadyCanceled = errors.New("invoice already canceled") // ErrInvoiceCannotOpen is returned when an attempt is made to move an // invoice to the open state. ErrInvoiceCannotOpen = errors.New("cannot move invoice to open") // ErrInvoiceCannotAccept is returned when an attempt is made to accept // an invoice while the invoice is not in the open state. ErrInvoiceCannotAccept = errors.New("cannot accept invoice") // ErrInvoicePreimageMismatch is returned when the preimage doesn't // match the invoice hash. ErrInvoicePreimageMismatch = errors.New("preimage does not match") // ErrEmptyHTLCSet is returned when attempting to accept or settle and // HTLC set that has no HTLCs. ErrEmptyHTLCSet = errors.New("cannot settle/accept empty HTLC set") )
var ( // ErrInvoiceExpiryTooSoon is returned when an invoice is attempted to be // accepted or settled with not enough blocks remaining. ErrInvoiceExpiryTooSoon = errors.New("invoice expiry too soon") // ErrInvoiceAmountTooLow is returned when an invoice is attempted to be // accepted or settled with an amount that is too low. ErrInvoiceAmountTooLow = errors.New("paid amount less than invoice amount") // ErrShuttingDown is returned when an operation failed because the // invoice registry is shutting down. ErrShuttingDown = errors.New("invoice registry shutting down") // ErrAutoSettling is returned when a settle request is made in // auto-settle mode. ErrAutoSettling = errors.New("lnmux is in auto-settle mode") ErrSettleRequested = errors.New("invoice settle already requested") )
Functions ¶
This section is empty.
Types ¶
type AcceptCallback ¶
type FailResolutionResult ¶
type FailResolutionResult uint8
FailResolutionResult provides metadata about a htlc that was failed by the registry. It can be used to take custom actions on resolution of the htlc.
const ( // ResultExpiryTooSoon is returned when we do not accept an invoice // payment because it expires too soon. ResultExpiryTooSoon FailResolutionResult // ResultInvoiceNotOpen is returned when a mpp invoice is not open. ResultInvoiceNotOpen // ResultMppTimeout is returned when an invoice paid with multiple // partial payments times out before it is fully paid. ResultMppTimeout // ResultAddressMismatch is returned when the payment address for a mpp // invoice does not match. ResultAddressMismatch // ResultHtlcSetTotalMismatch is returned when the amount paid by a // htlc does not match its set total. ResultHtlcSetTotalMismatch // ResultHtlcSetTotalTooLow is returned when a mpp set total is too low // for an invoice. ResultHtlcSetTotalTooLow // ResultHtlcSetOverpayment is returned when a mpp set is overpaid. ResultHtlcSetOverpayment // ResultInvoiceNotFound is returned when an attempt is made to pay an // invoice that is unknown to us. ResultInvoiceNotFound // ResultHtlcInvoiceTypeMismatch is returned when an AMP HTLC targets a // non-AMP invoice and vice versa. ResultHtlcInvoiceTypeMismatch // ResultCannotSettle is returned when the invoice cannot be settled in // the database. ResultCannotSettle // ResultInvoiceExpired is returned when an invoice has expired. ResultInvoiceExpired // ResultNoAcceptSubscriber is returned when an htlc is failed because there // is no application subscribed to accept events. ResultNoAcceptSubscriber // ResultAcceptTimeout is returned when the accept timeout is reached // without settlement after an invoice is accepted. ResultAcceptTimeout )
func (FailResolutionResult) FailureString ¶
func (f FailResolutionResult) FailureString() string
FailureString returns a string representation of the result.
Note: it is part of the FailureDetail interface.
func (FailResolutionResult) String ¶
func (f FailResolutionResult) String() string
String returns a string representation of the result.
type HtlcFailResolution ¶
type HtlcFailResolution struct { // Outcome indicates the outcome of the invoice registry update. Outcome FailResolutionResult }
HtlcFailResolution is an implementation of the HtlcResolution interface which is returned when a htlc is failed.
func NewFailResolution ¶
func NewFailResolution(outcome FailResolutionResult) *HtlcFailResolution
NewFailResolution returns a htlc failure resolution.
type HtlcResolution ¶
type HtlcResolution interface { }
HtlcResolution describes how an htlc should be resolved.
type HtlcSettleResolution ¶
type HtlcSettleResolution struct { // Preimage is the htlc preimage. Its value is nil in case of a cancel. Preimage lntypes.Preimage // Outcome indicates the outcome of the invoice registry update. Outcome SettleResolutionResult }
HtlcSettleResolution is an implementation of the HtlcResolution interface which is returned when a htlc is settled.
func NewSettleResolution ¶
func NewSettleResolution(preimage lntypes.Preimage, outcome SettleResolutionResult) *HtlcSettleResolution
NewSettleResolution returns a htlc resolution which is associated with a settle.
type Invoice ¶
type Invoice struct { types.InvoiceCreationData Settled bool // SettleDate is the exact time the invoice was settled. SettleDate time.Time // CreationDate is the exact time the invoice was created. CreationDate time.Time // PaymentRequest is the encoded payment request for this invoice. For // spontaneous (keysend) payments, this field will be empty. PaymentRequest string }
Invoice is a payment invoice generated by a payee in order to request payment for some good or service. The inclusion of invoices within Lightning creates a payment work flow for merchants very similar to that of the existing financial system within PayPal, etc. Invoices are added to the database when a payment is requested, then can be settled manually once the payment is received at the upper layer. For record keeping purposes, invoices are never deleted from the database, instead a bit is toggled denoting the invoice has been fully settled. Within the database, all invoices must have a unique payment hash which is generated by taking the sha256 of the payment preimage.
type InvoiceCallback ¶
type InvoiceCallback func(update InvoiceUpdate)
type InvoiceCreator ¶
type InvoiceCreator struct {
// contains filtered or unexported fields
}
func NewInvoiceCreator ¶
func NewInvoiceCreator(cfg *InvoiceCreatorConfig) (*InvoiceCreator, error)
func (*InvoiceCreator) Create ¶
func (c *InvoiceCreator) Create(amtMSat int64, expiry time.Duration, memo string, descHash *lntypes.Hash, cltvDelta uint64) ( *Invoice, lntypes.Preimage, error)
TODO: Add description hash.
func (*InvoiceCreator) Network ¶
func (c *InvoiceCreator) Network() *chaincfg.Params
func (*InvoiceCreator) NodePubKeys ¶
func (c *InvoiceCreator) NodePubKeys() []*btcec.PublicKey
func (*InvoiceCreator) PubKey ¶
func (c *InvoiceCreator) PubKey() *btcec.PublicKey
type InvoiceCreatorConfig ¶
type InvoiceCreatorConfig struct { KeyRing keychain.SecretKeyRing GwPubKeys []common.PubKey ActiveNetParams *chaincfg.Params // RoutingPolicy is the policy that is used for the hop hints. RoutingPolicy RoutingPolicy }
type InvoiceRegistry ¶
InvoiceRegistry is a central registry of all the outstanding invoices created by the daemon. The registry is a thin wrapper around a map in order to ensure that all updates/reads are thread safe.
func NewRegistry ¶
func NewRegistry(cdb *persistence.PostgresPersister, cfg *RegistryConfig) *InvoiceRegistry
NewRegistry creates a new invoice registry. The invoice registry wraps the persistent on-disk invoice storage with an additional in-memory layer. The in-memory layer is in place such that debug invoices can be added which are volatile yet available system wide within the daemon.
func (*InvoiceRegistry) AutoSettle ¶
func (i *InvoiceRegistry) AutoSettle() bool
func (*InvoiceRegistry) CancelInvoice ¶
func (i *InvoiceRegistry) CancelInvoice( hash lntypes.Hash, setID SetID) error
func (*InvoiceRegistry) NotifyExitHopHtlc ¶
func (i *InvoiceRegistry) NotifyExitHopHtlc(h *registryHtlc)
NotifyExitHopHtlc attempts to mark an invoice as settled. The return value describes how the htlc should be resolved.
When the preimage of the invoice is not yet known (hodl invoice), this function moves the invoice to the accepted state. When SettleHoldInvoice is called later, a resolution message will be send back to the caller via the provided hodlChan. Invoice registry sends on this channel what action needs to be taken on the htlc (settle or cancel). The caller needs to ensure that the channel is either buffered or received on from another goroutine to prevent deadlock.
In the case that the htlc is part of a larger set of htlcs that pay to the same invoice (multi-path payment), the htlc is held until the set is complete. If the set doesn't fully arrive in time, a timer will cancel the held htlc.
func (*InvoiceRegistry) RequestSettle ¶
func (i *InvoiceRegistry) RequestSettle(hash lntypes.Hash, setID SetID) error
func (*InvoiceRegistry) Run ¶
func (i *InvoiceRegistry) Run(ctx context.Context) error
Start starts the registry and all goroutines it needs to carry out its task.
func (*InvoiceRegistry) SubscribeAccept ¶
func (i *InvoiceRegistry) SubscribeAccept(callback AcceptCallback) ( func(), error)
type InvoiceUpdate ¶
type InvoiceUpdate struct {
State persistence.InvoiceState
}
type KeyRing ¶
type KeyRing struct { keychain.SecretKeyRing // contains filtered or unexported fields }
KeyRing is an implementation of both the KeyRing and SecretKeyRing interfaces backed by btcwallet's internal root waddrmgr. Internally, we'll be using a ScopedKeyManager to do all of our derivations, using the key scope and scope addr scehma defined above. Re-using the existing key scope construction means that all key derivation will be protected under the root seed of the wallet, making each derived key fully deterministic.
func NewKeyRing ¶
NewKeyRing creates a new implementation of the keychain.SecretKeyRing interface backed by btcwallet.
NOTE: The passed waddrmgr.Manager MUST be unlocked in order for the keychain to function.
func (*KeyRing) DeriveKey ¶
func (b *KeyRing) DeriveKey(keyLoc keychain.KeyLocator) (keychain.KeyDescriptor, error)
DeriveKey attempts to derive an arbitrary key specified by the passed KeyLocator. This may be used in several recovery scenarios, or when manually rotating something like our current default node key.
NOTE: This is part of the keychain.KeyRing interface.
func (*KeyRing) DeriveNextKey ¶
func (*KeyRing) DerivePrivKey ¶
func (b *KeyRing) DerivePrivKey(keyDesc keychain.KeyDescriptor) ( *btcec.PrivateKey, error)
DerivePrivKey attempts to derive the private key that corresponds to the passed key descriptor.
NOTE: This is part of the keychain.SecretKeyRing interface.
func (*KeyRing) ECDH ¶
func (b *KeyRing) ECDH(keyDesc keychain.KeyDescriptor, pub *btcec.PublicKey) ([32]byte, error)
ECDH performs a scalar multiplication (ECDH-like operation) between the target key descriptor and remote public key. The output returned will be the sha256 of the resulting shared point serialized in compressed format. If k is our private key, and P is the public key, we perform the following operation:
sx := k*P s := sha256(sx.SerializeCompressed())
NOTE: This is part of the keychain.ECDHRing interface.
func (*KeyRing) SignMessage ¶
func (b *KeyRing) SignMessage(keyLoc keychain.KeyLocator, msg []byte, doubleHash bool) (*ecdsa.Signature, error)
SignMessage signs the given message, single or double SHA256 hashing it first, with the private key described in the key locator.
NOTE: This is part of the keychain.MessageSignerRing interface.
func (*KeyRing) SignMessageCompact ¶
func (b *KeyRing) SignMessageCompact(keyLoc keychain.KeyLocator, msg []byte, doubleHash bool) ([]byte, error)
SignMessageCompact signs the given message, single or double SHA256 hashing it first, with the private key described in the key locator and returns the signature in the compact, public key recoverable format.
NOTE: This is part of the keychain.MessageSignerRing interface.
type MuxConfig ¶
type MuxConfig struct { KeyRing keychain.SecretKeyRing ActiveNetParams *chaincfg.Params SettledHandler *SettledHandler Lnd lnd.LndClient Logger *zap.SugaredLogger Registry *InvoiceRegistry // RoutingPolicy is the policy that is enforced for the hop towards the // virtual channel. RoutingPolicy RoutingPolicy }
type Payload ¶
type Payload interface { // MultiPath returns the record corresponding the option_mpp parsed from // the onion payload. MultiPath() *record.MPP }
Payload abstracts access to any additional fields provided in the final hop's TLV onion payload.
type RegistryConfig ¶
type RegistryConfig struct { // FinalCltvRejectDelta defines the number of blocks before the expiry // of the htlc where we no longer settle it as an exit hop and instead // cancel it back. Normally this value should be lower than the cltv // expiry of any invoice we create and the code effectuating this should // not be hit. FinalCltvRejectDelta int32 // HtlcHoldDuration defines for how long mpp htlcs are held while // waiting for the other set members to arrive. HtlcHoldDuration time.Duration // AcceptTimeout defines for how long a complete htlc set is held before the // invoice is cancelled. AcceptTimeout time.Duration // Clock holds the clock implementation that is used to provide // Now() and TickAfter() and is useful to stub out the clock functions // during testing. Clock clock.Clock Logger *zap.SugaredLogger // PrivKey is the private key that is used for calculating payment metadata // hmacs, which serve as the payment preimage. PrivKey [32]byte AutoSettle bool // GracePeriodWithoutSubscribers is the default period during which the subscriberManager is waiting for a subscriber // to reconnect. GracePeriodWithoutSubscribers time.Duration }
RegistryConfig contains the configuration parameters for invoice registry.
type RoutingPolicy ¶
type SettleResolutionResult ¶
type SettleResolutionResult uint8
SettleResolutionResult provides metadata which about a htlc that was failed by the registry. It can be used to take custom actions on resolution of the htlc.
const ( // ResultSettled is returned when we settle an invoice. ResultSettled SettleResolutionResult // ResultReplayToSettled is returned when we replay a settled invoice. ResultReplayToSettled )
func (SettleResolutionResult) String ¶
func (s SettleResolutionResult) String() string
String returns a string representation of the result.
type SettledHandler ¶
type SettledHandler struct {
// contains filtered or unexported fields
}
func NewSettledHandler ¶
func NewSettledHandler(cfg *SettledHandlerConfig) *SettledHandler
func (*SettledHandler) WaitForInvoiceSettled ¶
type SettledHandlerConfig ¶
type SettledHandlerConfig struct { Persister *persistence.PostgresPersister Logger *zap.SugaredLogger }