Skip to content

Commit 2731d09

Browse files
committed
graph: change ValidationBarrier usage in the builder code
This omits calls to InitJobDependencies, SignalDependants, and WaitForDependants. These changes have been made here because the router / builder code does not actually need job dependency management. Calls to the builder code (i.e. AddNode, AddEdge, UpdateEdge) are all blocking in the gossiper. This, combined with the fact that child jobs are run after parent jobs in the gossiper, means that the calls to the router will happen in the proper dependency order.
1 parent 6cabc74 commit 2731d09

File tree

2 files changed

+6
-118
lines changed

2 files changed

+6
-118
lines changed

graph/builder.go

Lines changed: 6 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package graph
33
import (
44
"bytes"
55
"fmt"
6-
"runtime"
76
"strings"
87
"sync"
98
"sync/atomic"
@@ -669,51 +668,21 @@ func (b *Builder) pruneZombieChans() error {
669668
// notifies topology changes, if any.
670669
//
671670
// NOTE: must be run inside goroutine.
672-
func (b *Builder) handleNetworkUpdate(vb *ValidationBarrier,
673-
update *routingMsg) {
674-
671+
func (b *Builder) handleNetworkUpdate(update *routingMsg) {
675672
defer b.wg.Done()
676-
defer vb.CompleteJob()
677-
678-
// If this message has an existing dependency, then we'll wait until
679-
// that has been fully validated before we proceed.
680-
err := vb.WaitForDependants(update.msg)
681-
if err != nil {
682-
switch {
683-
case IsError(err, ErrVBarrierShuttingDown):
684-
update.err <- err
685-
686-
case IsError(err, ErrParentValidationFailed):
687-
update.err <- NewErrf(ErrIgnored, err.Error()) //nolint
688-
689-
default:
690-
log.Warnf("unexpected error during validation "+
691-
"barrier shutdown: %v", err)
692-
update.err <- err
693-
}
694-
695-
return
696-
}
697673

698674
// Process the routing update to determine if this is either a new
699675
// update from our PoV or an update to a prior vertex/edge we
700676
// previously accepted.
701-
err = b.processUpdate(update.msg, update.op...)
677+
err := b.processUpdate(update.msg, update.op...)
702678
update.err <- err
703679

704-
// If this message had any dependencies, then we can now signal them to
705-
// continue.
706-
allowDependents := err == nil || IsError(err, ErrIgnored, ErrOutdated)
707-
vb.SignalDependants(update.msg, allowDependents)
708-
709680
// If the error is not nil here, there's no need to send topology
710681
// change.
711682
if err != nil {
712-
// We now decide to log an error or not. If allowDependents is
713-
// false, it means there is an error and the error is neither
714-
// ErrIgnored or ErrOutdated. In this case, we'll log an error.
715-
// Otherwise, we'll add debug log only.
716-
if allowDependents {
683+
// Log as a debug message if this is not an error we need to be
684+
// concerned about.
685+
if IsError(err, ErrIgnored, ErrOutdated) {
717686
log.Debugf("process network updates got: %v", err)
718687
} else {
719688
log.Errorf("process network updates got: %v", err)
@@ -753,31 +722,6 @@ func (b *Builder) networkHandler() {
753722

754723
b.stats.Reset()
755724

756-
// We'll use this validation barrier to ensure that we process all jobs
757-
// in the proper order during parallel validation.
758-
//
759-
// NOTE: For AssumeChannelValid, we bump up the maximum number of
760-
// concurrent validation requests since there are no blocks being
761-
// fetched. This significantly increases the performance of IGD for
762-
// neutrino nodes.
763-
//
764-
// However, we dial back to use multiple of the number of cores when
765-
// fully validating, to avoid fetching up to 1000 blocks from the
766-
// backend. On bitcoind, this will empirically cause massive latency
767-
// spikes when executing this many concurrent RPC calls. Critical
768-
// subsystems or basic rpc calls that rely on calls such as GetBestBlock
769-
// will hang due to excessive load.
770-
//
771-
// See https://github.com/lightningnetwork/lnd/issues/4892.
772-
var validationBarrier *ValidationBarrier
773-
if b.cfg.AssumeChannelValid {
774-
validationBarrier = NewValidationBarrier(1000, b.quit)
775-
} else {
776-
validationBarrier = NewValidationBarrier(
777-
4*runtime.NumCPU(), b.quit,
778-
)
779-
}
780-
781725
for {
782726
// If there are stats, resume the statTicker.
783727
if !b.stats.Empty() {
@@ -789,13 +733,8 @@ func (b *Builder) networkHandler() {
789733
// result we'll modify the channel graph accordingly depending
790734
// on the exact type of the message.
791735
case update := <-b.networkUpdates:
792-
// We'll set up any dependants, and wait until a free
793-
// slot for this job opens up, this allows us to not
794-
// have thousands of goroutines active.
795-
validationBarrier.InitJobDependencies(update.msg)
796-
797736
b.wg.Add(1)
798-
go b.handleNetworkUpdate(validationBarrier, update)
737+
go b.handleNetworkUpdate(update)
799738

800739
// TODO(roasbeef): remove all unconnected vertexes
801740
// after N blocks pass with no corresponding

graph/validation_barrier.go

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"fmt"
55
"sync"
66

7-
"github.com/lightningnetwork/lnd/graph/db/models"
87
"github.com/lightningnetwork/lnd/lnwire"
98
"github.com/lightningnetwork/lnd/routing/route"
109
)
@@ -125,33 +124,14 @@ func (v *ValidationBarrier) InitJobDependencies(job interface{}) {
125124
v.nodeAnnDependencies[route.Vertex(msg.NodeID1)] = signals
126125
v.nodeAnnDependencies[route.Vertex(msg.NodeID2)] = signals
127126
}
128-
case *models.ChannelEdgeInfo:
129-
130-
shortID := lnwire.NewShortChanIDFromInt(msg.ChannelID)
131-
if _, ok := v.chanAnnFinSignal[shortID]; !ok {
132-
signals := &validationSignals{
133-
allow: make(chan struct{}),
134-
deny: make(chan struct{}),
135-
}
136-
137-
v.chanAnnFinSignal[shortID] = signals
138-
v.chanEdgeDependencies[shortID] = signals
139-
140-
v.nodeAnnDependencies[route.Vertex(msg.NodeKey1Bytes)] = signals
141-
v.nodeAnnDependencies[route.Vertex(msg.NodeKey2Bytes)] = signals
142-
}
143127

144128
// These other types don't have any dependants, so no further
145129
// initialization needs to be done beyond just occupying a job slot.
146-
case *models.ChannelEdgePolicy:
147-
return
148130
case *lnwire.ChannelUpdate1:
149131
return
150132
case *lnwire.NodeAnnouncement:
151133
// TODO(roasbeef): node ann needs to wait on existing channel updates
152134
return
153-
case *models.LightningNode:
154-
return
155135
case *lnwire.AnnounceSignatures1:
156136
// TODO(roasbeef): need to wait on chan ann?
157137
return
@@ -187,20 +167,6 @@ func (v *ValidationBarrier) WaitForDependants(job interface{}) error {
187167
switch msg := job.(type) {
188168
// Any ChannelUpdate or NodeAnnouncement jobs will need to wait on the
189169
// completion of any active ChannelAnnouncement jobs related to them.
190-
case *models.ChannelEdgePolicy:
191-
shortID := lnwire.NewShortChanIDFromInt(msg.ChannelID)
192-
signals, ok = v.chanEdgeDependencies[shortID]
193-
194-
jobDesc = fmt.Sprintf("job=lnwire.ChannelEdgePolicy, scid=%v",
195-
msg.ChannelID)
196-
197-
case *models.LightningNode:
198-
vertex := route.Vertex(msg.PubKeyBytes)
199-
signals, ok = v.nodeAnnDependencies[vertex]
200-
201-
jobDesc = fmt.Sprintf("job=channeldb.LightningNode, pub=%s",
202-
vertex)
203-
204170
case *lnwire.ChannelUpdate1:
205171
signals, ok = v.chanEdgeDependencies[msg.ShortChannelID]
206172

@@ -217,7 +183,6 @@ func (v *ValidationBarrier) WaitForDependants(job interface{}) error {
217183
// return directly.
218184
case *lnwire.AnnounceSignatures1:
219185
// TODO(roasbeef): need to wait on chan ann?
220-
case *models.ChannelEdgeInfo:
221186
case *lnwire.ChannelAnnouncement1:
222187
}
223188

@@ -263,17 +228,6 @@ func (v *ValidationBarrier) SignalDependants(job interface{}, allow bool) {
263228
// If we've just finished executing a ChannelAnnouncement, then we'll
264229
// close out the signal, and remove the signal from the map of active
265230
// ones. This will allow/deny any dependent jobs to continue execution.
266-
case *models.ChannelEdgeInfo:
267-
shortID := lnwire.NewShortChanIDFromInt(msg.ChannelID)
268-
finSignals, ok := v.chanAnnFinSignal[shortID]
269-
if ok {
270-
if allow {
271-
close(finSignals.allow)
272-
} else {
273-
close(finSignals.deny)
274-
}
275-
delete(v.chanAnnFinSignal, shortID)
276-
}
277231
case *lnwire.ChannelAnnouncement1:
278232
finSignals, ok := v.chanAnnFinSignal[msg.ShortChannelID]
279233
if ok {
@@ -290,15 +244,10 @@ func (v *ValidationBarrier) SignalDependants(job interface{}, allow bool) {
290244
// For all other job types, we'll delete the tracking entries from the
291245
// map, as if we reach this point, then all dependants have already
292246
// finished executing and we can proceed.
293-
case *models.LightningNode:
294-
delete(v.nodeAnnDependencies, route.Vertex(msg.PubKeyBytes))
295247
case *lnwire.NodeAnnouncement:
296248
delete(v.nodeAnnDependencies, route.Vertex(msg.NodeID))
297249
case *lnwire.ChannelUpdate1:
298250
delete(v.chanEdgeDependencies, msg.ShortChannelID)
299-
case *models.ChannelEdgePolicy:
300-
shortID := lnwire.NewShortChanIDFromInt(msg.ChannelID)
301-
delete(v.chanEdgeDependencies, shortID)
302251

303252
case *lnwire.AnnounceSignatures1:
304253
return

0 commit comments

Comments
 (0)