lnwire: prep wire messages for TLV extensions
Messages: - UpdateFulfillHTLC - UpdateFee - UpdateFailMalformedHTLC - UpdateFailHTLC - UpdateAddHTLC - Shutdown - RevokeAndAck - ReplyShortChanIDsEnd - ReplyChannelRange - QueryShortChanIDs - QueryChannelRange - NodeAnnouncement - Init - GossipTimestampRange - FundingSigned - FundingLocked - FundingCreated - CommitSig - ClosingSigned - ChannelUpdate - ChannelReestablish - ChannelAnnouncement - AnnounceSignatures lnwire: update quickcheck tests, use constant for Error multi: update unit tests to pass deep equal assertions with messages In this commit, we update a series of unit tests in the code base to now pass due to the new wire message encode/decode logic. In many instances, we'll now manually set the extra bytes to an empty byte slice to avoid comparisons that fail due to one message having an empty byte slice and the other having a nil pointer.
This commit is contained in:
1 parent
a603ac4938
commit
9a6bb19770
32 files changed
+278
-231
No files matched your search
@@ -60,6 +60,11 @@ type ChannelReestablish struct {
|
||||
// LocalUnrevokedCommitPoint is the commitment point used in the
|
||||
// current un-revoked commitment transaction of the sending party.
|
||||
LocalUnrevokedCommitPoint *btcec.PublicKey
|
||||
|
||||
// ExtraData is the set of data that was appended to this message to
|
||||
// fill out the full maximum transport message size. These fields can
|
||||
// be used to specify optional data such as custom TLV fields.
|
||||
ExtraData ExtraOpaqueData
|
||||
}
|
||||
|
||||
// A compile time check to ensure ChannelReestablish implements the
|
||||
@@ -83,12 +88,20 @@ func (a *ChannelReestablish) Encode(w io.Writer, pver uint32) error {
|
||||
// If the commit point wasn't sent, then we won't write out any of the
|
||||
// remaining fields as they're optional.
|
||||
if a.LocalUnrevokedCommitPoint == nil {
|
||||
return nil
|
||||
// However, we'll still write out the extra data if it's
|
||||
// present.
|
||||
//
|
||||
// NOTE: This is here primarily for the quickcheck tests, in
|
||||
// practice, we'll always populate this field.
|
||||
return WriteElements(w, a.ExtraData)
|
||||
}
|
||||
|
||||
// Otherwise, we'll write out the remaining elements.
|
||||
return WriteElements(w, a.LastRemoteCommitSecret[:],
|
||||
a.LocalUnrevokedCommitPoint)
|
||||
return WriteElements(w,
|
||||
a.LastRemoteCommitSecret[:],
|
||||
a.LocalUnrevokedCommitPoint,
|
||||
a.ExtraData,
|
||||
)
|
||||
}
|
||||
|
||||
// Decode deserializes a serialized ChannelReestablish stored in the passed
|
||||
@@ -118,6 +131,9 @@ func (a *ChannelReestablish) Decode(r io.Reader, pver uint32) error {
|
||||
var buf [32]byte
|
||||
_, err = io.ReadFull(r, buf[:32])
|
||||
if err == io.EOF {
|
||||
// If there aren't any more bytes, then we'll emplace an empty
|
||||
// extra data to make our quickcheck tests happy.
|
||||
a.ExtraData = make([]byte, 0)
|
||||
return nil
|
||||
} else if err != nil {
|
||||
return err
|
||||
@@ -129,7 +145,11 @@ func (a *ChannelReestablish) Decode(r io.Reader, pver uint32) error {
|
||||
// We'll conclude by parsing out the commitment point. We don't check
|
||||
// the error in this case, as it has included the commit secret, then
|
||||
// they MUST also include the commit point.
|
||||
return ReadElement(r, &a.LocalUnrevokedCommitPoint)
|
||||
if err = ReadElement(r, &a.LocalUnrevokedCommitPoint); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return a.ExtraData.Decode(r)
|
||||
}
|
||||
|
||||
// MsgType returns the integer uniquely identifying this message type on the
|
||||
@@ -145,22 +165,5 @@ func (a *ChannelReestablish) MsgType() MessageType {
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (a *ChannelReestablish) MaxPayloadLength(pver uint32) uint32 {
|
||||
var length uint32
|
||||
|
||||
// ChanID - 32 bytes
|
||||
length += 32
|
||||
|
||||
// NextLocalCommitHeight - 8 bytes
|
||||
length += 8
|
||||
|
||||
// RemoteCommitTailHeight - 8 bytes
|
||||
length += 8
|
||||
|
||||
// LastRemoteCommitSecret - 32 bytes
|
||||
length += 32
|
||||
|
||||
// LocalUnrevokedCommitPoint - 33 bytes
|
||||
length += 33
|
||||
|
||||
return length
|
||||
return MaxMsgBody
|
||||
}
|
||||
Reference in new issue
Block a user