From 0b964d8e93aea801e83c4a34c2dcd61d13cf24c4 Mon Sep 17 00:00:00 2001 From: Elle Mouton Date: Tue, 7 Nov 2023 09:51:45 +0200 Subject: [PATCH] multi: update SignAliasUpdate to take ChannelUpdate interface --- discovery/gossiper.go | 26 +++----------------------- discovery/gossiper_test.go | 13 ++++--------- htlcswitch/mock.go | 17 +++++++++++++---- htlcswitch/switch.go | 25 ++++--------------------- server.go | 18 +++++------------- 5 files changed, 29 insertions(+), 70 deletions(-) diff --git a/discovery/gossiper.go b/discovery/gossiper.go index 54bd4ac73..2672e8227 100644 --- a/discovery/gossiper.go +++ b/discovery/gossiper.go @@ -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 } } diff --git a/discovery/gossiper_test.go b/discovery/gossiper_test.go index 3c994c203..935b77db2 100644 --- a/discovery/gossiper_test.go +++ b/discovery/gossiper_test.go @@ -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, diff --git a/htlcswitch/mock.go b/htlcswitch/mock.go index 761e77801..6372f2a04 100644 --- a/htlcswitch/mock.go +++ b/htlcswitch/mock.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/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{ diff --git a/htlcswitch/switch.go b/htlcswitch/switch.go index 2c7a62874..8d9eaf0b5 100644 --- a/htlcswitch/switch.go +++ b/htlcswitch/switch.go @@ -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 } diff --git a/server.go b/server.go index 157e82881..527ccfcb4 100644 --- a/server.go +++ b/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