Documentation
¶
Index ¶
- Constants
- Variables
- func DeserializeRoute(r io.Reader) (route.Route, error)
- func DisableLog()
- func ReadElement(r io.Reader, element interface{}) error
- func ReadElements(r io.Reader, elements ...interface{}) error
- func SerializeRoute(w io.Writer, r route.Route) error
- func UseLogger(logger btclog.Logger)
- func WriteElement(w io.Writer, element interface{}) error
- func WriteElements(w io.Writer, elements ...interface{}) error
- type DB
- type DBMPPayment
- type FailureReason
- type HTLCAttempt
- type HTLCAttemptInfo
- type HTLCFailInfo
- type HTLCFailReason
- type HTLCSettleInfo
- type KVStore
- func (p *KVStore) DeleteFailedAttempts(hash lntypes.Hash) error
- func (p *KVStore) DeletePayment(paymentHash lntypes.Hash, failedHtlcsOnly bool) error
- func (p *KVStore) DeletePayments(failedOnly, failedHtlcsOnly bool) (int, error)
- func (p *KVStore) Fail(paymentHash lntypes.Hash, reason FailureReason) (*MPPayment, error)
- func (p *KVStore) FailAttempt(hash lntypes.Hash, attemptID uint64, failInfo *HTLCFailInfo) (*MPPayment, error)
- func (p *KVStore) FetchInFlightPayments() ([]*MPPayment, error)
- func (p *KVStore) FetchPayment(paymentHash lntypes.Hash) (*MPPayment, error)
- func (p *KVStore) FetchPayments() ([]*MPPayment, error)
- func (p *KVStore) InitPayment(paymentHash lntypes.Hash, info *PaymentCreationInfo) error
- func (p *KVStore) QueryPayments(_ context.Context, query Query) (Response, error)
- func (p *KVStore) RegisterAttempt(paymentHash lntypes.Hash, attempt *HTLCAttemptInfo) (*MPPayment, error)
- func (p *KVStore) SettleAttempt(hash lntypes.Hash, attemptID uint64, settleInfo *HTLCSettleInfo) (*MPPayment, error)
- type MPPayment
- func (m *MPPayment) AllowMoreAttempts() (bool, error)
- func (m *MPPayment) GetAttempt(id uint64) (*HTLCAttempt, error)
- func (m *MPPayment) GetHTLCs() []HTLCAttempt
- func (m *MPPayment) GetState() *MPPaymentState
- func (m *MPPayment) GetStatus() PaymentStatus
- func (m *MPPayment) InFlightHTLCs() []HTLCAttempt
- func (m *MPPayment) NeedWaitAttempts() (bool, error)
- func (m *MPPayment) Registrable() error
- func (m *MPPayment) SentAmt() (lnwire.MilliSatoshi, lnwire.MilliSatoshi)
- func (m *MPPayment) SetState() error
- func (m *MPPayment) TerminalInfo() (*HTLCAttempt, *FailureReason)
- func (m *MPPayment) Terminated() bool
- type MPPaymentState
- type OptionModifier
- type PaymentControl
- type PaymentCreationInfo
- type PaymentReader
- type PaymentStatus
- type PaymentWriter
- type Query
- type Response
- type StoreOptions
- type UnknownElementType
Constants ¶
const ( // DefaultMaxPayments is the default maximum number of payments returned // in the payments query pagination. DefaultMaxPayments = 100 )
const Subsystem = "PYDB"
Subsystem defines the logging identifier for this subsystem.
Variables ¶
var ( // ErrAlreadyPaid signals we have already paid this payment hash. ErrAlreadyPaid = errors.New("invoice is already paid") // ErrPaymentInFlight signals that payment for this payment hash is // already "in flight" on the network. ErrPaymentInFlight = errors.New("payment is in transition") // ErrPaymentExists is returned when we try to initialize an already // existing payment that is not failed. ErrPaymentExists = errors.New("payment already exists") // ErrPaymentInternal is returned when performing the payment has a // conflicting state, such as, // - payment has StatusSucceeded but remaining amount is not zero. // - payment has StatusInitiated but remaining amount is zero. // - payment has StatusFailed but remaining amount is zero. ErrPaymentInternal = errors.New("internal error") // ErrPaymentNotInitiated is returned if the payment wasn't initiated. ErrPaymentNotInitiated = errors.New("payment isn't initiated") // ErrPaymentAlreadySucceeded is returned in the event we attempt to // change the status of a payment already succeeded. ErrPaymentAlreadySucceeded = errors.New("payment is already succeeded") // ErrPaymentAlreadyFailed is returned in the event we attempt to alter // a failed payment. ErrPaymentAlreadyFailed = errors.New("payment has already failed") // ErrUnknownPaymentStatus is returned when we do not recognize the // existing state of a payment. ErrUnknownPaymentStatus = errors.New("unknown payment status") // ErrPaymentTerminal is returned if we attempt to alter a payment that // already has reached a terminal condition. ErrPaymentTerminal = errors.New("payment has reached terminal " + "condition") // ErrAttemptAlreadySettled is returned if we try to alter an already // settled HTLC attempt. ErrAttemptAlreadySettled = errors.New("attempt already settled") // ErrAttemptAlreadyFailed is returned if we try to alter an already // failed HTLC attempt. ErrAttemptAlreadyFailed = errors.New("attempt already failed") // ErrValueMismatch is returned if we try to register a non-MPP attempt // with an amount that doesn't match the payment amount. ErrValueMismatch = errors.New("attempted value doesn't match payment " + "amount") // ErrValueExceedsAmt is returned if we try to register an attempt that // would take the total sent amount above the payment amount. ErrValueExceedsAmt = errors.New("attempted value exceeds payment " + "amount") // ErrNonMPPayment is returned if we try to register an MPP attempt for // a payment that already has a non-MPP attempt registered. ErrNonMPPayment = errors.New("payment has non-MPP attempts") // ErrMPPayment is returned if we try to register a non-MPP attempt for // a payment that already has an MPP attempt registered. ErrMPPayment = errors.New("payment has MPP attempts") // ErrMPPRecordInBlindedPayment is returned if we try to register an // attempt with an MPP record for a payment to a blinded path. ErrMPPRecordInBlindedPayment = errors.New("blinded payment cannot " + "contain MPP records") // ErrBlindedPaymentTotalAmountMismatch is returned if we try to // register an HTLC shard to a blinded route where the total amount // doesn't match existing shards. ErrBlindedPaymentTotalAmountMismatch = errors.New("blinded path " + "total amount mismatch") // ErrMPPPaymentAddrMismatch is returned if we try to register an MPP // shard where the payment address doesn't match existing shards. ErrMPPPaymentAddrMismatch = errors.New("payment address mismatch") // ErrMPPTotalAmountMismatch is returned if we try to register an MPP // shard where the total amount doesn't match existing shards. ErrMPPTotalAmountMismatch = errors.New("mp payment total amount " + "mismatch") // ErrPaymentPendingSettled is returned when we try to add a new // attempt to a payment that has at least one of its HTLCs settled. ErrPaymentPendingSettled = errors.New("payment has settled htlcs") // ErrPaymentPendingFailed is returned when we try to add a new attempt // to a payment that already has a failure reason. ErrPaymentPendingFailed = errors.New("payment has failure reason") // ErrSentExceedsTotal is returned if the payment's current total sent // amount exceed the total amount. ErrSentExceedsTotal = errors.New("total sent exceeds total amount") // ErrNoAttemptInfo is returned when no attempt info is stored yet. ErrNoAttemptInfo = errors.New("unable to find attempt info for " + "inflight payment") )
var ( // ErrNoSequenceNumber is returned if we look up a payment which does // not have a sequence number. ErrNoSequenceNumber = errors.New("sequence number not found") // ErrDuplicateNotFound is returned when we lookup a payment by its // index and cannot find a payment with a matching sequence number. ErrDuplicateNotFound = errors.New("duplicate payment not found") // ErrNoDuplicateBucket is returned when we expect to find duplicates // when looking up a payment from its index, but the payment does not // have any. ErrNoDuplicateBucket = errors.New("expected duplicate bucket") // ErrNoDuplicateNestedBucket is returned if we do not find duplicate // payments in their own sub-bucket. ErrNoDuplicateNestedBucket = errors.New("nested duplicate bucket not " + "found") // ErrNoSequenceNrIndex is returned when an attempt to lookup a payment // index is made for a sequence number that is not indexed. // // NOTE: Only used for the kv backend. ErrNoSequenceNrIndex = errors.New("payment sequence number index " + "does not exist") )
KV backend specific errors.
Functions ¶
func DeserializeRoute ¶
DeserializeRoute deserializes a route.
func DisableLog ¶
func DisableLog()
DisableLog disables all library log output. Logging output is disabled by default until UseLogger is called.
func ReadElement ¶
ReadElement deserializes a single element from the provided io.Reader.
func ReadElements ¶
ReadElements deserializes the provided io.Reader into a variadic list of target elements.
func SerializeRoute ¶
SerializeRoute serializes a route.
func UseLogger ¶
func UseLogger(logger btclog.Logger)
UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.
func WriteElement ¶
WriteElement serializes a single element into the provided io.Writer.
func WriteElements ¶
WriteElements serializes a variadic list of elements into the given io.Writer.
Types ¶
type DB ¶
type DB interface {
PaymentReader
PaymentWriter
}
DB represents the interface to the underlying payments database.
type DBMPPayment ¶
type DBMPPayment interface {
// GetState returns the current state of the payment.
GetState() *MPPaymentState
// Terminated returns true if the payment is in a final state.
Terminated() bool
// GetStatus returns the current status of the payment.
GetStatus() PaymentStatus
// NeedWaitAttempts specifies whether the payment needs to wait for the
// outcome of an attempt.
NeedWaitAttempts() (bool, error)
// GetHTLCs returns all HTLCs of this payment.
GetHTLCs() []HTLCAttempt
// InFlightHTLCs returns all HTLCs that are in flight.
InFlightHTLCs() []HTLCAttempt
// AllowMoreAttempts is used to decide whether we can safely attempt
// more HTLCs for a given payment state. Return an error if the payment
// is in an unexpected state.
AllowMoreAttempts() (bool, error)
// TerminalInfo returns the settled HTLC attempt or the payment's
// failure reason.
TerminalInfo() (*HTLCAttempt, *FailureReason)
}
DBMPPayment is an interface that represents the payment state during a payment lifecycle.
type FailureReason ¶
type FailureReason byte
FailureReason encodes the reason a payment ultimately failed.
const ( // FailureReasonTimeout indicates that the payment did timeout before a // successful payment attempt was made. FailureReasonTimeout FailureReason = 0 // FailureReasonNoRoute indicates no successful route to the // destination was found during path finding. FailureReasonNoRoute FailureReason = 1 // FailureReasonError indicates that an unexpected error happened during // payment. FailureReasonError FailureReason = 2 // FailureReasonPaymentDetails indicates that either the hash is unknown // or the final cltv delta or amount is incorrect. FailureReasonPaymentDetails FailureReason = 3 // FailureReasonInsufficientBalance indicates that we didn't have enough // balance to complete the payment. FailureReasonInsufficientBalance FailureReason = 4 // FailureReasonCanceled indicates that the payment was canceled by the // user. FailureReasonCanceled FailureReason = 5 )
func (FailureReason) Error ¶
func (r FailureReason) Error() string
Error returns a human-readable error string for the FailureReason.
func (FailureReason) String ¶
func (r FailureReason) String() string
String returns a human-readable FailureReason.
type HTLCAttempt ¶
type HTLCAttempt struct {
HTLCAttemptInfo
// Settle is the preimage of a successful payment. This serves as a
// proof of payment. It will only be non-nil for settled payments.
//
// NOTE: Can be nil if payment is not settled.
Settle *HTLCSettleInfo
// Fail is a failure reason code indicating the reason the payment
// failed. It is only non-nil for failed payments.
//
// NOTE: Can be nil if payment is not failed.
Failure *HTLCFailInfo
}
HTLCAttempt contains information about a specific HTLC attempt for a given payment. It contains the HTLCAttemptInfo used to send the HTLC, as well as a timestamp and any known outcome of the attempt.
type HTLCAttemptInfo ¶
type HTLCAttemptInfo struct {
// AttemptID is the unique ID used for this attempt.
AttemptID uint64
// Route is the route attempted to send the HTLC.
Route route.Route
// AttemptTime is the time at which this HTLC was attempted.
AttemptTime time.Time
// Hash is the hash used for this single HTLC attempt. For AMP payments
// this will differ across attempts, for non-AMP payments each attempt
// will use the same hash. This can be nil for older payment attempts,
// in which the payment's PaymentHash in the PaymentCreationInfo should
// be used.
Hash *lntypes.Hash
// contains filtered or unexported fields
}
HTLCAttemptInfo contains static information about a specific HTLC attempt for a payment. This information is used by the router to handle any errors coming back after an attempt is made, and to query the switch about the status of the attempt.
func (*HTLCAttemptInfo) Circuit ¶
func (h *HTLCAttemptInfo) Circuit() (*sphinx.Circuit, error)
Circuit returns the sphinx circuit for this attempt.
func (*HTLCAttemptInfo) OnionBlob ¶
func (h *HTLCAttemptInfo) OnionBlob() ([lnwire.OnionPacketSize]byte, error)
OnionBlob returns the onion blob created from the sphinx construction.
func (*HTLCAttemptInfo) SessionKey ¶
func (h *HTLCAttemptInfo) SessionKey() *btcec.PrivateKey
SessionKey returns the ephemeral key used for a htlc attempt. This function performs expensive ec-ops to obtain the session key if it is not cached.
type HTLCFailInfo ¶
type HTLCFailInfo struct {
// FailTime is the time at which this HTLC was failed.
FailTime time.Time
// Message is the wire message that failed this HTLC. This field will be
// populated when the failure reason is HTLCFailMessage.
Message lnwire.FailureMessage
// Reason is the failure reason for this HTLC.
Reason HTLCFailReason
// The position in the path of the intermediate or final node that
// generated the failure message. Position zero is the sender node. This
// field will be populated when the failure reason is either
// HTLCFailMessage or HTLCFailUnknown.
FailureSourceIndex uint32
}
HTLCFailInfo encapsulates the information that augments an HTLCAttempt in the event that the HTLC fails.
type HTLCFailReason ¶
type HTLCFailReason byte
HTLCFailReason is the reason an htlc failed.
const ( // HTLCFailUnknown is recorded for htlcs that failed with an unknown // reason. HTLCFailUnknown HTLCFailReason = 0 // HTLCFailUnreadable is recorded for htlcs that had a failure message // that couldn't be decrypted. HTLCFailUnreadable HTLCFailReason = 1 // HTLCFailInternal is recorded for htlcs that failed because of an // internal error. HTLCFailInternal HTLCFailReason = 2 // HTLCFailMessage is recorded for htlcs that failed with a network // failure message. HTLCFailMessage HTLCFailReason = 3 )
type HTLCSettleInfo ¶
type HTLCSettleInfo struct {
// Preimage is the preimage of a successful HTLC. This serves as a proof
// of payment.
Preimage lntypes.Preimage
// SettleTime is the time at which this HTLC was settled.
SettleTime time.Time
}
HTLCSettleInfo encapsulates the information that augments an HTLCAttempt in the event that the HTLC is successful.
type KVStore ¶
type KVStore struct {
// contains filtered or unexported fields
}
KVStore implements persistence for payments and payment attempts.
func NewKVStore ¶
func NewKVStore(db kvdb.Backend, options ...OptionModifier) (*KVStore, error)
NewKVStore creates a new KVStore for payments.
func NewKVTestDB ¶
func NewKVTestDB(t *testing.T, opts ...OptionModifier) *KVStore
NewKVTestDB is a helper function that creates an BBolt database for testing and there is no need to convert the interface to the KVStore because for some unit tests we still need access to the kvdb interface.
func (*KVStore) DeleteFailedAttempts ¶
DeleteFailedAttempts deletes all failed htlcs for a payment if configured by the KVStore db.
func (*KVStore) DeletePayment ¶
DeletePayment deletes a payment from the DB given its payment hash. If failedHtlcsOnly is set, only failed HTLC attempts of the payment will be deleted.
func (*KVStore) DeletePayments ¶
DeletePayments deletes all completed and failed payments from the DB. If failedOnly is set, only failed payments will be considered for deletion. If failedHtlcsOnly is set, the payment itself won't be deleted, only failed HTLC attempts. The method returns the number of deleted payments, which is always 0 if failedHtlcsOnly is set.
func (*KVStore) Fail ¶
Fail transitions a payment into the Failed state, and records the reason the payment failed. After invoking this method, InitPayment should return nil on its next call for this payment hash, allowing the switch to make a subsequent payment.
func (*KVStore) FailAttempt ¶
func (p *KVStore) FailAttempt(hash lntypes.Hash, attemptID uint64, failInfo *HTLCFailInfo) (*MPPayment, error)
FailAttempt marks the given payment attempt failed.
func (*KVStore) FetchInFlightPayments ¶
FetchInFlightPayments returns all payments with status InFlight.
func (*KVStore) FetchPayment ¶
FetchPayment returns information about a payment from the database.
func (*KVStore) FetchPayments ¶
FetchPayments returns all sent payments found in the DB.
func (*KVStore) InitPayment ¶
func (p *KVStore) InitPayment(paymentHash lntypes.Hash, info *PaymentCreationInfo) error
InitPayment checks or records the given PaymentCreationInfo with the DB, making sure it does not already exist as an in-flight payment. When this method returns successfully, the payment is guaranteed to be in the InFlight state.
func (*KVStore) QueryPayments ¶
QueryPayments is a query to the payments database which is restricted to a subset of payments by the payments query, containing an offset index and a maximum number of returned payments.
func (*KVStore) RegisterAttempt ¶
func (p *KVStore) RegisterAttempt(paymentHash lntypes.Hash, attempt *HTLCAttemptInfo) (*MPPayment, error)
RegisterAttempt atomically records the provided HTLCAttemptInfo to the DB.
func (*KVStore) SettleAttempt ¶
func (p *KVStore) SettleAttempt(hash lntypes.Hash, attemptID uint64, settleInfo *HTLCSettleInfo) (*MPPayment, error)
SettleAttempt marks the given attempt settled with the preimage. If this is a multi shard payment, this might implicitly mean that the full payment succeeded.
After invoking this method, InitPayment should always return an error to prevent us from making duplicate payments to the same payment hash. The provided preimage is atomically saved to the DB for record keeping.
type MPPayment ¶
type MPPayment struct {
// SequenceNum is a unique identifier used to sort the payments in
// order of creation.
SequenceNum uint64
// Info holds all static information about this payment, and is
// populated when the payment is initiated.
Info *PaymentCreationInfo
// HTLCs holds the information about individual HTLCs that we send in
// order to make the payment.
HTLCs []HTLCAttempt
// FailureReason is the failure reason code indicating the reason the
// payment failed.
//
// NOTE: Will only be set once the daemon has given up on the payment
// altogether.
FailureReason *FailureReason
// Status is the current PaymentStatus of this payment.
Status PaymentStatus
// State is the current state of the payment that holds a number of key
// insights and is used to determine what to do on each payment loop
// iteration.
State *MPPaymentState
}
MPPayment is a wrapper around a payment's PaymentCreationInfo and HTLCAttempts. All payments will have the PaymentCreationInfo set, any HTLCs made in attempts to be completed will populated in the HTLCs slice. Each populated HTLCAttempt represents an attempted HTLC, each of which may have the associated Settle or Fail struct populated if the HTLC is no longer in-flight.
func (*MPPayment) AllowMoreAttempts ¶
AllowMoreAttempts is used to decide whether we can safely attempt more HTLCs for a given payment state. Return an error if the payment is in an unexpected state.
func (*MPPayment) GetAttempt ¶
func (m *MPPayment) GetAttempt(id uint64) (*HTLCAttempt, error)
GetAttempt returns the specified htlc attempt on the payment.
func (*MPPayment) GetHTLCs ¶
func (m *MPPayment) GetHTLCs() []HTLCAttempt
GetHTLCs returns all the HTLCs for this payment.
func (*MPPayment) GetState ¶
func (m *MPPayment) GetState() *MPPaymentState
GetState returns the internal state of the payment.
func (*MPPayment) GetStatus ¶
func (m *MPPayment) GetStatus() PaymentStatus
GetStatus returns the current status of the payment.
func (*MPPayment) InFlightHTLCs ¶
func (m *MPPayment) InFlightHTLCs() []HTLCAttempt
InFlightHTLCs returns the HTLCs that are still in-flight, meaning they have not been settled or failed.
func (*MPPayment) NeedWaitAttempts ¶
NeedWaitAttempts decides whether we need to hold creating more HTLC attempts and wait for the results of the payment's inflight HTLCs. Return an error if the payment is in an unexpected state.
func (*MPPayment) Registrable ¶
Registrable returns an error to specify whether adding more HTLCs to the payment with its current status is allowed. A payment can accept new HTLC registrations when it's newly created, or none of its HTLCs is in a terminal state.
func (*MPPayment) SentAmt ¶
func (m *MPPayment) SentAmt() (lnwire.MilliSatoshi, lnwire.MilliSatoshi)
SentAmt returns the sum of sent amount and fees for HTLCs that are either settled or still in flight.
func (*MPPayment) SetState ¶
SetState calls the internal method setState. This is a temporary method to be used by the tests in routing. Once the tests are updated to use mocks, this method can be removed.
TODO(yy): delete.
func (*MPPayment) TerminalInfo ¶
func (m *MPPayment) TerminalInfo() (*HTLCAttempt, *FailureReason)
TerminalInfo returns any HTLC settle info recorded. If no settle info is recorded, any payment level failure will be returned. If neither a settle nor a failure is recorded, both return values will be nil.
func (*MPPayment) Terminated ¶
Terminated returns a bool to specify whether the payment is in a terminal state.
type MPPaymentState ¶
type MPPaymentState struct {
// NumAttemptsInFlight specifies the number of HTLCs the payment is
// waiting results for.
NumAttemptsInFlight int
// RemainingAmt specifies how much more money to be sent.
RemainingAmt lnwire.MilliSatoshi
// FeesPaid specifies the total fees paid so far that can be used to
// calculate remaining fee budget.
FeesPaid lnwire.MilliSatoshi
// HasSettledHTLC is true if at least one of the payment's HTLCs is
// settled.
HasSettledHTLC bool
// PaymentFailed is true if the payment has been marked as failed with
// a reason.
PaymentFailed bool
}
MPPaymentState wraps a series of info needed for a given payment, which is used by both MPP and AMP. This is a memory representation of the payment's current state and is updated whenever the payment is read from disk.
type OptionModifier ¶
type OptionModifier func(*StoreOptions)
OptionModifier is a function signature for modifying the default StoreOptions.
func WithKeepFailedPaymentAttempts ¶
func WithKeepFailedPaymentAttempts(n bool) OptionModifier
WithKeepFailedPaymentAttempts sets the KeepFailedPaymentAttempts to n.
func WithNoMigration ¶
func WithNoMigration(b bool) OptionModifier
WithNoMigration allows the database to be opened in read only mode by disabling migrations.
type PaymentControl ¶
type PaymentControl interface {
// InitPayment checks that no other payment with the same payment hash
// exists in the database before creating a new payment. However, it
// should allow the user making a subsequent payment if the payment is
// in a Failed state.
InitPayment(lntypes.Hash, *PaymentCreationInfo) error
// RegisterAttempt atomically records the provided HTLCAttemptInfo.
RegisterAttempt(lntypes.Hash, *HTLCAttemptInfo) (*MPPayment, error)
// SettleAttempt marks the given attempt settled with the preimage. If
// this is a multi shard payment, this might implicitly mean the
// full payment succeeded.
//
// After invoking this method, InitPayment should always return an
// error to prevent us from making duplicate payments to the same
// payment hash. The provided preimage is atomically saved to the DB
// for record keeping.
SettleAttempt(lntypes.Hash, uint64, *HTLCSettleInfo) (*MPPayment, error)
// FailAttempt marks the given payment attempt failed.
FailAttempt(lntypes.Hash, uint64, *HTLCFailInfo) (*MPPayment, error)
// Fail transitions a payment into the Failed state, and records
// the ultimate reason the payment failed. Note that this should only
// be called when all active attempts are already failed. After
// invoking this method, InitPayment should return nil on its next call
// for this payment hash, allowing the user to make a subsequent
// payment.
Fail(lntypes.Hash, FailureReason) (*MPPayment, error)
// DeleteFailedAttempts removes all failed HTLCs from the db. It should
// be called for a given payment whenever all inflight htlcs are
// completed, and the payment has reached a final terminal state.
DeleteFailedAttempts(lntypes.Hash) error
}
PaymentControl represents the interface to control the payment lifecycle and its database operations. This interface represents the control flow of how a payment should be handled in the database. They are not just writing operations but they inherently represent the flow of a payment. The methods are called in the following order.
1. InitPayment. 2. RegisterAttempt (a payment can have multiple attempts). 3. SettleAttempt or FailAttempt (attempts can also fail as long as the sending amount will be eventually settled). 4. Payment succeeds or "Fail" is called. 5. DeleteFailedAttempts is called which will delete all failed attempts for a payment to clean up the database.
type PaymentCreationInfo ¶
type PaymentCreationInfo struct {
// PaymentIdentifier is the hash this payment is paying to in case of
// non-AMP payments, and the SetID for AMP payments.
PaymentIdentifier lntypes.Hash
// Value is the amount we are paying.
Value lnwire.MilliSatoshi
// CreationTime is the time when this payment was initiated.
CreationTime time.Time
// PaymentRequest is the full payment request, if any.
PaymentRequest []byte
// FirstHopCustomRecords are the TLV records that are to be sent to the
// first hop of this payment. These records will be transmitted via the
// wire message only and therefore do not affect the onion payload size.
FirstHopCustomRecords lnwire.CustomRecords
}
PaymentCreationInfo is the information necessary to have ready when initiating a payment, moving it into state InFlight.
func (*PaymentCreationInfo) String ¶
func (p *PaymentCreationInfo) String() string
String returns a human-readable description of the payment creation info.
type PaymentReader ¶
type PaymentReader interface {
// QueryPayments queries the payments database and should support
// pagination.
QueryPayments(ctx context.Context, query Query) (Response, error)
// FetchPayment fetches the payment corresponding to the given payment
// hash.
FetchPayment(paymentHash lntypes.Hash) (*MPPayment, error)
// FetchInFlightPayments returns all payments with status InFlight.
FetchInFlightPayments() ([]*MPPayment, error)
}
PaymentReader represents the interface to read operations from the payments database.
type PaymentStatus ¶
type PaymentStatus byte
PaymentStatus represent current status of payment.
const ( // StatusInitiated is the status where a payment has just been // initiated. StatusInitiated PaymentStatus = 1 // StatusInFlight is the status where a payment has been initiated, but // a response has not been received. StatusInFlight PaymentStatus = 2 // StatusSucceeded is the status where a payment has been initiated and // the payment was completed successfully. StatusSucceeded PaymentStatus = 3 // StatusFailed is the status where a payment has been initiated and a // failure result has come back. StatusFailed PaymentStatus = 4 )
func (PaymentStatus) String ¶
func (ps PaymentStatus) String() string
String returns readable representation of payment status.
type PaymentWriter ¶
type PaymentWriter interface {
// DeletePayment deletes a payment from the DB given its payment hash.
DeletePayment(paymentHash lntypes.Hash, failedAttemptsOnly bool) error
// DeletePayments deletes all payments from the DB given the specified
// flags.
DeletePayments(failedOnly, failedAttemptsOnly bool) (int, error)
PaymentControl
}
PaymentWriter represents the interface to write operations to the payments database.
type Query ¶
type Query struct {
// IndexOffset determines the starting point of the payments query and
// is always exclusive. In normal order, the query starts at the next
// higher (available) index compared to IndexOffset. In reversed order,
// the query ends at the next lower (available) index compared to the
// IndexOffset. In the case of a zero index_offset, the query will start
// with the oldest payment when paginating forwards, or will end with
// the most recent payment when paginating backwards.
IndexOffset uint64
// MaxPayments is the maximal number of payments returned in the
// payments query.
MaxPayments uint64
// Reversed gives a meaning to the IndexOffset. If reversed is set to
// true, the query will fetch payments with indices lower than the
// IndexOffset, otherwise, it will return payments with indices greater
// than the IndexOffset.
Reversed bool
// If IncludeIncomplete is true, then return payments that have not yet
// fully completed. This means that pending payments, as well as failed
// payments will show up if this field is set to true.
IncludeIncomplete bool
// CountTotal indicates that all payments currently present in the
// payment index (complete and incomplete) should be counted.
CountTotal bool
// CreationDateStart, expressed in Unix seconds, if set, filters out
// all payments with a creation date greater than or equal to it.
CreationDateStart int64
// CreationDateEnd, expressed in Unix seconds, if set, filters out all
// payments with a creation date less than or equal to it.
CreationDateEnd int64
}
Query represents a query to the payments database starting or ending at a certain offset index. The number of retrieved records can be limited.
type Response ¶
type Response struct {
// Payments is the set of payments returned from the database for the
// Query.
Payments []*MPPayment
// FirstIndexOffset is the index of the first element in the set of
// returned MPPayments. Callers can use this to resume their query
// in the event that the slice has too many events to fit into a single
// response. The offset can be used to continue reverse pagination.
FirstIndexOffset uint64
// LastIndexOffset is the index of the last element in the set of
// returned MPPayments. Callers can use this to resume their query
// in the event that the slice has too many events to fit into a single
// response. The offset can be used to continue forward pagination.
LastIndexOffset uint64
// TotalCount represents the total number of payments that are currently
// stored in the payment database. This will only be set if the
// CountTotal field in the query was set to true.
TotalCount uint64
}
Response contains the result of a query to the payments database. It includes the set of payments that match the query and integers which represent the index of the first and last item returned in the series of payments. These integers allow callers to resume their query in the event that the query's response exceeds the max number of returnable events.
type StoreOptions ¶
type StoreOptions struct {
// NoMigration allows to open the database in readonly mode
NoMigration bool
// KeepFailedPaymentAttempts is a flag that determines whether to keep
// failed payment attempts for a settled payment in the db.
KeepFailedPaymentAttempts bool
}
StoreOptions holds parameters for the KVStore.
func DefaultOptions ¶
func DefaultOptions() *StoreOptions
DefaultOptions returns a StoreOptions populated with default values.
type UnknownElementType ¶
type UnknownElementType = channeldb.UnknownElementType
UnknownElementType is an alias for channeldb.UnknownElementType.