github.com/decred/dcrlnd@v0.7.6/channeldb/migration/lnwire21/open_channel.go (about) 1 package lnwire 2 3 import ( 4 "io" 5 6 "github.com/decred/dcrd/chaincfg/chainhash" 7 "github.com/decred/dcrd/dcrec/secp256k1/v4" 8 "github.com/decred/dcrd/dcrutil/v4" 9 ) 10 11 // FundingFlag represents the possible bit mask values for the ChannelFlags 12 // field within the OpenChannel struct. 13 type FundingFlag uint8 14 15 const ( 16 // FFAnnounceChannel is a FundingFlag that when set, indicates the 17 // initiator of a funding flow wishes to announce the channel to the 18 // greater network. 19 FFAnnounceChannel FundingFlag = 1 << iota 20 ) 21 22 // OpenChannel is the message Alice sends to Bob if we should like to create a 23 // channel with Bob where she's the sole provider of funds to the channel. 24 // Single funder channels simplify the initial funding workflow, are supported 25 // by nodes backed by SPV clients, and have a simpler security models than dual 26 // funded channels. 27 type OpenChannel struct { 28 // ChainHash is the target chain that the initiator wishes to open a 29 // channel within. 30 ChainHash chainhash.Hash 31 32 // PendingChannelID serves to uniquely identify the future channel 33 // created by the initiated single funder workflow. 34 PendingChannelID [32]byte 35 36 // FundingAmount is the amount of atoms that the initiator of the 37 // channel wishes to use as the total capacity of the channel. The 38 // initial balance of the funding will be this value minus the push 39 // amount (if set). 40 FundingAmount dcrutil.Amount 41 42 // PushAmount is the value that the initiating party wishes to "push" 43 // to the responding as part of the first commitment state. If the 44 // responder accepts, then this will be their initial balance. 45 PushAmount MilliAtom 46 47 // DustLimit is the specific dust limit the sender of this message 48 // would like enforced on their version of the commitment transaction. 49 // Any output below this value will be "trimmed" from the commitment 50 // transaction, with the amount of the HTLC going to dust. 51 DustLimit dcrutil.Amount 52 53 // MaxValueInFlight represents the maximum amount of coins that can be 54 // pending within the channel at any given time. If the amount of funds 55 // in limbo exceeds this amount, then the channel will be failed. 56 MaxValueInFlight MilliAtom 57 58 // ChannelReserve is the amount that the receiving party MUST 59 // maintain a balance above at all times. This is a safety mechanism to 60 // ensure that both sides always have skin in the game during the 61 // channel's lifetime. 62 ChannelReserve dcrutil.Amount 63 64 // HtlcMinimum is the smallest HTLC that the sender of this message 65 // will accept. 66 HtlcMinimum MilliAtom 67 68 // FeePerKiloByte is the initial fee rate that the initiator suggests 69 // for both commitment transaction. This value is expressed in atoms 70 // per kilobyte. 71 // 72 // TODO(halseth): make AtomsPerKWeight when fee estimation is in own 73 // package. Currently this will cause an import cycle. 74 FeePerKiloByte uint32 75 76 // CsvDelay is the number of blocks to use for the relative time lock 77 // in the pay-to-self output of both commitment transactions. 78 CsvDelay uint16 79 80 // MaxAcceptedHTLCs is the total number of incoming HTLC's that the 81 // sender of this channel will accept. 82 MaxAcceptedHTLCs uint16 83 84 // FundingKey is the key that should be used on behalf of the sender 85 // within the 2-of-2 multi-sig output that it contained within the 86 // funding transaction. 87 FundingKey *secp256k1.PublicKey 88 89 // RevocationPoint is the base revocation point for the sending party. 90 // Any commitment transaction belonging to the receiver of this message 91 // should use this key and their per-commitment point to derive the 92 // revocation key for the commitment transaction. 93 RevocationPoint *secp256k1.PublicKey 94 95 // PaymentPoint is the base payment point for the sending party. This 96 // key should be combined with the per commitment point for a 97 // particular commitment state in order to create the key that should 98 // be used in any output that pays directly to the sending party, and 99 // also within the HTLC covenant transactions. 100 PaymentPoint *secp256k1.PublicKey 101 102 // DelayedPaymentPoint is the delay point for the sending party. This 103 // key should be combined with the per commitment point to derive the 104 // keys that are used in outputs of the sender's commitment transaction 105 // where they claim funds. 106 DelayedPaymentPoint *secp256k1.PublicKey 107 108 // HtlcPoint is the base point used to derive the set of keys for this 109 // party that will be used within the HTLC public key scripts. This 110 // value is combined with the receiver's revocation base point in order 111 // to derive the keys that are used within HTLC scripts. 112 HtlcPoint *secp256k1.PublicKey 113 114 // FirstCommitmentPoint is the first commitment point for the sending 115 // party. This value should be combined with the receiver's revocation 116 // base point in order to derive the revocation keys that are placed 117 // within the commitment transaction of the sender. 118 FirstCommitmentPoint *secp256k1.PublicKey 119 120 // ChannelFlags is a bit-field which allows the initiator of the 121 // channel to specify further behavior surrounding the channel. 122 // Currently, the least significant bit of this bit field indicates the 123 // initiator of the channel wishes to advertise this channel publicly. 124 ChannelFlags FundingFlag 125 126 // UpfrontShutdownScript is the script to which the channel funds should 127 // be paid when mutually closing the channel. This field is optional, and 128 // and has a length prefix, so a zero will be written if it is not set 129 // and its length followed by the script will be written if it is set. 130 UpfrontShutdownScript DeliveryAddress 131 } 132 133 // A compile time check to ensure OpenChannel implements the lnwire.Message 134 // interface. 135 var _ Message = (*OpenChannel)(nil) 136 137 // Encode serializes the target OpenChannel into the passed io.Writer 138 // implementation. Serialization will observe the rules defined by the passed 139 // protocol version. 140 // 141 // This is part of the lnwire.Message interface. 142 func (o *OpenChannel) Encode(w io.Writer, pver uint32) error { 143 return WriteElements(w, 144 o.ChainHash[:], 145 o.PendingChannelID[:], 146 o.FundingAmount, 147 o.PushAmount, 148 o.DustLimit, 149 o.MaxValueInFlight, 150 o.ChannelReserve, 151 o.HtlcMinimum, 152 o.FeePerKiloByte, 153 o.CsvDelay, 154 o.MaxAcceptedHTLCs, 155 o.FundingKey, 156 o.RevocationPoint, 157 o.PaymentPoint, 158 o.DelayedPaymentPoint, 159 o.HtlcPoint, 160 o.FirstCommitmentPoint, 161 o.ChannelFlags, 162 o.UpfrontShutdownScript, 163 ) 164 } 165 166 // Decode deserializes the serialized OpenChannel stored in the passed 167 // io.Reader into the target OpenChannel using the deserialization rules 168 // defined by the passed protocol version. 169 // 170 // This is part of the lnwire.Message interface. 171 func (o *OpenChannel) Decode(r io.Reader, pver uint32) error { 172 if err := ReadElements(r, 173 o.ChainHash[:], 174 o.PendingChannelID[:], 175 &o.FundingAmount, 176 &o.PushAmount, 177 &o.DustLimit, 178 &o.MaxValueInFlight, 179 &o.ChannelReserve, 180 &o.HtlcMinimum, 181 &o.FeePerKiloByte, 182 &o.CsvDelay, 183 &o.MaxAcceptedHTLCs, 184 &o.FundingKey, 185 &o.RevocationPoint, 186 &o.PaymentPoint, 187 &o.DelayedPaymentPoint, 188 &o.HtlcPoint, 189 &o.FirstCommitmentPoint, 190 &o.ChannelFlags, 191 ); err != nil { 192 return err 193 } 194 195 // Check for the optional upfront shutdown script field. If it is not there, 196 // silence the EOF error. 197 err := ReadElement(r, &o.UpfrontShutdownScript) 198 if err != nil && err != io.EOF { 199 return err 200 } 201 202 return nil 203 } 204 205 // MsgType returns the MessageType code which uniquely identifies this message 206 // as an OpenChannel on the wire. 207 // 208 // This is part of the lnwire.Message interface. 209 func (o *OpenChannel) MsgType() MessageType { 210 return MsgOpenChannel 211 } 212 213 // MaxPayloadLength returns the maximum allowed payload length for a 214 // OpenChannel message. 215 // 216 // This is part of the lnwire.Message interface. 217 func (o *OpenChannel) MaxPayloadLength(uint32) uint32 { 218 // (32 * 2) + (8 * 6) + (4 * 1) + (2 * 2) + (33 * 6) + 1 219 var length uint32 = 319 // base length 220 221 // Upfront shutdown script max length. 222 length += 2 + deliveryAddressMaxSize 223 224 return length 225 }