Skip to content

Commit

Permalink
discovery+graph: track job set dependencies in ValidationBarrier
Browse files Browse the repository at this point in the history
Prior to this commit, it was rare, but possible that proper
validation order was not adhered to when using the ValidationBarrier.
This commit does two things that fix this:
- removes the concept of allow / deny. Having this in place was a
  minor optimization and removing it makes the solution simpler.
- changes the job dependency tracking to track sets of parent jobs
  rather than individual parent jobs.

As a note, the purpose of the ValidationBarrier is that it allows us
to launch gossip validation jobs in goroutines while still ensuring
that the validation order of these goroutines is adhered to when it
comes to validating ChannelAnnouncement _before_ ChannelUpdate and
_before_ NodeAnnouncement.
  • Loading branch information
Crypt-iQ committed Nov 6, 2024
1 parent 91818cb commit bad8e9a
Show file tree
Hide file tree
Showing 3 changed files with 465 additions and 127 deletions.
18 changes: 13 additions & 5 deletions discovery/gossiper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1470,11 +1470,18 @@ func (d *AuthenticatedGossiper) networkHandler() {
// We'll set up any dependent, and wait until a free
// slot for this job opens up, this allow us to not
// have thousands of goroutines active.
validationBarrier.InitJobDependencies(announcement.msg)
annJobID, err := validationBarrier.InitJobDependencies(
announcement.msg,
)
if err != nil {
announcement.err <- err
continue
}

d.wg.Add(1)
go d.handleNetworkMessages(
announcement, &announcements, validationBarrier,
announcement, &announcements,
validationBarrier, annJobID,
)

// The trickle timer has ticked, which indicates we should
Expand Down Expand Up @@ -1525,7 +1532,8 @@ func (d *AuthenticatedGossiper) networkHandler() {
//
// NOTE: must be run as a goroutine.
func (d *AuthenticatedGossiper) handleNetworkMessages(nMsg *networkMsg,
deDuped *deDupedAnnouncements, vb *graph.ValidationBarrier) {
deDuped *deDupedAnnouncements, vb *graph.ValidationBarrier,
jobID graph.JobID) {

defer d.wg.Done()
defer vb.CompleteJob()
Expand All @@ -1536,7 +1544,7 @@ func (d *AuthenticatedGossiper) handleNetworkMessages(nMsg *networkMsg,

// 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)
err := vb.WaitForParents(jobID, nMsg.msg)
if err != nil {
log.Debugf("Validating network message %s got err: %v",
nMsg.msg.MsgType(), err)
Expand Down Expand Up @@ -1566,7 +1574,7 @@ func (d *AuthenticatedGossiper) handleNetworkMessages(nMsg *networkMsg,

// If this message had any dependencies, then we can now signal them to
// continue.
vb.SignalDependants(nMsg.msg, allow)
vb.SignalDependents(nMsg.msg, jobID)

// If the announcement was accepted, then add the emitted announcements
// to our announce batch to be broadcast once the trickle timer ticks
Expand Down
Loading

0 comments on commit bad8e9a

Please sign in to comment.