mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 09:53:54 +01:00
b368e476c5
In this commit, we update the Sig type to support ECDSA and schnorr signatures. We need to do this as the HTLC signatures will become schnorr sigs for taproot channels. The current spec draft opts to overload this field since both the sigs are actually 64 bytes in length. The only consideration with this move is that callers need to "coerce" a sig to the proper type if they need schnorr signatures.
87 lines
2.6 KiB
Go
87 lines
2.6 KiB
Go
package netann
|
|
|
|
import (
|
|
"bytes"
|
|
|
|
"github.com/lightningnetwork/lnd/channeldb"
|
|
"github.com/lightningnetwork/lnd/lnwire"
|
|
)
|
|
|
|
// CreateChanAnnouncement is a helper function which creates all channel
|
|
// announcements given the necessary channel related database items. This
|
|
// function is used to transform out database structs into the corresponding wire
|
|
// structs for announcing new channels to other peers, or simply syncing up a
|
|
// peer's initial routing table upon connect.
|
|
func CreateChanAnnouncement(chanProof *channeldb.ChannelAuthProof,
|
|
chanInfo *channeldb.ChannelEdgeInfo,
|
|
e1, e2 *channeldb.ChannelEdgePolicy) (*lnwire.ChannelAnnouncement,
|
|
*lnwire.ChannelUpdate, *lnwire.ChannelUpdate, error) {
|
|
|
|
// First, using the parameters of the channel, along with the channel
|
|
// authentication chanProof, we'll create re-create the original
|
|
// authenticated channel announcement.
|
|
chanID := lnwire.NewShortChanIDFromInt(chanInfo.ChannelID)
|
|
chanAnn := &lnwire.ChannelAnnouncement{
|
|
ShortChannelID: chanID,
|
|
NodeID1: chanInfo.NodeKey1Bytes,
|
|
NodeID2: chanInfo.NodeKey2Bytes,
|
|
ChainHash: chanInfo.ChainHash,
|
|
BitcoinKey1: chanInfo.BitcoinKey1Bytes,
|
|
BitcoinKey2: chanInfo.BitcoinKey2Bytes,
|
|
Features: lnwire.NewRawFeatureVector(),
|
|
ExtraOpaqueData: chanInfo.ExtraOpaqueData,
|
|
}
|
|
|
|
err := chanAnn.Features.Decode(bytes.NewReader(chanInfo.Features))
|
|
if err != nil {
|
|
return nil, nil, nil, err
|
|
}
|
|
chanAnn.BitcoinSig1, err = lnwire.NewSigFromECDSARawSignature(
|
|
chanProof.BitcoinSig1Bytes,
|
|
)
|
|
if err != nil {
|
|
return nil, nil, nil, err
|
|
}
|
|
chanAnn.BitcoinSig2, err = lnwire.NewSigFromECDSARawSignature(
|
|
chanProof.BitcoinSig2Bytes,
|
|
)
|
|
if err != nil {
|
|
return nil, nil, nil, err
|
|
}
|
|
chanAnn.NodeSig1, err = lnwire.NewSigFromECDSARawSignature(
|
|
chanProof.NodeSig1Bytes,
|
|
)
|
|
if err != nil {
|
|
return nil, nil, nil, err
|
|
}
|
|
chanAnn.NodeSig2, err = lnwire.NewSigFromECDSARawSignature(
|
|
chanProof.NodeSig2Bytes,
|
|
)
|
|
if err != nil {
|
|
return nil, nil, nil, err
|
|
}
|
|
|
|
// We'll unconditionally queue the channel's existence chanProof as it
|
|
// will need to be processed before either of the channel update
|
|
// networkMsgs.
|
|
|
|
// Since it's up to a node's policy as to whether they advertise the
|
|
// edge in a direction, we don't create an advertisement if the edge is
|
|
// nil.
|
|
var edge1Ann, edge2Ann *lnwire.ChannelUpdate
|
|
if e1 != nil {
|
|
edge1Ann, err = ChannelUpdateFromEdge(chanInfo, e1)
|
|
if err != nil {
|
|
return nil, nil, nil, err
|
|
}
|
|
}
|
|
if e2 != nil {
|
|
edge2Ann, err = ChannelUpdateFromEdge(chanInfo, e2)
|
|
if err != nil {
|
|
return nil, nil, nil, err
|
|
}
|
|
}
|
|
|
|
return chanAnn, edge1Ann, edge2Ann, nil
|
|
}
|