mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-17 20:31:41 +02:00
funding: modify fundingManager config to use SignMessage for ann's
This commit modifies the fundingManager config to use the a SignMesage function rather than two distinct functions for singing one half the channel announcement proofs. This change unifies the signing of messages under a single abstraction: the MessageSigner interface.
This commit is contained in:
parent
9205d3c0a7
commit
eb37dba3f6
@ -140,18 +140,11 @@ type fundingConfig struct {
|
|||||||
// so that the channel creation process can be completed.
|
// so that the channel creation process can be completed.
|
||||||
Notifier chainntnfs.ChainNotifier
|
Notifier chainntnfs.ChainNotifier
|
||||||
|
|
||||||
// SignNodeKey is used to generate a signature of a given node identity
|
// SignMessage signs an arbitrary method with a given public key. The
|
||||||
// public key signed under the passed node funding key. This function
|
// actual digest signed is the double sha-256 of the message. In the
|
||||||
// closure is used to generate one half the channel proof which attests
|
// case that the private key corresponding to the passed public key
|
||||||
// the target nodeKey is indeed in control of the channel funding key
|
// cannot be located, then an error is returned.
|
||||||
// in question.
|
SignMessage func(pubKey *btcec.PublicKey, msg []byte) (*btcec.Signature, error)
|
||||||
SignNodeKey func(nodeKey, fundingKey *btcec.PublicKey) (*btcec.Signature, error)
|
|
||||||
|
|
||||||
// SignAnnouncement is used to generate the signatures for channel
|
|
||||||
// update, and node announcements, and also to generate the proof for
|
|
||||||
// the channel announcements. The key used to generate this signature
|
|
||||||
// is the identity public key of the running daemon.
|
|
||||||
SignAnnouncement func(msg lnwire.Message) (*btcec.Signature, error)
|
|
||||||
|
|
||||||
// SendAnnouncement is used by the FundingManager to announce newly
|
// SendAnnouncement is used by the FundingManager to announce newly
|
||||||
// created channels to the rest of the Lightning Network.
|
// created channels to the rest of the Lightning Network.
|
||||||
@ -1064,7 +1057,7 @@ func (f *fundingManager) newChanAnnouncement(localPubKey, remotePubKey *btcec.Pu
|
|||||||
chanFlags = 1
|
chanFlags = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(roasbeef): add real sig, populate proper FeeSchema
|
// TODO(roasbeef): populate proper FeeSchema
|
||||||
chanUpdateAnn := &lnwire.ChannelUpdateAnnouncement{
|
chanUpdateAnn := &lnwire.ChannelUpdateAnnouncement{
|
||||||
ShortChannelID: chanID,
|
ShortChannelID: chanID,
|
||||||
Timestamp: uint32(time.Now().Unix()),
|
Timestamp: uint32(time.Now().Unix()),
|
||||||
@ -1077,9 +1070,13 @@ func (f *fundingManager) newChanAnnouncement(localPubKey, remotePubKey *btcec.Pu
|
|||||||
|
|
||||||
// With the channel update announcement constructed, we'll generate a
|
// With the channel update announcement constructed, we'll generate a
|
||||||
// signature that signs a double-sha digest of the announcement.
|
// signature that signs a double-sha digest of the announcement.
|
||||||
// This'll serve to authenticate this announcement and other Other
|
// This'll serve to authenticate this announcement and any other future
|
||||||
// future updates we may send.
|
// updates we may send.
|
||||||
chanUpdateAnn.Signature, err = f.cfg.SignAnnouncement(chanUpdateAnn)
|
chanUpdateMsg, err := chanUpdateAnn.DataToSign()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
chanUpdateAnn.Signature, err = f.cfg.SignMessage(f.cfg.IDKey, chanUpdateMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Errorf("unable to generate channel "+
|
return nil, errors.Errorf("unable to generate channel "+
|
||||||
"update announcement signature: %v", err)
|
"update announcement signature: %v", err)
|
||||||
@ -1092,12 +1089,16 @@ func (f *fundingManager) newChanAnnouncement(localPubKey, remotePubKey *btcec.Pu
|
|||||||
// public key under the funding key itself.
|
// public key under the funding key itself.
|
||||||
// TODO(roasbeef): need to revisit, ensure signatures are signed
|
// TODO(roasbeef): need to revisit, ensure signatures are signed
|
||||||
// properly
|
// properly
|
||||||
nodeSig, err := f.cfg.SignAnnouncement(chanAnn)
|
chanAnnMsg, err := chanAnn.DataToSign()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
nodeSig, err := f.cfg.SignMessage(f.cfg.IDKey, chanAnnMsg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Errorf("unable to generate node "+
|
return nil, errors.Errorf("unable to generate node "+
|
||||||
"signature for channel announcement: %v", err)
|
"signature for channel announcement: %v", err)
|
||||||
}
|
}
|
||||||
bitcoinSig, err := f.cfg.SignNodeKey(localPubKey, localFundingKey)
|
bitcoinSig, err := f.cfg.SignMessage(localFundingKey, selfBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Errorf("unable to generate bitcoin "+
|
return nil, errors.Errorf("unable to generate bitcoin "+
|
||||||
"signature for node public key: %v", err)
|
"signature for node public key: %v", err)
|
||||||
|
6
lnd.go
6
lnd.go
@ -138,6 +138,7 @@ func lndMain() error {
|
|||||||
}
|
}
|
||||||
signer := wc
|
signer := wc
|
||||||
bio := wc
|
bio := wc
|
||||||
|
fundingSigner := wc
|
||||||
|
|
||||||
// Create, and start the lnwallet, which handles the core payment
|
// Create, and start the lnwallet, which handles the core payment
|
||||||
// channel logic, and exposes control via proxy state machines.
|
// channel logic, and exposes control via proxy state machines.
|
||||||
@ -159,9 +160,8 @@ func lndMain() error {
|
|||||||
net.JoinHostPort("", strconv.Itoa(cfg.PeerPort)),
|
net.JoinHostPort("", strconv.Itoa(cfg.PeerPort)),
|
||||||
}
|
}
|
||||||
|
|
||||||
fundingSigner := btcwallet.NewFundingSigner(wc)
|
server, err := newServer(defaultListenAddrs, notifier, bio,
|
||||||
server, err := newServer(defaultListenAddrs, notifier, bio, wallet,
|
fundingSigner, wallet, chanDB)
|
||||||
chanDB, fundingSigner)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
srvrLog.Errorf("unable to create server: %v\n", err)
|
srvrLog.Errorf("unable to create server: %v\n", err)
|
||||||
return err
|
return err
|
||||||
|
26
server.go
26
server.go
@ -18,7 +18,6 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/discovery"
|
"github.com/lightningnetwork/lnd/discovery"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet/btcwallet"
|
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
"github.com/lightningnetwork/lnd/lnwire"
|
||||||
"github.com/lightningnetwork/lnd/routing"
|
"github.com/lightningnetwork/lnd/routing"
|
||||||
"github.com/roasbeef/btcd/btcec"
|
"github.com/roasbeef/btcd/btcec"
|
||||||
@ -39,6 +38,10 @@ type server struct {
|
|||||||
// connections.
|
// connections.
|
||||||
identityPriv *btcec.PrivateKey
|
identityPriv *btcec.PrivateKey
|
||||||
|
|
||||||
|
// nodeSigner is an implementation of the MessageSigner implementation
|
||||||
|
// that's backed by the identituy private key of the running lnd node.
|
||||||
|
nodeSigner *nodeSigner
|
||||||
|
|
||||||
// lightningID is the sha256 of the public key corresponding to our
|
// lightningID is the sha256 of the public key corresponding to our
|
||||||
// long-term identity private key.
|
// long-term identity private key.
|
||||||
lightningID [32]byte
|
lightningID [32]byte
|
||||||
@ -96,8 +99,8 @@ type server struct {
|
|||||||
// newServer creates a new instance of the server which is to listen using the
|
// newServer creates a new instance of the server which is to listen using the
|
||||||
// passed listener address.
|
// passed listener address.
|
||||||
func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
|
func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
|
||||||
bio lnwallet.BlockChainIO, wallet *lnwallet.LightningWallet,
|
bio lnwallet.BlockChainIO, fundingSigner lnwallet.MessageSigner,
|
||||||
chanDB *channeldb.DB, fundingSigner *btcwallet.FundingSigner) (*server, error) {
|
wallet *lnwallet.LightningWallet, chanDB *channeldb.DB) (*server, error) {
|
||||||
|
|
||||||
privKey, err := wallet.GetIdentitykey()
|
privKey, err := wallet.GetIdentitykey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -125,6 +128,7 @@ func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
|
|||||||
htlcSwitch: newHtlcSwitch(),
|
htlcSwitch: newHtlcSwitch(),
|
||||||
|
|
||||||
identityPriv: privKey,
|
identityPriv: privKey,
|
||||||
|
nodeSigner: newNodeSigner(privKey),
|
||||||
|
|
||||||
// TODO(roasbeef): derive proper onion key based on rotation
|
// TODO(roasbeef): derive proper onion key based on rotation
|
||||||
// schedule
|
// schedule
|
||||||
@ -200,8 +204,8 @@ func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
|
|||||||
// Initialize graph with authenticated lightning node. We need to
|
// Initialize graph with authenticated lightning node. We need to
|
||||||
// generate a valid signature in order for other nodes on the network
|
// generate a valid signature in order for other nodes on the network
|
||||||
// to accept our announcement.
|
// to accept our announcement.
|
||||||
messageSigner := lnwallet.NewMessageSigner(s.identityPriv)
|
self.AuthSig, err = discovery.SignAnnouncement(s.nodeSigner,
|
||||||
self.AuthSig, err = discovery.SignAnnouncement(messageSigner,
|
s.identityPriv.PubKey(),
|
||||||
&lnwire.NodeAnnouncement{
|
&lnwire.NodeAnnouncement{
|
||||||
Timestamp: uint32(self.LastUpdate.Unix()),
|
Timestamp: uint32(self.LastUpdate.Unix()),
|
||||||
Addresses: self.Addresses,
|
Addresses: self.Addresses,
|
||||||
@ -258,14 +262,12 @@ func newServer(listenAddrs []string, notifier chainntnfs.ChainNotifier,
|
|||||||
IDKey: s.identityPriv.PubKey(),
|
IDKey: s.identityPriv.PubKey(),
|
||||||
Wallet: wallet,
|
Wallet: wallet,
|
||||||
Notifier: s.chainNotifier,
|
Notifier: s.chainNotifier,
|
||||||
SignNodeKey: func(nodeKey,
|
SignMessage: func(pubKey *btcec.PublicKey, msg []byte) (*btcec.Signature, error) {
|
||||||
fundingKey *btcec.PublicKey) (*btcec.Signature, error) {
|
if pubKey.IsEqual(s.identityPriv.PubKey()) {
|
||||||
|
return s.nodeSigner.SignMessage(pubKey, msg)
|
||||||
|
}
|
||||||
|
|
||||||
data := nodeKey.SerializeCompressed()
|
return fundingSigner.SignMessage(pubKey, msg)
|
||||||
return fundingSigner.SignData(data, fundingKey)
|
|
||||||
},
|
|
||||||
SignAnnouncement: func(msg lnwire.Message) (*btcec.Signature, error) {
|
|
||||||
return discovery.SignAnnouncement(messageSigner, msg)
|
|
||||||
},
|
},
|
||||||
SendAnnouncement: func(msg lnwire.Message) error {
|
SendAnnouncement: func(msg lnwire.Message) error {
|
||||||
s.discoverSrv.ProcessLocalAnnouncement(msg,
|
s.discoverSrv.ProcessLocalAnnouncement(msg,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user