lnwire: add FailMPPTimeout message

This commit is contained in:
carla 2019-12-20 12:25:08 +02:00
parent d2e395d5f2
commit 1d3bb5aed6
No known key found for this signature in database
GPG Key ID: 4CA7FE54A6213C91
2 changed files with 28 additions and 0 deletions

@ -80,6 +80,7 @@ const (
CodeFinalIncorrectHtlcAmount FailCode = 19
CodeExpiryTooFar FailCode = 21
CodeInvalidOnionPayload = FlagPerm | 22
CodeMPPTimeout FailCode = 23
)
// String returns the string representation of the failure code.
@ -154,6 +155,9 @@ func (c FailCode) String() string {
case CodeInvalidOnionPayload:
return "InvalidOnionPayload"
case CodeMPPTimeout:
return "MPPTimeout"
default:
return "<unknown>"
}
@ -1182,6 +1186,26 @@ func (f *InvalidOnionPayload) Encode(w io.Writer, pver uint32) error {
return WriteElements(w, f.Offset)
}
// FailMPPTimeout is returned if the complete amount for a multi part payment
// was not received within a reasonable time.
//
// NOTE: May only be returned by the final node in the path.
type FailMPPTimeout struct{}
// Code returns the failure unique code.
//
// NOTE: Part of the FailureMessage interface.
func (f *FailMPPTimeout) Code() FailCode {
return CodeMPPTimeout
}
// Returns a human readable string describing the target FailureMessage.
//
// NOTE: Implements the error interface.
func (f *FailMPPTimeout) Error() string {
return f.Code().String()
}
// DecodeFailure decodes, validates, and parses the lnwire onion failure, for
// the provided protocol version.
func DecodeFailure(r io.Reader, pver uint32) (FailureMessage, error) {
@ -1366,6 +1390,9 @@ func makeEmptyOnionError(code FailCode) (FailureMessage, error) {
case CodeInvalidOnionPayload:
return &InvalidOnionPayload{}, nil
case CodeMPPTimeout:
return &FailMPPTimeout{}, nil
default:
return nil, errors.Errorf("unknown error code: %v", code)
}

@ -38,6 +38,7 @@ var onionFailures = []FailureMessage{
&FailUnknownNextPeer{},
&FailIncorrectPaymentAmount{},
&FailFinalExpiryTooSoon{},
&FailMPPTimeout{},
NewFailIncorrectDetails(99, 100),
NewInvalidOnionVersion(testOnionHash),