From b5fd32ff77890207d68580bd1eb51872ea14ce79 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Wed, 15 Aug 2018 15:51:01 +0200 Subject: [PATCH] discovery+routing: move validation logic to routing package Previously, gossiper was the only object that validated channel updates. Because updates can also be received as part of a failed payment session in the routing package, validation logic needs to be available there too. Gossiper already depends on routing and having routing call the validation logic inside gossiper would be a circular dependency. Therefore the validation was moved to routing. --- discovery/gossiper.go | 12 ++++++------ {discovery => routing}/ann_validation.go | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) rename {discovery => routing}/ann_validation.go (99%) diff --git a/discovery/gossiper.go b/discovery/gossiper.go index 87c98be2f..f15eec317 100644 --- a/discovery/gossiper.go +++ b/discovery/gossiper.go @@ -1520,7 +1520,7 @@ func (d *AuthenticatedGossiper) processRejectedEdge( if err != nil { return nil, err } - err = ValidateChannelAnn(chanAnn) + err = routing.ValidateChannelAnn(chanAnn) if err != nil { err := fmt.Errorf("assembled channel announcement proof "+ "for shortChanID=%v isn't valid: %v", @@ -1598,7 +1598,7 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement( return nil } - if err := ValidateNodeAnn(msg); err != nil { + if err := routing.ValidateNodeAnn(msg); err != nil { err := fmt.Errorf("unable to validate "+ "node announcement: %v", err) log.Error(err) @@ -1701,7 +1701,7 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement( // formed. var proof *channeldb.ChannelAuthProof if nMsg.isRemote { - if err := ValidateChannelAnn(msg); err != nil { + if err := routing.ValidateChannelAnn(msg); err != nil { err := fmt.Errorf("unable to validate "+ "announcement: %v", err) d.rejectMtx.Lock() @@ -1993,7 +1993,7 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement( // Validate the channel announcement with the expected public // key, In the case of an invalid channel , we'll return an // error to the caller and exit early. - if err := ValidateChannelUpdateAnn(pubKey, msg); err != nil { + if err := routing.ValidateChannelUpdateAnn(pubKey, msg); err != nil { rErr := fmt.Errorf("unable to validate channel "+ "update announcement for short_chan_id=%v: %v", spew.Sdump(msg.ShortChannelID), err) @@ -2297,7 +2297,7 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement( // With all the necessary components assembled validate the // full channel announcement proof. - if err := ValidateChannelAnn(chanAnn); err != nil { + if err := routing.ValidateChannelAnn(chanAnn); err != nil { err := fmt.Errorf("channel announcement proof "+ "for short_chan_id=%v isn't valid: %v", shortChanID, err) @@ -2505,7 +2505,7 @@ func (d *AuthenticatedGossiper) updateChannel(info *channeldb.ChannelEdgeInfo, // To ensure that our signature is valid, we'll verify it ourself // before committing it to the slice returned. - err = ValidateChannelUpdateAnn(d.selfKey, chanUpdate) + err = routing.ValidateChannelUpdateAnn(d.selfKey, chanUpdate) if err != nil { return nil, nil, fmt.Errorf("generated invalid channel "+ "update sig: %v", err) diff --git a/discovery/ann_validation.go b/routing/ann_validation.go similarity index 99% rename from discovery/ann_validation.go rename to routing/ann_validation.go index 6ca07f640..257ac3fda 100644 --- a/discovery/ann_validation.go +++ b/routing/ann_validation.go @@ -1,4 +1,4 @@ -package discovery +package routing import ( "bytes"