routing: handle onion errors in ChannelRouter

This commit is contained in:
John Griffith 2017-09-08 12:39:24 +02:00 committed by Olaoluwa Osuntokun
parent 54c4fc4559
commit 1057a1a7c3
2 changed files with 45 additions and 3 deletions

@ -1021,6 +1021,7 @@ func (r *ChannelRouter) SendPayment(payment *LightningPayment) ([32]byte, *Route
// target payment using the multi-hop route. We'll try each route // target payment using the multi-hop route. We'll try each route
// serially until either once succeeds, or we've exhausted our set of // serially until either once succeeds, or we've exhausted our set of
// available paths. // available paths.
routes:
for _, route := range routes { for _, route := range routes {
log.Tracef("Attempting to send payment %x, using route: %v", log.Tracef("Attempting to send payment %x, using route: %v",
payment.PaymentHash, newLogClosure(func() string { payment.PaymentHash, newLogClosure(func() string {
@ -1056,7 +1057,49 @@ func (r *ChannelRouter) SendPayment(payment *LightningPayment) ([32]byte, *Route
if sendError != nil { if sendError != nil {
log.Errorf("Attempt to send payment %x failed: %v", log.Errorf("Attempt to send payment %x failed: %v",
payment.PaymentHash, sendError) payment.PaymentHash, sendError)
continue
switch sendError.(type) {
case *lnwire.FailTemporaryNodeFailure:
continue
case *lnwire.FailPermanentNodeFailure:
continue
case *lnwire.FailRequiredNodeFeatureMissing:
continue
case *lnwire.FailPermanentChannelFailure:
continue
case *lnwire.FailRequiredChannelFeatureMissing:
break routes
case *lnwire.FailUnknownNextPeer:
continue
case *lnwire.FailUnknownPaymentHash:
break routes
case *lnwire.FailIncorrectPaymentAmount:
break routes
case *lnwire.FailFinalExpiryTooSoon:
break routes
case *lnwire.FailInvalidOnionVersion:
break routes
case *lnwire.FailInvalidOnionHmac:
break routes
case *lnwire.FailInvalidOnionKey:
break routes
case *lnwire.FailTemporaryChannelFailure:
continue
case *lnwire.FailAmountBelowMinimum:
break routes
case *lnwire.FailFeeInsufficient:
break routes
case *lnwire.FailExpiryTooSoon:
break routes
case *lnwire.FailChannelDisabled:
continue
case *lnwire.FailFinalIncorrectCltvExpiry:
break routes
case *lnwire.FailFinalIncorrectHtlcAmount:
break routes
case *lnwire.FailInvalidRealm:
break routes
}
} }
return preImage, route, nil return preImage, route, nil

@ -2,7 +2,6 @@ package routing
import ( import (
"bytes" "bytes"
"errors"
"fmt" "fmt"
"image/color" "image/color"
"testing" "testing"
@ -180,7 +179,7 @@ func TestSendPaymentRouteFailureFallback(t *testing.T) {
_ *lnwire.UpdateAddHTLC, _ *sphinx.Circuit) ([32]byte, error) { _ *lnwire.UpdateAddHTLC, _ *sphinx.Circuit) ([32]byte, error) {
if ctx.aliases["luoji"].IsEqual(n) { if ctx.aliases["luoji"].IsEqual(n) {
return [32]byte{}, errors.New("send error") return [32]byte{}, &lnwire.FailChannelDisabled{}
} }
return preImage, nil return preImage, nil