lnwire: Add upfront shutdown messages and feature bit

This commit adds the feature bit and additional fields
required in `open_channel` and `accept_channel` wire
messages for `option_upfront_shutdown_script`.
This commit is contained in:
Steven Roose authored and carla committed 2019-12-03 11:38:21 +02:00
1 parent db21c394b2
commit 2fb7172725
8 files changed
+198 -21

No files matched your search

+26 -3
View File
@@ -122,6 +122,12 @@ type OpenChannel struct {
// Currently, the least significant bit of this bit field indicates the
// initiator of the channel wishes to advertise this channel publicly.
ChannelFlags FundingFlag
// UpfrontShutdownScript is the script to which the channel funds should
// be paid when mutually closing the channel. This field is optional, and
// and has a length prefix, so a zero will be written if it is not set
// and its length followed by the script will be written if it is set.
UpfrontShutdownScript DeliveryAddress
}
// A compile time check to ensure OpenChannel implements the lnwire.Message
@@ -153,6 +159,7 @@ func (o *OpenChannel) Encode(w io.Writer, pver uint32) error {
o.HtlcPoint,
o.FirstCommitmentPoint,
o.ChannelFlags,
o.UpfrontShutdownScript,
)
}
@@ -162,7 +169,7 @@ func (o *OpenChannel) Encode(w io.Writer, pver uint32) error {
//
// This is part of the lnwire.Message interface.
func (o *OpenChannel) Decode(r io.Reader, pver uint32) error {
return ReadElements(r,
if err := ReadElements(r,
o.ChainHash[:],
o.PendingChannelID[:],
&o.FundingAmount,
@@ -181,7 +188,18 @@ func (o *OpenChannel) Decode(r io.Reader, pver uint32) error {
&o.HtlcPoint,
&o.FirstCommitmentPoint,
&o.ChannelFlags,
)
); err != nil {
return err
}
// Check for the optional upfront shutdown script field. If it is not there,
// silence the EOF error.
err := ReadElement(r, &o.UpfrontShutdownScript)
if err != nil && err != io.EOF {
return err
}
return nil
}
// MsgType returns the MessageType code which uniquely identifies this message
@@ -198,5 +216,10 @@ func (o *OpenChannel) MsgType() MessageType {
// This is part of the lnwire.Message interface.
func (o *OpenChannel) MaxPayloadLength(uint32) uint32 {
// (32 * 2) + (8 * 6) + (4 * 1) + (2 * 2) + (33 * 6) + 1
return 319
var length uint32 = 319 // base length
// Upfront shutdown script max length.
length += 2 + deliveryAddressMaxSize
return length
}