htlcswitch: do not consider unknown failures an error
This commit is contained in:
7 files changed
+186
-112
No files matched your search
@@ -31,10 +31,10 @@ type ForwardingError struct {
|
||||
// returned.
|
||||
func (f *ForwardingError) Error() string {
|
||||
if f.ExtraMsg == "" {
|
||||
return f.FailureMessage.Error()
|
||||
return fmt.Sprintf("%v", f.FailureMessage)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("%v: %v", f.FailureMessage.Error(), f.ExtraMsg)
|
||||
return fmt.Sprintf("%v: %v", f.FailureMessage, f.ExtraMsg)
|
||||
}
|
||||
|
||||
// ErrorDecrypter is an interface that is used to decrypt the onion encrypted
|
||||
@@ -274,10 +274,14 @@ func (s *SphinxErrorDecrypter) DecryptError(reason lnwire.OpaqueReason) (
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Decode the failure. If an error occurs, we leave the failure message
|
||||
// field nil.
|
||||
r := bytes.NewReader(failure.Message)
|
||||
failureMsg, err := lnwire.DecodeFailure(r, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return &ForwardingError{
|
||||
FailureSourceIdx: failure.SenderIdx,
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &ForwardingError{
|
||||
|
||||
@@ -2344,4 +2344,37 @@ func TestInvalidFailure(t *testing.T) {
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("err wasn't received")
|
||||
}
|
||||
|
||||
// Modify the decryption to simulate that decryption went alright, but
|
||||
// the failure cannot be decoded.
|
||||
deobfuscator = SphinxErrorDecrypter{
|
||||
OnionErrorDecrypter: &mockOnionErrorDecryptor{
|
||||
sourceIdx: 2,
|
||||
message: []byte{200},
|
||||
},
|
||||
}
|
||||
|
||||
resultChan, err = s.GetPaymentResult(
|
||||
paymentID, rhash, &deobfuscator,
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
select {
|
||||
case result := <-resultChan:
|
||||
fErr, ok := result.Error.(*ForwardingError)
|
||||
if !ok {
|
||||
t.Fatal("expected ForwardingError")
|
||||
}
|
||||
if fErr.FailureSourceIdx != 2 {
|
||||
t.Fatal("unexpected error source index")
|
||||
}
|
||||
if fErr.FailureMessage != nil {
|
||||
t.Fatal("expected empty failure message")
|
||||
}
|
||||
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("err wasn't received")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user