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:
24 files changed
+500
-193
No files matched your search
+57
-14
@@ -2,26 +2,48 @@ package lnwire
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/roasbeef/btcd/btcec"
|
||||
"github.com/roasbeef/btcutil"
|
||||
|
||||
"io"
|
||||
)
|
||||
|
||||
// CloseRequest is sent by either side in order to initiate the cooperative
|
||||
// closure of a channel. This message is rather sparse as both side implicitly
|
||||
// know to craft a transaction sending the settled funds of both parties to the
|
||||
// final delivery addresses negotiated during the funding workflow.
|
||||
//
|
||||
// NOTE: The requester is able to only send a signature to initiate the
|
||||
// cooperative channel closure as all transactions are assembled observing
|
||||
// BIP 69 which defines a cannonical ordering for input/outputs. Therefore,
|
||||
// both sides are able to arrive at an identical closure transaction as they
|
||||
// know the order of the inputs/outputs.
|
||||
type CloseRequest struct {
|
||||
ReservationID uint64
|
||||
// ChannelID serves to identify which channel is to be closed.
|
||||
ChannelID uint64
|
||||
|
||||
RequesterCloseSig *btcec.Signature // Requester's Commitment
|
||||
Fee btcutil.Amount
|
||||
// RequesterCloseSig is the signature of the requester for the fully
|
||||
// assembled closing transaction.
|
||||
RequesterCloseSig *btcec.Signature
|
||||
|
||||
// Fee is the required fee-per-KB the closing transaction must have.
|
||||
// It is recommended that a "sufficient" fee be paid in order to achieve
|
||||
// timely channel closure.
|
||||
Fee btcutil.Amount
|
||||
}
|
||||
|
||||
// Decode deserializes a serialized CloseRequest stored in the passed io.Reader
|
||||
// observing the specified protocol version.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *CloseRequest) Decode(r io.Reader, pver uint32) error {
|
||||
// ReservationID (8)
|
||||
// ChannelID (8)
|
||||
// RequesterCloseSig (73)
|
||||
// First byte length then sig
|
||||
// Fee (8)
|
||||
err := readElements(r,
|
||||
&c.ReservationID,
|
||||
&c.ChannelID,
|
||||
&c.RequesterCloseSig,
|
||||
&c.Fee)
|
||||
if err != nil {
|
||||
@@ -31,19 +53,25 @@ func (c *CloseRequest) Decode(r io.Reader, pver uint32) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Creates a new CloseRequest
|
||||
// NewCloseRequest creates a new CloseRequest.
|
||||
func NewCloseRequest() *CloseRequest {
|
||||
return &CloseRequest{}
|
||||
}
|
||||
|
||||
// Serializes the item from the CloseRequest struct
|
||||
// Writes the data to w
|
||||
// A compile time check to ensure CloseRequest implements the lnwire.Message
|
||||
// interface.
|
||||
var _ Message = (*CloseRequest)(nil)
|
||||
|
||||
// Encode serializes the target CloseRequest into the passed io.Writer observing
|
||||
// the protocol version specified.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *CloseRequest) Encode(w io.Writer, pver uint32) error {
|
||||
// ReservationID
|
||||
// ChannelID
|
||||
// RequesterCloseSig
|
||||
// Fee
|
||||
err := writeElements(w,
|
||||
c.ReservationID,
|
||||
c.ChannelID,
|
||||
c.RequesterCloseSig,
|
||||
c.Fee)
|
||||
if err != nil {
|
||||
@@ -53,25 +81,40 @@ func (c *CloseRequest) Encode(w io.Writer, pver uint32) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Command returns the integer uniquely identifying this message type on the
|
||||
// wire.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *CloseRequest) Command() uint32 {
|
||||
return CmdCloseRequest
|
||||
}
|
||||
|
||||
func (c *CloseRequest) MaxPayloadLength(uint32) uint32 {
|
||||
// MaxPayloadLength returns the maximum allowed payload size for this message
|
||||
// observing the specified protocol version.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *CloseRequest) MaxPayloadLength(pver uint32) uint32 {
|
||||
// 8 + 73 + 8
|
||||
return 89
|
||||
}
|
||||
|
||||
// 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 CloseRequest are valid.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *CloseRequest) Validate() error {
|
||||
// Fee must be greater than 0
|
||||
// Fee must be greater than 0.
|
||||
if c.Fee < 0 {
|
||||
return fmt.Errorf("Fee must be greater than zero.")
|
||||
}
|
||||
|
||||
// We're good!
|
||||
return nil
|
||||
}
|
||||
|
||||
// String returns the string representation of the target CloseRequest.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *CloseRequest) String() string {
|
||||
var serializedSig []byte
|
||||
if c.RequesterCloseSig != nil && c.RequesterCloseSig.R != nil {
|
||||
@@ -79,7 +122,7 @@ func (c *CloseRequest) String() string {
|
||||
}
|
||||
|
||||
return fmt.Sprintf("\n--- Begin CloseRequest ---\n") +
|
||||
fmt.Sprintf("ReservationID:\t\t%d\n", c.ReservationID) +
|
||||
fmt.Sprintf("ChannelID:\t\t%d\n", c.ChannelID) +
|
||||
fmt.Sprintf("CloseSig\t\t%x\n", serializedSig) +
|
||||
fmt.Sprintf("Fee:\t\t\t%d\n", c.Fee) +
|
||||
fmt.Sprintf("--- End CloseRequest ---\n")
|
||||
|
||||
Reference in new issue
Block a user