Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kvdb/postgres: remove global application level lock #8529

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions channeldb/payment_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (p *PaymentControl) InitPayment(paymentHash lntypes.Hash,
prefetchPayment(tx, paymentHash)
bucket, err := createPaymentBucket(tx, paymentHash)
if err != nil {
return err
return fmt.Errorf("couldn't create bucket: %w", err)
}

// Get the existing status of this payment, if any.
Expand All @@ -171,14 +171,15 @@ func (p *PaymentControl) InitPayment(paymentHash lntypes.Hash,
// retrying the payment or return a specific error.
case err == nil:
if err := paymentStatus.initializable(); err != nil {
updateErr = err
updateErr = fmt.Errorf("initialize: %w", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So If I revert this back to just:

updateErr = err

Then strangely, the sendtoroute_multi_path_payment starts to pass again 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, I also don't wrap the error down below, pushing this up as a commit to see how CI fares now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure why, but when we wrap the error here, this error check fails, causing the whole itest to fail:

case mpp != nil && errors.Is(err, channeldb.ErrPaymentExists):

return nil
}

// Otherwise, if the error is not `ErrPaymentNotInitiated`,
// we'll return the error.
case !errors.Is(err, ErrPaymentNotInitiated):
return err
return fmt.Errorf("couldn't fetch payment status: %w",
err)
}

// Before we set our new sequence number, we check whether this
Expand All @@ -190,7 +191,8 @@ func (p *PaymentControl) InitPayment(paymentHash lntypes.Hash,
if seqBytes != nil {
indexBucket := tx.ReadWriteBucket(paymentsIndexBucket)
if err := indexBucket.Delete(seqBytes); err != nil {
return err
return fmt.Errorf("couldn't delete index "+
"bucket: %w", err)
}
}

Expand All @@ -201,38 +203,45 @@ func (p *PaymentControl) InitPayment(paymentHash lntypes.Hash,
tx, sequenceNum, info.PaymentIdentifier,
)
if err != nil {
return err
return fmt.Errorf("couldn't create payment index "+
"entry: %w", err)
}

err = bucket.Put(paymentSequenceKey, sequenceNum)
if err != nil {
return err
return fmt.Errorf("couldn't put sequence key: %w", err)
}

// Add the payment info to the bucket, which contains the
// static information for this payment
err = bucket.Put(paymentCreationInfoKey, infoBytes)
if err != nil {
return err
return fmt.Errorf("couldn't put creation key info: %w",
err)
}

// We'll delete any lingering HTLCs to start with, in case we
// are initializing a payment that was attempted earlier, but
// left in a state where we could retry.
err = bucket.DeleteNestedBucket(paymentHtlcsBucket)
if err != nil && err != kvdb.ErrBucketNotFound {
return err
if err != nil && !errors.Is(err, kvdb.ErrBucketNotFound) {
return fmt.Errorf("couldn't delete nested bucket: %w",
err)
}

// Also delete any lingering failure info now that we are
// re-attempting.
return bucket.Delete(paymentFailInfoKey)
})
if err != nil {
return err
return fmt.Errorf("error in batch: %w", err)
}

if updateErr != nil {
return fmt.Errorf("update err: %w", updateErr)
}

return updateErr
return nil
}

// DeleteFailedAttempts deletes all failed htlcs for a payment if configured
Expand Down Expand Up @@ -521,7 +530,7 @@ func (p *PaymentControl) Fail(paymentHash lntypes.Hash,

prefetchPayment(tx, paymentHash)
bucket, err := fetchPaymentBucketUpdate(tx, paymentHash)
if err == ErrPaymentNotInitiated {
if errors.Is(err, ErrPaymentNotInitiated) {
updateErr = ErrPaymentNotInitiated
return nil
} else if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions kvdb/sqlbase/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const (
DefaultInitialRetryDelay = time.Millisecond * 50

// DefaultMaxRetryDelay is the default maximum delay between retries.
DefaultMaxRetryDelay = time.Second * 5
DefaultMaxRetryDelay = time.Second
)

// Config holds a set of configuration options of a sql database connection.
Expand Down Expand Up @@ -345,7 +345,7 @@ func (db *db) executeTransaction(f func(tx walletdb.ReadWriteTx) error,
}
}

return commitErr
return nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should still return the commitErr as otherwise, if it can't be mapped to a SQLError, then we always return nil, when the actual error should be thread through.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also revisiting this section, it should be trying to map the commitErr here, now fnErrr (shadowed from above).

}

// If we get to this point, then we weren't able to successfully commit
Expand Down
2 changes: 1 addition & 1 deletion lnrpc/routerrpc/router_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ func (s *Server) subscribePayment(identifier lntypes.Hash) (
sub, err := router.Tower.SubscribePayment(identifier)

switch {
case err == channeldb.ErrPaymentNotInitiated:
case errors.Is(err, channeldb.ErrPaymentNotInitiated):
return nil, status.Error(codes.NotFound, err.Error())
case err != nil:
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion routing/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2442,7 +2442,8 @@ func (r *ChannelRouter) PreparePayment(payment *LightningPayment) (
// control.
paySession, err := r.cfg.SessionSource.NewPaymentSession(payment)
if err != nil {
return nil, nil, err
return nil, nil, fmt.Errorf("error creating payment session: "+
"%w", err)
}

// Record this payment hash with the ControlTower, ensuring it is not
Expand Down
Loading