lnwire: document commitment+HTLC update msgs

This commit adds some cursory documentation along wit minor field
modifications to all messages which deal with adding HTLC’s, or
updating remote commitment transactions.

The messages for dual funding of channel is left purposefully
undocumented as all initial negotiations will be single funder by
default.

A revamp of the testing infrastructure of lnwire will be committed in
the near future.
This commit is contained in:
Olaoluwa Osuntokun committed 2016-05-23 13:54:41 -07:00
1 parent b202831868
commit 913ae259de
24 files changed
+500 -193

No files matched your search

+45 -10
View File
@@ -5,16 +5,30 @@ import (
"io"
)
// Multiple Clearing Requests are possible by putting this inside an array of
// clearing requests
// ErrorGeneric represents a generic error bound to an exact channel. The
// message format is purposefully general in order to allow expressino of a wide
// array of possible errors. Each ErrorGeneric message is directed at a particular
// open channel referenced by ChannelID.
type ErrorGeneric struct {
// We can use a different data type for this if necessary...
// ChannelID references the active channel in which the error occured
// within.
ChannelID uint64
// Some kind of message
// Max length 8192
// TODO(roasbeef): uint16 for problem type?
// ErrorID uint16
// Problem is a human-readable string further elaborating upon the
// nature of the exact error. The maxmium allowed length of this
// message is 8192 bytes.
Problem string
// TODO(roasbeef): add SerializeSize?
}
// Decode deserializes a serialized ErrorGeneric message stored in the
// passed io.Reader observing the specified protocol version.
//
// This is part of the lnwire.Message interface.
func (c *ErrorGeneric) Decode(r io.Reader, pver uint32) error {
// ChannelID(8)
// Problem
@@ -29,13 +43,19 @@ func (c *ErrorGeneric) Decode(r io.Reader, pver uint32) error {
return nil
}
// Creates a new ErrorGeneric
// NewErrorGeneric creates a new ErrorGeneric message.
func NewErrorGeneric() *ErrorGeneric {
return &ErrorGeneric{}
}
// Serializes the item from the ErrorGeneric struct
// Writes the data to w
// A compile time check to ensure ErrorGeneric implements the lnwire.Message
// interface.
var _ Message = (*ErrorGeneric)(nil)
// Encode serializes the target ErrorGeneric into the passed io.Writer
// observing the protocol version specified.
//
// This is part of the lnwire.Message interface.
func (c *ErrorGeneric) Encode(w io.Writer, pver uint32) error {
err := writeElements(w,
c.ChannelID,
@@ -48,24 +68,39 @@ func (c *ErrorGeneric) Encode(w io.Writer, pver uint32) error {
return nil
}
// Command returns the integer uniquely identifying an ErrorGeneric message on
// the wire.
//
// This is part of the lnwire.Message interface.
func (c *ErrorGeneric) Command() uint32 {
return CmdErrorGeneric
}
// MaxPayloadLength returns the maximum allowed payload size for a
// ErrorGeneric complete message observing the specified protocol version.
//
// This is part of the lnwire.Message interface.
func (c *ErrorGeneric) MaxPayloadLength(uint32) uint32 {
// 8+8192
return 8208
}
// Makes sure the struct data is valid (e.g. no negatives or invalid pkscripts)
// Validate performs any necessary sanity checks to ensure all fields present
// on the ErrorGeneric are valid.
//
// This is part of the lnwire.Message interface.
func (c *ErrorGeneric) Validate() error {
if len(c.Problem) > 8192 {
return fmt.Errorf("Problem string length too long")
return fmt.Errorf("problem string length too long")
}
// We're good!
return nil
}
// String returns the string representation of the target ErrorGeneric.
//
// This is part of the lnwire.Message interface.
func (c *ErrorGeneric) String() string {
return fmt.Sprintf("\n--- Begin ErrorGeneric ---\n") +
fmt.Sprintf("ChannelID:\t%d\n", c.ChannelID) +