channeldb: derive PaymentStatus implicitly from stored info

This commit is contained in:
Johan T. Halseth 2019-05-23 20:05:31 +02:00
parent d705b8a013
commit 95b4828780
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
3 changed files with 15 additions and 41 deletions

View File

@ -145,12 +145,6 @@ func (p *paymentControl) InitPayment(paymentHash lntypes.Hash,
return err
}
// We'll move it into the InFlight state.
err = bucket.Put(paymentStatusKey, StatusInFlight.Bytes())
if err != nil {
return err
}
// Add the payment info to the bucket, which contains the
// static information for this payment
err = bucket.Put(paymentCreationInfoKey, infoBytes)
@ -243,12 +237,7 @@ func (p *paymentControl) Success(paymentHash lntypes.Hash,
// Record the successful payment info atomically to the
// payments record.
err = bucket.Put(paymentSettleInfoKey, preimage[:])
if err != nil {
return err
}
return bucket.Put(paymentStatusKey, StatusSucceeded.Bytes())
return bucket.Put(paymentSettleInfoKey, preimage[:])
})
if err != nil {
return err
@ -284,14 +273,7 @@ func (p *paymentControl) Fail(paymentHash lntypes.Hash,
// Put the failure reason in the bucket for record keeping.
v := []byte{byte(reason)}
err = bucket.Put(paymentFailInfoKey, v)
if err != nil {
return err
}
// A failed response was received for an InFlight payment, mark
// it as Failed to allow subsequent attempts.
return bucket.Put(paymentStatusKey, StatusFailed.Bytes())
return bucket.Put(paymentFailInfoKey, v)
})
if err != nil {
return err
@ -331,19 +313,22 @@ func nextPaymentSequence(tx *bbolt.Tx) ([]byte, error) {
return b, nil
}
// fetchPaymentStatus fetches the payment status from the bucket. If the
// status isn't found, it will default to "StatusUnknown".
// fetchPaymentStatus fetches the payment status of the payment. If the payment
// isn't found, it will default to "StatusUnknown".
func fetchPaymentStatus(bucket *bbolt.Bucket) PaymentStatus {
// The default status for all payments that aren't recorded in
// database.
var paymentStatus = StatusUnknown
paymentStatusBytes := bucket.Get(paymentStatusKey)
if paymentStatusBytes != nil {
paymentStatus.FromBytes(paymentStatusBytes)
if bucket.Get(paymentSettleInfoKey) != nil {
return StatusSucceeded
}
return paymentStatus
if bucket.Get(paymentFailInfoKey) != nil {
return StatusFailed
}
if bucket.Get(paymentCreationInfoKey) != nil {
return StatusInFlight
}
return StatusUnknown
}
// ensureInFlight checks whether the payment found in the given bucket has

View File

@ -843,13 +843,6 @@ func migrateOutgoingPayments(tx *bbolt.Tx) error {
return err
}
// Since only completed payments were previously stored as
// OutgoingPayments, set the status as Completed.
err = bucket.Put(paymentStatusKey, StatusSucceeded.Bytes())
if err != nil {
return err
}
return nil
})
if err != nil {

View File

@ -53,10 +53,6 @@ var (
//
paymentsRootBucket = []byte("payments-root-bucket")
// paymentStatusKey is a key used in the payment's sub-bucket to store
// the status of the payment.
paymentStatusKey = []byte("payment-status-key")
// paymentDublicateBucket is the name of a optional sub-bucket within
// the payment hash bucket, that is used to hold duplicate payments to
// a payment hash. This is needed to support information from earlier