From 152a438fbe6cc4fc519e9374c3cdb99f2bd3bc10 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Sun, 20 Nov 2022 08:25:01 +0800 Subject: [PATCH] discovery: move `shouldBroadcast` inside goroutine This commit moves the `shouldBroadcast` logic closer to the execution logic of deciding whether we want to broadcast the announcements. This is a pure code refactor and should make no difference in announcing message unless the `d.syncMgr.IsGraphSynced()` gives different results inside the goroutine. --- discovery/gossiper.go | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/discovery/gossiper.go b/discovery/gossiper.go index 5b9d025da..77d23bde1 100644 --- a/discovery/gossiper.go +++ b/discovery/gossiper.go @@ -1187,12 +1187,6 @@ func (d *AuthenticatedGossiper) networkHandler() { announcement.msg.MsgType(), announcement.isRemote) - // We should only broadcast this message forward if it - // originated from us or it wasn't received as part of - // our initial historical sync. - shouldBroadcast := !announcement.isRemote || - d.syncMgr.IsGraphSynced() - switch announcement.msg.(type) { // Channel announcement signatures are amongst the only // messages that we'll process serially. @@ -1232,8 +1226,7 @@ func (d *AuthenticatedGossiper) networkHandler() { d.wg.Add(1) go d.handleNetworkMessages( - announcement, &announcements, - validationBarrier, shouldBroadcast, + announcement, &announcements, validationBarrier, ) // The trickle timer has ticked, which indicates we should @@ -1305,12 +1298,15 @@ func (d *AuthenticatedGossiper) networkHandler() { // // NOTE: must be run as a goroutine. func (d *AuthenticatedGossiper) handleNetworkMessages(nMsg *networkMsg, - deDuped *deDupedAnnouncements, vb *routing.ValidationBarrier, - shouldBroadcast bool) { + deDuped *deDupedAnnouncements, vb *routing.ValidationBarrier) { defer d.wg.Done() defer vb.CompleteJob() + // We should only broadcast this message forward if it originated from + // us or it wasn't received as part of our initial historical sync. + shouldBroadcast := !nMsg.isRemote || d.syncMgr.IsGraphSynced() + // If this message has an existing dependency, then we'll wait until // that has been fully validated before we proceed. err := vb.WaitForDependants(nMsg.msg)