channeldb+routing: store all payment htlcs
This commit converts the database structure of a payment so that it can not just store the last htlc attempt, but all attempts that have been made. This is a preparation for mpp sending. In addition to that, we now also persist the fail time of an htlc. In a later commit, the full failure reason will be added as well. A key change is made to the control tower interface. Previously the control tower wasn't aware of individual htlc outcomes. The payment remained in-flight with the latest attempt recorded, but an outcome was only set when the payment finished. With this commit, the outcome of every htlc is expected by the control tower and recorded in the database. Co-authored-by: Johan T. Halseth <johanth@gmail.com>
This commit is contained in:
1 parent
8558534417
commit
48c0e42c26
10 files changed
+550
-274
No files matched your search
+30
-17
@@ -14,7 +14,6 @@ import (
|
||||
// restarts. Payments are transitioned through various payment states, and the
|
||||
// ControlTower interface provides access to driving the state transitions.
|
||||
type ControlTower interface {
|
||||
// InitPayment atomically moves the payment into the InFlight state.
|
||||
// This method checks that no suceeded payment exist for this payment
|
||||
// hash.
|
||||
InitPayment(lntypes.Hash, *channeldb.PaymentCreationInfo) error
|
||||
@@ -22,17 +21,25 @@ type ControlTower interface {
|
||||
// RegisterAttempt atomically records the provided HTLCAttemptInfo.
|
||||
RegisterAttempt(lntypes.Hash, *channeldb.HTLCAttemptInfo) error
|
||||
|
||||
// Success transitions a payment into the Succeeded state. 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.
|
||||
Success(lntypes.Hash, lntypes.Preimage) error
|
||||
// SettleAttempt marks the given attempt settled with the preimage. If
|
||||
// this is a multi shard payment, this might implicitly mean the 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, *channeldb.HTLCSettleInfo) error
|
||||
|
||||
// FailAttempt marks the given payment attempt failed.
|
||||
FailAttempt(lntypes.Hash, uint64, *channeldb.HTLCFailInfo) error
|
||||
|
||||
// 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.
|
||||
// ultimate reason the payment failed. Note that this should only be
|
||||
// called when all active 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, channeldb.FailureReason) error
|
||||
|
||||
// FetchInFlightPayments returns all payments with status InFlight.
|
||||
@@ -99,14 +106,13 @@ func (p *controlTower) RegisterAttempt(paymentHash lntypes.Hash,
|
||||
return p.db.RegisterAttempt(paymentHash, attempt)
|
||||
}
|
||||
|
||||
// Success transitions a payment into the Succeeded state. 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.
|
||||
func (p *controlTower) Success(paymentHash lntypes.Hash,
|
||||
preimage lntypes.Preimage) error {
|
||||
// SettleAttempt marks the given attempt settled with the preimage. If
|
||||
// this is a multi shard payment, this might implicitly mean the the
|
||||
// full payment succeeded.
|
||||
func (p *controlTower) SettleAttempt(paymentHash lntypes.Hash,
|
||||
attemptID uint64, settleInfo *channeldb.HTLCSettleInfo) error {
|
||||
|
||||
payment, err := p.db.Success(paymentHash, preimage)
|
||||
payment, err := p.db.SettleAttempt(paymentHash, attemptID, settleInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -119,6 +125,13 @@ func (p *controlTower) Success(paymentHash lntypes.Hash,
|
||||
return nil
|
||||
}
|
||||
|
||||
// FailAttempt marks the given payment attempt failed.
|
||||
func (p *controlTower) FailAttempt(paymentHash lntypes.Hash,
|
||||
attemptID uint64, failInfo *channeldb.HTLCFailInfo) error {
|
||||
|
||||
return p.db.FailAttempt(paymentHash, attemptID, failInfo)
|
||||
}
|
||||
|
||||
// createSuccessResult creates a success result to send to subscribers.
|
||||
func createSuccessResult(htlcs []channeldb.HTLCAttempt) *PaymentResult {
|
||||
// Extract any preimage from the list of HTLCs.
|
||||
|
||||
Reference in new issue
Block a user