Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
34 changes: 17 additions & 17 deletions channeldb/payment_control.go → channeldb/payments_kv_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,17 @@ var (
"does not exist")
)

// PaymentControl implements persistence for payments and payment attempts.
type PaymentControl struct {
// KVPaymentsDB implements persistence for payments and payment attempts.
type KVPaymentsDB struct {
paymentSeqMx sync.Mutex
currPaymentSeq uint64
storedPaymentSeq uint64
db *DB
}

// NewPaymentControl creates a new instance of the PaymentControl.
func NewPaymentControl(db *DB) *PaymentControl {
return &PaymentControl{
// NewKVPaymentsDB creates a new instance of the KVPaymentsDB.
func NewKVPaymentsDB(db *DB) *KVPaymentsDB {
return &KVPaymentsDB{
db: db,
}
}
Expand All @@ -149,7 +149,7 @@ func NewPaymentControl(db *DB) *PaymentControl {
// making sure it does not already exist as an in-flight payment. When this
// method returns successfully, the payment is guaranteed to be in the InFlight
// state.
func (p *PaymentControl) InitPayment(paymentHash lntypes.Hash,
func (p *KVPaymentsDB) InitPayment(paymentHash lntypes.Hash,
info *PaymentCreationInfo) error {

// Obtain a new sequence number for this payment. This is used
Expand Down Expand Up @@ -252,8 +252,8 @@ func (p *PaymentControl) InitPayment(paymentHash lntypes.Hash,
}

// DeleteFailedAttempts deletes all failed htlcs for a payment if configured
// by the PaymentControl db.
func (p *PaymentControl) DeleteFailedAttempts(hash lntypes.Hash) error {
// by the KVPaymentsDB db.
func (p *KVPaymentsDB) DeleteFailedAttempts(hash lntypes.Hash) error {
if !p.db.keepFailedPaymentAttempts {
const failedHtlcsOnly = true
err := p.db.DeletePayment(hash, failedHtlcsOnly)
Expand Down Expand Up @@ -318,7 +318,7 @@ func deserializePaymentIndex(r io.Reader) (lntypes.Hash, error) {

// RegisterAttempt atomically records the provided HTLCAttemptInfo to the
// DB.
func (p *PaymentControl) RegisterAttempt(paymentHash lntypes.Hash,
func (p *KVPaymentsDB) RegisterAttempt(paymentHash lntypes.Hash,
attempt *HTLCAttemptInfo) (*MPPayment, error) {

// Serialize the information before opening the db transaction.
Expand Down Expand Up @@ -467,7 +467,7 @@ func (p *PaymentControl) RegisterAttempt(paymentHash lntypes.Hash,
// 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 *PaymentControl) SettleAttempt(hash lntypes.Hash,
func (p *KVPaymentsDB) SettleAttempt(hash lntypes.Hash,
attemptID uint64, settleInfo *HTLCSettleInfo) (*MPPayment, error) {

var b bytes.Buffer
Expand All @@ -480,7 +480,7 @@ func (p *PaymentControl) SettleAttempt(hash lntypes.Hash,
}

// FailAttempt marks the given payment attempt failed.
func (p *PaymentControl) FailAttempt(hash lntypes.Hash,
func (p *KVPaymentsDB) FailAttempt(hash lntypes.Hash,
attemptID uint64, failInfo *HTLCFailInfo) (*MPPayment, error) {

var b bytes.Buffer
Expand All @@ -493,7 +493,7 @@ func (p *PaymentControl) FailAttempt(hash lntypes.Hash,
}

// updateHtlcKey updates a database key for the specified htlc.
func (p *PaymentControl) updateHtlcKey(paymentHash lntypes.Hash,
func (p *KVPaymentsDB) updateHtlcKey(paymentHash lntypes.Hash,
attemptID uint64, key, value []byte) (*MPPayment, error) {

aid := make([]byte, 8)
Expand Down Expand Up @@ -561,7 +561,7 @@ func (p *PaymentControl) updateHtlcKey(paymentHash lntypes.Hash,
// 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.
func (p *PaymentControl) Fail(paymentHash lntypes.Hash,
func (p *KVPaymentsDB) Fail(paymentHash lntypes.Hash,
reason FailureReason) (*MPPayment, error) {

var (
Expand All @@ -585,7 +585,7 @@ func (p *PaymentControl) Fail(paymentHash lntypes.Hash,

// We mark the payment as failed as long as it is known. This
// lets the last attempt to fail with a terminal write its
// failure to the PaymentControl without synchronizing with
// failure to the KVPaymentsDB without synchronizing with
// other attempts.
_, err = fetchPaymentStatus(bucket)
if errors.Is(err, ErrPaymentNotInitiated) {
Expand Down Expand Up @@ -618,7 +618,7 @@ func (p *PaymentControl) Fail(paymentHash lntypes.Hash,
}

// FetchPayment returns information about a payment from the database.
func (p *PaymentControl) FetchPayment(paymentHash lntypes.Hash) (
func (p *KVPaymentsDB) FetchPayment(paymentHash lntypes.Hash) (
*MPPayment, error) {

var payment *MPPayment
Expand Down Expand Up @@ -714,7 +714,7 @@ func fetchPaymentBucketUpdate(tx kvdb.RwTx, paymentHash lntypes.Hash) (

// nextPaymentSequence returns the next sequence number to store for a new
// payment.
func (p *PaymentControl) nextPaymentSequence() ([]byte, error) {
func (p *KVPaymentsDB) nextPaymentSequence() ([]byte, error) {
p.paymentSeqMx.Lock()
defer p.paymentSeqMx.Unlock()

Expand Down Expand Up @@ -774,7 +774,7 @@ func fetchPaymentStatus(bucket kvdb.RBucket) (PaymentStatus, error) {
}

// FetchInFlightPayments returns all payments with status InFlight.
func (p *PaymentControl) FetchInFlightPayments() ([]*MPPayment, error) {
func (p *KVPaymentsDB) FetchInFlightPayments() ([]*MPPayment, error) {
var (
inFlights []*MPPayment
start = time.Now()
Expand Down
Loading
Loading