@@ -22,10 +22,6 @@ const (
2222// HTLCs and other parameters. This message is also used to redeclare initially
2323// set channel parameters.
2424type ChannelUpdate2 struct {
25- // Signature is used to validate the announced data and prove the
26- // ownership of node id.
27- Signature Sig
28-
2925 // ChainHash denotes the target chain that this channel was opened
3026 // within. This value should be the genesis hash of the target chain.
3127 // Along with the short channel ID, this uniquely identifies the
@@ -74,28 +70,29 @@ type ChannelUpdate2 struct {
7470 // millionth of a satoshi.
7571 FeeProportionalMillionths tlv.RecordT [tlv.TlvType18 , uint32 ]
7672
77- // ExtraOpaqueData is the set of data that was appended to this message
78- // to fill out the full maximum transport message size. These fields can
79- // be used to specify optional data such as custom TLV fields.
80- ExtraOpaqueData ExtraOpaqueData
73+ // Signature is used to validate the announced data and prove the
74+ // ownership of node id.
75+ Signature tlv.RecordT [tlv.TlvType160 , Sig ]
76+
77+ // Any extra fields in the signed range that we do not yet know about,
78+ // but we need to keep them for signature validation and to produce a
79+ // valid message.
80+ ExtraSignedFields
81+ }
82+
83+ // Encode serializes the target ChannelUpdate2 into the passed io.Writer
84+ // observing the protocol version specified.
85+ //
86+ // This is part of the lnwire.Message interface.
87+ func (c * ChannelUpdate2 ) Encode (w * bytes.Buffer , _ uint32 ) error {
88+ return EncodePureTLVMessage (c , w )
8189}
8290
8391// Decode deserializes a serialized ChannelUpdate2 stored in the passed
8492// io.Reader observing the specified protocol version.
8593//
8694// This is part of the lnwire.Message interface.
8795func (c * ChannelUpdate2 ) Decode (r io.Reader , _ uint32 ) error {
88- err := ReadElement (r , & c .Signature )
89- if err != nil {
90- return err
91- }
92- c .Signature .ForceSchnorr ()
93-
94- return c .DecodeTLVRecords (r )
95- }
96-
97- // DecodeTLVRecords decodes only the TLV section of the message.
98- func (c * ChannelUpdate2 ) DecodeTLVRecords (r io.Reader ) error {
9996 // First extract into extra opaque data.
10097 var tlvRecords ExtraOpaqueData
10198 if err := ReadElements (r , & tlvRecords ); err != nil {
@@ -111,10 +108,12 @@ func (c *ChannelUpdate2) DecodeTLVRecords(r io.Reader) error {
111108 & secondPeer , & c .CLTVExpiryDelta , & c .HTLCMinimumMsat ,
112109 & c .HTLCMaximumMsat , & c .FeeBaseMsat ,
113110 & c .FeeProportionalMillionths ,
111+ & c .Signature ,
114112 )
115113 if err != nil {
116114 return err
117115 }
116+ c .Signature .Val .ForceSchnorr ()
118117
119118 // By default, the chain-hash is the bitcoin mainnet genesis block hash.
120119 c .ChainHash .Val = * chaincfg .MainNetParams .GenesisHash
@@ -150,38 +149,21 @@ func (c *ChannelUpdate2) DecodeTLVRecords(r io.Reader) error {
150149 c .FeeProportionalMillionths .Val = defaultFeeProportionalMillionths //nolint:ll
151150 }
152151
153- if len (tlvRecords ) != 0 {
154- c .ExtraOpaqueData = tlvRecords
155- }
152+ c .ExtraSignedFields = ExtraSignedFieldsFromTypeMap (typeMap )
156153
157- return c . ExtraOpaqueData . ValidateTLV ()
154+ return nil
158155}
159156
160- // Encode serializes the target ChannelUpdate2 into the passed io.Writer
161- // observing the protocol version specified.
157+ // AllRecords returns all the TLV records for the message. This will include all
158+ // the records we know about along with any that we don't know about but that
159+ // fall in the signed TLV range.
162160//
163- // This is part of the lnwire.Message interface.
164- func (c * ChannelUpdate2 ) Encode (w * bytes.Buffer , _ uint32 ) error {
165- _ , err := w .Write (c .Signature .RawBytes ())
166- if err != nil {
167- return err
168- }
169-
170- _ , err = c .DataToSign ()
171- if err != nil {
172- return err
173- }
174-
175- return WriteBytes (w , c .ExtraOpaqueData )
176- }
161+ // NOTE: this is part of the PureTLVMessage interface.
162+ func (c * ChannelUpdate2 ) AllRecords () []tlv.Record {
163+ var recordProducers []tlv.RecordProducer
177164
178- // DataToSign is used to retrieve part of the announcement message which should
179- // be signed. For the ChannelUpdate2 message, this includes the serialised TLV
180- // records.
181- func (c * ChannelUpdate2 ) DataToSign () ([]byte , error ) {
182165 // The chain-hash record is only included if it is _not_ equal to the
183166 // bitcoin mainnet genisis block hash.
184- var recordProducers []tlv.RecordProducer
185167 if ! c .ChainHash .Val .IsEqual (chaincfg .MainNetParams .GenesisHash ) {
186168 hash := tlv .ZeroRecordT [tlv.TlvType0 , [32 ]byte ]()
187169 hash .Val = c .ChainHash .Val
@@ -190,7 +172,7 @@ func (c *ChannelUpdate2) DataToSign() ([]byte, error) {
190172 }
191173
192174 recordProducers = append (recordProducers ,
193- & c .ShortChannelID , & c .BlockHeight ,
175+ & c .ShortChannelID , & c .BlockHeight , & c . Signature ,
194176 )
195177
196178 // Only include the disable flags if any bit is set.
@@ -225,12 +207,11 @@ func (c *ChannelUpdate2) DataToSign() ([]byte, error) {
225207 )
226208 }
227209
228- err := EncodeMessageExtraData (& c .ExtraOpaqueData , recordProducers ... )
229- if err != nil {
230- return nil , err
231- }
210+ recordProducers = append (recordProducers , RecordsAsProducers (
211+ tlv .MapToRecords (c .ExtraSignedFields ),
212+ )... )
232213
233- return c . ExtraOpaqueData , nil
214+ return ProduceRecordsSorted ( recordProducers ... )
234215}
235216
236217// MsgType returns the integer uniquely identifying this message type on the
@@ -248,14 +229,14 @@ func (c *ChannelUpdate2) SerializedSize() (uint32, error) {
248229 return MessageSerializedSize (c )
249230}
250231
251- func (c * ChannelUpdate2 ) ExtraData () ExtraOpaqueData {
252- return c .ExtraOpaqueData
253- }
254-
255232// A compile time check to ensure ChannelUpdate2 implements the
256233// lnwire.Message interface.
257234var _ Message = (* ChannelUpdate2 )(nil )
258235
236+ // A compile time check to ensure ChannelUpdate2 implements the
237+ // lnwire.PureTLVMessage interface.
238+ var _ PureTLVMessage = (* ChannelUpdate2 )(nil )
239+
259240// SCID returns the ShortChannelID of the channel that the update applies to.
260241//
261242// NOTE: this is part of the ChannelUpdate interface.
0 commit comments