Skip to content

Commit 21112cf

Browse files
committed
htlcswitch: rename paymentID to attemptID for clarity
1 parent 941716d commit 21112cf

File tree

2 files changed

+36
-37
lines changed

2 files changed

+36
-37
lines changed

htlcswitch/payment_result.go

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -90,41 +90,41 @@ type networkResultStore struct {
9090
results map[uint64][]chan *networkResult
9191
resultsMtx sync.Mutex
9292

93-
// paymentIDMtx is a multimutex used to make sure the database and
94-
// result subscribers map is consistent for each payment ID in case of
93+
// attemptIDMtx is a multimutex used to make sure the database and
94+
// result subscribers map is consistent for each attempt ID in case of
9595
// concurrent callers.
96-
paymentIDMtx *multimutex.Mutex[uint64]
96+
attemptIDMtx *multimutex.Mutex[uint64]
9797
}
9898

9999
func newNetworkResultStore(db kvdb.Backend) *networkResultStore {
100100
return &networkResultStore{
101101
backend: db,
102102
results: make(map[uint64][]chan *networkResult),
103-
paymentIDMtx: multimutex.NewMutex[uint64](),
103+
attemptIDMtx: multimutex.NewMutex[uint64](),
104104
}
105105
}
106106

107-
// storeResult stores the networkResult for the given paymentID, and
108-
// notifies any subscribers.
109-
func (store *networkResultStore) storeResult(paymentID uint64,
107+
// storeResult stores the networkResult for the given attemptID, and notifies
108+
// any subscribers.
109+
func (store *networkResultStore) storeResult(attemptID uint64,
110110
result *networkResult) error {
111111

112-
// We get a mutex for this payment ID. This is needed to ensure
112+
// We get a mutex for this attempt ID. This is needed to ensure
113113
// consistency between the database state and the subscribers in case
114114
// of concurrent calls.
115-
store.paymentIDMtx.Lock(paymentID)
116-
defer store.paymentIDMtx.Unlock(paymentID)
115+
store.attemptIDMtx.Lock(attemptID)
116+
defer store.attemptIDMtx.Unlock(attemptID)
117117

118-
log.Debugf("Storing result for paymentID=%v", paymentID)
118+
log.Debugf("Storing result for attemptID=%v", attemptID)
119119

120120
// Serialize the payment result.
121121
var b bytes.Buffer
122122
if err := serializeNetworkResult(&b, result); err != nil {
123123
return err
124124
}
125125

126-
var paymentIDBytes [8]byte
127-
binary.BigEndian.PutUint64(paymentIDBytes[:], paymentID)
126+
var attemptIDBytes [8]byte
127+
binary.BigEndian.PutUint64(attemptIDBytes[:], attemptID)
128128

129129
err := kvdb.Batch(store.backend, func(tx kvdb.RwTx) error {
130130
networkResults, err := tx.CreateTopLevelBucket(
@@ -134,7 +134,7 @@ func (store *networkResultStore) storeResult(paymentID uint64,
134134
return err
135135
}
136136

137-
return networkResults.Put(paymentIDBytes[:], b.Bytes())
137+
return networkResults.Put(attemptIDBytes[:], b.Bytes())
138138
})
139139
if err != nil {
140140
return err
@@ -143,28 +143,27 @@ func (store *networkResultStore) storeResult(paymentID uint64,
143143
// Now that the result is stored in the database, we can notify any
144144
// active subscribers.
145145
store.resultsMtx.Lock()
146-
for _, res := range store.results[paymentID] {
146+
for _, res := range store.results[attemptID] {
147147
res <- result
148148
}
149-
delete(store.results, paymentID)
149+
delete(store.results, attemptID)
150150
store.resultsMtx.Unlock()
151151

152152
return nil
153153
}
154154

155-
// subscribeResult is used to get the payment result for the given
156-
// payment ID. It returns a channel on which the result will be delivered when
157-
// ready.
158-
func (store *networkResultStore) subscribeResult(paymentID uint64) (
155+
// subscribeResult is used to get the HTLC attempt result for the given attempt
156+
// ID. It returns a channel on which the result will be delivered when ready.
157+
func (store *networkResultStore) subscribeResult(attemptID uint64) (
159158
<-chan *networkResult, error) {
160159

161160
// We get a mutex for this payment ID. This is needed to ensure
162161
// consistency between the database state and the subscribers in case
163162
// of concurrent calls.
164-
store.paymentIDMtx.Lock(paymentID)
165-
defer store.paymentIDMtx.Unlock(paymentID)
163+
store.attemptIDMtx.Lock(attemptID)
164+
defer store.attemptIDMtx.Unlock(attemptID)
166165

167-
log.Debugf("Subscribing to result for paymentID=%v", paymentID)
166+
log.Debugf("Subscribing to result for attemptID=%v", attemptID)
168167

169168
var (
170169
result *networkResult
@@ -173,7 +172,7 @@ func (store *networkResultStore) subscribeResult(paymentID uint64) (
173172

174173
err := kvdb.View(store.backend, func(tx kvdb.RTx) error {
175174
var err error
176-
result, err = fetchResult(tx, paymentID)
175+
result, err = fetchResult(tx, attemptID)
177176
switch {
178177

179178
// Result not yet available, we will notify once a result is
@@ -205,8 +204,8 @@ func (store *networkResultStore) subscribeResult(paymentID uint64) (
205204
// Otherwise we store the result channel for when the result is
206205
// available.
207206
store.resultsMtx.Lock()
208-
store.results[paymentID] = append(
209-
store.results[paymentID], resultChan,
207+
store.results[attemptID] = append(
208+
store.results[attemptID], resultChan,
210209
)
211210
store.resultsMtx.Unlock()
212211

@@ -234,16 +233,16 @@ func (store *networkResultStore) getResult(pid uint64) (
234233
}
235234

236235
func fetchResult(tx kvdb.RTx, pid uint64) (*networkResult, error) {
237-
var paymentIDBytes [8]byte
238-
binary.BigEndian.PutUint64(paymentIDBytes[:], pid)
236+
var attemptIDBytes [8]byte
237+
binary.BigEndian.PutUint64(attemptIDBytes[:], pid)
239238

240239
networkResults := tx.ReadBucket(networkResultStoreBucketKey)
241240
if networkResults == nil {
242241
return nil, ErrPaymentIDNotFound
243242
}
244243

245244
// Check whether a result is already available.
246-
resultBytes := networkResults.Get(paymentIDBytes[:])
245+
resultBytes := networkResults.Get(attemptIDBytes[:])
247246
if resultBytes == nil {
248247
return nil, ErrPaymentIDNotFound
249248
}

htlcswitch/switch.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -431,11 +431,11 @@ func (s *Switch) ProcessContractResolution(msg contractcourt.ResolutionMsg) erro
431431
}
432432
}
433433

434-
// GetAttemptResult returns the result of the payment attempt with the given
434+
// GetAttemptResult returns the result of the HTLC attempt with the given
435435
// attemptID. The paymentHash should be set to the payment's overall hash, or
436436
// in case of AMP payments the payment's unique identifier.
437437
//
438-
// The method returns a channel where the payment result will be sent when
438+
// The method returns a channel where the HTLC attempt result will be sent when
439439
// available, or an error is encountered during forwarding. When a result is
440440
// received on the channel, the HTLC is guaranteed to no longer be in flight.
441441
// The switch shutting down is signaled by closing the channel. If the
@@ -452,9 +452,9 @@ func (s *Switch) GetAttemptResult(attemptID uint64, paymentHash lntypes.Hash,
452452
}
453453
)
454454

455-
// If the payment is not found in the circuit map, check whether a
456-
// result is already available.
457-
// Assumption: no one will add this payment ID other than the caller.
455+
// If the HTLC is not found in the circuit map, check whether a result
456+
// is already available.
457+
// Assumption: no one will add this attempt ID other than the caller.
458458
if s.circuits.LookupCircuit(inKey) == nil {
459459
res, err := s.networkResults.getResult(attemptID)
460460
if err != nil {
@@ -464,7 +464,7 @@ func (s *Switch) GetAttemptResult(attemptID uint64, paymentHash lntypes.Hash,
464464
c <- res
465465
nChan = c
466466
} else {
467-
// The payment was committed to the circuits, subscribe for a
467+
// The HTLC was committed to the circuits, subscribe for a
468468
// result.
469469
nChan, err = s.networkResults.subscribeResult(attemptID)
470470
if err != nil {
@@ -474,7 +474,7 @@ func (s *Switch) GetAttemptResult(attemptID uint64, paymentHash lntypes.Hash,
474474

475475
resultChan := make(chan *PaymentResult, 1)
476476

477-
// Since the payment was known, we can start a goroutine that can
477+
// Since the attempt was known, we can start a goroutine that can
478478
// extract the result when it is available, and pass it on to the
479479
// caller.
480480
s.wg.Add(1)
@@ -939,7 +939,7 @@ func (s *Switch) handleLocalResponse(pkt *htlcPacket) {
939939
// Store the result to the db. This will also notify subscribers about
940940
// the result.
941941
if err := s.networkResults.storeResult(attemptID, n); err != nil {
942-
log.Errorf("Unable to complete payment for pid=%v: %v",
942+
log.Errorf("Unable to store attempt result for pid=%v: %v",
943943
attemptID, err)
944944
return
945945
}

0 commit comments

Comments
 (0)