Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions discovery/chan_series.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,21 @@ func (c *ChanSeries) UpdatesInHorizon(chain chainhash.Hash,
return nil, err
}

updates = append(updates, chanAnn)
// Create a slice to hold the `channel_announcement` and

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we expand one of the ApplyGossipFilter unit tests to cover this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is mocked in the ApplyGossipFilter tests, I also find it weird to test it there. I will build the tests in a separate PR given it's a bit involved.

// potentially two `channel_update` msgs.
//
// NOTE: Based on BOLT7, if a channel_announcement has no
// corresponding channel_updates, we must not send the
// channel_announcement. Thus we use this slice to decide we
// want to send this `channel_announcement` or not. By the end
// of the operation, if the len of the slice is 1, we will not
// send the `channel_announcement`. Otherwise, when sending the
// msgs, the `channel_announcement` must be sent prior to any
// corresponding `channel_update` or `node_annoucement`, that's
// why we create a slice here to maintain the order.
chanUpdates := make([]lnwire.Message, 0, 3)
chanUpdates = append(chanUpdates, chanAnn)

if edge1 != nil {
// We don't want to send channel updates that don't
// conform to the spec (anymore).
Expand All @@ -145,18 +159,28 @@ func (c *ChanSeries) UpdatesInHorizon(chain chainhash.Hash,
log.Errorf("not sending invalid channel "+
"update %v: %v", edge1, err)
} else {
updates = append(updates, edge1)
chanUpdates = append(chanUpdates, edge1)
}
}

if edge2 != nil {
err := netann.ValidateChannelUpdateFields(0, edge2)
if err != nil {
log.Errorf("not sending invalid channel "+
"update %v: %v", edge2, err)
} else {
updates = append(updates, edge2)
chanUpdates = append(chanUpdates, edge2)
}
}

// If there's no corresponding `channel_update` to send, skip
// sending this `channel_announcement`.
if len(chanUpdates) < 2 {
Comment thread
yyforyongyu marked this conversation as resolved.
continue
}

// Append the all the msgs to the slice.
updates = append(updates, chanUpdates...)
}

// Next, we'll send out all the node announcements that have an update
Expand Down