multi: thread context through DeletePayment
This commit is contained in:
5 files changed
+32
-17
No files matched your search
@@ -31,7 +31,8 @@ type PaymentReader interface {
|
|||||||
// database.
|
// database.
|
||||||
type PaymentWriter interface {
|
type PaymentWriter interface {
|
||||||
// DeletePayment deletes a payment from the DB given its payment hash.
|
// DeletePayment deletes a payment from the DB given its payment hash.
|
||||||
DeletePayment(paymentHash lntypes.Hash, failedAttemptsOnly bool) error
|
DeletePayment(ctx context.Context, paymentHash lntypes.Hash,
|
||||||
|
failedAttemptsOnly bool) error
|
||||||
|
|
||||||
// DeletePayments deletes all payments from the DB given the specified
|
// DeletePayments deletes all payments from the DB given the specified
|
||||||
// flags.
|
// flags.
|
||||||
|
|||||||
@@ -295,7 +295,7 @@ func (p *KVStore) DeleteFailedAttempts(hash lntypes.Hash) error {
|
|||||||
// logic. This decision should be made in the application layer.
|
// logic. This decision should be made in the application layer.
|
||||||
if !p.keepFailedPaymentAttempts {
|
if !p.keepFailedPaymentAttempts {
|
||||||
const failedHtlcsOnly = true
|
const failedHtlcsOnly = true
|
||||||
err := p.DeletePayment(hash, failedHtlcsOnly)
|
err := p.DeletePayment(context.TODO(), hash, failedHtlcsOnly)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -1275,7 +1275,7 @@ func fetchPaymentWithSequenceNumber(tx kvdb.RTx, paymentHash lntypes.Hash,
|
|||||||
// DeletePayment deletes a payment from the DB given its payment hash. If
|
// DeletePayment deletes a payment from the DB given its payment hash. If
|
||||||
// failedHtlcsOnly is set, only failed HTLC attempts of the payment will be
|
// failedHtlcsOnly is set, only failed HTLC attempts of the payment will be
|
||||||
// deleted.
|
// deleted.
|
||||||
func (p *KVStore) DeletePayment(paymentHash lntypes.Hash,
|
func (p *KVStore) DeletePayment(_ context.Context, paymentHash lntypes.Hash,
|
||||||
failedHtlcsOnly bool) error {
|
failedHtlcsOnly bool) error {
|
||||||
|
|
||||||
return kvdb.Update(p.db, func(tx kvdb.RwTx) error {
|
return kvdb.Update(p.db, func(tx kvdb.RwTx) error {
|
||||||
|
|||||||
+26
-10
@@ -511,8 +511,8 @@ func testDeleteFailedAttempts(t *testing.T, keepFailedPaymentAttempts bool) {
|
|||||||
// operation are performed in general therefore we do NOT expect an
|
// operation are performed in general therefore we do NOT expect an
|
||||||
// error in this case.
|
// error in this case.
|
||||||
if keepFailedPaymentAttempts {
|
if keepFailedPaymentAttempts {
|
||||||
require.NoError(
|
require.NoError(t, paymentDB.DeleteFailedAttempts(
|
||||||
t, paymentDB.DeleteFailedAttempts(payments[1].id),
|
payments[1].id),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
require.Error(t, paymentDB.DeleteFailedAttempts(payments[1].id))
|
require.Error(t, paymentDB.DeleteFailedAttempts(payments[1].id))
|
||||||
@@ -656,6 +656,8 @@ func TestMPPRecordValidation(t *testing.T) {
|
|||||||
func TestDeleteSinglePayment(t *testing.T) {
|
func TestDeleteSinglePayment(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
ctx := t.Context()
|
||||||
|
|
||||||
paymentDB, _ := NewTestDB(t)
|
paymentDB, _ := NewTestDB(t)
|
||||||
|
|
||||||
// Register four payments:
|
// Register four payments:
|
||||||
@@ -687,7 +689,9 @@ func TestDeleteSinglePayment(t *testing.T) {
|
|||||||
assertDBPayments(t, paymentDB, payments)
|
assertDBPayments(t, paymentDB, payments)
|
||||||
|
|
||||||
// Delete HTLC attempts for first payment only.
|
// Delete HTLC attempts for first payment only.
|
||||||
require.NoError(t, paymentDB.DeletePayment(payments[0].id, true))
|
require.NoError(t, paymentDB.DeletePayment(
|
||||||
|
ctx, payments[0].id, true,
|
||||||
|
))
|
||||||
|
|
||||||
// The first payment is the only altered one as its failed HTLC should
|
// The first payment is the only altered one as its failed HTLC should
|
||||||
// have been removed but is still present as payment.
|
// have been removed but is still present as payment.
|
||||||
@@ -695,19 +699,25 @@ func TestDeleteSinglePayment(t *testing.T) {
|
|||||||
assertDBPayments(t, paymentDB, payments)
|
assertDBPayments(t, paymentDB, payments)
|
||||||
|
|
||||||
// Delete the first payment completely.
|
// Delete the first payment completely.
|
||||||
require.NoError(t, paymentDB.DeletePayment(payments[0].id, false))
|
require.NoError(t, paymentDB.DeletePayment(
|
||||||
|
ctx, payments[0].id, false,
|
||||||
|
))
|
||||||
|
|
||||||
// The first payment should have been deleted.
|
// The first payment should have been deleted.
|
||||||
assertDBPayments(t, paymentDB, payments[1:])
|
assertDBPayments(t, paymentDB, payments[1:])
|
||||||
|
|
||||||
// Now delete the second payment completely.
|
// Now delete the second payment completely.
|
||||||
require.NoError(t, paymentDB.DeletePayment(payments[1].id, false))
|
require.NoError(t, paymentDB.DeletePayment(
|
||||||
|
ctx, payments[1].id, false,
|
||||||
|
))
|
||||||
|
|
||||||
// The Second payment should have been deleted.
|
// The Second payment should have been deleted.
|
||||||
assertDBPayments(t, paymentDB, payments[2:])
|
assertDBPayments(t, paymentDB, payments[2:])
|
||||||
|
|
||||||
// Delete failed HTLC attempts for the third payment.
|
// Delete failed HTLC attempts for the third payment.
|
||||||
require.NoError(t, paymentDB.DeletePayment(payments[2].id, true))
|
require.NoError(t, paymentDB.DeletePayment(
|
||||||
|
ctx, payments[2].id, true,
|
||||||
|
))
|
||||||
|
|
||||||
// Only the successful HTLC attempt should be left for the third
|
// Only the successful HTLC attempt should be left for the third
|
||||||
// payment.
|
// payment.
|
||||||
@@ -715,21 +725,27 @@ func TestDeleteSinglePayment(t *testing.T) {
|
|||||||
assertDBPayments(t, paymentDB, payments[2:])
|
assertDBPayments(t, paymentDB, payments[2:])
|
||||||
|
|
||||||
// Now delete the third payment completely.
|
// Now delete the third payment completely.
|
||||||
require.NoError(t, paymentDB.DeletePayment(payments[2].id, false))
|
require.NoError(t, paymentDB.DeletePayment(
|
||||||
|
ctx, payments[2].id, false,
|
||||||
|
))
|
||||||
|
|
||||||
// Only the last payment should be left.
|
// Only the last payment should be left.
|
||||||
assertDBPayments(t, paymentDB, payments[3:])
|
assertDBPayments(t, paymentDB, payments[3:])
|
||||||
|
|
||||||
// Deleting HTLC attempts from InFlight payments should not work and an
|
// Deleting HTLC attempts from InFlight payments should not work and an
|
||||||
// error returned.
|
// error returned.
|
||||||
require.Error(t, paymentDB.DeletePayment(payments[3].id, true))
|
require.Error(t, paymentDB.DeletePayment(
|
||||||
|
ctx, payments[3].id, true,
|
||||||
|
))
|
||||||
|
|
||||||
// The payment is InFlight and therefore should not have been altered.
|
// The payment is InFlight and therefore should not have been altered.
|
||||||
assertDBPayments(t, paymentDB, payments[3:])
|
assertDBPayments(t, paymentDB, payments[3:])
|
||||||
|
|
||||||
// Finally deleting the InFlight payment should also not work and an
|
// Finally deleting the InFlight payment should also not work and an
|
||||||
// error returned.
|
// error returned.
|
||||||
require.Error(t, paymentDB.DeletePayment(payments[3].id, false))
|
require.Error(t, paymentDB.DeletePayment(
|
||||||
|
ctx, payments[3].id, false,
|
||||||
|
))
|
||||||
|
|
||||||
// The payment is InFlight and therefore should not have been altered.
|
// The payment is InFlight and therefore should not have been altered.
|
||||||
assertDBPayments(t, paymentDB, payments[3:])
|
assertDBPayments(t, paymentDB, payments[3:])
|
||||||
@@ -2597,7 +2613,7 @@ func TestQueryPayments(t *testing.T) {
|
|||||||
|
|
||||||
// We delete the whole payment.
|
// We delete the whole payment.
|
||||||
err = paymentDB.DeletePayment(
|
err = paymentDB.DeletePayment(
|
||||||
paymentInfos[1].PaymentIdentifier, false,
|
ctx, paymentInfos[1].PaymentIdentifier, false,
|
||||||
)
|
)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
|||||||
@@ -1206,11 +1206,9 @@ func computePaymentStatusFromDB(ctx context.Context, cfg *sqldb.QueryConfig,
|
|||||||
//
|
//
|
||||||
// This method is part of the PaymentWriter interface, which is embedded in
|
// This method is part of the PaymentWriter interface, which is embedded in
|
||||||
// the DB interface.
|
// the DB interface.
|
||||||
func (s *SQLStore) DeletePayment(paymentHash lntypes.Hash,
|
func (s *SQLStore) DeletePayment(ctx context.Context, paymentHash lntypes.Hash,
|
||||||
failedHtlcsOnly bool) error {
|
failedHtlcsOnly bool) error {
|
||||||
|
|
||||||
ctx := context.TODO()
|
|
||||||
|
|
||||||
err := s.db.ExecTx(ctx, sqldb.WriteTxOpt(), func(db SQLQueries) error {
|
err := s.db.ExecTx(ctx, sqldb.WriteTxOpt(), func(db SQLQueries) error {
|
||||||
dbPayment, err := fetchPaymentByHash(ctx, db, paymentHash)
|
dbPayment, err := fetchPaymentByHash(ctx, db, paymentHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+1
-1
@@ -7741,7 +7741,7 @@ func (r *rpcServer) DeletePayment(ctx context.Context,
|
|||||||
rpcsLog.Infof("[DeletePayment] payment_identifier=%v, "+
|
rpcsLog.Infof("[DeletePayment] payment_identifier=%v, "+
|
||||||
"failed_htlcs_only=%v", hash, req.FailedHtlcsOnly)
|
"failed_htlcs_only=%v", hash, req.FailedHtlcsOnly)
|
||||||
|
|
||||||
err = r.server.paymentsDB.DeletePayment(hash, req.FailedHtlcsOnly)
|
err = r.server.paymentsDB.DeletePayment(ctx, hash, req.FailedHtlcsOnly)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user