lnwire: fix ordering of the UpdateAddHTLC message on the wire

This commit fixes a diversion from the way the UpdateAddHTLC message is
defined within the specification. We had the HTLC expiry value in the
wrong place on the wire, which meant that we couldn’t parse the
messages as sent by the other LN implementations.
This commit is contained in:
Olaoluwa Osuntokun 2017-09-12 17:58:42 +02:00
parent 1e5949cfbb
commit 9a93f83370
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
2 changed files with 18 additions and 17 deletions

@ -26,11 +26,6 @@ type UpdateAddHTLC struct {
// with each offered HTLC. // with each offered HTLC.
ID uint64 ID uint64
// Expiry is the number of blocks after which this HTLC should expire.
// It is the receiver's duty to ensure that the outgoing HTLC has a
// sufficient expiry value to allow her to redeem the incoming HTLC.
Expiry uint32
// Amount is the amount of millisatoshis this HTLC is worth. // Amount is the amount of millisatoshis this HTLC is worth.
Amount MilliSatoshi Amount MilliSatoshi
@ -39,6 +34,11 @@ type UpdateAddHTLC struct {
// upstream peer in order to fully settle the HTLC. // upstream peer in order to fully settle the HTLC.
PaymentHash [32]byte PaymentHash [32]byte
// Expiry is the number of blocks after which this HTLC should expire.
// It is the receiver's duty to ensure that the outgoing HTLC has a
// sufficient expiry value to allow her to redeem the incoming HTLC.
Expiry uint32
// OnionBlob is the raw serialized mix header used to route an HTLC in // OnionBlob is the raw serialized mix header used to route an HTLC in
// a privacy-preserving manner. The mix header is defined currently to // a privacy-preserving manner. The mix header is defined currently to
// be parsed as a 4-tuple: (groupElement, routingInfo, headerMAC, // be parsed as a 4-tuple: (groupElement, routingInfo, headerMAC,
@ -69,9 +69,9 @@ func (c *UpdateAddHTLC) Decode(r io.Reader, pver uint32) error {
return readElements(r, return readElements(r,
&c.ChanID, &c.ChanID,
&c.ID, &c.ID,
&c.Expiry,
&c.Amount, &c.Amount,
c.PaymentHash[:], c.PaymentHash[:],
&c.Expiry,
c.OnionBlob[:], c.OnionBlob[:],
) )
} }
@ -84,9 +84,9 @@ func (c *UpdateAddHTLC) Encode(w io.Writer, pver uint32) error {
return writeElements(w, return writeElements(w,
c.ChanID, c.ChanID,
c.ID, c.ID,
c.Expiry,
c.Amount, c.Amount,
c.PaymentHash[:], c.PaymentHash[:],
c.Expiry,
c.OnionBlob[:], c.OnionBlob[:],
) )
} }

@ -5,10 +5,10 @@ import (
"io" "io"
) )
// UpdateFailMalformedHTLC is sent by either the payment forwarder or by payment // UpdateFailMalformedHTLC is sent by either the payment forwarder or by
// receiver to the payment sender in order to notify it that the onion blob // payment receiver to the payment sender in order to notify it that the onion
// can't be parsed. For that reason we send this message instead of obfuscate // blob can't be parsed. For that reason we send this message instead of
// the onion failure. // obfuscate the onion failure.
type UpdateFailMalformedHTLC struct { type UpdateFailMalformedHTLC struct {
// ChanID is the particular active channel that this // ChanID is the particular active channel that this
// UpdateFailMalformedHTLC is bound to. // UpdateFailMalformedHTLC is bound to.
@ -26,8 +26,8 @@ type UpdateFailMalformedHTLC struct {
FailureCode FailCode FailureCode FailCode
} }
// A compile time check to ensure UpdateFailMalformedHTLC implements the lnwire.Message // A compile time check to ensure UpdateFailMalformedHTLC implements the
// interface. // lnwire.Message interface.
var _ Message = (*UpdateFailMalformedHTLC)(nil) var _ Message = (*UpdateFailMalformedHTLC)(nil)
// Decode deserializes a serialized UpdateFailMalformedHTLC message stored in the passed // Decode deserializes a serialized UpdateFailMalformedHTLC message stored in the passed
@ -43,8 +43,8 @@ func (c *UpdateFailMalformedHTLC) Decode(r io.Reader, pver uint32) error {
) )
} }
// Encode serializes the target UpdateFailMalformedHTLC into the passed io.Writer observing // Encode serializes the target UpdateFailMalformedHTLC into the passed
// the protocol version specified. // io.Writer observing the protocol version specified.
// //
// This is part of the lnwire.Message interface. // This is part of the lnwire.Message interface.
func (c *UpdateFailMalformedHTLC) Encode(w io.Writer, pver uint32) error { func (c *UpdateFailMalformedHTLC) Encode(w io.Writer, pver uint32) error {
@ -64,8 +64,9 @@ func (c *UpdateFailMalformedHTLC) MsgType() MessageType {
return MsgUpdateFailMalformedHTLC return MsgUpdateFailMalformedHTLC
} }
// MaxPayloadLength returns the maximum allowed payload size for a UpdateFailMalformedHTLC // MaxPayloadLength returns the maximum allowed payload size for a
// complete message observing the specified protocol version. // UpdateFailMalformedHTLC complete message observing the specified protocol
// version.
// //
// This is part of the lnwire.Message interface. // This is part of the lnwire.Message interface.
func (c *UpdateFailMalformedHTLC) MaxPayloadLength(uint32) uint32 { func (c *UpdateFailMalformedHTLC) MaxPayloadLength(uint32) uint32 {