mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-07-28 13:52:55 +02:00
lnwire21: add CodeInvalidBlinding
To prevent the need to copy the entire onion_error.go file for a new Mission Control migration, this commit just updates the existing lnwire21/onion_error.go file with the new CodeInvalidBlinding code. The lnwire21 should not really ever be updated but adding a new code should be fine as it does not affect old migrations since this is a new code.
This commit is contained in:
@@ -54,6 +54,8 @@ type FailCode uint16
|
||||
|
||||
// The currently defined onion failure types within this current version of the
|
||||
// Lightning protocol.
|
||||
//
|
||||
//nolint:lll
|
||||
const (
|
||||
CodeNone FailCode = 0
|
||||
CodeInvalidRealm = FlagBadOnion | 1
|
||||
@@ -80,6 +82,7 @@ const (
|
||||
CodeExpiryTooFar FailCode = 21
|
||||
CodeInvalidOnionPayload = FlagPerm | 22
|
||||
CodeMPPTimeout FailCode = 23
|
||||
CodeInvalidBlinding = FlagBadOnion | FlagPerm | 24
|
||||
)
|
||||
|
||||
// String returns the string representation of the failure code.
|
||||
@@ -157,6 +160,9 @@ func (c FailCode) String() string {
|
||||
case CodeMPPTimeout:
|
||||
return "MPPTimeout"
|
||||
|
||||
case CodeInvalidBlinding:
|
||||
return "InvalidBlinding"
|
||||
|
||||
default:
|
||||
return "<unknown>"
|
||||
}
|
||||
@@ -571,6 +577,51 @@ func (f *FailInvalidOnionKey) Error() string {
|
||||
return fmt.Sprintf("InvalidOnionKey(onion_sha=%x)", f.OnionSHA256[:])
|
||||
}
|
||||
|
||||
// FailInvalidBlinding is returned if there has been a route blinding related
|
||||
// error.
|
||||
type FailInvalidBlinding struct {
|
||||
OnionSHA256 [sha256.Size]byte
|
||||
}
|
||||
|
||||
// Code returns the failure unique code.
|
||||
//
|
||||
// NOTE: Part of the FailureMessage interface.
|
||||
func (f *FailInvalidBlinding) Code() FailCode {
|
||||
return CodeInvalidBlinding
|
||||
}
|
||||
|
||||
// Returns a human readable string describing the target FailureMessage.
|
||||
//
|
||||
// NOTE: Implements the error interface.
|
||||
func (f *FailInvalidBlinding) Error() string {
|
||||
return f.Code().String()
|
||||
}
|
||||
|
||||
// Decode decodes the failure from bytes stream.
|
||||
//
|
||||
// NOTE: Part of the Serializable interface.
|
||||
func (f *FailInvalidBlinding) Decode(r io.Reader, _ uint32) error {
|
||||
return ReadElement(r, f.OnionSHA256[:])
|
||||
}
|
||||
|
||||
// Encode writes the failure in bytes stream.
|
||||
//
|
||||
// NOTE: Part of the Serializable interface.
|
||||
func (f *FailInvalidBlinding) Encode(w *bytes.Buffer, _ uint32) error {
|
||||
return WriteElement(w, f.OnionSHA256[:])
|
||||
}
|
||||
|
||||
// NewInvalidBlinding creates new instance of FailInvalidBlinding.
|
||||
func NewInvalidBlinding(onion []byte) *FailInvalidBlinding {
|
||||
// The spec allows empty onion hashes for invalid blinding, so we only
|
||||
// include our onion hash if it's provided.
|
||||
if onion == nil {
|
||||
return &FailInvalidBlinding{}
|
||||
}
|
||||
|
||||
return &FailInvalidBlinding{OnionSHA256: sha256.Sum256(onion)}
|
||||
}
|
||||
|
||||
// parseChannelUpdateCompatabilityMode will attempt to parse a channel updated
|
||||
// encoded into an onion error payload in two ways. First, we'll try the
|
||||
// compatibility oriented version wherein we'll _skip_ the length prefixing on
|
||||
@@ -1392,6 +1443,9 @@ func makeEmptyOnionError(code FailCode) (FailureMessage, error) {
|
||||
case CodeMPPTimeout:
|
||||
return &FailMPPTimeout{}, nil
|
||||
|
||||
case CodeInvalidBlinding:
|
||||
return &FailInvalidBlinding{}, nil
|
||||
|
||||
default:
|
||||
return nil, errors.Errorf("unknown error code: %v", code)
|
||||
}
|
||||
|
Reference in New Issue
Block a user