mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-04-06 19:18:12 +02:00
multi: update SignAliasUpdate to take ChannelUpdate interface
This commit is contained in:
parent
a5afcd21b7
commit
0b964d8e93
@ -9,7 +9,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
|
||||
"github.com/btcsuite/btcd/btcec/v2/schnorr/musig2"
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
@ -337,8 +336,7 @@ type Config struct {
|
||||
|
||||
// SignAliasUpdate is used to re-sign a channel update using the
|
||||
// remote's alias if the option-scid-alias feature bit was negotiated.
|
||||
SignAliasUpdate func(u *lnwire.ChannelUpdate1) (*ecdsa.Signature,
|
||||
error)
|
||||
SignAliasUpdate func(u lnwire.ChannelUpdate) error
|
||||
|
||||
// FindBaseByAlias finds the SCID stored in the graph by an alias SCID.
|
||||
// This is used for channels that have negotiated the option-scid-alias
|
||||
@ -1830,21 +1828,12 @@ func (d *AuthenticatedGossiper) processChanPolicyUpdate(
|
||||
if foundAlias != defaultAlias {
|
||||
chanUpdate.ShortChannelID = foundAlias
|
||||
|
||||
sig, err := d.cfg.SignAliasUpdate(chanUpdate)
|
||||
err := d.cfg.SignAliasUpdate(chanUpdate)
|
||||
if err != nil {
|
||||
log.Errorf("Unable to sign alias "+
|
||||
"update: %v", err)
|
||||
continue
|
||||
}
|
||||
|
||||
lnSig, err := lnwire.NewSigFromSignature(sig)
|
||||
if err != nil {
|
||||
log.Errorf("Unable to create sig: %v",
|
||||
err)
|
||||
continue
|
||||
}
|
||||
|
||||
chanUpdate.Signature = lnSig
|
||||
}
|
||||
|
||||
remotePubKey := remotePubFromChanInfo(
|
||||
@ -3238,21 +3227,12 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
|
||||
// negotiated channels.
|
||||
upd.ShortChannelID = *remoteAlias
|
||||
|
||||
sig, err := d.cfg.SignAliasUpdate(upd)
|
||||
err := d.cfg.SignAliasUpdate(upd)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
nMsg.err <- err
|
||||
return nil, false
|
||||
}
|
||||
|
||||
lnSig, err := lnwire.NewSigFromSignature(sig)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
nMsg.err <- err
|
||||
return nil, false
|
||||
}
|
||||
|
||||
upd.Signature = lnSig
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
@ -759,10 +758,8 @@ func createTestCtx(t *testing.T, startHeight uint32, isChanPeer bool) (
|
||||
return false
|
||||
}
|
||||
|
||||
signAliasUpdate := func(*lnwire.ChannelUpdate1) (*ecdsa.Signature,
|
||||
error) {
|
||||
|
||||
return nil, nil
|
||||
signAliasUpdate := func(lnwire.ChannelUpdate) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
findBaseByAlias := func(lnwire.ShortChannelID) (lnwire.ShortChannelID,
|
||||
@ -1472,10 +1469,8 @@ func TestSignatureAnnouncementRetryAtStartup(t *testing.T) {
|
||||
return false
|
||||
}
|
||||
|
||||
signAliasUpdate := func(*lnwire.ChannelUpdate1) (*ecdsa.Signature,
|
||||
error) {
|
||||
|
||||
return nil, nil
|
||||
signAliasUpdate := func(lnwire.ChannelUpdate) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
findBaseByAlias := func(lnwire.ShortChannelID) (lnwire.ShortChannelID,
|
||||
|
@ -16,7 +16,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/go-errors/errors"
|
||||
@ -166,10 +165,20 @@ type mockServer struct {
|
||||
var _ lnpeer.Peer = (*mockServer)(nil)
|
||||
|
||||
func initSwitchWithDB(startingHeight uint32, db *channeldb.DB) (*Switch, error) {
|
||||
signAliasUpdate := func(u *lnwire.ChannelUpdate1) (*ecdsa.Signature,
|
||||
error) {
|
||||
signAliasUpdate := func(update lnwire.ChannelUpdate) error {
|
||||
s, err := lnwire.NewSigFromSignature(testSig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return testSig, nil
|
||||
switch u := update.(type) {
|
||||
case *lnwire.ChannelUpdate1:
|
||||
u.Signature = s
|
||||
case *lnwire.ChannelUpdate2:
|
||||
u.Signature = s
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
cfg := Config{
|
||||
|
@ -9,7 +9,6 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/davecgh/go-spew/spew"
|
||||
@ -221,8 +220,7 @@ type Config struct {
|
||||
// option_scid_alias channels. This avoids a potential privacy leak by
|
||||
// replacing the public, confirmed SCID with the alias in the
|
||||
// ChannelUpdate.
|
||||
SignAliasUpdate func(u *lnwire.ChannelUpdate1) (*ecdsa.Signature,
|
||||
error)
|
||||
SignAliasUpdate func(u lnwire.ChannelUpdate) error
|
||||
|
||||
// IsAlias returns whether or not a given SCID is an alias.
|
||||
IsAlias func(scid lnwire.ShortChannelID) bool
|
||||
@ -2646,12 +2644,7 @@ func (s *Switch) failAliasUpdate(scid lnwire.ShortChannelID,
|
||||
|
||||
// Replace the baseScid with the passed-in alias.
|
||||
update.ShortChannelID = scid
|
||||
sig, err := s.cfg.SignAliasUpdate(update)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
update.Signature, err = lnwire.NewSigFromSignature(sig)
|
||||
err = s.cfg.SignAliasUpdate(update)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
@ -2672,12 +2665,7 @@ func (s *Switch) failAliasUpdate(scid lnwire.ShortChannelID,
|
||||
// the UTXO in case the channel is private. In the outgoing
|
||||
// case, since the alias was used, we do the same thing.
|
||||
update.ShortChannelID = scid
|
||||
sig, err := s.cfg.SignAliasUpdate(update)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
update.Signature, err = lnwire.NewSigFromSignature(sig)
|
||||
err = s.cfg.SignAliasUpdate(update)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
@ -2727,12 +2715,7 @@ func (s *Switch) failAliasUpdate(scid lnwire.ShortChannelID,
|
||||
// Since this happens on the incoming side, it's not actually
|
||||
// possible to know what the sender used in the onion.
|
||||
update.ShortChannelID = aliases[0]
|
||||
sig, err := s.cfg.SignAliasUpdate(update)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
update.Signature, err = lnwire.NewSigFromSignature(sig)
|
||||
err := s.cfg.SignAliasUpdate(update)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
18
server.go
18
server.go
@ -16,7 +16,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/btcec/v2/ecdsa"
|
||||
"github.com/btcsuite/btcd/btcutil"
|
||||
"github.com/btcsuite/btcd/chaincfg/chainhash"
|
||||
"github.com/btcsuite/btcd/connmgr"
|
||||
@ -1741,18 +1740,11 @@ func (s *server) UpdateRoutingConfig(cfg *routing.MissionControlConfig) {
|
||||
routerCfg.MaxMcHistory = cfg.MaxMcHistory
|
||||
}
|
||||
|
||||
// signAliasUpdate takes a ChannelUpdate and returns the signature. This is
|
||||
// used for option_scid_alias channels where the ChannelUpdate to be sent back
|
||||
// may differ from what is on disk.
|
||||
func (s *server) signAliasUpdate(u *lnwire.ChannelUpdate1) (*ecdsa.Signature,
|
||||
error) {
|
||||
|
||||
data, err := u.DataToSign()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return s.cc.MsgSigner.SignMessage(s.identityKeyLoc, data, true)
|
||||
// signAliasUpdate takes a ChannelUpdate and re-signs it. The signature is set
|
||||
// the update accordingly. This is used for option_scid_alias channels where the
|
||||
// ChannelUpdate to be sent back may differ from what is on disk.
|
||||
func (s *server) signAliasUpdate(u lnwire.ChannelUpdate) error {
|
||||
return netann.SignChannelUpdate(s.cc.KeyRing, s.identityKeyLoc, u)
|
||||
}
|
||||
|
||||
// createLivenessMonitor creates a set of health checks using our configured
|
||||
|
Loading…
x
Reference in New Issue
Block a user