Skip to content

Commit f900beb

Browse files
committed
fixup! channeldb: rename PaymentControl struct
1 parent db54a9c commit f900beb

File tree

4 files changed

+39
-39
lines changed

4 files changed

+39
-39
lines changed

channeldb/payment_kv_store.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,17 @@ var (
130130
"does not exist")
131131
)
132132

133-
// KVStore implements persistence for payments and payment attempts.
134-
type KVStore struct {
133+
// KVPaymentsDB implements persistence for payments and payment attempts.
134+
type KVPaymentsDB struct {
135135
paymentSeqMx sync.Mutex
136136
currPaymentSeq uint64
137137
storedPaymentSeq uint64
138138
db *DB
139139
}
140140

141-
// NewKVStore creates a new instance of the KVStore.
142-
func NewKVStore(db *DB) *KVStore {
143-
return &KVStore{
141+
// NewKVPaymentsDB creates a new instance of the KVPaymentsDB.
142+
func NewKVPaymentsDB(db *DB) *KVPaymentsDB {
143+
return &KVPaymentsDB{
144144
db: db,
145145
}
146146
}
@@ -149,7 +149,7 @@ func NewKVStore(db *DB) *KVStore {
149149
// making sure it does not already exist as an in-flight payment. When this
150150
// method returns successfully, the payment is guaranteed to be in the InFlight
151151
// state.
152-
func (p *KVStore) InitPayment(paymentHash lntypes.Hash,
152+
func (p *KVPaymentsDB) InitPayment(paymentHash lntypes.Hash,
153153
info *PaymentCreationInfo) error {
154154

155155
// Obtain a new sequence number for this payment. This is used
@@ -252,8 +252,8 @@ func (p *KVStore) InitPayment(paymentHash lntypes.Hash,
252252
}
253253

254254
// DeleteFailedAttempts deletes all failed htlcs for a payment if configured
255-
// by the KVStore db.
256-
func (p *KVStore) DeleteFailedAttempts(hash lntypes.Hash) error {
255+
// by the KVPaymentsDB db.
256+
func (p *KVPaymentsDB) DeleteFailedAttempts(hash lntypes.Hash) error {
257257
if !p.db.keepFailedPaymentAttempts {
258258
const failedHtlcsOnly = true
259259
err := p.db.DeletePayment(hash, failedHtlcsOnly)
@@ -318,7 +318,7 @@ func deserializePaymentIndex(r io.Reader) (lntypes.Hash, error) {
318318

319319
// RegisterAttempt atomically records the provided HTLCAttemptInfo to the
320320
// DB.
321-
func (p *KVStore) RegisterAttempt(paymentHash lntypes.Hash,
321+
func (p *KVPaymentsDB) RegisterAttempt(paymentHash lntypes.Hash,
322322
attempt *HTLCAttemptInfo) (*MPPayment, error) {
323323

324324
// Serialize the information before opening the db transaction.
@@ -467,7 +467,7 @@ func (p *KVStore) RegisterAttempt(paymentHash lntypes.Hash,
467467
// After invoking this method, InitPayment should always return an error to
468468
// prevent us from making duplicate payments to the same payment hash. The
469469
// provided preimage is atomically saved to the DB for record keeping.
470-
func (p *KVStore) SettleAttempt(hash lntypes.Hash,
470+
func (p *KVPaymentsDB) SettleAttempt(hash lntypes.Hash,
471471
attemptID uint64, settleInfo *HTLCSettleInfo) (*MPPayment, error) {
472472

473473
var b bytes.Buffer
@@ -480,7 +480,7 @@ func (p *KVStore) SettleAttempt(hash lntypes.Hash,
480480
}
481481

482482
// FailAttempt marks the given payment attempt failed.
483-
func (p *KVStore) FailAttempt(hash lntypes.Hash,
483+
func (p *KVPaymentsDB) FailAttempt(hash lntypes.Hash,
484484
attemptID uint64, failInfo *HTLCFailInfo) (*MPPayment, error) {
485485

486486
var b bytes.Buffer
@@ -493,7 +493,7 @@ func (p *KVStore) FailAttempt(hash lntypes.Hash,
493493
}
494494

495495
// updateHtlcKey updates a database key for the specified htlc.
496-
func (p *KVStore) updateHtlcKey(paymentHash lntypes.Hash,
496+
func (p *KVPaymentsDB) updateHtlcKey(paymentHash lntypes.Hash,
497497
attemptID uint64, key, value []byte) (*MPPayment, error) {
498498

499499
aid := make([]byte, 8)
@@ -561,7 +561,7 @@ func (p *KVStore) updateHtlcKey(paymentHash lntypes.Hash,
561561
// payment failed. After invoking this method, InitPayment should return nil on
562562
// its next call for this payment hash, allowing the switch to make a
563563
// subsequent payment.
564-
func (p *KVStore) Fail(paymentHash lntypes.Hash,
564+
func (p *KVPaymentsDB) Fail(paymentHash lntypes.Hash,
565565
reason FailureReason) (*MPPayment, error) {
566566

567567
var (
@@ -585,7 +585,7 @@ func (p *KVStore) Fail(paymentHash lntypes.Hash,
585585

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

620620
// FetchPayment returns information about a payment from the database.
621-
func (p *KVStore) FetchPayment(paymentHash lntypes.Hash) (
621+
func (p *KVPaymentsDB) FetchPayment(paymentHash lntypes.Hash) (
622622
*MPPayment, error) {
623623

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

715715
// nextPaymentSequence returns the next sequence number to store for a new
716716
// payment.
717-
func (p *KVStore) nextPaymentSequence() ([]byte, error) {
717+
func (p *KVPaymentsDB) nextPaymentSequence() ([]byte, error) {
718718
p.paymentSeqMx.Lock()
719719
defer p.paymentSeqMx.Unlock()
720720

@@ -774,7 +774,7 @@ func fetchPaymentStatus(bucket kvdb.RBucket) (PaymentStatus, error) {
774774
}
775775

776776
// FetchInFlightPayments returns all payments with status InFlight.
777-
func (p *KVStore) FetchInFlightPayments() ([]*MPPayment, error) {
777+
func (p *KVPaymentsDB) FetchInFlightPayments() ([]*MPPayment, error) {
778778
var (
779779
inFlights []*MPPayment
780780
start = time.Now()

routing/control_tower.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func (s *controlTowerSubscriberImpl) Updates() <-chan interface{} {
151151
// controlTower is persistent implementation of ControlTower to restrict
152152
// double payment sending.
153153
type controlTower struct {
154-
db *channeldb.PaymentControl
154+
db *channeldb.KVPaymentsDB
155155

156156
// subscriberIndex is used to provide a unique id for each subscriber
157157
// to all payments. This is used to easily remove the subscriber when
@@ -168,7 +168,7 @@ type controlTower struct {
168168
}
169169

170170
// NewControlTower creates a new instance of the controlTower.
171-
func NewControlTower(db *channeldb.PaymentControl) ControlTower {
171+
func NewControlTower(db *channeldb.KVPaymentsDB) ControlTower {
172172
return &controlTower{
173173
db: db,
174174
subscribersAllPayments: make(

routing/control_tower_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func TestControlTowerSubscribeUnknown(t *testing.T) {
4949

5050
db := initDB(t, false)
5151

52-
pControl := NewControlTower(channeldb.NewPaymentControl(db))
52+
pControl := NewControlTower(channeldb.NewKVPaymentsDB(db))
5353

5454
// Subscription should fail when the payment is not known.
5555
_, err := pControl.SubscribePayment(lntypes.Hash{1})
@@ -63,7 +63,7 @@ func TestControlTowerSubscribeSuccess(t *testing.T) {
6363

6464
db := initDB(t, false)
6565

66-
pControl := NewControlTower(channeldb.NewPaymentControl(db))
66+
pControl := NewControlTower(channeldb.NewKVPaymentsDB(db))
6767

6868
// Initiate a payment.
6969
info, attempt, preimg, err := genInfo()
@@ -156,33 +156,33 @@ func TestControlTowerSubscribeSuccess(t *testing.T) {
156156
}
157157
}
158158

159-
// TestPaymentControlSubscribeFail tests that payment updates for a
159+
// TestKVPaymentsDBSubscribeFail tests that payment updates for a
160160
// failed payment are properly sent to subscribers.
161-
func TestPaymentControlSubscribeFail(t *testing.T) {
161+
func TestKVPaymentsDBSubscribeFail(t *testing.T) {
162162
t.Parallel()
163163

164164
t.Run("register attempt, keep failed payments", func(t *testing.T) {
165-
testPaymentControlSubscribeFail(t, true, true)
165+
testKVPaymentsDBSubscribeFail(t, true, true)
166166
})
167167
t.Run("register attempt, delete failed payments", func(t *testing.T) {
168-
testPaymentControlSubscribeFail(t, true, false)
168+
testKVPaymentsDBSubscribeFail(t, true, false)
169169
})
170170
t.Run("no register attempt, keep failed payments", func(t *testing.T) {
171-
testPaymentControlSubscribeFail(t, false, true)
171+
testKVPaymentsDBSubscribeFail(t, false, true)
172172
})
173173
t.Run("no register attempt, delete failed payments", func(t *testing.T) {
174-
testPaymentControlSubscribeFail(t, false, false)
174+
testKVPaymentsDBSubscribeFail(t, false, false)
175175
})
176176
}
177177

178-
// TestPaymentControlSubscribeAllSuccess tests that multiple payments are
178+
// TestKVPaymentsDBSubscribeAllSuccess tests that multiple payments are
179179
// properly sent to subscribers of TrackPayments.
180-
func TestPaymentControlSubscribeAllSuccess(t *testing.T) {
180+
func TestKVPaymentsDBSubscribeAllSuccess(t *testing.T) {
181181
t.Parallel()
182182

183183
db := initDB(t, true)
184184

185-
pControl := NewControlTower(channeldb.NewPaymentControl(db))
185+
pControl := NewControlTower(channeldb.NewKVPaymentsDB(db))
186186

187187
// Initiate a payment.
188188
info1, attempt1, preimg1, err := genInfo()
@@ -288,14 +288,14 @@ func TestPaymentControlSubscribeAllSuccess(t *testing.T) {
288288
require.Equal(t, attempt2.Route, htlc2.Route, "unexpected htlc route.")
289289
}
290290

291-
// TestPaymentControlSubscribeAllImmediate tests whether already inflight
291+
// TestKVPaymentsDBSubscribeAllImmediate tests whether already inflight
292292
// payments are reported at the start of the SubscribeAllPayments subscription.
293-
func TestPaymentControlSubscribeAllImmediate(t *testing.T) {
293+
func TestKVPaymentsDBSubscribeAllImmediate(t *testing.T) {
294294
t.Parallel()
295295

296296
db := initDB(t, true)
297297

298-
pControl := NewControlTower(channeldb.NewPaymentControl(db))
298+
pControl := NewControlTower(channeldb.NewKVPaymentsDB(db))
299299

300300
// Initiate a payment.
301301
info, attempt, _, err := genInfo()
@@ -325,14 +325,14 @@ func TestPaymentControlSubscribeAllImmediate(t *testing.T) {
325325
}
326326
}
327327

328-
// TestPaymentControlUnsubscribeSuccess tests that when unsubscribed, there are
328+
// TestKVPaymentsDBUnsubscribeSuccess tests that when unsubscribed, there are
329329
// no more notifications to that specific subscription.
330-
func TestPaymentControlUnsubscribeSuccess(t *testing.T) {
330+
func TestKVPaymentsDBUnsubscribeSuccess(t *testing.T) {
331331
t.Parallel()
332332

333333
db := initDB(t, true)
334334

335-
pControl := NewControlTower(channeldb.NewPaymentControl(db))
335+
pControl := NewControlTower(channeldb.NewKVPaymentsDB(db))
336336

337337
subscription1, err := pControl.SubscribeAllPayments()
338338
require.NoError(t, err, "expected subscribe to succeed, but got: %v")
@@ -396,12 +396,12 @@ func TestPaymentControlUnsubscribeSuccess(t *testing.T) {
396396
require.Len(t, subscription2.Updates(), 0)
397397
}
398398

399-
func testPaymentControlSubscribeFail(t *testing.T, registerAttempt,
399+
func testKVPaymentsDBSubscribeFail(t *testing.T, registerAttempt,
400400
keepFailedPaymentAttempts bool) {
401401

402402
db := initDB(t, keepFailedPaymentAttempts)
403403

404-
pControl := NewControlTower(channeldb.NewPaymentControl(db))
404+
pControl := NewControlTower(channeldb.NewKVPaymentsDB(db))
405405

406406
// Initiate a payment.
407407
info, attempt, _, err := genInfo()

server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ func newServer(ctx context.Context, cfg *Config, listenAddrs []net.Addr,
11271127
PathFindingConfig: pathFindingConfig,
11281128
}
11291129

1130-
paymentControl := channeldb.NewPaymentControl(dbs.ChanStateDB)
1130+
paymentControl := channeldb.NewKVPaymentsDB(dbs.ChanStateDB)
11311131

11321132
s.controlTower = routing.NewControlTower(paymentControl)
11331133

0 commit comments

Comments
 (0)