routing: use Identifier in place of PaymentHash

Since we want to support AMP payment using a different unique payment
identifier (AMP payments don't go to one specific hash), we change the
nomenclature to be Identifier instead of PaymentHash.
This commit is contained in:
Johan T. Halseth
2021-03-31 12:23:08 +02:00
parent 6104d12cf8
commit f07c9d002c
17 changed files with 296 additions and 245 deletions

View File

@ -24,7 +24,7 @@ type paymentLifecycle struct {
router *ChannelRouter
totalAmount lnwire.MilliSatoshi
feeLimit lnwire.MilliSatoshi
paymentHash lntypes.Hash
identifier lntypes.Hash
paySession PaymentSession
shardTracker shards.ShardTracker
timeoutChan <-chan time.Time
@ -86,7 +86,7 @@ func (p *paymentLifecycle) paymentState(payment *channeldb.MPPayment) (
func (p *paymentLifecycle) resumePayment() ([32]byte, *route.Route, error) {
shardHandler := &shardHandler{
router: p.router,
paymentHash: p.paymentHash,
identifier: p.identifier,
shardTracker: p.shardTracker,
shardErrors: make(chan error),
quit: make(chan struct{}),
@ -101,7 +101,7 @@ func (p *paymentLifecycle) resumePayment() ([32]byte, *route.Route, error) {
// up goroutines that'll collect their results and deliver them to the
// lifecycle loop below.
payment, err := p.router.cfg.Control.FetchPayment(
p.paymentHash,
p.identifier,
)
if err != nil {
return [32]byte{}, nil, err
@ -110,8 +110,8 @@ func (p *paymentLifecycle) resumePayment() ([32]byte, *route.Route, error) {
for _, a := range payment.InFlightHTLCs() {
a := a
log.Infof("Resuming payment shard %v for hash %v",
a.AttemptID, p.paymentHash)
log.Infof("Resuming payment shard %v for payment %v",
a.AttemptID, p.identifier)
shardHandler.collectResultAsync(&a.HTLCAttemptInfo)
}
@ -131,7 +131,7 @@ lifecycle:
// act on the latest available information, whether we are
// resuming an existing payment or just sent a new attempt.
payment, err := p.router.cfg.Control.FetchPayment(
p.paymentHash,
p.identifier,
)
if err != nil {
return [32]byte{}, nil, err
@ -146,7 +146,7 @@ lifecycle:
log.Debugf("Payment %v in state terminate=%v, "+
"active_shards=%v, rem_value=%v, fee_limit=%v",
p.paymentHash, state.terminate, state.numShardsInFlight,
p.identifier, state.terminate, state.numShardsInFlight,
state.remainingAmt, state.remainingFees)
switch {
@ -193,7 +193,7 @@ lifecycle:
// return with an error the moment all active shards
// have finished.
saveErr := p.router.cfg.Control.Fail(
p.paymentHash, channeldb.FailureReasonTimeout,
p.identifier, channeldb.FailureReasonTimeout,
)
if saveErr != nil {
return [32]byte{}, nil, saveErr
@ -215,7 +215,7 @@ lifecycle:
)
if err != nil {
log.Warnf("Failed to find route for payment %v: %v",
p.paymentHash, err)
p.identifier, err)
routeErr, ok := err.(noRouteError)
if !ok {
@ -229,10 +229,10 @@ lifecycle:
failureCode := routeErr.FailureReason()
log.Debugf("Marking payment %v permanently "+
"failed with no route: %v",
p.paymentHash, failureCode)
p.identifier, failureCode)
saveErr := p.router.cfg.Control.Fail(
p.paymentHash, failureCode,
p.identifier, failureCode,
)
if saveErr != nil {
return [32]byte{}, nil, saveErr
@ -261,8 +261,8 @@ lifecycle:
// were pathfinding. We know we're in a terminal state here,
// so we can continue and wait for our last shards to return.
case err == channeldb.ErrPaymentTerminal:
log.Infof("Payment: %v in terminal state, abandoning "+
"shard", p.paymentHash)
log.Infof("Payment %v in terminal state, abandoning "+
"shard", p.identifier)
continue lifecycle
@ -275,7 +275,7 @@ lifecycle:
if outcome.err != nil {
log.Warnf("Failed to launch shard %v for "+
"payment %v: %v", attempt.AttemptID,
p.paymentHash, outcome.err)
p.identifier, outcome.err)
// We must inspect the error to know whether it was
// critical or not, to decide whether we should
@ -301,7 +301,7 @@ lifecycle:
// shardHandler holds what is necessary to send and collect the result of
// shards.
type shardHandler struct {
paymentHash lntypes.Hash
identifier lntypes.Hash
router *ChannelRouter
shardTracker shards.ShardTracker
@ -398,7 +398,7 @@ func (p *shardHandler) launchShard(rt *route.Route,
// 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 comes back.
err = p.router.cfg.Control.RegisterAttempt(p.paymentHash, attempt)
err = p.router.cfg.Control.RegisterAttempt(p.identifier, attempt)
if err != nil {
return nil, nil, err
}
@ -450,7 +450,7 @@ func (p *shardHandler) collectResultAsync(attempt *channeldb.HTLCAttemptInfo) {
log.Errorf("Error collecting result for "+
"shard %v for payment %v: %v",
attempt.AttemptID, p.paymentHash, err)
attempt.AttemptID, p.identifier, err)
}
select {
@ -515,7 +515,7 @@ func (p *shardHandler) collectResult(attempt *channeldb.HTLCAttemptInfo) (
// Now ask the switch to return the result of the payment when
// available.
resultChan, err := p.router.cfg.Payer.GetPaymentResult(
attempt.AttemptID, p.paymentHash, errorDecryptor,
attempt.AttemptID, p.identifier, errorDecryptor,
)
switch {
@ -524,9 +524,9 @@ func (p *shardHandler) collectResult(attempt *channeldb.HTLCAttemptInfo) (
// 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 %v not found in "+
log.Debugf("Attempt ID %v for payment %v not found in "+
"the Switch, retrying.", attempt.AttemptID,
p.paymentHash)
p.identifier)
attempt, cErr := p.failAttempt(attempt, err)
if cErr != nil {
@ -582,7 +582,7 @@ func (p *shardHandler) collectResult(attempt *channeldb.HTLCAttemptInfo) (
// We successfully got a payment result back from the switch.
log.Debugf("Payment %v succeeded with pid=%v",
p.paymentHash, attempt.AttemptID)
p.identifier, attempt.AttemptID)
// Report success to mission control.
err = p.router.cfg.MissionControl.ReportPaymentSuccess(
@ -596,7 +596,7 @@ func (p *shardHandler) collectResult(attempt *channeldb.HTLCAttemptInfo) (
// In case of success we atomically store settle result to the DB move
// the shard to the settled state.
htlcAttempt, err := p.router.cfg.Control.SettleAttempt(
p.paymentHash, attempt.AttemptID,
p.identifier, attempt.AttemptID,
&channeldb.HTLCSettleInfo{
Preimage: result.Preimage,
SettleTime: p.router.cfg.Clock.Now(),
@ -696,7 +696,7 @@ func (p *shardHandler) sendPaymentAttempt(
htlcAdd *lnwire.UpdateAddHTLC) error {
log.Tracef("Attempting to send payment %v (pid=%v), "+
"using route: %v", p.paymentHash, attempt.AttemptID,
"using route: %v", p.identifier, attempt.AttemptID,
newLogClosure(func() string {
return spew.Sdump(attempt.Route)
}),
@ -712,12 +712,12 @@ func (p *shardHandler) sendPaymentAttempt(
if err != nil {
log.Errorf("Failed sending attempt %d for payment "+
"%v to switch: %v", attempt.AttemptID,
p.paymentHash, err)
p.identifier, err)
return err
}
log.Debugf("Payment %v (pid=%v) successfully sent to switch, route: %v",
p.paymentHash, attempt.AttemptID, &attempt.Route)
p.identifier, attempt.AttemptID, &attempt.Route)
return nil
}
@ -737,9 +737,9 @@ func (p *shardHandler) handleSendError(attempt *channeldb.HTLCAttemptInfo,
}
log.Infof("Payment %v failed: final_outcome=%v, raw_err=%v",
p.paymentHash, *reason, sendErr)
p.identifier, *reason, sendErr)
err := p.router.cfg.Control.Fail(p.paymentHash, *reason)
err := p.router.cfg.Control.Fail(p.identifier, *reason)
if err != nil {
return err
}
@ -752,7 +752,7 @@ func (p *shardHandler) failAttempt(attempt *channeldb.HTLCAttemptInfo,
sendError error) (*channeldb.HTLCAttempt, error) {
log.Warnf("Attempt %v for payment %v failed: %v", attempt.AttemptID,
p.paymentHash, sendError)
p.identifier, sendError)
failInfo := marshallError(
sendError,
@ -767,7 +767,7 @@ func (p *shardHandler) failAttempt(attempt *channeldb.HTLCAttemptInfo,
}
return p.router.cfg.Control.FailAttempt(
p.paymentHash, attempt.AttemptID,
p.identifier, attempt.AttemptID,
failInfo,
)
}