mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-08-28 14:40:51 +02:00
discovery+graph: track job set dependencies in ValidationBarrier
This commit does two things: - 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 abstact 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.
This commit is contained in:
@@ -517,6 +517,9 @@ type AuthenticatedGossiper struct {
|
||||
// AuthenticatedGossiper lock.
|
||||
chanUpdateRateLimiter map[uint64][2]*rate.Limiter
|
||||
|
||||
// vb is used to enforce job dependency ordering of gossip messages.
|
||||
vb *graph.ValidationBarrier
|
||||
|
||||
sync.Mutex
|
||||
}
|
||||
|
||||
@@ -542,6 +545,8 @@ func New(cfg Config, selfKeyDesc *keychain.KeyDescriptor) *AuthenticatedGossiper
|
||||
banman: newBanman(),
|
||||
}
|
||||
|
||||
gossiper.vb = graph.NewValidationBarrier(1000, gossiper.quit)
|
||||
|
||||
gossiper.syncMgr = newSyncManager(&SyncManagerCfg{
|
||||
ChainHash: cfg.ChainHash,
|
||||
ChanSeries: cfg.ChanSeries,
|
||||
@@ -1409,10 +1414,6 @@ func (d *AuthenticatedGossiper) networkHandler() {
|
||||
log.Errorf("Unable to rebroadcast stale announcements: %v", err)
|
||||
}
|
||||
|
||||
// We'll use this validation to ensure that we process jobs in their
|
||||
// dependency order during parallel validation.
|
||||
validationBarrier := graph.NewValidationBarrier(1000, d.quit)
|
||||
|
||||
for {
|
||||
select {
|
||||
// A new policy update has arrived. We'll commit it to the
|
||||
@@ -1481,11 +1482,17 @@ 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 := d.vb.InitJobDependencies(
|
||||
announcement.msg,
|
||||
)
|
||||
if err != nil {
|
||||
announcement.err <- err
|
||||
continue
|
||||
}
|
||||
|
||||
d.wg.Add(1)
|
||||
go d.handleNetworkMessages(
|
||||
announcement, &announcements, validationBarrier,
|
||||
announcement, &announcements, annJobID,
|
||||
)
|
||||
|
||||
// The trickle timer has ticked, which indicates we should
|
||||
@@ -1536,10 +1543,10 @@ func (d *AuthenticatedGossiper) networkHandler() {
|
||||
//
|
||||
// NOTE: must be run as a goroutine.
|
||||
func (d *AuthenticatedGossiper) handleNetworkMessages(nMsg *networkMsg,
|
||||
deDuped *deDupedAnnouncements, vb *graph.ValidationBarrier) {
|
||||
deDuped *deDupedAnnouncements, jobID graph.JobID) {
|
||||
|
||||
defer d.wg.Done()
|
||||
defer vb.CompleteJob()
|
||||
defer d.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.
|
||||
@@ -1547,7 +1554,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 := d.vb.WaitForParents(jobID, nMsg.msg)
|
||||
if err != nil {
|
||||
log.Debugf("Validating network message %s got err: %v",
|
||||
nMsg.msg.MsgType(), err)
|
||||
@@ -1577,7 +1584,16 @@ 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)
|
||||
err = d.vb.SignalDependents(nMsg.msg, jobID)
|
||||
if err != nil {
|
||||
// Something is wrong if SignalDependents returns an error.
|
||||
log.Errorf("SignalDependents returned error for msg=%v with "+
|
||||
"JobID=%v", spew.Sdump(nMsg.msg), jobID)
|
||||
|
||||
nMsg.err <- err
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// If the announcement was accepted, then add the emitted announcements
|
||||
// to our announce batch to be broadcast once the trickle timer ticks
|
||||
|
Reference in New Issue
Block a user