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.
This commit is contained in:
yyforyongyu 2022-11-20 08:25:01 +08:00
parent b237dbfd74
commit 152a438fbe
No known key found for this signature in database
GPG key ID: 9BCD95C4FF296868

View file

@ -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)