• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 13910460983

17 Mar 2025 09:43PM UTC coverage: 58.351% (+0.04%) from 58.315%
13910460983

Pull #9607

github

web-flow
Merge 4d7b24dea into 053d63e11
Pull Request #9607: discovery: unify rate.Limiter across all gossip peers

29 of 36 new or added lines in 2 files covered. (80.56%)

28 existing lines in 5 files now uncovered.

94869 of 162584 relevant lines covered (58.35%)

1.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

73.97
/discovery/syncer.go
1
package discovery
2

3
import (
4
        "errors"
5
        "fmt"
6
        "math"
7
        "math/rand"
8
        "sort"
9
        "sync"
10
        "sync/atomic"
11
        "time"
12

13
        "github.com/btcsuite/btcd/chaincfg/chainhash"
14
        "github.com/lightningnetwork/lnd/graph"
15
        graphdb "github.com/lightningnetwork/lnd/graph/db"
16
        "github.com/lightningnetwork/lnd/lnpeer"
17
        "github.com/lightningnetwork/lnd/lnwire"
18
)
19

20
// SyncerType encapsulates the different types of syncing mechanisms for a
21
// gossip syncer.
22
type SyncerType uint8
23

24
const (
25
        // ActiveSync denotes that a gossip syncer:
26
        //
27
        // 1. Should not attempt to synchronize with the remote peer for
28
        //    missing channels.
29
        // 2. Should respond to queries from the remote peer.
30
        // 3. Should receive new updates from the remote peer.
31
        //
32
        // They are started in a chansSynced state in order to accomplish their
33
        // responsibilities above.
34
        ActiveSync SyncerType = iota
35

36
        // PassiveSync denotes that a gossip syncer:
37
        //
38
        // 1. Should not attempt to synchronize with the remote peer for
39
        //    missing channels.
40
        // 2. Should respond to queries from the remote peer.
41
        // 3. Should not receive new updates from the remote peer.
42
        //
43
        // They are started in a chansSynced state in order to accomplish their
44
        // responsibilities above.
45
        PassiveSync
46

47
        // PinnedSync denotes an ActiveSync that doesn't count towards the
48
        // default active syncer limits and is always active throughout the
49
        // duration of the peer's connection. Each pinned syncer will begin by
50
        // performing a historical sync to ensure we are well synchronized with
51
        // their routing table.
52
        PinnedSync
53
)
54

55
// String returns a human readable string describing the target SyncerType.
56
func (t SyncerType) String() string {
3✔
57
        switch t {
3✔
58
        case ActiveSync:
3✔
59
                return "ActiveSync"
3✔
60
        case PassiveSync:
3✔
61
                return "PassiveSync"
3✔
62
        case PinnedSync:
3✔
63
                return "PinnedSync"
3✔
64
        default:
×
65
                return fmt.Sprintf("unknown sync type %d", t)
×
66
        }
67
}
68

69
// IsActiveSync returns true if the SyncerType should set a GossipTimestampRange
70
// allowing new gossip messages to be received from the peer.
71
func (t SyncerType) IsActiveSync() bool {
3✔
72
        switch t {
3✔
73
        case ActiveSync, PinnedSync:
3✔
74
                return true
3✔
75
        default:
3✔
76
                return false
3✔
77
        }
78
}
79

80
// syncerState is an enum that represents the current state of the GossipSyncer.
81
// As the syncer is a state machine, we'll gate our actions based off of the
82
// current state and the next incoming message.
83
type syncerState uint32
84

85
const (
86
        // syncingChans is the default state of the GossipSyncer. We start in
87
        // this state when a new peer first connects and we don't yet know if
88
        // we're fully synchronized.
89
        syncingChans syncerState = iota
90

91
        // waitingQueryRangeReply is the second main phase of the GossipSyncer.
92
        // We enter this state after we send out our first QueryChannelRange
93
        // reply. We'll stay in this state until the remote party sends us a
94
        // ReplyShortChanIDsEnd message that indicates they've responded to our
95
        // query entirely. After this state, we'll transition to
96
        // waitingQueryChanReply after we send out requests for all the new
97
        // chan ID's to us.
98
        waitingQueryRangeReply
99

100
        // queryNewChannels is the third main phase of the GossipSyncer.  In
101
        // this phase we'll send out all of our QueryShortChanIDs messages in
102
        // response to the new channels that we don't yet know about.
103
        queryNewChannels
104

105
        // waitingQueryChanReply is the fourth main phase of the GossipSyncer.
106
        // We enter this phase once we've sent off a query chink to the remote
107
        // peer.  We'll stay in this phase until we receive a
108
        // ReplyShortChanIDsEnd message which indicates that the remote party
109
        // has responded to all of our requests.
110
        waitingQueryChanReply
111

112
        // chansSynced is the terminal stage of the GossipSyncer. Once we enter
113
        // this phase, we'll send out our update horizon, which filters out the
114
        // set of channel updates that we're interested in. In this state,
115
        // we'll be able to accept any outgoing messages from the
116
        // AuthenticatedGossiper, and decide if we should forward them to our
117
        // target peer based on its update horizon.
118
        chansSynced
119

120
        // syncerIdle is a state in which the gossip syncer can handle external
121
        // requests to transition or perform historical syncs. It is used as the
122
        // initial state for pinned syncers, as well as a fallthrough case for
123
        // chansSynced allowing fully synced peers to facilitate requests.
124
        syncerIdle
125
)
126

127
// String returns a human readable string describing the target syncerState.
128
func (s syncerState) String() string {
3✔
129
        switch s {
3✔
130
        case syncingChans:
3✔
131
                return "syncingChans"
3✔
132

133
        case waitingQueryRangeReply:
3✔
134
                return "waitingQueryRangeReply"
3✔
135

136
        case queryNewChannels:
3✔
137
                return "queryNewChannels"
3✔
138

139
        case waitingQueryChanReply:
3✔
140
                return "waitingQueryChanReply"
3✔
141

142
        case chansSynced:
3✔
143
                return "chansSynced"
3✔
144

145
        case syncerIdle:
3✔
146
                return "syncerIdle"
3✔
147

148
        default:
×
149
                return "UNKNOWN STATE"
×
150
        }
151
}
152

153
const (
154
        // DefaultMaxUndelayedQueryReplies specifies how many gossip queries we
155
        // will respond to immediately before starting to delay responses.
156
        DefaultMaxUndelayedQueryReplies = 50
157

158
        // DefaultDelayedQueryReplyInterval is the length of time we will wait
159
        // before responding to gossip queries after replying to
160
        // maxUndelayedQueryReplies queries.
161
        DefaultDelayedQueryReplyInterval = 5 * time.Second
162

163
        // maxQueryChanRangeReplies specifies the default limit of replies to
164
        // process for a single QueryChannelRange request.
165
        maxQueryChanRangeReplies = 500
166

167
        // maxQueryChanRangeRepliesZlibFactor specifies the factor applied to
168
        // the maximum number of replies allowed for zlib encoded replies.
169
        maxQueryChanRangeRepliesZlibFactor = 4
170

171
        // chanRangeQueryBuffer is the number of blocks back that we'll go when
172
        // asking the remote peer for their any channels they know of beyond
173
        // our highest known channel ID.
174
        chanRangeQueryBuffer = 144
175

176
        // syncTransitionTimeout is the default timeout in which we'll wait up
177
        // to when attempting to perform a sync transition.
178
        syncTransitionTimeout = 5 * time.Second
179

180
        // requestBatchSize is the maximum number of channels we will query the
181
        // remote peer for in a QueryShortChanIDs message.
182
        requestBatchSize = 500
183

184
        // syncerBufferSize is the size of the syncer's buffers.
185
        syncerBufferSize = 5
186
)
187

188
var (
189
        // encodingTypeToChunkSize maps an encoding type, to the max number of
190
        // short chan ID's using the encoding type that we can fit into a
191
        // single message safely.
192
        encodingTypeToChunkSize = map[lnwire.QueryEncoding]int32{
193
                lnwire.EncodingSortedPlain: 8000,
194
        }
195

196
        // ErrGossipSyncerExiting signals that the syncer has been killed.
197
        ErrGossipSyncerExiting = errors.New("gossip syncer exiting")
198

199
        // ErrSyncTransitionTimeout is an error returned when we've timed out
200
        // attempting to perform a sync transition.
201
        ErrSyncTransitionTimeout = errors.New("timed out attempting to " +
202
                "transition sync type")
203

204
        // zeroTimestamp is the timestamp we'll use when we want to indicate to
205
        // peers that we do not want to receive any new graph updates.
206
        zeroTimestamp time.Time
207
)
208

209
// syncTransitionReq encapsulates a request for a gossip syncer sync transition.
210
type syncTransitionReq struct {
211
        newSyncType SyncerType
212
        errChan     chan error
213
}
214

215
// historicalSyncReq encapsulates a request for a gossip syncer to perform a
216
// historical sync.
217
type historicalSyncReq struct {
218
        // doneChan is a channel that serves as a signal and is closed to ensure
219
        // the historical sync is attempted by the time we return to the caller.
220
        doneChan chan struct{}
221
}
222

223
// gossipSyncerCfg is a struct that packages all the information a GossipSyncer
224
// needs to carry out its duties.
225
type gossipSyncerCfg struct {
226
        // chainHash is the chain that this syncer is responsible for.
227
        chainHash chainhash.Hash
228

229
        // peerPub is the public key of the peer we're syncing with, serialized
230
        // in compressed format.
231
        peerPub [33]byte
232

233
        // channelSeries is the primary interface that we'll use to generate
234
        // our queries and respond to the queries of the remote peer.
235
        channelSeries ChannelGraphTimeSeries
236

237
        // encodingType is the current encoding type we're aware of. Requests
238
        // with different encoding types will be rejected.
239
        encodingType lnwire.QueryEncoding
240

241
        // chunkSize is the max number of short chan IDs using the syncer's
242
        // encoding type that we can fit into a single message safely.
243
        chunkSize int32
244

245
        // batchSize is the max number of channels the syncer will query from
246
        // the remote node in a single QueryShortChanIDs request.
247
        batchSize int32
248

249
        // sendToPeer sends a variadic number of messages to the remote peer.
250
        // This method should not block while waiting for sends to be written
251
        // to the wire.
252
        sendToPeer func(...lnwire.Message) error
253

254
        // sendToPeerSync sends a variadic number of messages to the remote
255
        // peer, blocking until all messages have been sent successfully or a
256
        // write error is encountered.
257
        sendToPeerSync func(...lnwire.Message) error
258

259
        // noSyncChannels will prevent the GossipSyncer from spawning a
260
        // channelGraphSyncer, meaning we will not try to reconcile unknown
261
        // channels with the remote peer.
262
        noSyncChannels bool
263

264
        // noReplyQueries will prevent the GossipSyncer from spawning a
265
        // replyHandler, meaning we will not reply to queries from our remote
266
        // peer.
267
        noReplyQueries bool
268

269
        // noTimestampQueryOption will prevent the GossipSyncer from querying
270
        // timestamps of announcement messages from the peer, and it will
271
        // prevent it from responding to timestamp queries.
272
        noTimestampQueryOption bool
273

274
        // ignoreHistoricalFilters will prevent syncers from replying with
275
        // historical data when the remote peer sets a gossip_timestamp_range.
276
        // This prevents ranges with old start times from causing us to dump the
277
        // graph on connect.
278
        ignoreHistoricalFilters bool
279

280
        // bestHeight returns the latest height known of the chain.
281
        bestHeight func() uint32
282

283
        // markGraphSynced updates the SyncManager's perception of whether we
284
        // have completed at least one historical sync.
285
        markGraphSynced func()
286

287
        // maxQueryChanRangeReplies is the maximum number of replies we'll allow
288
        // for a single QueryChannelRange request.
289
        maxQueryChanRangeReplies uint32
290

291
        // isStillZombieChannel takes the timestamps of the latest channel
292
        // updates for a channel and returns true if the channel should be
293
        // considered a zombie based on these timestamps.
294
        isStillZombieChannel func(time.Time, time.Time) bool
295

296
        // maybeAddDelay is used to implement rate limiting for gossip queries.
297
        maybeAddDelay func() time.Duration
298
}
299

300
// GossipSyncer is a struct that handles synchronizing the channel graph state
301
// with a remote peer. The GossipSyncer implements a state machine that will
302
// progressively ensure we're synchronized with the channel state of the remote
303
// node. Once both nodes have been synchronized, we'll use an update filter to
304
// filter out which messages should be sent to a remote peer based on their
305
// update horizon. If the update horizon isn't specified, then we won't send
306
// them any channel updates at all.
307
type GossipSyncer struct {
308
        started sync.Once
309
        stopped sync.Once
310

311
        // state is the current state of the GossipSyncer.
312
        //
313
        // NOTE: This variable MUST be used atomically.
314
        state uint32
315

316
        // syncType denotes the SyncerType the gossip syncer is currently
317
        // exercising.
318
        //
319
        // NOTE: This variable MUST be used atomically.
320
        syncType uint32
321

322
        // remoteUpdateHorizon is the update horizon of the remote peer. We'll
323
        // use this to properly filter out any messages.
324
        remoteUpdateHorizon *lnwire.GossipTimestampRange
325

326
        // localUpdateHorizon is our local update horizon, we'll use this to
327
        // determine if we've already sent out our update.
328
        localUpdateHorizon *lnwire.GossipTimestampRange
329

330
        // syncTransitions is a channel through which new sync type transition
331
        // requests will be sent through. These requests should only be handled
332
        // when the gossip syncer is in a chansSynced state to ensure its state
333
        // machine behaves as expected.
334
        syncTransitionReqs chan *syncTransitionReq
335

336
        // historicalSyncReqs is a channel that serves as a signal for the
337
        // gossip syncer to perform a historical sync. These can only be done
338
        // once the gossip syncer is in a chansSynced state to ensure its state
339
        // machine behaves as expected.
340
        historicalSyncReqs chan *historicalSyncReq
341

342
        // genHistoricalChanRangeQuery when true signals to the gossip syncer
343
        // that it should request the remote peer for all of its known channel
344
        // IDs starting from the genesis block of the chain. This can only
345
        // happen if the gossip syncer receives a request to attempt a
346
        // historical sync. It can be unset if the syncer ever transitions from
347
        // PassiveSync to ActiveSync.
348
        genHistoricalChanRangeQuery bool
349

350
        // gossipMsgs is a channel that all responses to our queries from the
351
        // target peer will be sent over, these will be read by the
352
        // channelGraphSyncer.
353
        gossipMsgs chan lnwire.Message
354

355
        // queryMsgs is a channel that all queries from the remote peer will be
356
        // received over, these will be read by the replyHandler.
357
        queryMsgs chan lnwire.Message
358

359
        // curQueryRangeMsg keeps track of the latest QueryChannelRange message
360
        // we've sent to a peer to ensure we've consumed all expected replies.
361
        // This field is primarily used within the waitingQueryChanReply state.
362
        curQueryRangeMsg *lnwire.QueryChannelRange
363

364
        // prevReplyChannelRange keeps track of the previous ReplyChannelRange
365
        // message we've received from a peer to ensure they've fully replied to
366
        // our query by ensuring they covered our requested block range. This
367
        // field is primarily used within the waitingQueryChanReply state.
368
        prevReplyChannelRange *lnwire.ReplyChannelRange
369

370
        // bufferedChanRangeReplies is used in the waitingQueryChanReply to
371
        // buffer all the chunked response to our query.
372
        bufferedChanRangeReplies []graphdb.ChannelUpdateInfo
373

374
        // numChanRangeRepliesRcvd is used to track the number of replies
375
        // received as part of a QueryChannelRange. This field is primarily used
376
        // within the waitingQueryChanReply state.
377
        numChanRangeRepliesRcvd uint32
378

379
        // newChansToQuery is used to pass the set of channels we should query
380
        // for from the waitingQueryChanReply state to the queryNewChannels
381
        // state.
382
        newChansToQuery []lnwire.ShortChannelID
383

384
        cfg gossipSyncerCfg
385

386
        // syncedSignal is a channel that, if set, will be closed when the
387
        // GossipSyncer reaches its terminal chansSynced state.
388
        syncedSignal chan struct{}
389

390
        // syncerSema is used to more finely control the syncer's ability to
391
        // respond to gossip timestamp range messages.
392
        syncerSema chan struct{}
393

394
        sync.Mutex
395

396
        quit chan struct{}
397
        wg   sync.WaitGroup
398
}
399

400
// newGossipSyncer returns a new instance of the GossipSyncer populated using
401
// the passed config.
402
func newGossipSyncer(cfg gossipSyncerCfg, sema chan struct{}) *GossipSyncer {
3✔
403
        return &GossipSyncer{
3✔
404
                cfg:                cfg,
3✔
405
                syncTransitionReqs: make(chan *syncTransitionReq),
3✔
406
                historicalSyncReqs: make(chan *historicalSyncReq),
3✔
407
                gossipMsgs:         make(chan lnwire.Message, syncerBufferSize),
3✔
408
                queryMsgs:          make(chan lnwire.Message, syncerBufferSize),
3✔
409
                syncerSema:         sema,
3✔
410
                quit:               make(chan struct{}),
3✔
411
        }
3✔
412
}
3✔
413

414
// Start starts the GossipSyncer and any goroutines that it needs to carry out
415
// its duties.
416
func (g *GossipSyncer) Start() {
3✔
417
        g.started.Do(func() {
6✔
418
                log.Debugf("Starting GossipSyncer(%x)", g.cfg.peerPub[:])
3✔
419

3✔
420
                // TODO(conner): only spawn channelGraphSyncer if remote
3✔
421
                // supports gossip queries, and only spawn replyHandler if we
3✔
422
                // advertise support
3✔
423
                if !g.cfg.noSyncChannels {
6✔
424
                        g.wg.Add(1)
3✔
425
                        go g.channelGraphSyncer()
3✔
426
                }
3✔
427
                if !g.cfg.noReplyQueries {
6✔
428
                        g.wg.Add(1)
3✔
429
                        go g.replyHandler()
3✔
430
                }
3✔
431
        })
432
}
433

434
// Stop signals the GossipSyncer for a graceful exit, then waits until it has
435
// exited.
436
func (g *GossipSyncer) Stop() {
3✔
437
        g.stopped.Do(func() {
6✔
438
                log.Debugf("Stopping GossipSyncer(%x)", g.cfg.peerPub[:])
3✔
439
                defer log.Debugf("GossipSyncer(%x) stopped", g.cfg.peerPub[:])
3✔
440

3✔
441
                close(g.quit)
3✔
442
                g.wg.Wait()
3✔
443
        })
3✔
444
}
445

446
// handleSyncingChans handles the state syncingChans for the GossipSyncer. When
447
// in this state, we will send a QueryChannelRange msg to our peer and advance
448
// the syncer's state to waitingQueryRangeReply.
449
func (g *GossipSyncer) handleSyncingChans() {
3✔
450
        // Prepare the query msg.
3✔
451
        queryRangeMsg, err := g.genChanRangeQuery(g.genHistoricalChanRangeQuery)
3✔
452
        if err != nil {
3✔
453
                log.Errorf("Unable to gen chan range query: %v", err)
×
454
                return
×
455
        }
×
456

457
        // Acquire a lock so the following state transition is atomic.
458
        //
459
        // NOTE: We must lock the following steps as it's possible we get an
460
        // immediate response (ReplyChannelRange) after sending the query msg.
461
        // The response is handled in ProcessQueryMsg, which requires the
462
        // current state to be waitingQueryRangeReply.
463
        g.Lock()
3✔
464
        defer g.Unlock()
3✔
465

3✔
466
        // Send the msg to the remote peer, which is non-blocking as
3✔
467
        // `sendToPeer` only queues the msg in Brontide.
3✔
468
        err = g.cfg.sendToPeer(queryRangeMsg)
3✔
469
        if err != nil {
3✔
470
                log.Errorf("Unable to send chan range query: %v", err)
×
471
                return
×
472
        }
×
473

474
        // With the message sent successfully, we'll transition into the next
475
        // state where we wait for their reply.
476
        g.setSyncState(waitingQueryRangeReply)
3✔
477
}
478

479
// channelGraphSyncer is the main goroutine responsible for ensuring that we
480
// properly channel graph state with the remote peer, and also that we only
481
// send them messages which actually pass their defined update horizon.
482
func (g *GossipSyncer) channelGraphSyncer() {
3✔
483
        defer g.wg.Done()
3✔
484

3✔
485
        for {
6✔
486
                state := g.syncState()
3✔
487
                syncType := g.SyncType()
3✔
488

3✔
489
                log.Debugf("GossipSyncer(%x): state=%v, type=%v",
3✔
490
                        g.cfg.peerPub[:], state, syncType)
3✔
491

3✔
492
                switch state {
3✔
493
                // When we're in this state, we're trying to synchronize our
494
                // view of the network with the remote peer. We'll kick off
495
                // this sync by asking them for the set of channels they
496
                // understand, as we'll as responding to any other queries by
497
                // them.
498
                case syncingChans:
3✔
499
                        g.handleSyncingChans()
3✔
500

501
                // In this state, we've sent out our initial channel range
502
                // query and are waiting for the final response from the remote
503
                // peer before we perform a diff to see with channels they know
504
                // of that we don't.
505
                case waitingQueryRangeReply:
3✔
506
                        // We'll wait to either process a new message from the
3✔
507
                        // remote party, or exit due to the gossiper exiting,
3✔
508
                        // or us being signalled to do so.
3✔
509
                        select {
3✔
510
                        case msg := <-g.gossipMsgs:
3✔
511
                                // The remote peer is sending a response to our
3✔
512
                                // initial query, we'll collate this response,
3✔
513
                                // and see if it's the final one in the series.
3✔
514
                                // If so, we can then transition to querying
3✔
515
                                // for the new channels.
3✔
516
                                queryReply, ok := msg.(*lnwire.ReplyChannelRange)
3✔
517
                                if ok {
6✔
518
                                        err := g.processChanRangeReply(queryReply)
3✔
519
                                        if err != nil {
3✔
520
                                                log.Errorf("Unable to "+
×
521
                                                        "process chan range "+
×
522
                                                        "query: %v", err)
×
523
                                                return
×
524
                                        }
×
525
                                        continue
3✔
526
                                }
527

528
                                log.Warnf("Unexpected message: %T in state=%v",
×
529
                                        msg, state)
×
530

531
                        case <-g.quit:
×
532
                                return
×
533
                        }
534

535
                // We'll enter this state once we've discovered which channels
536
                // the remote party knows of that we don't yet know of
537
                // ourselves.
538
                case queryNewChannels:
3✔
539
                        // First, we'll attempt to continue our channel
3✔
540
                        // synchronization by continuing to send off another
3✔
541
                        // query chunk.
3✔
542
                        done := g.synchronizeChanIDs()
3✔
543

3✔
544
                        // If this wasn't our last query, then we'll need to
3✔
545
                        // transition to our waiting state.
3✔
546
                        if !done {
6✔
547
                                continue
3✔
548
                        }
549

550
                        // If we're fully synchronized, then we can transition
551
                        // to our terminal state.
552
                        g.setSyncState(chansSynced)
3✔
553

3✔
554
                        // Ensure that the sync manager becomes aware that the
3✔
555
                        // historical sync completed so synced_to_graph is
3✔
556
                        // updated over rpc.
3✔
557
                        g.cfg.markGraphSynced()
3✔
558

559
                // In this state, we've just sent off a new query for channels
560
                // that we don't yet know of. We'll remain in this state until
561
                // the remote party signals they've responded to our query in
562
                // totality.
563
                case waitingQueryChanReply:
3✔
564
                        // Once we've sent off our query, we'll wait for either
3✔
565
                        // an ending reply, or just another query from the
3✔
566
                        // remote peer.
3✔
567
                        select {
3✔
568
                        case msg := <-g.gossipMsgs:
3✔
569
                                // If this is the final reply to one of our
3✔
570
                                // queries, then we'll loop back into our query
3✔
571
                                // state to send of the remaining query chunks.
3✔
572
                                _, ok := msg.(*lnwire.ReplyShortChanIDsEnd)
3✔
573
                                if ok {
6✔
574
                                        g.setSyncState(queryNewChannels)
3✔
575
                                        continue
3✔
576
                                }
577

578
                                log.Warnf("Unexpected message: %T in state=%v",
×
579
                                        msg, state)
×
580

581
                        case <-g.quit:
×
582
                                return
×
583
                        }
584

585
                // This is our final terminal state where we'll only reply to
586
                // any further queries by the remote peer.
587
                case chansSynced:
3✔
588
                        g.Lock()
3✔
589
                        if g.syncedSignal != nil {
6✔
590
                                close(g.syncedSignal)
3✔
591
                                g.syncedSignal = nil
3✔
592
                        }
3✔
593
                        g.Unlock()
3✔
594

3✔
595
                        // If we haven't yet sent out our update horizon, and
3✔
596
                        // we want to receive real-time channel updates, we'll
3✔
597
                        // do so now.
3✔
598
                        if g.localUpdateHorizon == nil &&
3✔
599
                                syncType.IsActiveSync() {
6✔
600

3✔
601
                                err := g.sendGossipTimestampRange(
3✔
602
                                        time.Now(), math.MaxUint32,
3✔
603
                                )
3✔
604
                                if err != nil {
3✔
605
                                        log.Errorf("Unable to send update "+
×
606
                                                "horizon to %x: %v",
×
607
                                                g.cfg.peerPub, err)
×
608
                                }
×
609
                        }
610
                        // With our horizon set, we'll simply reply to any new
611
                        // messages or process any state transitions and exit if
612
                        // needed.
613
                        fallthrough
3✔
614

615
                // Pinned peers will begin in this state, since they will
616
                // immediately receive a request to perform a historical sync.
617
                // Otherwise, we fall through after ending in chansSynced to
618
                // facilitate new requests.
619
                case syncerIdle:
3✔
620
                        select {
3✔
621
                        case req := <-g.syncTransitionReqs:
3✔
622
                                req.errChan <- g.handleSyncTransition(req)
3✔
623

624
                        case req := <-g.historicalSyncReqs:
3✔
625
                                g.handleHistoricalSync(req)
3✔
626

627
                        case <-g.quit:
3✔
628
                                return
3✔
629
                        }
630
                }
631
        }
632
}
633

634
// replyHandler is an event loop whose sole purpose is to reply to the remote
635
// peers queries. Our replyHandler will respond to messages generated by their
636
// channelGraphSyncer, and vice versa. Each party's channelGraphSyncer drives
637
// the other's replyHandler, allowing the replyHandler to operate independently
638
// from the state machine maintained on the same node.
639
//
640
// NOTE: This method MUST be run as a goroutine.
641
func (g *GossipSyncer) replyHandler() {
3✔
642
        defer g.wg.Done()
3✔
643

3✔
644
        for {
6✔
645
                select {
3✔
646
                case msg := <-g.queryMsgs:
3✔
647
                        err := g.replyPeerQueries(msg)
3✔
648
                        switch {
3✔
649
                        case err == ErrGossipSyncerExiting:
×
650
                                return
×
651

652
                        case err == lnpeer.ErrPeerExiting:
×
653
                                return
×
654

655
                        case err != nil:
×
656
                                log.Errorf("Unable to reply to peer "+
×
657
                                        "query: %v", err)
×
658
                        }
659

660
                case <-g.quit:
3✔
661
                        return
3✔
662
                }
663
        }
664
}
665

666
// sendGossipTimestampRange constructs and sets a GossipTimestampRange for the
667
// syncer and sends it to the remote peer.
668
func (g *GossipSyncer) sendGossipTimestampRange(firstTimestamp time.Time,
669
        timestampRange uint32) error {
3✔
670

3✔
671
        endTimestamp := firstTimestamp.Add(
3✔
672
                time.Duration(timestampRange) * time.Second,
3✔
673
        )
3✔
674

3✔
675
        log.Infof("GossipSyncer(%x): applying gossipFilter(start=%v, end=%v)",
3✔
676
                g.cfg.peerPub[:], firstTimestamp, endTimestamp)
3✔
677

3✔
678
        localUpdateHorizon := &lnwire.GossipTimestampRange{
3✔
679
                ChainHash:      g.cfg.chainHash,
3✔
680
                FirstTimestamp: uint32(firstTimestamp.Unix()),
3✔
681
                TimestampRange: timestampRange,
3✔
682
        }
3✔
683

3✔
684
        if err := g.cfg.sendToPeer(localUpdateHorizon); err != nil {
3✔
685
                return err
×
686
        }
×
687

688
        if firstTimestamp == zeroTimestamp && timestampRange == 0 {
3✔
689
                g.localUpdateHorizon = nil
×
690
        } else {
3✔
691
                g.localUpdateHorizon = localUpdateHorizon
3✔
692
        }
3✔
693

694
        return nil
3✔
695
}
696

697
// synchronizeChanIDs is called by the channelGraphSyncer when we need to query
698
// the remote peer for its known set of channel IDs within a particular block
699
// range. This method will be called continually until the entire range has
700
// been queried for with a response received. We'll chunk our requests as
701
// required to ensure they fit into a single message. We may re-renter this
702
// state in the case that chunking is required.
703
func (g *GossipSyncer) synchronizeChanIDs() bool {
3✔
704
        // If we're in this state yet there are no more new channels to query
3✔
705
        // for, then we'll transition to our final synced state and return true
3✔
706
        // to signal that we're fully synchronized.
3✔
707
        if len(g.newChansToQuery) == 0 {
6✔
708
                log.Infof("GossipSyncer(%x): no more chans to query",
3✔
709
                        g.cfg.peerPub[:])
3✔
710

3✔
711
                return true
3✔
712
        }
3✔
713

714
        // Otherwise, we'll issue our next chunked query to receive replies
715
        // for.
716
        var queryChunk []lnwire.ShortChannelID
3✔
717

3✔
718
        // If the number of channels to query for is less than the chunk size,
3✔
719
        // then we can issue a single query.
3✔
720
        if int32(len(g.newChansToQuery)) < g.cfg.batchSize {
6✔
721
                queryChunk = g.newChansToQuery
3✔
722
                g.newChansToQuery = nil
3✔
723

3✔
724
        } else {
3✔
725
                // Otherwise, we'll need to only query for the next chunk.
×
726
                // We'll slice into our query chunk, then slide down our main
×
727
                // pointer down by the chunk size.
×
728
                queryChunk = g.newChansToQuery[:g.cfg.batchSize]
×
729
                g.newChansToQuery = g.newChansToQuery[g.cfg.batchSize:]
×
730
        }
×
731

732
        log.Infof("GossipSyncer(%x): querying for %v new channels",
3✔
733
                g.cfg.peerPub[:], len(queryChunk))
3✔
734

3✔
735
        // Change the state before sending the query msg.
3✔
736
        g.setSyncState(waitingQueryChanReply)
3✔
737

3✔
738
        // With our chunk obtained, we'll send over our next query, then return
3✔
739
        // false indicating that we're net yet fully synced.
3✔
740
        err := g.cfg.sendToPeer(&lnwire.QueryShortChanIDs{
3✔
741
                ChainHash:    g.cfg.chainHash,
3✔
742
                EncodingType: lnwire.EncodingSortedPlain,
3✔
743
                ShortChanIDs: queryChunk,
3✔
744
        })
3✔
745
        if err != nil {
3✔
746
                log.Errorf("Unable to sync chan IDs: %v", err)
×
747
        }
×
748

749
        return false
3✔
750
}
751

752
// isLegacyReplyChannelRange determines where a ReplyChannelRange message is
753
// considered legacy. There was a point where lnd used to include the same query
754
// over multiple replies, rather than including the portion of the query the
755
// reply is handling. We'll use this as a way of detecting whether we are
756
// communicating with a legacy node so we can properly sync with them.
757
func isLegacyReplyChannelRange(query *lnwire.QueryChannelRange,
758
        reply *lnwire.ReplyChannelRange) bool {
3✔
759

3✔
760
        return (reply.ChainHash == query.ChainHash &&
3✔
761
                reply.FirstBlockHeight == query.FirstBlockHeight &&
3✔
762
                reply.NumBlocks == query.NumBlocks)
3✔
763
}
3✔
764

765
// processChanRangeReply is called each time the GossipSyncer receives a new
766
// reply to the initial range query to discover new channels that it didn't
767
// previously know of.
768
func (g *GossipSyncer) processChanRangeReply(msg *lnwire.ReplyChannelRange) error {
3✔
769
        // isStale returns whether the timestamp is too far into the past.
3✔
770
        isStale := func(timestamp time.Time) bool {
6✔
771
                return time.Since(timestamp) > graph.DefaultChannelPruneExpiry
3✔
772
        }
3✔
773

774
        // isSkewed returns whether the timestamp is too far into the future.
775
        isSkewed := func(timestamp time.Time) bool {
6✔
776
                return time.Until(timestamp) > graph.DefaultChannelPruneExpiry
3✔
777
        }
3✔
778

779
        // If we're not communicating with a legacy node, we'll apply some
780
        // further constraints on their reply to ensure it satisfies our query.
781
        if !isLegacyReplyChannelRange(g.curQueryRangeMsg, msg) {
3✔
782
                // The first block should be within our original request.
×
783
                if msg.FirstBlockHeight < g.curQueryRangeMsg.FirstBlockHeight {
×
784
                        return fmt.Errorf("reply includes channels for height "+
×
785
                                "%v prior to query %v", msg.FirstBlockHeight,
×
786
                                g.curQueryRangeMsg.FirstBlockHeight)
×
787
                }
×
788

789
                // The last block should also be. We don't need to check the
790
                // intermediate ones because they should already be in sorted
791
                // order.
792
                replyLastHeight := msg.LastBlockHeight()
×
793
                queryLastHeight := g.curQueryRangeMsg.LastBlockHeight()
×
794
                if replyLastHeight > queryLastHeight {
×
795
                        return fmt.Errorf("reply includes channels for height "+
×
796
                                "%v after query %v", replyLastHeight,
×
797
                                queryLastHeight)
×
798
                }
×
799

800
                // If we've previously received a reply for this query, look at
801
                // its last block to ensure the current reply properly follows
802
                // it.
803
                if g.prevReplyChannelRange != nil {
×
804
                        prevReply := g.prevReplyChannelRange
×
805
                        prevReplyLastHeight := prevReply.LastBlockHeight()
×
806

×
807
                        // The current reply can either start from the previous
×
808
                        // reply's last block, if there are still more channels
×
809
                        // for the same block, or the block after.
×
810
                        if msg.FirstBlockHeight != prevReplyLastHeight &&
×
811
                                msg.FirstBlockHeight != prevReplyLastHeight+1 {
×
812

×
813
                                return fmt.Errorf("first block of reply %v "+
×
814
                                        "does not continue from last block of "+
×
815
                                        "previous %v", msg.FirstBlockHeight,
×
816
                                        prevReplyLastHeight)
×
817
                        }
×
818
                }
819
        }
820

821
        g.prevReplyChannelRange = msg
3✔
822

3✔
823
        for i, scid := range msg.ShortChanIDs {
6✔
824
                info := graphdb.NewChannelUpdateInfo(
3✔
825
                        scid, time.Time{}, time.Time{},
3✔
826
                )
3✔
827

3✔
828
                if len(msg.Timestamps) != 0 {
6✔
829
                        t1 := time.Unix(int64(msg.Timestamps[i].Timestamp1), 0)
3✔
830
                        info.Node1UpdateTimestamp = t1
3✔
831

3✔
832
                        t2 := time.Unix(int64(msg.Timestamps[i].Timestamp2), 0)
3✔
833
                        info.Node2UpdateTimestamp = t2
3✔
834

3✔
835
                        // Sort out all channels with outdated or skewed
3✔
836
                        // timestamps. Both timestamps need to be out of
3✔
837
                        // boundaries for us to skip the channel and not query
3✔
838
                        // it later on.
3✔
839
                        switch {
3✔
840
                        case isStale(info.Node1UpdateTimestamp) &&
841
                                isStale(info.Node2UpdateTimestamp):
×
842

×
843
                                continue
×
844

845
                        case isSkewed(info.Node1UpdateTimestamp) &&
846
                                isSkewed(info.Node2UpdateTimestamp):
×
847

×
848
                                continue
×
849

850
                        case isStale(info.Node1UpdateTimestamp) &&
851
                                isSkewed(info.Node2UpdateTimestamp):
×
852

×
853
                                continue
×
854

855
                        case isStale(info.Node2UpdateTimestamp) &&
856
                                isSkewed(info.Node1UpdateTimestamp):
×
857

×
858
                                continue
×
859
                        }
860
                }
861

862
                g.bufferedChanRangeReplies = append(
3✔
863
                        g.bufferedChanRangeReplies, info,
3✔
864
                )
3✔
865
        }
866

867
        switch g.cfg.encodingType {
3✔
868
        case lnwire.EncodingSortedPlain:
3✔
869
                g.numChanRangeRepliesRcvd++
3✔
870
        case lnwire.EncodingSortedZlib:
×
871
                g.numChanRangeRepliesRcvd += maxQueryChanRangeRepliesZlibFactor
×
872
        default:
×
873
                return fmt.Errorf("unhandled encoding type %v", g.cfg.encodingType)
×
874
        }
875

876
        log.Infof("GossipSyncer(%x): buffering chan range reply of size=%v",
3✔
877
                g.cfg.peerPub[:], len(msg.ShortChanIDs))
3✔
878

3✔
879
        // If this isn't the last response and we can continue to receive more,
3✔
880
        // then we can exit as we've already buffered the latest portion of the
3✔
881
        // streaming reply.
3✔
882
        maxReplies := g.cfg.maxQueryChanRangeReplies
3✔
883
        switch {
3✔
884
        // If we're communicating with a legacy node, we'll need to look at the
885
        // complete field.
886
        case isLegacyReplyChannelRange(g.curQueryRangeMsg, msg):
3✔
887
                if msg.Complete == 0 && g.numChanRangeRepliesRcvd < maxReplies {
3✔
888
                        return nil
×
889
                }
×
890

891
        // Otherwise, we'll look at the reply's height range.
892
        default:
×
893
                replyLastHeight := msg.LastBlockHeight()
×
894
                queryLastHeight := g.curQueryRangeMsg.LastBlockHeight()
×
895

×
896
                // TODO(wilmer): This might require some padding if the remote
×
897
                // node is not aware of the last height we sent them, i.e., is
×
898
                // behind a few blocks from us.
×
899
                if replyLastHeight < queryLastHeight &&
×
900
                        g.numChanRangeRepliesRcvd < maxReplies {
×
901

×
902
                        return nil
×
903
                }
×
904
        }
905

906
        log.Infof("GossipSyncer(%x): filtering through %v chans",
3✔
907
                g.cfg.peerPub[:], len(g.bufferedChanRangeReplies))
3✔
908

3✔
909
        // Otherwise, this is the final response, so we'll now check to see
3✔
910
        // which channels they know of that we don't.
3✔
911
        newChans, err := g.cfg.channelSeries.FilterKnownChanIDs(
3✔
912
                g.cfg.chainHash, g.bufferedChanRangeReplies,
3✔
913
                g.cfg.isStillZombieChannel,
3✔
914
        )
3✔
915
        if err != nil {
3✔
916
                return fmt.Errorf("unable to filter chan ids: %w", err)
×
917
        }
×
918

919
        // As we've received the entirety of the reply, we no longer need to
920
        // hold on to the set of buffered replies or the original query that
921
        // prompted the replies, so we'll let that be garbage collected now.
922
        g.curQueryRangeMsg = nil
3✔
923
        g.prevReplyChannelRange = nil
3✔
924
        g.bufferedChanRangeReplies = nil
3✔
925
        g.numChanRangeRepliesRcvd = 0
3✔
926

3✔
927
        // If there aren't any channels that we don't know of, then we can
3✔
928
        // switch straight to our terminal state.
3✔
929
        if len(newChans) == 0 {
6✔
930
                log.Infof("GossipSyncer(%x): remote peer has no new chans",
3✔
931
                        g.cfg.peerPub[:])
3✔
932

3✔
933
                g.setSyncState(chansSynced)
3✔
934

3✔
935
                // Ensure that the sync manager becomes aware that the
3✔
936
                // historical sync completed so synced_to_graph is updated over
3✔
937
                // rpc.
3✔
938
                g.cfg.markGraphSynced()
3✔
939
                return nil
3✔
940
        }
3✔
941

942
        // Otherwise, we'll set the set of channels that we need to query for
943
        // the next state, and also transition our state.
944
        g.newChansToQuery = newChans
3✔
945
        g.setSyncState(queryNewChannels)
3✔
946

3✔
947
        log.Infof("GossipSyncer(%x): starting query for %v new chans",
3✔
948
                g.cfg.peerPub[:], len(newChans))
3✔
949

3✔
950
        return nil
3✔
951
}
952

953
// genChanRangeQuery generates the initial message we'll send to the remote
954
// party when we're kicking off the channel graph synchronization upon
955
// connection. The historicalQuery boolean can be used to generate a query from
956
// the genesis block of the chain.
957
func (g *GossipSyncer) genChanRangeQuery(
958
        historicalQuery bool) (*lnwire.QueryChannelRange, error) {
3✔
959

3✔
960
        // First, we'll query our channel graph time series for its highest
3✔
961
        // known channel ID.
3✔
962
        newestChan, err := g.cfg.channelSeries.HighestChanID(g.cfg.chainHash)
3✔
963
        if err != nil {
3✔
964
                return nil, err
×
965
        }
×
966

967
        // Once we have the chan ID of the newest, we'll obtain the block height
968
        // of the channel, then subtract our default horizon to ensure we don't
969
        // miss any channels. By default, we go back 1 day from the newest
970
        // channel, unless we're attempting a historical sync, where we'll
971
        // actually start from the genesis block instead.
972
        var startHeight uint32
3✔
973
        switch {
3✔
974
        case historicalQuery:
3✔
975
                fallthrough
3✔
976
        case newestChan.BlockHeight <= chanRangeQueryBuffer:
3✔
977
                startHeight = 0
3✔
978
        default:
×
979
                startHeight = newestChan.BlockHeight - chanRangeQueryBuffer
×
980
        }
981

982
        // Determine the number of blocks to request based on our best height.
983
        // We'll take into account any potential underflows and explicitly set
984
        // numBlocks to its minimum value of 1 if so.
985
        bestHeight := g.cfg.bestHeight()
3✔
986
        numBlocks := bestHeight - startHeight
3✔
987
        if int64(numBlocks) < 1 {
3✔
988
                numBlocks = 1
×
989
        }
×
990

991
        log.Infof("GossipSyncer(%x): requesting new chans from height=%v "+
3✔
992
                "and %v blocks after", g.cfg.peerPub[:], startHeight, numBlocks)
3✔
993

3✔
994
        // Finally, we'll craft the channel range query, using our starting
3✔
995
        // height, then asking for all known channels to the foreseeable end of
3✔
996
        // the main chain.
3✔
997
        query := &lnwire.QueryChannelRange{
3✔
998
                ChainHash:        g.cfg.chainHash,
3✔
999
                FirstBlockHeight: startHeight,
3✔
1000
                NumBlocks:        numBlocks,
3✔
1001
        }
3✔
1002

3✔
1003
        if !g.cfg.noTimestampQueryOption {
6✔
1004
                query.QueryOptions = lnwire.NewTimestampQueryOption()
3✔
1005
        }
3✔
1006

1007
        g.curQueryRangeMsg = query
3✔
1008

3✔
1009
        return query, nil
3✔
1010
}
1011

1012
// maybeAddMsgDelay will add a delay to the gossip syncer if the peer has been
1013
// requesting too much.
1014
func (g *GossipSyncer) maybeAddMsgDelay() error {
3✔
1015
        delay := g.cfg.maybeAddDelay()
3✔
1016

3✔
1017
        // If we've already replied a handful of times, we will start to delay
3✔
1018
        // responses back to the remote peer. This can help prevent DOS attacks
3✔
1019
        // where the remote peer spams us endlessly.
3✔
1020
        if delay > 0 {
3✔
1021
                log.Infof("GossipSyncer(%x): rate limiting gossip replies, "+
×
1022
                        "responding in %s", g.cfg.peerPub[:], delay)
×
1023

×
1024
                select {
×
1025
                case <-time.After(delay):
×
1026
                case <-g.quit:
×
1027
                        return ErrGossipSyncerExiting
×
1028
                }
1029
        }
1030

1031
        return nil
3✔
1032
}
1033

1034
// replyPeerQueries is called in response to any query by the remote peer.
1035
// We'll examine our state and send back our best response.
1036
func (g *GossipSyncer) replyPeerQueries(msg lnwire.Message) error {
3✔
1037
        switch msg := msg.(type) {
3✔
1038

1039
        // In this state, we'll also handle any incoming channel range queries
1040
        // from the remote peer as they're trying to sync their state as well.
1041
        case *lnwire.QueryChannelRange:
3✔
1042
                return g.replyChanRangeQuery(msg)
3✔
1043

1044
        // If the remote peer skips straight to requesting new channels that
1045
        // they don't know of, then we'll ensure that we also handle this case.
1046
        case *lnwire.QueryShortChanIDs:
3✔
1047
                return g.replyShortChanIDs(msg)
3✔
1048

1049
        default:
×
1050
                return fmt.Errorf("unknown message: %T", msg)
×
1051
        }
1052
}
1053

1054
// replyChanRangeQuery will be dispatched in response to a channel range query
1055
// by the remote node. We'll query the channel time series for channels that
1056
// meet the channel range, then chunk our responses to the remote node. We also
1057
// ensure that our final fragment carries the "complete" bit to indicate the
1058
// end of our streaming response.
1059
func (g *GossipSyncer) replyChanRangeQuery(query *lnwire.QueryChannelRange) error {
3✔
1060
        // Before responding, we'll check to ensure that the remote peer is
3✔
1061
        // querying for the same chain that we're on. If not, we'll send back a
3✔
1062
        // response with a complete value of zero to indicate we're on a
3✔
1063
        // different chain.
3✔
1064
        if g.cfg.chainHash != query.ChainHash {
3✔
1065
                log.Warnf("Remote peer requested QueryChannelRange for "+
×
1066
                        "chain=%v, we're on chain=%v", query.ChainHash,
×
1067
                        g.cfg.chainHash)
×
1068

×
1069
                return g.cfg.sendToPeerSync(&lnwire.ReplyChannelRange{
×
1070
                        ChainHash:        query.ChainHash,
×
1071
                        FirstBlockHeight: query.FirstBlockHeight,
×
1072
                        NumBlocks:        query.NumBlocks,
×
1073
                        Complete:         0,
×
1074
                        EncodingType:     g.cfg.encodingType,
×
1075
                        ShortChanIDs:     nil,
×
1076
                })
×
1077
        }
×
1078

1079
        log.Infof("GossipSyncer(%x): filtering chan range: start_height=%v, "+
3✔
1080
                "num_blocks=%v", g.cfg.peerPub[:], query.FirstBlockHeight,
3✔
1081
                query.NumBlocks)
3✔
1082

3✔
1083
        // Check if the query asked for timestamps. We will only serve
3✔
1084
        // timestamps if this has not been disabled with
3✔
1085
        // noTimestampQueryOption.
3✔
1086
        withTimestamps := query.WithTimestamps() &&
3✔
1087
                !g.cfg.noTimestampQueryOption
3✔
1088

3✔
1089
        // Next, we'll consult the time series to obtain the set of known
3✔
1090
        // channel ID's that match their query.
3✔
1091
        startBlock := query.FirstBlockHeight
3✔
1092
        endBlock := query.LastBlockHeight()
3✔
1093
        channelRanges, err := g.cfg.channelSeries.FilterChannelRange(
3✔
1094
                query.ChainHash, startBlock, endBlock, withTimestamps,
3✔
1095
        )
3✔
1096
        if err != nil {
3✔
1097
                return err
×
1098
        }
×
1099

1100
        // TODO(roasbeef): means can't send max uint above?
1101
        //  * or make internal 64
1102

1103
        // We'll send our response in a streaming manner, chunk-by-chunk. We do
1104
        // this as there's a transport message size limit which we'll need to
1105
        // adhere to. We also need to make sure all of our replies cover the
1106
        // expected range of the query.
1107
        sendReplyForChunk := func(channelChunk []graphdb.ChannelUpdateInfo,
3✔
1108
                firstHeight, lastHeight uint32, finalChunk bool) error {
6✔
1109

3✔
1110
                // The number of blocks contained in the current chunk (the
3✔
1111
                // total span) is the difference between the last channel ID and
3✔
1112
                // the first in the range. We add one as even if all channels
3✔
1113
                // returned are in the same block, we need to count that.
3✔
1114
                numBlocks := lastHeight - firstHeight + 1
3✔
1115
                complete := uint8(0)
3✔
1116
                if finalChunk {
6✔
1117
                        complete = 1
3✔
1118
                }
3✔
1119

1120
                var timestamps lnwire.Timestamps
3✔
1121
                if withTimestamps {
6✔
1122
                        timestamps = make(lnwire.Timestamps, len(channelChunk))
3✔
1123
                }
3✔
1124

1125
                scids := make([]lnwire.ShortChannelID, len(channelChunk))
3✔
1126
                for i, info := range channelChunk {
6✔
1127
                        scids[i] = info.ShortChannelID
3✔
1128

3✔
1129
                        if !withTimestamps {
3✔
1130
                                continue
×
1131
                        }
1132

1133
                        timestamps[i].Timestamp1 = uint32(
3✔
1134
                                info.Node1UpdateTimestamp.Unix(),
3✔
1135
                        )
3✔
1136

3✔
1137
                        timestamps[i].Timestamp2 = uint32(
3✔
1138
                                info.Node2UpdateTimestamp.Unix(),
3✔
1139
                        )
3✔
1140
                }
1141

1142
                if err := g.maybeAddMsgDelay(); err != nil {
3✔
NEW
1143
                        return err
×
NEW
1144
                }
×
1145

1146
                return g.cfg.sendToPeerSync(&lnwire.ReplyChannelRange{
3✔
1147
                        ChainHash:        query.ChainHash,
3✔
1148
                        NumBlocks:        numBlocks,
3✔
1149
                        FirstBlockHeight: firstHeight,
3✔
1150
                        Complete:         complete,
3✔
1151
                        EncodingType:     g.cfg.encodingType,
3✔
1152
                        ShortChanIDs:     scids,
3✔
1153
                        Timestamps:       timestamps,
3✔
1154
                })
3✔
1155
        }
1156

1157
        var (
3✔
1158
                firstHeight  = query.FirstBlockHeight
3✔
1159
                lastHeight   uint32
3✔
1160
                channelChunk []graphdb.ChannelUpdateInfo
3✔
1161
        )
3✔
1162

3✔
1163
        // chunkSize is the maximum number of SCIDs that we can safely put in a
3✔
1164
        // single message. If we also need to include timestamps though, then
3✔
1165
        // this number is halved since encoding two timestamps takes the same
3✔
1166
        // number of bytes as encoding an SCID.
3✔
1167
        chunkSize := g.cfg.chunkSize
3✔
1168
        if withTimestamps {
6✔
1169
                chunkSize /= 2
3✔
1170
        }
3✔
1171

1172
        for _, channelRange := range channelRanges {
6✔
1173
                channels := channelRange.Channels
3✔
1174
                numChannels := int32(len(channels))
3✔
1175
                numLeftToAdd := chunkSize - int32(len(channelChunk))
3✔
1176

3✔
1177
                // Include the current block in the ongoing chunk if it can fit
3✔
1178
                // and move on to the next block.
3✔
1179
                if numChannels <= numLeftToAdd {
6✔
1180
                        channelChunk = append(channelChunk, channels...)
3✔
1181
                        continue
3✔
1182
                }
1183

1184
                // Otherwise, we need to send our existing channel chunk as is
1185
                // as its own reply and start a new one for the current block.
1186
                // We'll mark the end of our current chunk as the height before
1187
                // the current block to ensure the whole query range is replied
1188
                // to.
1189
                log.Infof("GossipSyncer(%x): sending range chunk of size=%v",
×
1190
                        g.cfg.peerPub[:], len(channelChunk))
×
1191

×
1192
                lastHeight = channelRange.Height - 1
×
1193
                err := sendReplyForChunk(
×
1194
                        channelChunk, firstHeight, lastHeight, false,
×
1195
                )
×
1196
                if err != nil {
×
1197
                        return err
×
1198
                }
×
1199

1200
                // With the reply constructed, we'll start tallying channels for
1201
                // our next one keeping in mind our chunk size. This may result
1202
                // in channels for this block being left out from the reply, but
1203
                // this isn't an issue since we'll randomly shuffle them and we
1204
                // assume a historical gossip sync is performed at a later time.
1205
                firstHeight = channelRange.Height
×
1206
                finalChunkSize := numChannels
×
1207
                exceedsChunkSize := numChannels > chunkSize
×
1208
                if exceedsChunkSize {
×
1209
                        rand.Shuffle(len(channels), func(i, j int) {
×
1210
                                channels[i], channels[j] = channels[j], channels[i]
×
1211
                        })
×
1212
                        finalChunkSize = chunkSize
×
1213
                }
1214
                channelChunk = channels[:finalChunkSize]
×
1215

×
1216
                // Sort the chunk once again if we had to shuffle it.
×
1217
                if exceedsChunkSize {
×
1218
                        sort.Slice(channelChunk, func(i, j int) bool {
×
1219
                                id1 := channelChunk[i].ShortChannelID.ToUint64()
×
1220
                                id2 := channelChunk[j].ShortChannelID.ToUint64()
×
1221

×
1222
                                return id1 < id2
×
1223
                        })
×
1224
                }
1225
        }
1226

1227
        // Send the remaining chunk as the final reply.
1228
        log.Infof("GossipSyncer(%x): sending final chan range chunk, size=%v",
3✔
1229
                g.cfg.peerPub[:], len(channelChunk))
3✔
1230

3✔
1231
        return sendReplyForChunk(
3✔
1232
                channelChunk, firstHeight, query.LastBlockHeight(), true,
3✔
1233
        )
3✔
1234
}
1235

1236
// replyShortChanIDs will be dispatched in response to a query by the remote
1237
// node for information concerning a set of short channel ID's. Our response
1238
// will be sent in a streaming chunked manner to ensure that we remain below
1239
// the current transport level message size.
1240
func (g *GossipSyncer) replyShortChanIDs(query *lnwire.QueryShortChanIDs) error {
3✔
1241
        // Before responding, we'll check to ensure that the remote peer is
3✔
1242
        // querying for the same chain that we're on. If not, we'll send back a
3✔
1243
        // response with a complete value of zero to indicate we're on a
3✔
1244
        // different chain.
3✔
1245
        if g.cfg.chainHash != query.ChainHash {
3✔
1246
                log.Warnf("Remote peer requested QueryShortChanIDs for "+
×
1247
                        "chain=%v, we're on chain=%v", query.ChainHash,
×
1248
                        g.cfg.chainHash)
×
1249

×
1250
                return g.cfg.sendToPeerSync(&lnwire.ReplyShortChanIDsEnd{
×
1251
                        ChainHash: query.ChainHash,
×
1252
                        Complete:  0,
×
1253
                })
×
1254
        }
×
1255

1256
        if len(query.ShortChanIDs) == 0 {
3✔
1257
                log.Infof("GossipSyncer(%x): ignoring query for blank short chan ID's",
×
1258
                        g.cfg.peerPub[:])
×
1259
                return nil
×
1260
        }
×
1261

1262
        log.Infof("GossipSyncer(%x): fetching chan anns for %v chans",
3✔
1263
                g.cfg.peerPub[:], len(query.ShortChanIDs))
3✔
1264

3✔
1265
        // Now that we know we're on the same chain, we'll query the channel
3✔
1266
        // time series for the set of messages that we know of which satisfies
3✔
1267
        // the requirement of being a chan ann, chan update, or a node ann
3✔
1268
        // related to the set of queried channels.
3✔
1269
        replyMsgs, err := g.cfg.channelSeries.FetchChanAnns(
3✔
1270
                query.ChainHash, query.ShortChanIDs,
3✔
1271
        )
3✔
1272
        if err != nil {
3✔
1273
                return fmt.Errorf("unable to fetch chan anns for %v..., %w",
×
1274
                        query.ShortChanIDs[0].ToUint64(), err)
×
1275
        }
×
1276

1277
        // Reply with any messages related to those channel ID's, we'll write
1278
        // each one individually and synchronously to throttle the sends and
1279
        // perform buffering of responses in the syncer as opposed to the peer.
1280
        for _, msg := range replyMsgs {
6✔
1281
                if err := g.maybeAddMsgDelay(); err != nil {
3✔
NEW
1282
                        return err
×
NEW
1283
                }
×
1284

1285
                err := g.cfg.sendToPeerSync(msg)
3✔
1286
                if err != nil {
3✔
1287
                        return err
×
1288
                }
×
1289
        }
1290

1291
        // Regardless of whether we had any messages to reply with, send over
1292
        // the sentinel message to signal that the stream has terminated.
1293
        return g.cfg.sendToPeerSync(&lnwire.ReplyShortChanIDsEnd{
3✔
1294
                ChainHash: query.ChainHash,
3✔
1295
                Complete:  1,
3✔
1296
        })
3✔
1297
}
1298

1299
// ApplyGossipFilter applies a gossiper filter sent by the remote node to the
1300
// state machine. Once applied, we'll ensure that we don't forward any messages
1301
// to the peer that aren't within the time range of the filter.
1302
func (g *GossipSyncer) ApplyGossipFilter(filter *lnwire.GossipTimestampRange) error {
3✔
1303
        g.Lock()
3✔
1304

3✔
1305
        g.remoteUpdateHorizon = filter
3✔
1306

3✔
1307
        startTime := time.Unix(int64(g.remoteUpdateHorizon.FirstTimestamp), 0)
3✔
1308
        endTime := startTime.Add(
3✔
1309
                time.Duration(g.remoteUpdateHorizon.TimestampRange) * time.Second,
3✔
1310
        )
3✔
1311

3✔
1312
        g.Unlock()
3✔
1313

3✔
1314
        // If requested, don't reply with historical gossip data when the remote
3✔
1315
        // peer sets their gossip timestamp range.
3✔
1316
        if g.cfg.ignoreHistoricalFilters {
3✔
1317
                return nil
×
1318
        }
×
1319

1320
        select {
3✔
1321
        case <-g.syncerSema:
3✔
1322
        case <-g.quit:
×
1323
                return ErrGossipSyncerExiting
×
1324
        }
1325

1326
        // We don't put this in a defer because if the goroutine is launched,
1327
        // it needs to be called when the goroutine is stopped.
1328
        returnSema := func() {
6✔
1329
                g.syncerSema <- struct{}{}
3✔
1330
        }
3✔
1331

1332
        // Now that the remote peer has applied their filter, we'll query the
1333
        // database for all the messages that are beyond this filter.
1334
        newUpdatestoSend, err := g.cfg.channelSeries.UpdatesInHorizon(
3✔
1335
                g.cfg.chainHash, startTime, endTime,
3✔
1336
        )
3✔
1337
        if err != nil {
3✔
1338
                returnSema()
×
1339
                return err
×
1340
        }
×
1341

1342
        log.Infof("GossipSyncer(%x): applying new remote update horizon: "+
3✔
1343
                "start=%v, end=%v, backlog_size=%v", g.cfg.peerPub[:],
3✔
1344
                startTime, endTime, len(newUpdatestoSend))
3✔
1345

3✔
1346
        // If we don't have any to send, then we can return early.
3✔
1347
        if len(newUpdatestoSend) == 0 {
6✔
1348
                returnSema()
3✔
1349
                return nil
3✔
1350
        }
3✔
1351

1352
        // We'll conclude by launching a goroutine to send out any updates.
1353
        g.wg.Add(1)
3✔
1354
        go func() {
6✔
1355
                defer g.wg.Done()
3✔
1356
                defer returnSema()
3✔
1357

3✔
1358
                for _, msg := range newUpdatestoSend {
6✔
1359
                        if err := g.maybeAddMsgDelay(); err != nil {
3✔
NEW
1360
                                log.Errorf("Unable to send message for "+
×
NEW
1361
                                        "peer catch up: %v", err)
×
NEW
1362
                        }
×
1363

1364
                        err := g.cfg.sendToPeerSync(msg)
3✔
1365
                        switch {
3✔
1366
                        case err == ErrGossipSyncerExiting:
×
1367
                                return
×
1368

1369
                        case err == lnpeer.ErrPeerExiting:
×
1370
                                return
×
1371

1372
                        case err != nil:
×
1373
                                log.Errorf("Unable to send message for "+
×
1374
                                        "peer catch up: %v", err)
×
1375
                        }
1376
                }
1377
        }()
1378

1379
        return nil
3✔
1380
}
1381

1382
// FilterGossipMsgs takes a set of gossip messages, and only send it to a peer
1383
// iff the message is within the bounds of their set gossip filter. If the peer
1384
// doesn't have a gossip filter set, then no messages will be forwarded.
1385
func (g *GossipSyncer) FilterGossipMsgs(msgs ...msgWithSenders) {
3✔
1386
        // If the peer doesn't have an update horizon set, then we won't send
3✔
1387
        // it any new update messages.
3✔
1388
        if g.remoteUpdateHorizon == nil {
6✔
1389
                log.Tracef("GossipSyncer(%x): skipped due to nil "+
3✔
1390
                        "remoteUpdateHorizon", g.cfg.peerPub[:])
3✔
1391
                return
3✔
1392
        }
3✔
1393

1394
        // If we've been signaled to exit, or are exiting, then we'll stop
1395
        // short.
1396
        select {
3✔
1397
        case <-g.quit:
×
1398
                return
×
1399
        default:
3✔
1400
        }
1401

1402
        // TODO(roasbeef): need to ensure that peer still online...send msg to
1403
        // gossiper on peer termination to signal peer disconnect?
1404

1405
        var err error
3✔
1406

3✔
1407
        // Before we filter out the messages, we'll construct an index over the
3✔
1408
        // set of channel announcements and channel updates. This will allow us
3✔
1409
        // to quickly check if we should forward a chan ann, based on the known
3✔
1410
        // channel updates for a channel.
3✔
1411
        chanUpdateIndex := make(
3✔
1412
                map[lnwire.ShortChannelID][]*lnwire.ChannelUpdate1,
3✔
1413
        )
3✔
1414
        for _, msg := range msgs {
6✔
1415
                chanUpdate, ok := msg.msg.(*lnwire.ChannelUpdate1)
3✔
1416
                if !ok {
6✔
1417
                        continue
3✔
1418
                }
1419

1420
                chanUpdateIndex[chanUpdate.ShortChannelID] = append(
3✔
1421
                        chanUpdateIndex[chanUpdate.ShortChannelID], chanUpdate,
3✔
1422
                )
3✔
1423
        }
1424

1425
        // We'll construct a helper function that we'll us below to determine
1426
        // if a given messages passes the gossip msg filter.
1427
        g.Lock()
3✔
1428
        startTime := time.Unix(int64(g.remoteUpdateHorizon.FirstTimestamp), 0)
3✔
1429
        endTime := startTime.Add(
3✔
1430
                time.Duration(g.remoteUpdateHorizon.TimestampRange) * time.Second,
3✔
1431
        )
3✔
1432
        g.Unlock()
3✔
1433

3✔
1434
        passesFilter := func(timeStamp uint32) bool {
6✔
1435
                t := time.Unix(int64(timeStamp), 0)
3✔
1436
                return t.Equal(startTime) ||
3✔
1437
                        (t.After(startTime) && t.Before(endTime))
3✔
1438
        }
3✔
1439

1440
        msgsToSend := make([]lnwire.Message, 0, len(msgs))
3✔
1441
        for _, msg := range msgs {
6✔
1442
                // If the target peer is the peer that sent us this message,
3✔
1443
                // then we'll exit early as we don't need to filter this
3✔
1444
                // message.
3✔
1445
                if _, ok := msg.senders[g.cfg.peerPub]; ok {
6✔
1446
                        continue
3✔
1447
                }
1448

1449
                switch msg := msg.msg.(type) {
3✔
1450

1451
                // For each channel announcement message, we'll only send this
1452
                // message if the channel updates for the channel are between
1453
                // our time range.
1454
                case *lnwire.ChannelAnnouncement1:
3✔
1455
                        // First, we'll check if the channel updates are in
3✔
1456
                        // this message batch.
3✔
1457
                        chanUpdates, ok := chanUpdateIndex[msg.ShortChannelID]
3✔
1458
                        if !ok {
6✔
1459
                                // If not, we'll attempt to query the database
3✔
1460
                                // to see if we know of the updates.
3✔
1461
                                chanUpdates, err = g.cfg.channelSeries.FetchChanUpdates(
3✔
1462
                                        g.cfg.chainHash, msg.ShortChannelID,
3✔
1463
                                )
3✔
1464
                                if err != nil {
3✔
1465
                                        log.Warnf("no channel updates found for "+
×
1466
                                                "short_chan_id=%v",
×
1467
                                                msg.ShortChannelID)
×
1468
                                        continue
×
1469
                                }
1470
                        }
1471

1472
                        for _, chanUpdate := range chanUpdates {
6✔
1473
                                if passesFilter(chanUpdate.Timestamp) {
6✔
1474
                                        msgsToSend = append(msgsToSend, msg)
3✔
1475
                                        break
3✔
1476
                                }
1477
                        }
1478

1479
                        if len(chanUpdates) == 0 {
6✔
1480
                                msgsToSend = append(msgsToSend, msg)
3✔
1481
                        }
3✔
1482

1483
                // For each channel update, we'll only send if it the timestamp
1484
                // is between our time range.
1485
                case *lnwire.ChannelUpdate1:
3✔
1486
                        if passesFilter(msg.Timestamp) {
6✔
1487
                                msgsToSend = append(msgsToSend, msg)
3✔
1488
                        }
3✔
1489

1490
                // Similarly, we only send node announcements if the update
1491
                // timestamp ifs between our set gossip filter time range.
1492
                case *lnwire.NodeAnnouncement:
3✔
1493
                        if passesFilter(msg.Timestamp) {
6✔
1494
                                msgsToSend = append(msgsToSend, msg)
3✔
1495
                        }
3✔
1496
                }
1497
        }
1498

1499
        log.Tracef("GossipSyncer(%x): filtered gossip msgs: set=%v, sent=%v",
3✔
1500
                g.cfg.peerPub[:], len(msgs), len(msgsToSend))
3✔
1501

3✔
1502
        if len(msgsToSend) == 0 {
6✔
1503
                return
3✔
1504
        }
3✔
1505

1506
        g.cfg.sendToPeer(msgsToSend...)
3✔
1507
}
1508

1509
// ProcessQueryMsg is used by outside callers to pass new channel time series
1510
// queries to the internal processing goroutine.
1511
func (g *GossipSyncer) ProcessQueryMsg(msg lnwire.Message, peerQuit <-chan struct{}) error {
3✔
1512
        var msgChan chan lnwire.Message
3✔
1513
        switch msg.(type) {
3✔
1514
        case *lnwire.QueryChannelRange, *lnwire.QueryShortChanIDs:
3✔
1515
                msgChan = g.queryMsgs
3✔
1516

1517
        // Reply messages should only be expected in states where we're waiting
1518
        // for a reply.
1519
        case *lnwire.ReplyChannelRange, *lnwire.ReplyShortChanIDsEnd:
3✔
1520
                g.Lock()
3✔
1521
                syncState := g.syncState()
3✔
1522
                g.Unlock()
3✔
1523

3✔
1524
                if syncState != waitingQueryRangeReply &&
3✔
1525
                        syncState != waitingQueryChanReply {
3✔
1526

×
1527
                        return fmt.Errorf("unexpected msg %T received in "+
×
1528
                                "state %v", msg, syncState)
×
1529
                }
×
1530
                msgChan = g.gossipMsgs
3✔
1531

1532
        default:
×
1533
                msgChan = g.gossipMsgs
×
1534
        }
1535

1536
        select {
3✔
1537
        case msgChan <- msg:
3✔
1538
        case <-peerQuit:
×
1539
        case <-g.quit:
×
1540
        }
1541

1542
        return nil
3✔
1543
}
1544

1545
// setSyncState sets the gossip syncer's state to the given state.
1546
func (g *GossipSyncer) setSyncState(state syncerState) {
3✔
1547
        atomic.StoreUint32(&g.state, uint32(state))
3✔
1548
}
3✔
1549

1550
// syncState returns the current syncerState of the target GossipSyncer.
1551
func (g *GossipSyncer) syncState() syncerState {
3✔
1552
        return syncerState(atomic.LoadUint32(&g.state))
3✔
1553
}
3✔
1554

1555
// ResetSyncedSignal returns a channel that will be closed in order to serve as
1556
// a signal for when the GossipSyncer has reached its chansSynced state.
1557
func (g *GossipSyncer) ResetSyncedSignal() chan struct{} {
3✔
1558
        g.Lock()
3✔
1559
        defer g.Unlock()
3✔
1560

3✔
1561
        syncedSignal := make(chan struct{})
3✔
1562

3✔
1563
        syncState := syncerState(atomic.LoadUint32(&g.state))
3✔
1564
        if syncState == chansSynced {
4✔
1565
                close(syncedSignal)
1✔
1566
                return syncedSignal
1✔
1567
        }
1✔
1568

1569
        g.syncedSignal = syncedSignal
3✔
1570
        return g.syncedSignal
3✔
1571
}
1572

1573
// ProcessSyncTransition sends a request to the gossip syncer to transition its
1574
// sync type to a new one.
1575
//
1576
// NOTE: This can only be done once the gossip syncer has reached its final
1577
// chansSynced state.
1578
func (g *GossipSyncer) ProcessSyncTransition(newSyncType SyncerType) error {
3✔
1579
        errChan := make(chan error, 1)
3✔
1580
        select {
3✔
1581
        case g.syncTransitionReqs <- &syncTransitionReq{
1582
                newSyncType: newSyncType,
1583
                errChan:     errChan,
1584
        }:
3✔
1585
        case <-time.After(syncTransitionTimeout):
×
1586
                return ErrSyncTransitionTimeout
×
1587
        case <-g.quit:
×
1588
                return ErrGossipSyncerExiting
×
1589
        }
1590

1591
        select {
3✔
1592
        case err := <-errChan:
3✔
1593
                return err
3✔
1594
        case <-g.quit:
×
1595
                return ErrGossipSyncerExiting
×
1596
        }
1597
}
1598

1599
// handleSyncTransition handles a new sync type transition request.
1600
//
1601
// NOTE: The gossip syncer might have another sync state as a result of this
1602
// transition.
1603
func (g *GossipSyncer) handleSyncTransition(req *syncTransitionReq) error {
3✔
1604
        // Return early from any NOP sync transitions.
3✔
1605
        syncType := g.SyncType()
3✔
1606
        if syncType == req.newSyncType {
3✔
1607
                return nil
×
1608
        }
×
1609

1610
        log.Debugf("GossipSyncer(%x): transitioning from %v to %v",
3✔
1611
                g.cfg.peerPub, syncType, req.newSyncType)
3✔
1612

3✔
1613
        var (
3✔
1614
                firstTimestamp time.Time
3✔
1615
                timestampRange uint32
3✔
1616
        )
3✔
1617

3✔
1618
        switch req.newSyncType {
3✔
1619
        // If an active sync has been requested, then we should resume receiving
1620
        // new graph updates from the remote peer.
1621
        case ActiveSync, PinnedSync:
3✔
1622
                firstTimestamp = time.Now()
3✔
1623
                timestampRange = math.MaxUint32
3✔
1624

1625
        // If a PassiveSync transition has been requested, then we should no
1626
        // longer receive any new updates from the remote peer. We can do this
1627
        // by setting our update horizon to a range in the past ensuring no
1628
        // graph updates match the timestamp range.
1629
        case PassiveSync:
×
1630
                firstTimestamp = zeroTimestamp
×
1631
                timestampRange = 0
×
1632

1633
        default:
×
1634
                return fmt.Errorf("unhandled sync transition %v",
×
1635
                        req.newSyncType)
×
1636
        }
1637

1638
        err := g.sendGossipTimestampRange(firstTimestamp, timestampRange)
3✔
1639
        if err != nil {
3✔
1640
                return fmt.Errorf("unable to send local update horizon: %w",
×
1641
                        err)
×
1642
        }
×
1643

1644
        g.setSyncType(req.newSyncType)
3✔
1645

3✔
1646
        return nil
3✔
1647
}
1648

1649
// setSyncType sets the gossip syncer's sync type to the given type.
1650
func (g *GossipSyncer) setSyncType(syncType SyncerType) {
3✔
1651
        atomic.StoreUint32(&g.syncType, uint32(syncType))
3✔
1652
}
3✔
1653

1654
// SyncType returns the current SyncerType of the target GossipSyncer.
1655
func (g *GossipSyncer) SyncType() SyncerType {
3✔
1656
        return SyncerType(atomic.LoadUint32(&g.syncType))
3✔
1657
}
3✔
1658

1659
// historicalSync sends a request to the gossip syncer to perofmr a historical
1660
// sync.
1661
//
1662
// NOTE: This can only be done once the gossip syncer has reached its final
1663
// chansSynced state.
1664
func (g *GossipSyncer) historicalSync() error {
3✔
1665
        done := make(chan struct{})
3✔
1666

3✔
1667
        select {
3✔
1668
        case g.historicalSyncReqs <- &historicalSyncReq{
1669
                doneChan: done,
1670
        }:
3✔
1671
        case <-time.After(syncTransitionTimeout):
×
1672
                return ErrSyncTransitionTimeout
×
1673
        case <-g.quit:
×
1674
                return ErrGossiperShuttingDown
×
1675
        }
1676

1677
        select {
3✔
1678
        case <-done:
3✔
1679
                return nil
3✔
1680
        case <-g.quit:
×
1681
                return ErrGossiperShuttingDown
×
1682
        }
1683
}
1684

1685
// handleHistoricalSync handles a request to the gossip syncer to perform a
1686
// historical sync.
1687
func (g *GossipSyncer) handleHistoricalSync(req *historicalSyncReq) {
3✔
1688
        // We'll go back to our initial syncingChans state in order to request
3✔
1689
        // the remote peer to give us all of the channel IDs they know of
3✔
1690
        // starting from the genesis block.
3✔
1691
        g.genHistoricalChanRangeQuery = true
3✔
1692
        g.setSyncState(syncingChans)
3✔
1693
        close(req.doneChan)
3✔
1694
}
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc