Skip to content

Commit 9eb9cd4

Browse files
committed
graph -> discovery: move ValidationBarrier to discovery
1 parent 9eafcc5 commit 9eb9cd4

File tree

4 files changed

+23
-36
lines changed

4 files changed

+23
-36
lines changed

discovery/gossiper.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ type AuthenticatedGossiper struct {
518518
chanUpdateRateLimiter map[uint64][2]*rate.Limiter
519519

520520
// vb is used to enforce job dependency ordering of gossip messages.
521-
vb *graph.ValidationBarrier
521+
vb *ValidationBarrier
522522

523523
sync.Mutex
524524
}
@@ -545,7 +545,7 @@ func New(cfg Config, selfKeyDesc *keychain.KeyDescriptor) *AuthenticatedGossiper
545545
banman: newBanman(),
546546
}
547547

548-
gossiper.vb = graph.NewValidationBarrier(1000, gossiper.quit)
548+
gossiper.vb = NewValidationBarrier(1000, gossiper.quit)
549549

550550
gossiper.syncMgr = newSyncManager(&SyncManagerCfg{
551551
ChainHash: cfg.ChainHash,
@@ -1537,7 +1537,7 @@ func (d *AuthenticatedGossiper) networkHandler() {
15371537
//
15381538
// NOTE: must be run as a goroutine.
15391539
func (d *AuthenticatedGossiper) handleNetworkMessages(nMsg *networkMsg,
1540-
deDuped *deDupedAnnouncements, jobID graph.JobID) {
1540+
deDuped *deDupedAnnouncements, jobID JobID) {
15411541

15421542
defer d.wg.Done()
15431543
defer d.vb.CompleteJob()
@@ -1553,12 +1553,7 @@ func (d *AuthenticatedGossiper) handleNetworkMessages(nMsg *networkMsg,
15531553
log.Debugf("Validating network message %s got err: %v",
15541554
nMsg.msg.MsgType(), err)
15551555

1556-
if !graph.IsError(
1557-
err,
1558-
graph.ErrVBarrierShuttingDown,
1559-
graph.ErrParentValidationFailed,
1560-
) {
1561-
1556+
if err == ErrVBarrierShuttingDown {
15621557
log.Warnf("unexpected error during validation "+
15631558
"barrier shutdown: %v", err)
15641559
}
@@ -2416,7 +2411,6 @@ func (d *AuthenticatedGossiper) handleNodeAnnouncement(nMsg *networkMsg,
24162411
err,
24172412
graph.ErrOutdated,
24182413
graph.ErrIgnored,
2419-
graph.ErrVBarrierShuttingDown,
24202414
) {
24212415

24222416
log.Error(err)
@@ -3156,7 +3150,6 @@ func (d *AuthenticatedGossiper) handleChanUpdate(nMsg *networkMsg,
31563150
if graph.IsError(
31573151
err, graph.ErrOutdated,
31583152
graph.ErrIgnored,
3159-
graph.ErrVBarrierShuttingDown,
31603153
) {
31613154

31623155
log.Debugf("Update edge for short_chan_id(%v) got: %v",

graph/validation_barrier.go renamed to discovery/validation_barrier.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package graph
1+
package discovery
22

33
import (
44
"fmt"
@@ -11,6 +11,13 @@ import (
1111
"github.com/lightningnetwork/lnd/routing/route"
1212
)
1313

14+
var (
15+
// ErrVBarrierShuttingDown signals that the barrier has been requested
16+
// to shutdown, and that the caller should not treat the wait condition
17+
// as fulfilled.
18+
ErrVBarrierShuttingDown = errors.New("ValidationBarrier shutting down")
19+
)
20+
1421
// JobID identifies an active job in the validation barrier. It is large so
1522
// that we don't need to worry about overflows.
1623
type JobID uint64
@@ -296,8 +303,7 @@ func (v *ValidationBarrier) WaitForParents(childJobID JobID,
296303
for {
297304
select {
298305
case <-v.quit:
299-
return NewErrf(ErrVBarrierShuttingDown,
300-
"validation barrier shutting down")
306+
return ErrVBarrierShuttingDown
301307

302308
case <-jobChan:
303309
// Every time this is sent on or if it's closed, a

graph/validation_barrier_test.go renamed to discovery/validation_barrier_test.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
package graph_test
1+
package discovery
22

33
import (
44
"encoding/binary"
55
"testing"
66
"time"
77

8-
"github.com/lightningnetwork/lnd/graph"
98
"github.com/lightningnetwork/lnd/lnwire"
109
"github.com/stretchr/testify/require"
1110
)
@@ -22,7 +21,7 @@ func TestValidationBarrierSemaphore(t *testing.T) {
2221
)
2322

2423
quit := make(chan struct{})
25-
barrier := graph.NewValidationBarrier(numTasks, quit)
24+
barrier := NewValidationBarrier(numTasks, quit)
2625

2726
// Saturate the semaphore with jobs.
2827
for i := 0; i < numTasks; i++ {
@@ -70,12 +69,12 @@ func TestValidationBarrierQuit(t *testing.T) {
7069
)
7170

7271
quit := make(chan struct{})
73-
barrier := graph.NewValidationBarrier(2*numTasks, quit)
72+
barrier := NewValidationBarrier(2*numTasks, quit)
7473

7574
// Create a set of unique channel announcements that we will prep for
7675
// validation.
7776
anns := make([]*lnwire.ChannelAnnouncement1, 0, numTasks)
78-
parentJobIDs := make([]graph.JobID, 0, numTasks)
77+
parentJobIDs := make([]JobID, 0, numTasks)
7978
for i := 0; i < numTasks; i++ {
8079
anns = append(anns, &lnwire.ChannelAnnouncement1{
8180
ShortChannelID: lnwire.NewShortChanIDFromInt(uint64(i)),
@@ -91,7 +90,7 @@ func TestValidationBarrierQuit(t *testing.T) {
9190
// Create a set of channel updates, that must wait until their
9291
// associated channel announcement has been verified.
9392
chanUpds := make([]*lnwire.ChannelUpdate1, 0, numTasks)
94-
childJobIDs := make([]graph.JobID, 0, numTasks)
93+
childJobIDs := make([]JobID, 0, numTasks)
9594
for i := 0; i < numTasks; i++ {
9695
chanUpds = append(chanUpds, &lnwire.ChannelUpdate1{
9796
ShortChannelID: lnwire.NewShortChanIDFromInt(uint64(i)),
@@ -154,11 +153,9 @@ func TestValidationBarrierQuit(t *testing.T) {
154153
t.Fatalf("unexpected failure while waiting: %v", err)
155154

156155
// Last half should return the shutdown error.
157-
case i >= numTasks/2 && !graph.IsError(
158-
err, graph.ErrVBarrierShuttingDown,
159-
):
156+
case i >= numTasks/2 && err != ErrVBarrierShuttingDown:
160157
t.Fatalf("expected failure after quitting: want %v, "+
161-
"got %v", graph.ErrVBarrierShuttingDown, err)
158+
"got %v", ErrVBarrierShuttingDown, err)
162159
}
163160
}
164161
}
@@ -175,7 +172,7 @@ func TestValidationBarrierParentJobsClear(t *testing.T) {
175172
)
176173

177174
quit := make(chan struct{})
178-
barrier := graph.NewValidationBarrier(numTasks, quit)
175+
barrier := NewValidationBarrier(numTasks, quit)
179176

180177
sharedScid := lnwire.NewShortChanIDFromInt(0)
181178
sharedNodeID := nodeIDFromInt(0)
@@ -221,8 +218,8 @@ func TestValidationBarrierParentJobsClear(t *testing.T) {
221218
childID2, err := barrier.InitJobDependencies(node1)
222219
require.NoError(t, err)
223220

224-
run := func(vb *graph.ValidationBarrier, childJobID graph.JobID,
225-
job interface{}, resp chan error, start chan error) {
221+
run := func(vb *ValidationBarrier, childJobID JobID, job interface{},
222+
resp chan error, start chan error) {
226223

227224
close(start)
228225

graph/errors.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,6 @@ const (
2828
// ErrInvalidFundingOutput is returned if the channel funding output
2929
// fails validation.
3030
ErrInvalidFundingOutput
31-
32-
// ErrVBarrierShuttingDown signals that the barrier has been requested
33-
// to shutdown, and that the caller should not treat the wait condition
34-
// as fulfilled.
35-
ErrVBarrierShuttingDown
36-
37-
// ErrParentValidationFailed signals that the validation of a
38-
// dependent's parent failed, so the dependent must not be processed.
39-
ErrParentValidationFailed
4031
)
4132

4233
// Error is a structure that represent the error inside the graph package,

0 commit comments

Comments
 (0)