channeldb+multi: rename Grounded->Unknown, Completed->Succeeded

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

@ -22,9 +22,9 @@ var (
// switch.
ErrPaymentNotInitiated = errors.New("payment isn't initiated")
// ErrPaymentAlreadyCompleted is returned in the event we attempt to
// recomplete a completed payment.
ErrPaymentAlreadyCompleted = errors.New("payment is already completed")
// 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
// re-fail a failed payment.
@ -42,14 +42,14 @@ var (
// 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 completed payment exist for this payment
// This method checks that no suceeded payment exist for this payment
// hash.
InitPayment(lntypes.Hash, *PaymentCreationInfo) error
// RegisterAttempt atomically records the provided PaymentAttemptInfo.
RegisterAttempt(lntypes.Hash, *PaymentAttemptInfo) error
// Success transitions a payment into the Completed state. After
// 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
@ -113,7 +113,7 @@ func (p *paymentControl) InitPayment(paymentHash lntypes.Hash,
// This is a new payment that is being initialized for the
// first time.
case StatusGrounded:
case StatusUnknown:
// We already have an InFlight payment on the network. We will
// disallow any new payments.
@ -121,9 +121,9 @@ func (p *paymentControl) InitPayment(paymentHash lntypes.Hash,
takeoffErr = ErrPaymentInFlight
return nil
// We've already completed a payment to this payment hash,
// We've already succeeded a payment to this payment hash,
// forbid the switch from sending another.
case StatusCompleted:
case StatusSucceeded:
takeoffErr = ErrAlreadyPaid
return nil
@ -217,7 +217,7 @@ func (p *paymentControl) RegisterAttempt(paymentHash lntypes.Hash,
return updateErr
}
// Success transitions a payment into the Completed state. After invoking this
// 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.
@ -248,7 +248,7 @@ func (p *paymentControl) Success(paymentHash lntypes.Hash,
return err
}
return bucket.Put(paymentStatusKey, StatusCompleted.Bytes())
return bucket.Put(paymentStatusKey, StatusSucceeded.Bytes())
})
if err != nil {
return err
@ -332,11 +332,11 @@ func nextPaymentSequence(tx *bbolt.Tx) ([]byte, error) {
}
// fetchPaymentStatus fetches the payment status from the bucket. If the
// status isn't found, it will default to "StatusGrounded".
// status 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 = StatusGrounded
var paymentStatus = StatusUnknown
paymentStatusBytes := bucket.Get(paymentStatusKey)
if paymentStatusBytes != nil {
@ -360,12 +360,12 @@ func ensureInFlight(bucket *bbolt.Bucket) error {
// Our records show the payment as unknown, meaning it never
// should have left the switch.
case paymentStatus == StatusGrounded:
case paymentStatus == StatusUnknown:
return ErrPaymentNotInitiated
// The payment succeeded previously.
case paymentStatus == StatusCompleted:
return ErrPaymentAlreadyCompleted
case paymentStatus == StatusSucceeded:
return ErrPaymentAlreadySucceeded
// The payment was already failed.
case paymentStatus == StatusFailed:

@ -130,12 +130,12 @@ func TestPaymentControlSwitchFail(t *testing.T) {
nil,
)
// Verifies that status was changed to StatusCompleted.
// Verifies that status was changed to StatusSucceeded.
if err := pControl.Success(info.PaymentHash, preimg); err != nil {
t.Fatalf("error shouldn't have been received, got: %v", err)
}
assertPaymentStatus(t, db, info.PaymentHash, StatusCompleted)
assertPaymentStatus(t, db, info.PaymentHash, StatusSucceeded)
assertPaymentInfo(t, db, info.PaymentHash, info, attempt, preimg, nil)
// Attempt a final payment, which should now fail since the prior
@ -207,7 +207,7 @@ func TestPaymentControlSwitchDoubleSend(t *testing.T) {
if err := pControl.Success(info.PaymentHash, preimg); err != nil {
t.Fatalf("error shouldn't have been received, got: %v", err)
}
assertPaymentStatus(t, db, info.PaymentHash, StatusCompleted)
assertPaymentStatus(t, db, info.PaymentHash, StatusSucceeded)
assertPaymentInfo(t, db, info.PaymentHash, info, attempt, preimg, nil)
err = pControl.InitPayment(info.PaymentHash, info)
@ -239,7 +239,7 @@ func TestPaymentControlSuccessesWithoutInFlight(t *testing.T) {
t.Fatalf("expected ErrPaymentNotInitiated, got %v", err)
}
assertPaymentStatus(t, db, info.PaymentHash, StatusGrounded)
assertPaymentStatus(t, db, info.PaymentHash, StatusUnknown)
assertPaymentInfo(
t, db, info.PaymentHash, nil, nil, lntypes.Preimage{},
nil,
@ -269,7 +269,7 @@ func TestPaymentControlFailsWithoutInFlight(t *testing.T) {
t.Fatalf("expected ErrPaymentNotInitiated, got %v", err)
}
assertPaymentStatus(t, db, info.PaymentHash, StatusGrounded)
assertPaymentStatus(t, db, info.PaymentHash, StatusUnknown)
assertPaymentInfo(
t, db, info.PaymentHash, nil, nil, lntypes.Preimage{}, nil,
)
@ -280,7 +280,7 @@ func assertPaymentStatus(t *testing.T, db *DB,
t.Helper()
var paymentStatus = StatusGrounded
var paymentStatus = StatusUnknown
err := db.View(func(tx *bbolt.Tx) error {
payments := tx.Bucket(paymentsRootBucket)
if payments == nil {

@ -132,18 +132,18 @@ func (db *DB) fetchAllPayments() ([]*outgoingPayment, error) {
}
// fetchPaymentStatus returns the payment status for outgoing payment.
// If status of the payment isn't found, it will default to "StatusGrounded".
// If status of the payment isn't found, it will default to "StatusUnknown".
//
// NOTE: Deprecated. Kept around for migration purposes.
func (db *DB) fetchPaymentStatus(paymentHash [32]byte) (PaymentStatus, error) {
var paymentStatus = StatusGrounded
var paymentStatus = StatusUnknown
err := db.View(func(tx *bbolt.Tx) error {
var err error
paymentStatus, err = fetchPaymentStatusTx(tx, paymentHash)
return err
})
if err != nil {
return StatusGrounded, err
return StatusUnknown, err
}
return paymentStatus, nil
@ -151,13 +151,13 @@ func (db *DB) fetchPaymentStatus(paymentHash [32]byte) (PaymentStatus, error) {
// fetchPaymentStatusTx is a helper method that returns the payment status for
// outgoing payment. If status of the payment isn't found, it will default to
// "StatusGrounded". It accepts the boltdb transactions such that this method
// "StatusUnknown". It accepts the boltdb transactions such that this method
// can be composed into other atomic operations.
//
// NOTE: Deprecated. Kept around for migration purposes.
func fetchPaymentStatusTx(tx *bbolt.Tx, paymentHash [32]byte) (PaymentStatus, error) {
// The default status for all payments that aren't recorded in database.
var paymentStatus = StatusGrounded
var paymentStatus = StatusUnknown
bucket := tx.Bucket(paymentStatusBucket)
if bucket == nil {

@ -451,7 +451,7 @@ func paymentStatusesMigration(tx *bbolt.Tx) error {
// Update status for current payment to completed. If it fails,
// the migration is aborted and the payment bucket is returned
// to its previous state.
return paymentStatuses.Put(paymentHash[:], StatusCompleted.Bytes())
return paymentStatuses.Put(paymentHash[:], StatusSucceeded.Bytes())
})
if err != nil {
return err
@ -845,7 +845,7 @@ func migrateOutgoingPayments(tx *bbolt.Tx) error {
// Since only completed payments were previously stored as
// OutgoingPayments, set the status as Completed.
err = bucket.Put(paymentStatusKey, StatusCompleted.Bytes())
err = bucket.Put(paymentStatusKey, StatusSucceeded.Bytes())
if err != nil {
return err
}

@ -46,9 +46,9 @@ func TestPaymentStatusesMigration(t *testing.T) {
}
// We should receive default status if we have any in database.
if paymentStatus != StatusGrounded {
if paymentStatus != StatusUnknown {
t.Fatalf("wrong payment status: expected %v, got %v",
StatusGrounded.String(), paymentStatus.String())
StatusUnknown.String(), paymentStatus.String())
}
// Lastly, we'll add a locally-sourced circuit and
@ -146,9 +146,9 @@ func TestPaymentStatusesMigration(t *testing.T) {
t.Fatalf("unable to fetch payment status: %v", err)
}
if paymentStatus != StatusCompleted {
if paymentStatus != StatusSucceeded {
t.Fatalf("wrong payment status: expected %v, got %v",
StatusCompleted.String(), paymentStatus.String())
StatusSucceeded.String(), paymentStatus.String())
}
inFlightHash := [32]byte{
@ -184,9 +184,9 @@ func TestPaymentStatusesMigration(t *testing.T) {
t.Fatalf("unable to fetch payment status: %v", err)
}
if paymentStatus != StatusGrounded {
if paymentStatus != StatusUnknown {
t.Fatalf("wrong payment status: expected %v, got %v",
StatusGrounded.String(), paymentStatus.String())
StatusUnknown.String(), paymentStatus.String())
}
}
@ -640,7 +640,7 @@ func TestOutgoingPaymentsMigration(t *testing.T) {
for i, p := range sentPayments {
// The payment status should be Completed.
if p.Status != StatusCompleted {
if p.Status != StatusSucceeded {
t.Fatalf("expected Completed, got %v", p.Status)
}

@ -105,17 +105,17 @@ const (
type PaymentStatus byte
const (
// StatusGrounded is the status where a payment has never been
// initiated.
StatusGrounded PaymentStatus = 0
// StatusUnknown is the status where a payment has never been initiated
// and hence is unknown.
StatusUnknown PaymentStatus = 0
// StatusInFlight is the status where a payment has been initiated, but
// a response has not been received.
StatusInFlight PaymentStatus = 1
// StatusCompleted is the status where a payment has been initiated and
// StatusSucceeded is the status where a payment has been initiated and
// the payment was completed successfully.
StatusCompleted PaymentStatus = 2
StatusSucceeded PaymentStatus = 2
// StatusFailed is the status where a payment has been initiated and a
// failure result has come back.
@ -134,7 +134,7 @@ func (ps *PaymentStatus) FromBytes(status []byte) error {
}
switch PaymentStatus(status[0]) {
case StatusGrounded, StatusInFlight, StatusCompleted, StatusFailed:
case StatusUnknown, StatusInFlight, StatusSucceeded, StatusFailed:
*ps = PaymentStatus(status[0])
default:
return errors.New("unknown payment status")
@ -146,12 +146,12 @@ func (ps *PaymentStatus) FromBytes(status []byte) error {
// String returns readable representation of payment status.
func (ps PaymentStatus) String() string {
switch ps {
case StatusGrounded:
return "Grounded"
case StatusUnknown:
return "Unknown"
case StatusInFlight:
return "In Flight"
case StatusCompleted:
return "Completed"
case StatusSucceeded:
return "Succeeded"
case StatusFailed:
return "Failed"
default: