2016-12-07 16:46:22 +01:00
|
|
|
package lnwire
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2016-12-22 21:24:48 +01:00
|
|
|
"io"
|
|
|
|
|
2018-06-05 03:34:16 +02:00
|
|
|
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
2016-12-07 16:46:22 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// ChannelAnnouncement message is used to announce the existence of a channel
|
|
|
|
// between two peers in the overlay, which is propagated by the discovery
|
|
|
|
// service over broadcast handler.
|
|
|
|
type ChannelAnnouncement struct {
|
|
|
|
// This signatures are used by nodes in order to create cross
|
|
|
|
// references between node's channel and node. Requiring both nodes
|
|
|
|
// to sign indicates they are both willing to route other payments via
|
|
|
|
// this node.
|
2018-01-31 04:41:52 +01:00
|
|
|
NodeSig1 Sig
|
|
|
|
NodeSig2 Sig
|
2016-12-07 16:46:22 +01:00
|
|
|
|
|
|
|
// This signatures are used by nodes in order to create cross
|
|
|
|
// references between node's channel and node. Requiring the bitcoin
|
|
|
|
// signatures proves they control the channel.
|
2018-01-31 04:41:52 +01:00
|
|
|
BitcoinSig1 Sig
|
|
|
|
BitcoinSig2 Sig
|
2017-03-27 17:22:37 +02:00
|
|
|
|
2017-08-22 07:46:56 +02:00
|
|
|
// Features is the feature vector that encodes the features supported
|
|
|
|
// by the target node. This field can be used to signal the type of the
|
|
|
|
// channel, or modifications to the fields that would normally follow
|
|
|
|
// this vector.
|
2017-10-11 20:37:54 +02:00
|
|
|
Features *RawFeatureVector
|
2017-08-22 07:46:56 +02:00
|
|
|
|
|
|
|
// ChainHash denotes the target chain that this channel was opened
|
|
|
|
// within. This value should be the genesis hash of the target chain.
|
|
|
|
ChainHash chainhash.Hash
|
|
|
|
|
|
|
|
// ShortChannelID is the unique description of the funding transaction,
|
|
|
|
// or where exactly it's located within the target blockchain.
|
2017-03-27 17:22:37 +02:00
|
|
|
ShortChannelID ShortChannelID
|
2016-12-07 16:46:22 +01:00
|
|
|
|
|
|
|
// The public keys of the two nodes who are operating the channel, such
|
2017-03-27 17:22:37 +02:00
|
|
|
// that is NodeID1 the numerically-lesser than NodeID2 (ascending
|
|
|
|
// numerical order).
|
2018-01-31 04:53:49 +01:00
|
|
|
NodeID1 [33]byte
|
|
|
|
NodeID2 [33]byte
|
2016-12-07 16:46:22 +01:00
|
|
|
|
|
|
|
// Public keys which corresponds to the keys which was declared in
|
|
|
|
// multisig funding transaction output.
|
2018-01-31 04:53:49 +01:00
|
|
|
BitcoinKey1 [33]byte
|
|
|
|
BitcoinKey2 [33]byte
|
2018-09-01 04:33:05 +02:00
|
|
|
|
|
|
|
// ExtraOpaqueData is the set of data that was appended to this
|
|
|
|
// message, some of which we may not actually know how to iterate or
|
|
|
|
// parse. By holding onto this data, we ensure that we're able to
|
|
|
|
// properly validate the set of signatures that cover these new fields,
|
|
|
|
// and ensure we're able to make upgrades to the network in a forwards
|
|
|
|
// compatible manner.
|
2020-01-28 02:25:36 +01:00
|
|
|
ExtraOpaqueData ExtraOpaqueData
|
2016-12-07 16:46:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// A compile time check to ensure ChannelAnnouncement implements the
|
|
|
|
// lnwire.Message interface.
|
|
|
|
var _ Message = (*ChannelAnnouncement)(nil)
|
|
|
|
|
|
|
|
// Decode deserializes a serialized ChannelAnnouncement stored in the passed
|
|
|
|
// io.Reader observing the specified protocol version.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-02-23 20:56:47 +01:00
|
|
|
func (a *ChannelAnnouncement) Decode(r io.Reader, pver uint32) error {
|
2020-01-28 02:25:36 +01:00
|
|
|
return ReadElements(r,
|
2017-03-27 17:22:37 +02:00
|
|
|
&a.NodeSig1,
|
|
|
|
&a.NodeSig2,
|
|
|
|
&a.BitcoinSig1,
|
|
|
|
&a.BitcoinSig2,
|
2017-08-22 07:46:56 +02:00
|
|
|
&a.Features,
|
|
|
|
a.ChainHash[:],
|
|
|
|
&a.ShortChannelID,
|
2017-03-27 17:22:37 +02:00
|
|
|
&a.NodeID1,
|
|
|
|
&a.NodeID2,
|
|
|
|
&a.BitcoinKey1,
|
|
|
|
&a.BitcoinKey2,
|
2020-01-28 02:25:36 +01:00
|
|
|
&a.ExtraOpaqueData,
|
2016-12-07 16:46:22 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Encode serializes the target ChannelAnnouncement into the passed io.Writer
|
|
|
|
// observing the protocol version specified.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2021-06-17 08:17:30 +02:00
|
|
|
func (a *ChannelAnnouncement) Encode(w *bytes.Buffer, pver uint32) error {
|
2021-06-18 09:15:44 +02:00
|
|
|
if err := WriteSig(w, a.NodeSig1); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteSig(w, a.NodeSig2); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteSig(w, a.BitcoinSig1); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteSig(w, a.BitcoinSig2); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteRawFeatureVector(w, a.Features); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteBytes(w, a.ChainHash[:]); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteShortChannelID(w, a.ShortChannelID); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteBytes(w, a.NodeID1[:]); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteBytes(w, a.NodeID2[:]); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteBytes(w, a.BitcoinKey1[:]); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteBytes(w, a.BitcoinKey2[:]); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return WriteBytes(w, a.ExtraOpaqueData)
|
2016-12-07 16:46:22 +01:00
|
|
|
}
|
|
|
|
|
2017-04-20 00:57:43 +02:00
|
|
|
// MsgType returns the integer uniquely identifying this message type on the
|
2016-12-07 16:46:22 +01:00
|
|
|
// wire.
|
|
|
|
//
|
|
|
|
// This is part of the lnwire.Message interface.
|
2017-04-20 00:57:43 +02:00
|
|
|
func (a *ChannelAnnouncement) MsgType() MessageType {
|
|
|
|
return MsgChannelAnnouncement
|
2016-12-07 16:46:22 +01:00
|
|
|
}
|
|
|
|
|
2017-08-22 07:46:56 +02:00
|
|
|
// DataToSign is used to retrieve part of the announcement message which should
|
|
|
|
// be signed.
|
2017-02-23 20:56:47 +01:00
|
|
|
func (a *ChannelAnnouncement) DataToSign() ([]byte, error) {
|
2016-12-07 16:46:22 +01:00
|
|
|
// We should not include the signatures itself.
|
2021-06-18 09:15:44 +02:00
|
|
|
b := make([]byte, 0, MaxMsgBody)
|
|
|
|
buf := bytes.NewBuffer(b)
|
|
|
|
|
|
|
|
if err := WriteRawFeatureVector(buf, a.Features); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteBytes(buf, a.ChainHash[:]); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteShortChannelID(buf, a.ShortChannelID); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteBytes(buf, a.NodeID1[:]); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteBytes(buf, a.NodeID2[:]); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteBytes(buf, a.BitcoinKey1[:]); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteBytes(buf, a.BitcoinKey2[:]); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := WriteBytes(buf, a.ExtraOpaqueData); err != nil {
|
2016-12-07 16:46:22 +01:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-06-18 09:15:44 +02:00
|
|
|
return buf.Bytes(), nil
|
2016-12-07 16:46:22 +01:00
|
|
|
}
|