@@ -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
9999func 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
236235func 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 }
0 commit comments