Skip to content

Commit 33ab4b9

Browse files
committed
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.
1 parent 1acc839 commit 33ab4b9

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

channeldb/migration/lnwire21/onion_error.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ type FailCode uint16
5454

5555
// The currently defined onion failure types within this current version of the
5656
// Lightning protocol.
57+
//
58+
//nolint:lll
5759
const (
5860
CodeNone FailCode = 0
5961
CodeInvalidRealm = FlagBadOnion | 1
@@ -80,6 +82,7 @@ const (
8082
CodeExpiryTooFar FailCode = 21
8183
CodeInvalidOnionPayload = FlagPerm | 22
8284
CodeMPPTimeout FailCode = 23
85+
CodeInvalidBlinding = FlagBadOnion | FlagPerm | 24
8386
)
8487

8588
// String returns the string representation of the failure code.
@@ -157,6 +160,9 @@ func (c FailCode) String() string {
157160
case CodeMPPTimeout:
158161
return "MPPTimeout"
159162

163+
case CodeInvalidBlinding:
164+
return "InvalidBlinding"
165+
160166
default:
161167
return "<unknown>"
162168
}
@@ -571,6 +577,51 @@ func (f *FailInvalidOnionKey) Error() string {
571577
return fmt.Sprintf("InvalidOnionKey(onion_sha=%x)", f.OnionSHA256[:])
572578
}
573579

580+
// FailInvalidBlinding is returned if there has been a route blinding related
581+
// error.
582+
type FailInvalidBlinding struct {
583+
OnionSHA256 [sha256.Size]byte
584+
}
585+
586+
// Code returns the failure unique code.
587+
//
588+
// NOTE: Part of the FailureMessage interface.
589+
func (f *FailInvalidBlinding) Code() FailCode {
590+
return CodeInvalidBlinding
591+
}
592+
593+
// Returns a human readable string describing the target FailureMessage.
594+
//
595+
// NOTE: Implements the error interface.
596+
func (f *FailInvalidBlinding) Error() string {
597+
return f.Code().String()
598+
}
599+
600+
// Decode decodes the failure from bytes stream.
601+
//
602+
// NOTE: Part of the Serializable interface.
603+
func (f *FailInvalidBlinding) Decode(r io.Reader, _ uint32) error {
604+
return ReadElement(r, f.OnionSHA256[:])
605+
}
606+
607+
// Encode writes the failure in bytes stream.
608+
//
609+
// NOTE: Part of the Serializable interface.
610+
func (f *FailInvalidBlinding) Encode(w *bytes.Buffer, _ uint32) error {
611+
return WriteElement(w, f.OnionSHA256[:])
612+
}
613+
614+
// NewInvalidBlinding creates new instance of FailInvalidBlinding.
615+
func NewInvalidBlinding(onion []byte) *FailInvalidBlinding {
616+
// The spec allows empty onion hashes for invalid blinding, so we only
617+
// include our onion hash if it's provided.
618+
if onion == nil {
619+
return &FailInvalidBlinding{}
620+
}
621+
622+
return &FailInvalidBlinding{OnionSHA256: sha256.Sum256(onion)}
623+
}
624+
574625
// parseChannelUpdateCompatabilityMode will attempt to parse a channel updated
575626
// encoded into an onion error payload in two ways. First, we'll try the
576627
// compatibility oriented version wherein we'll _skip_ the length prefixing on
@@ -1392,6 +1443,9 @@ func makeEmptyOnionError(code FailCode) (FailureMessage, error) {
13921443
case CodeMPPTimeout:
13931444
return &FailMPPTimeout{}, nil
13941445

1446+
case CodeInvalidBlinding:
1447+
return &FailInvalidBlinding{}, nil
1448+
13951449
default:
13961450
return nil, errors.Errorf("unknown error code: %v", code)
13971451
}

0 commit comments

Comments
 (0)