discovery/multi: move SignAnnouncement to netann
This commit is contained in:
parent
b03c3c2df3
commit
df44d19936
@ -20,6 +20,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/multimutex"
|
||||
"github.com/lightningnetwork/lnd/netann"
|
||||
"github.com/lightningnetwork/lnd/routing"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
"github.com/lightningnetwork/lnd/ticker"
|
||||
@ -2469,7 +2470,9 @@ func (d *AuthenticatedGossiper) updateChannel(info *channeldb.ChannelEdgeInfo,
|
||||
|
||||
// With the update applied, we'll generate a new signature over a
|
||||
// digest of the channel announcement itself.
|
||||
sig, err := SignAnnouncement(d.cfg.AnnSigner, d.selfKey, chanUpdate)
|
||||
sig, err := netann.SignAnnouncement(
|
||||
d.cfg.AnnSigner, d.selfKey, chanUpdate,
|
||||
)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import (
|
||||
"github.com/lightningnetwork/lnd/lnpeer"
|
||||
"github.com/lightningnetwork/lnd/lntest/wait"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
"github.com/lightningnetwork/lnd/netann"
|
||||
"github.com/lightningnetwork/lnd/routing"
|
||||
"github.com/lightningnetwork/lnd/routing/route"
|
||||
"github.com/lightningnetwork/lnd/ticker"
|
||||
@ -550,7 +551,7 @@ func createNodeAnnouncement(priv *btcec.PrivateKey,
|
||||
}
|
||||
|
||||
signer := mockSigner{priv}
|
||||
sig, err := SignAnnouncement(&signer, priv.PubKey(), a)
|
||||
sig, err := netann.SignAnnouncement(&signer, priv.PubKey(), a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -602,7 +603,7 @@ func createUpdateAnnouncement(blockHeight uint32,
|
||||
func signUpdate(nodeKey *btcec.PrivateKey, a *lnwire.ChannelUpdate) error {
|
||||
pub := nodeKey.PubKey()
|
||||
signer := mockSigner{nodeKey}
|
||||
sig, err := SignAnnouncement(&signer, pub, a)
|
||||
sig, err := netann.SignAnnouncement(&signer, pub, a)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -644,7 +645,7 @@ func createRemoteChannelAnnouncement(blockHeight uint32,
|
||||
|
||||
pub := nodeKeyPriv1.PubKey()
|
||||
signer := mockSigner{nodeKeyPriv1}
|
||||
sig, err := SignAnnouncement(&signer, pub, a)
|
||||
sig, err := netann.SignAnnouncement(&signer, pub, a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -655,7 +656,7 @@ func createRemoteChannelAnnouncement(blockHeight uint32,
|
||||
|
||||
pub = nodeKeyPriv2.PubKey()
|
||||
signer = mockSigner{nodeKeyPriv2}
|
||||
sig, err = SignAnnouncement(&signer, pub, a)
|
||||
sig, err = netann.SignAnnouncement(&signer, pub, a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -666,7 +667,7 @@ func createRemoteChannelAnnouncement(blockHeight uint32,
|
||||
|
||||
pub = bitcoinKeyPriv1.PubKey()
|
||||
signer = mockSigner{bitcoinKeyPriv1}
|
||||
sig, err = SignAnnouncement(&signer, pub, a)
|
||||
sig, err = netann.SignAnnouncement(&signer, pub, a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -677,7 +678,7 @@ func createRemoteChannelAnnouncement(blockHeight uint32,
|
||||
|
||||
pub = bitcoinKeyPriv2.PubKey()
|
||||
signer = mockSigner{bitcoinKeyPriv2}
|
||||
sig, err = SignAnnouncement(&signer, pub, a)
|
||||
sig, err = netann.SignAnnouncement(&signer, pub, a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -1,10 +1,7 @@
|
||||
package discovery
|
||||
|
||||
import (
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/go-errors/errors"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
@ -109,34 +106,6 @@ func CreateChanAnnouncement(chanProof *channeldb.ChannelAuthProof,
|
||||
return chanAnn, edge1Ann, edge2Ann, nil
|
||||
}
|
||||
|
||||
// SignAnnouncement is a helper function which is used to sign any outgoing
|
||||
// channel node node announcement messages.
|
||||
func SignAnnouncement(signer lnwallet.MessageSigner, pubKey *btcec.PublicKey,
|
||||
msg lnwire.Message) (*btcec.Signature, error) {
|
||||
|
||||
var (
|
||||
data []byte
|
||||
err error
|
||||
)
|
||||
|
||||
switch m := msg.(type) {
|
||||
case *lnwire.ChannelAnnouncement:
|
||||
data, err = m.DataToSign()
|
||||
case *lnwire.ChannelUpdate:
|
||||
data, err = m.DataToSign()
|
||||
case *lnwire.NodeAnnouncement:
|
||||
data, err = m.DataToSign()
|
||||
default:
|
||||
return nil, errors.New("can't sign message " +
|
||||
"of this format")
|
||||
}
|
||||
if err != nil {
|
||||
return nil, errors.Errorf("unable to get data to sign: %v", err)
|
||||
}
|
||||
|
||||
return signer.SignMessage(pubKey, data)
|
||||
}
|
||||
|
||||
// remotePubFromChanInfo returns the public key of the remote peer given a
|
||||
// ChannelEdgeInfo that describe a channel we have with them.
|
||||
func remotePubFromChanInfo(chanInfo *channeldb.ChannelEdgeInfo,
|
||||
|
36
netann/sign.go
Normal file
36
netann/sign.go
Normal file
@ -0,0 +1,36 @@
|
||||
package netann
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
"github.com/lightningnetwork/lnd/lnwire"
|
||||
)
|
||||
|
||||
// SignAnnouncement signs any type of gossip message that is announced on the
|
||||
// network.
|
||||
func SignAnnouncement(signer lnwallet.MessageSigner, pubKey *btcec.PublicKey,
|
||||
msg lnwire.Message) (*btcec.Signature, error) {
|
||||
|
||||
var (
|
||||
data []byte
|
||||
err error
|
||||
)
|
||||
|
||||
switch m := msg.(type) {
|
||||
case *lnwire.ChannelAnnouncement:
|
||||
data, err = m.DataToSign()
|
||||
case *lnwire.ChannelUpdate:
|
||||
data, err = m.DataToSign()
|
||||
case *lnwire.NodeAnnouncement:
|
||||
data, err = m.DataToSign()
|
||||
default:
|
||||
return nil, fmt.Errorf("can't sign %T message", m)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to get data to sign: %v", err)
|
||||
}
|
||||
|
||||
return signer.SignMessage(pubKey, data)
|
||||
}
|
@ -651,7 +651,7 @@ func newServer(listenAddrs []net.Addr, chanDB *channeldb.DB,
|
||||
|
||||
// With the announcement generated, we'll sign it to properly
|
||||
// authenticate the message on the network.
|
||||
authSig, err := discovery.SignAnnouncement(
|
||||
authSig, err := netann.SignAnnouncement(
|
||||
s.nodeSigner, s.identityPriv.PubKey(), nodeAnn,
|
||||
)
|
||||
if err != nil {
|
||||
@ -2068,7 +2068,7 @@ func (s *server) genNodeAnnouncement(refresh bool,
|
||||
// Now that the announcement is fully updated, we'll generate a new
|
||||
// signature over the announcement to ensure nodes on the network
|
||||
// accepted the new authenticated announcement.
|
||||
sig, err := discovery.SignAnnouncement(
|
||||
sig, err := netann.SignAnnouncement(
|
||||
s.nodeSigner, s.identityPriv.PubKey(), s.currentNodeAnn,
|
||||
)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user