htlcswitch+routing+routerrpc: return error source as index
This commit is contained in:
11 files changed
+245
-310
No files matched your search
+10
-9
@@ -6,17 +6,18 @@ import (
|
||||
"io"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/lightningnetwork/lightning-onion"
|
||||
sphinx "github.com/lightningnetwork/lightning-onion"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
// ForwardingError wraps an lnwire.FailureMessage in a struct that also
|
||||
// includes the source of the error.
|
||||
type ForwardingError struct {
|
||||
// ErrorSource is the public key of the node that sent the error. With
|
||||
// this information, the dispatcher of a payment can modify their set
|
||||
// of candidate routes in response to the type of error extracted.
|
||||
ErrorSource *btcec.PublicKey
|
||||
// FailureSourceIdx is the index of the node that sent the failure. With
|
||||
// this information, the dispatcher of a payment can modify their set of
|
||||
// candidate routes in response to the type of failure extracted. Index
|
||||
// zero is the self node.
|
||||
FailureSourceIdx int
|
||||
|
||||
// ExtraMsg is an additional error message that callers can provide in
|
||||
// order to provide context specific error details.
|
||||
@@ -256,20 +257,20 @@ type SphinxErrorDecrypter struct {
|
||||
// NOTE: Part of the ErrorDecrypter interface.
|
||||
func (s *SphinxErrorDecrypter) DecryptError(reason lnwire.OpaqueReason) (*ForwardingError, error) {
|
||||
|
||||
source, failureData, err := s.OnionErrorDecrypter.DecryptError(reason)
|
||||
failure, err := s.OnionErrorDecrypter.DecryptError(reason)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r := bytes.NewReader(failureData)
|
||||
r := bytes.NewReader(failure.Message)
|
||||
failureMsg, err := lnwire.DecodeFailure(r, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &ForwardingError{
|
||||
ErrorSource: source,
|
||||
FailureMessage: failureMsg,
|
||||
FailureSourceIdx: failure.SenderIdx,
|
||||
FailureMessage: failureMsg,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user