github.com/decred/dcrlnd@v0.7.6/channeldb/migration/lnwire21/accept_channel.go (about)

     1  package lnwire
     2  
     3  import (
     4  	"io"
     5  
     6  	"github.com/decred/dcrd/dcrec/secp256k1/v4"
     7  	"github.com/decred/dcrd/dcrutil/v4"
     8  )
     9  
    10  // AcceptChannel is the message Bob sends to Alice after she initiates the
    11  // single funder channel workflow via an AcceptChannel message. Once Alice
    12  // receives Bob's response, then she has all the items necessary to construct
    13  // the funding transaction, and both commitment transactions.
    14  type AcceptChannel struct {
    15  	// PendingChannelID serves to uniquely identify the future channel
    16  	// created by the initiated single funder workflow.
    17  	PendingChannelID [32]byte
    18  
    19  	// DustLimit is the specific dust limit the sender of this message
    20  	// would like enforced on their version of the commitment transaction.
    21  	// Any output below this value will be "trimmed" from the commitment
    22  	// transaction, with the amount of the HTLC going to dust.
    23  	DustLimit dcrutil.Amount
    24  
    25  	// MaxValueInFlight represents the maximum amount of coins that can be
    26  	// pending within the channel at any given time. If the amount of funds
    27  	// in limbo exceeds this amount, then the channel will be failed.
    28  	MaxValueInFlight MilliAtom
    29  
    30  	// ChannelReserve is the amount of DCR that the receiving party MUST
    31  	// maintain a balance above at all times. This is a safety mechanism to
    32  	// ensure that both sides always have skin in the game during the
    33  	// channel's lifetime.
    34  	ChannelReserve dcrutil.Amount
    35  
    36  	// HtlcMinimum is the smallest HTLC that the sender of this message
    37  	// will accept.
    38  	HtlcMinimum MilliAtom
    39  
    40  	// MinAcceptDepth is the minimum depth that the initiator of the
    41  	// channel should wait before considering the channel open.
    42  	MinAcceptDepth uint32
    43  
    44  	// CsvDelay is the number of blocks to use for the relative time lock
    45  	// in the pay-to-self output of both commitment transactions.
    46  	CsvDelay uint16
    47  
    48  	// MaxAcceptedHTLCs is the total number of incoming HTLC's that the
    49  	// sender of this channel will accept.
    50  	//
    51  	// TODO(roasbeef): acks the initiator's, same with max in flight?
    52  	MaxAcceptedHTLCs uint16
    53  
    54  	// FundingKey is the key that should be used on behalf of the sender
    55  	// within the 2-of-2 multi-sig output that it contained within the
    56  	// funding transaction.
    57  	FundingKey *secp256k1.PublicKey
    58  
    59  	// RevocationPoint is the base revocation point for the sending party.
    60  	// Any commitment transaction belonging to the receiver of this message
    61  	// should use this key and their per-commitment point to derive the
    62  	// revocation key for the commitment transaction.
    63  	RevocationPoint *secp256k1.PublicKey
    64  
    65  	// PaymentPoint is the base payment point for the sending party. This
    66  	// key should be combined with the per commitment point for a
    67  	// particular commitment state in order to create the key that should
    68  	// be used in any output that pays directly to the sending party, and
    69  	// also within the HTLC covenant transactions.
    70  	PaymentPoint *secp256k1.PublicKey
    71  
    72  	// DelayedPaymentPoint is the delay point for the sending party. This
    73  	// key should be combined with the per commitment point to derive the
    74  	// keys that are used in outputs of the sender's commitment transaction
    75  	// where they claim funds.
    76  	DelayedPaymentPoint *secp256k1.PublicKey
    77  
    78  	// HtlcPoint is the base point used to derive the set of keys for this
    79  	// party that will be used within the HTLC public key scripts.  This
    80  	// value is combined with the receiver's revocation base point in order
    81  	// to derive the keys that are used within HTLC scripts.
    82  	HtlcPoint *secp256k1.PublicKey
    83  
    84  	// FirstCommitmentPoint is the first commitment point for the sending
    85  	// party. This value should be combined with the receiver's revocation
    86  	// base point in order to derive the revocation keys that are placed
    87  	// within the commitment transaction of the sender.
    88  	FirstCommitmentPoint *secp256k1.PublicKey
    89  
    90  	// UpfrontShutdownScript is the script to which the channel funds should
    91  	// be paid when mutually closing the channel. This field is optional, and
    92  	// and has a length prefix, so a zero will be written if it is not set
    93  	// and its length followed by the script will be written if it is set.
    94  	UpfrontShutdownScript DeliveryAddress
    95  }
    96  
    97  // A compile time check to ensure AcceptChannel implements the lnwire.Message
    98  // interface.
    99  var _ Message = (*AcceptChannel)(nil)
   100  
   101  // Encode serializes the target AcceptChannel into the passed io.Writer
   102  // implementation. Serialization will observe the rules defined by the passed
   103  // protocol version.
   104  //
   105  // This is part of the lnwire.Message interface.
   106  func (a *AcceptChannel) Encode(w io.Writer, pver uint32) error {
   107  	return WriteElements(w,
   108  		a.PendingChannelID[:],
   109  		a.DustLimit,
   110  		a.MaxValueInFlight,
   111  		a.ChannelReserve,
   112  		a.HtlcMinimum,
   113  		a.MinAcceptDepth,
   114  		a.CsvDelay,
   115  		a.MaxAcceptedHTLCs,
   116  		a.FundingKey,
   117  		a.RevocationPoint,
   118  		a.PaymentPoint,
   119  		a.DelayedPaymentPoint,
   120  		a.HtlcPoint,
   121  		a.FirstCommitmentPoint,
   122  		a.UpfrontShutdownScript,
   123  	)
   124  }
   125  
   126  // Decode deserializes the serialized AcceptChannel stored in the passed
   127  // io.Reader into the target AcceptChannel using the deserialization rules
   128  // defined by the passed protocol version.
   129  //
   130  // This is part of the lnwire.Message interface.
   131  func (a *AcceptChannel) Decode(r io.Reader, pver uint32) error {
   132  	// Read all the mandatory fields in the accept message.
   133  	err := ReadElements(r,
   134  		a.PendingChannelID[:],
   135  		&a.DustLimit,
   136  		&a.MaxValueInFlight,
   137  		&a.ChannelReserve,
   138  		&a.HtlcMinimum,
   139  		&a.MinAcceptDepth,
   140  		&a.CsvDelay,
   141  		&a.MaxAcceptedHTLCs,
   142  		&a.FundingKey,
   143  		&a.RevocationPoint,
   144  		&a.PaymentPoint,
   145  		&a.DelayedPaymentPoint,
   146  		&a.HtlcPoint,
   147  		&a.FirstCommitmentPoint,
   148  	)
   149  	if err != nil {
   150  		return err
   151  	}
   152  
   153  	// Check for the optional upfront shutdown script field. If it is not there,
   154  	// silence the EOF error.
   155  	err = ReadElement(r, &a.UpfrontShutdownScript)
   156  	if err != nil && err != io.EOF {
   157  		return err
   158  	}
   159  	return nil
   160  }
   161  
   162  // MsgType returns the MessageType code which uniquely identifies this message
   163  // as an AcceptChannel on the wire.
   164  //
   165  // This is part of the lnwire.Message interface.
   166  func (a *AcceptChannel) MsgType() MessageType {
   167  	return MsgAcceptChannel
   168  }
   169  
   170  // MaxPayloadLength returns the maximum allowed payload length for a
   171  // AcceptChannel message.
   172  //
   173  // This is part of the lnwire.Message interface.
   174  func (a *AcceptChannel) MaxPayloadLength(uint32) uint32 {
   175  	// 32 + (8 * 4) + (4 * 1) + (2 * 2) + (33 * 6)
   176  	var length uint32 = 270 // base length
   177  
   178  	// Upfront shutdown script max length.
   179  	length += 2 + deliveryAddressMaxSize
   180  
   181  	return length
   182  }