channeldb: rename PaymentAttemptInfo to HTLCAttemptInfo
To better distinguish payments from HTLCs, we rename the attempt info struct to HTLCAttemptInfo. We also embed it into the HTLCAttempt struct, to avoid having to duplicate this information. The paymentID term is renamed to attemptID.
This commit is contained in:
1 parent
967b4b2dc3
commit
bee2380441
10 files changed
+75
-88
No files matched your search
@@ -19,8 +19,8 @@ type ControlTower interface {
|
||||
// hash.
|
||||
InitPayment(lntypes.Hash, *channeldb.PaymentCreationInfo) error
|
||||
|
||||
// RegisterAttempt atomically records the provided PaymentAttemptInfo.
|
||||
RegisterAttempt(lntypes.Hash, *channeldb.PaymentAttemptInfo) error
|
||||
// RegisterAttempt atomically records the provided HTLCAttemptInfo.
|
||||
RegisterAttempt(lntypes.Hash, *channeldb.HTLCAttemptInfo) error
|
||||
|
||||
// Success transitions a payment into the Succeeded state. After
|
||||
// invoking this method, InitPayment should always return an error to
|
||||
@@ -91,10 +91,10 @@ func (p *controlTower) InitPayment(paymentHash lntypes.Hash,
|
||||
return p.db.InitPayment(paymentHash, info)
|
||||
}
|
||||
|
||||
// RegisterAttempt atomically records the provided PaymentAttemptInfo to the
|
||||
// RegisterAttempt atomically records the provided HTLCAttemptInfo to the
|
||||
// DB.
|
||||
func (p *controlTower) RegisterAttempt(paymentHash lntypes.Hash,
|
||||
attempt *channeldb.PaymentAttemptInfo) error {
|
||||
attempt *channeldb.HTLCAttemptInfo) error {
|
||||
|
||||
return p.db.RegisterAttempt(paymentHash, attempt)
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ func initDB() (*channeldb.DB, error) {
|
||||
return db, err
|
||||
}
|
||||
|
||||
func genInfo() (*channeldb.PaymentCreationInfo, *channeldb.PaymentAttemptInfo,
|
||||
func genInfo() (*channeldb.PaymentCreationInfo, *channeldb.HTLCAttemptInfo,
|
||||
lntypes.Preimage, error) {
|
||||
|
||||
preimage, err := genPreimage()
|
||||
@@ -314,8 +314,8 @@ func genInfo() (*channeldb.PaymentCreationInfo, *channeldb.PaymentAttemptInfo,
|
||||
CreationTime: time.Unix(time.Now().Unix(), 0),
|
||||
PaymentRequest: []byte("hola"),
|
||||
},
|
||||
&channeldb.PaymentAttemptInfo{
|
||||
PaymentID: 1,
|
||||
&channeldb.HTLCAttemptInfo{
|
||||
AttemptID: 1,
|
||||
SessionKey: priv,
|
||||
Route: testRoute,
|
||||
}, preimage, nil
|
||||
|
||||
@@ -178,7 +178,7 @@ type initArgs struct {
|
||||
}
|
||||
|
||||
type registerArgs struct {
|
||||
a *channeldb.PaymentAttemptInfo
|
||||
a *channeldb.HTLCAttemptInfo
|
||||
}
|
||||
|
||||
type successArgs struct {
|
||||
@@ -238,7 +238,7 @@ func (m *mockControlTower) InitPayment(phash lntypes.Hash,
|
||||
}
|
||||
|
||||
func (m *mockControlTower) RegisterAttempt(phash lntypes.Hash,
|
||||
a *channeldb.PaymentAttemptInfo) error {
|
||||
a *channeldb.HTLCAttemptInfo) error {
|
||||
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
|
||||
@@ -35,7 +35,7 @@ type paymentLifecycle struct {
|
||||
timeoutChan <-chan time.Time
|
||||
currentHeight int32
|
||||
finalCLTVDelta uint16
|
||||
attempt *channeldb.PaymentAttemptInfo
|
||||
attempt *channeldb.HTLCAttemptInfo
|
||||
circuit *sphinx.Circuit
|
||||
lastError error
|
||||
}
|
||||
@@ -97,17 +97,17 @@ func (p *paymentLifecycle) resumePayment() ([32]byte, *route.Route, error) {
|
||||
// Now ask the switch to return the result of the payment when
|
||||
// available.
|
||||
resultChan, err := p.router.cfg.Payer.GetPaymentResult(
|
||||
p.attempt.PaymentID, p.payment.PaymentHash, errorDecryptor,
|
||||
p.attempt.AttemptID, p.payment.PaymentHash, errorDecryptor,
|
||||
)
|
||||
switch {
|
||||
|
||||
// If this payment ID is unknown to the Switch, it means it was
|
||||
// If this attempt ID is unknown to the Switch, it means it was
|
||||
// never checkpointed and forwarded by the switch before a
|
||||
// restart. In this case we can safely send a new payment
|
||||
// attempt, and wait for its result to be available.
|
||||
case err == htlcswitch.ErrPaymentIDNotFound:
|
||||
log.Debugf("Payment ID %v for hash %x not found in "+
|
||||
"the Switch, retrying.", p.attempt.PaymentID,
|
||||
"the Switch, retrying.", p.attempt.AttemptID,
|
||||
p.payment.PaymentHash)
|
||||
|
||||
// Reset the attempt to indicate we want to make a new
|
||||
@@ -117,8 +117,8 @@ func (p *paymentLifecycle) resumePayment() ([32]byte, *route.Route, error) {
|
||||
|
||||
// A critical, unexpected error was encountered.
|
||||
case err != nil:
|
||||
log.Errorf("Failed getting result for paymentID %d "+
|
||||
"from switch: %v", p.attempt.PaymentID, err)
|
||||
log.Errorf("Failed getting result for attemptID %d "+
|
||||
"from switch: %v", p.attempt.AttemptID, err)
|
||||
|
||||
return [32]byte{}, nil, err
|
||||
}
|
||||
@@ -161,11 +161,11 @@ func (p *paymentLifecycle) resumePayment() ([32]byte, *route.Route, error) {
|
||||
|
||||
// We successfully got a payment result back from the switch.
|
||||
log.Debugf("Payment %x succeeded with pid=%v",
|
||||
p.payment.PaymentHash, p.attempt.PaymentID)
|
||||
p.payment.PaymentHash, p.attempt.AttemptID)
|
||||
|
||||
// Report success to mission control.
|
||||
err = p.router.cfg.MissionControl.ReportPaymentSuccess(
|
||||
p.attempt.PaymentID, &p.attempt.Route,
|
||||
p.attempt.AttemptID, &p.attempt.Route,
|
||||
)
|
||||
if err != nil {
|
||||
log.Errorf("Error reporting payment success to mc: %v",
|
||||
@@ -331,21 +331,21 @@ func (p *paymentLifecycle) createNewPaymentAttempt() (lnwire.ShortChannelID,
|
||||
|
||||
// We generate a new, unique payment ID that we will use for
|
||||
// this HTLC.
|
||||
paymentID, err := p.router.cfg.NextPaymentID()
|
||||
attemptID, err := p.router.cfg.NextPaymentID()
|
||||
if err != nil {
|
||||
return lnwire.ShortChannelID{}, nil, err
|
||||
}
|
||||
|
||||
// We now have all the information needed to populate
|
||||
// the current attempt information.
|
||||
p.attempt = &channeldb.PaymentAttemptInfo{
|
||||
PaymentID: paymentID,
|
||||
p.attempt = &channeldb.HTLCAttemptInfo{
|
||||
AttemptID: attemptID,
|
||||
SessionKey: sessionKey,
|
||||
Route: *rt,
|
||||
}
|
||||
|
||||
// Before sending this HTLC to the switch, we checkpoint the
|
||||
// fresh paymentID and route to the DB. This lets us know on
|
||||
// fresh attemptID and route to the DB. This lets us know on
|
||||
// startup the ID of the payment that we attempted to send,
|
||||
// such that we can query the Switch for its whereabouts. The
|
||||
// route is needed to handle the result when it eventually
|
||||
@@ -363,7 +363,7 @@ func (p *paymentLifecycle) sendPaymentAttempt(firstHop lnwire.ShortChannelID,
|
||||
htlcAdd *lnwire.UpdateAddHTLC) error {
|
||||
|
||||
log.Tracef("Attempting to send payment %x (pid=%v), "+
|
||||
"using route: %v", p.payment.PaymentHash, p.attempt.PaymentID,
|
||||
"using route: %v", p.payment.PaymentHash, p.attempt.AttemptID,
|
||||
newLogClosure(func() string {
|
||||
return spew.Sdump(p.attempt.Route)
|
||||
}),
|
||||
@@ -374,17 +374,17 @@ func (p *paymentLifecycle) sendPaymentAttempt(firstHop lnwire.ShortChannelID,
|
||||
// such that we can resume waiting for the result after a
|
||||
// restart.
|
||||
err := p.router.cfg.Payer.SendHTLC(
|
||||
firstHop, p.attempt.PaymentID, htlcAdd,
|
||||
firstHop, p.attempt.AttemptID, htlcAdd,
|
||||
)
|
||||
if err != nil {
|
||||
log.Errorf("Failed sending attempt %d for payment "+
|
||||
"%x to switch: %v", p.attempt.PaymentID,
|
||||
"%x to switch: %v", p.attempt.AttemptID,
|
||||
p.payment.PaymentHash, err)
|
||||
return err
|
||||
}
|
||||
|
||||
log.Debugf("Payment %x (pid=%v) successfully sent to switch, route: %v",
|
||||
p.payment.PaymentHash, p.attempt.PaymentID, &p.attempt.Route)
|
||||
p.payment.PaymentHash, p.attempt.AttemptID, &p.attempt.Route)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -394,7 +394,7 @@ func (p *paymentLifecycle) sendPaymentAttempt(firstHop lnwire.ShortChannelID,
|
||||
func (p *paymentLifecycle) handleSendError(sendErr error) error {
|
||||
|
||||
reason := p.router.processSendError(
|
||||
p.attempt.PaymentID, &p.attempt.Route, sendErr,
|
||||
p.attempt.AttemptID, &p.attempt.Route, sendErr,
|
||||
)
|
||||
if reason == nil {
|
||||
// Save the forwarding error so it can be returned if
|
||||
|
||||
+1
-1
@@ -1768,7 +1768,7 @@ func (r *ChannelRouter) SendToRoute(hash lntypes.Hash, route *route.Route) (
|
||||
// router will call this method for every payment still in-flight according to
|
||||
// the ControlTower.
|
||||
func (r *ChannelRouter) sendPayment(
|
||||
existingAttempt *channeldb.PaymentAttemptInfo,
|
||||
existingAttempt *channeldb.HTLCAttemptInfo,
|
||||
payment *LightningPayment, paySession PaymentSession) (
|
||||
[32]byte, *route.Route, error) {
|
||||
|
||||
|
||||
Reference in new issue
Block a user