From 5ff5838d7495fc3f441c07e61b538f35788f86a1 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Wed, 14 Sep 2022 12:22:09 +0200 Subject: [PATCH] lnwire: add extra opaque data to FailIncorrectDetails --- lnwire/onion_error.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/lnwire/onion_error.go b/lnwire/onion_error.go index 0f252c59d..11d1fa5da 100644 --- a/lnwire/onion_error.go +++ b/lnwire/onion_error.go @@ -345,6 +345,9 @@ type FailIncorrectDetails struct { // height is the block height when the htlc was received. height uint32 + + // extraOpaqueData contains additional failure message tlv data. + extraOpaqueData ExtraOpaqueData } // NewFailIncorrectDetails makes a new instance of the FailIncorrectDetails @@ -353,8 +356,9 @@ func NewFailIncorrectDetails(amt MilliSatoshi, height uint32) *FailIncorrectDetails { return &FailIncorrectDetails{ - amount: amt, - height: height, + amount: amt, + height: height, + extraOpaqueData: []byte{}, } } @@ -368,6 +372,11 @@ func (f *FailIncorrectDetails) Height() uint32 { return f.height } +// ExtraOpaqueData returns additional failure message tlv data. +func (f *FailIncorrectDetails) ExtraOpaqueData() ExtraOpaqueData { + return f.extraOpaqueData +} + // Code returns the failure unique code. // // NOTE: Part of the FailureMessage interface. @@ -413,7 +422,7 @@ func (f *FailIncorrectDetails) Decode(r io.Reader, pver uint32) error { return err } - return nil + return f.extraOpaqueData.Decode(r) } // Encode writes the failure in bytes stream. @@ -424,7 +433,11 @@ func (f *FailIncorrectDetails) Encode(w *bytes.Buffer, pver uint32) error { return err } - return WriteUint32(w, f.height) + if err := WriteUint32(w, f.height); err != nil { + return err + } + + return f.extraOpaqueData.Encode(w) } // FailFinalExpiryTooSoon is returned if the cltv_expiry is too low, the final