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

lightningnetwork / lnd / 15959600311

29 Jun 2025 09:33PM UTC coverage: 67.577% (-0.03%) from 67.606%
15959600311

Pull #8825

github

web-flow
Merge b3542eca4 into 6290edf14
Pull Request #8825: lnd: use persisted node announcement settings across restarts

44 of 49 new or added lines in 1 file covered. (89.8%)

92 existing lines in 17 files now uncovered.

135081 of 199891 relevant lines covered (67.58%)

21854.87 hits per line

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

84.97
/discovery/syncer.go
1
package discovery
2

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

135
        case waitingQueryRangeReply:
3✔
136
                return "waitingQueryRangeReply"
3✔
137

138
        case queryNewChannels:
3✔
139
                return "queryNewChannels"
3✔
140

141
        case waitingQueryChanReply:
3✔
142
                return "waitingQueryChanReply"
3✔
143

144
        case chansSynced:
4✔
145
                return "chansSynced"
4✔
146

147
        case syncerIdle:
3✔
148
                return "syncerIdle"
3✔
149

150
        default:
×
151
                return "UNKNOWN STATE"
×
152
        }
153
}
154

155
const (
156
        // maxQueryChanRangeReplies specifies the default limit of replies to
157
        // process for a single QueryChannelRange request.
158
        maxQueryChanRangeReplies = 500
159

160
        // maxQueryChanRangeRepliesZlibFactor specifies the factor applied to
161
        // the maximum number of replies allowed for zlib encoded replies.
162
        maxQueryChanRangeRepliesZlibFactor = 4
163

164
        // chanRangeQueryBuffer is the number of blocks back that we'll go when
165
        // asking the remote peer for their any channels they know of beyond
166
        // our highest known channel ID.
167
        chanRangeQueryBuffer = 144
168

169
        // syncTransitionTimeout is the default timeout in which we'll wait up
170
        // to when attempting to perform a sync transition.
171
        syncTransitionTimeout = 5 * time.Second
172

173
        // requestBatchSize is the maximum number of channels we will query the
174
        // remote peer for in a QueryShortChanIDs message.
175
        requestBatchSize = 500
176

177
        // syncerBufferSize is the size of the syncer's buffers.
178
        syncerBufferSize = 50
179
)
180

181
var (
182
        // encodingTypeToChunkSize maps an encoding type, to the max number of
183
        // short chan ID's using the encoding type that we can fit into a
184
        // single message safely.
185
        encodingTypeToChunkSize = map[lnwire.QueryEncoding]int32{
186
                lnwire.EncodingSortedPlain: 8000,
187
        }
188

189
        // ErrGossipSyncerExiting signals that the syncer has been killed.
190
        ErrGossipSyncerExiting = errors.New("gossip syncer exiting")
191

192
        // ErrSyncTransitionTimeout is an error returned when we've timed out
193
        // attempting to perform a sync transition.
194
        ErrSyncTransitionTimeout = errors.New("timed out attempting to " +
195
                "transition sync type")
196

197
        // zeroTimestamp is the timestamp we'll use when we want to indicate to
198
        // peers that we do not want to receive any new graph updates.
199
        zeroTimestamp time.Time
200
)
201

202
// syncTransitionReq encapsulates a request for a gossip syncer sync transition.
203
type syncTransitionReq struct {
204
        newSyncType SyncerType
205
        errChan     chan error
206
}
207

208
// historicalSyncReq encapsulates a request for a gossip syncer to perform a
209
// historical sync.
210
type historicalSyncReq struct {
211
        // doneChan is a channel that serves as a signal and is closed to ensure
212
        // the historical sync is attempted by the time we return to the caller.
213
        doneChan chan struct{}
214
}
215

216
// gossipSyncerCfg is a struct that packages all the information a GossipSyncer
217
// needs to carry out its duties.
218
type gossipSyncerCfg struct {
219
        // chainHash is the chain that this syncer is responsible for.
220
        chainHash chainhash.Hash
221

222
        // peerPub is the public key of the peer we're syncing with, serialized
223
        // in compressed format.
224
        peerPub [33]byte
225

226
        // channelSeries is the primary interface that we'll use to generate
227
        // our queries and respond to the queries of the remote peer.
228
        channelSeries ChannelGraphTimeSeries
229

230
        // encodingType is the current encoding type we're aware of. Requests
231
        // with different encoding types will be rejected.
232
        encodingType lnwire.QueryEncoding
233

234
        // chunkSize is the max number of short chan IDs using the syncer's
235
        // encoding type that we can fit into a single message safely.
236
        chunkSize int32
237

238
        // batchSize is the max number of channels the syncer will query from
239
        // the remote node in a single QueryShortChanIDs request.
240
        batchSize int32
241

242
        // sendToPeer sends a variadic number of messages to the remote peer.
243
        // This method should not block while waiting for sends to be written
244
        // to the wire.
245
        sendToPeer func(context.Context, ...lnwire.Message) error
246

247
        // sendToPeerSync sends a variadic number of messages to the remote
248
        // peer, blocking until all messages have been sent successfully or a
249
        // write error is encountered.
250
        sendToPeerSync func(context.Context, ...lnwire.Message) error
251

252
        // noSyncChannels will prevent the GossipSyncer from spawning a
253
        // channelGraphSyncer, meaning we will not try to reconcile unknown
254
        // channels with the remote peer.
255
        noSyncChannels bool
256

257
        // noReplyQueries will prevent the GossipSyncer from spawning a
258
        // replyHandler, meaning we will not reply to queries from our remote
259
        // peer.
260
        noReplyQueries bool
261

262
        // noTimestampQueryOption will prevent the GossipSyncer from querying
263
        // timestamps of announcement messages from the peer, and it will
264
        // prevent it from responding to timestamp queries.
265
        noTimestampQueryOption bool
266

267
        // ignoreHistoricalFilters will prevent syncers from replying with
268
        // historical data when the remote peer sets a gossip_timestamp_range.
269
        // This prevents ranges with old start times from causing us to dump the
270
        // graph on connect.
271
        ignoreHistoricalFilters bool
272

273
        // bestHeight returns the latest height known of the chain.
274
        bestHeight func() uint32
275

276
        // markGraphSynced updates the SyncManager's perception of whether we
277
        // have completed at least one historical sync.
278
        markGraphSynced func()
279

280
        // maxQueryChanRangeReplies is the maximum number of replies we'll allow
281
        // for a single QueryChannelRange request.
282
        maxQueryChanRangeReplies uint32
283

284
        // isStillZombieChannel takes the timestamps of the latest channel
285
        // updates for a channel and returns true if the channel should be
286
        // considered a zombie based on these timestamps.
287
        isStillZombieChannel func(time.Time, time.Time) bool
288
}
289

290
// GossipSyncer is a struct that handles synchronizing the channel graph state
291
// with a remote peer. The GossipSyncer implements a state machine that will
292
// progressively ensure we're synchronized with the channel state of the remote
293
// node. Once both nodes have been synchronized, we'll use an update filter to
294
// filter out which messages should be sent to a remote peer based on their
295
// update horizon. If the update horizon isn't specified, then we won't send
296
// them any channel updates at all.
297
type GossipSyncer struct {
298
        started sync.Once
299
        stopped sync.Once
300

301
        // state is the current state of the GossipSyncer.
302
        //
303
        // NOTE: This variable MUST be used atomically.
304
        state uint32
305

306
        // syncType denotes the SyncerType the gossip syncer is currently
307
        // exercising.
308
        //
309
        // NOTE: This variable MUST be used atomically.
310
        syncType uint32
311

312
        // remoteUpdateHorizon is the update horizon of the remote peer. We'll
313
        // use this to properly filter out any messages.
314
        remoteUpdateHorizon *lnwire.GossipTimestampRange
315

316
        // localUpdateHorizon is our local update horizon, we'll use this to
317
        // determine if we've already sent out our update.
318
        localUpdateHorizon *lnwire.GossipTimestampRange
319

320
        // syncTransitions is a channel through which new sync type transition
321
        // requests will be sent through. These requests should only be handled
322
        // when the gossip syncer is in a chansSynced state to ensure its state
323
        // machine behaves as expected.
324
        syncTransitionReqs chan *syncTransitionReq
325

326
        // historicalSyncReqs is a channel that serves as a signal for the
327
        // gossip syncer to perform a historical sync. These can only be done
328
        // once the gossip syncer is in a chansSynced state to ensure its state
329
        // machine behaves as expected.
330
        historicalSyncReqs chan *historicalSyncReq
331

332
        // genHistoricalChanRangeQuery when true signals to the gossip syncer
333
        // that it should request the remote peer for all of its known channel
334
        // IDs starting from the genesis block of the chain. This can only
335
        // happen if the gossip syncer receives a request to attempt a
336
        // historical sync. It can be unset if the syncer ever transitions from
337
        // PassiveSync to ActiveSync.
338
        genHistoricalChanRangeQuery bool
339

340
        // gossipMsgs is a channel that all responses to our queries from the
341
        // target peer will be sent over, these will be read by the
342
        // channelGraphSyncer.
343
        gossipMsgs chan lnwire.Message
344

345
        // queryMsgs is a channel that all queries from the remote peer will be
346
        // received over, these will be read by the replyHandler.
347
        queryMsgs chan lnwire.Message
348

349
        // curQueryRangeMsg keeps track of the latest QueryChannelRange message
350
        // we've sent to a peer to ensure we've consumed all expected replies.
351
        // This field is primarily used within the waitingQueryChanReply state.
352
        curQueryRangeMsg *lnwire.QueryChannelRange
353

354
        // prevReplyChannelRange keeps track of the previous ReplyChannelRange
355
        // message we've received from a peer to ensure they've fully replied to
356
        // our query by ensuring they covered our requested block range. This
357
        // field is primarily used within the waitingQueryChanReply state.
358
        prevReplyChannelRange *lnwire.ReplyChannelRange
359

360
        // bufferedChanRangeReplies is used in the waitingQueryChanReply to
361
        // buffer all the chunked response to our query.
362
        bufferedChanRangeReplies []graphdb.ChannelUpdateInfo
363

364
        // numChanRangeRepliesRcvd is used to track the number of replies
365
        // received as part of a QueryChannelRange. This field is primarily used
366
        // within the waitingQueryChanReply state.
367
        numChanRangeRepliesRcvd uint32
368

369
        // newChansToQuery is used to pass the set of channels we should query
370
        // for from the waitingQueryChanReply state to the queryNewChannels
371
        // state.
372
        newChansToQuery []lnwire.ShortChannelID
373

374
        cfg gossipSyncerCfg
375

376
        // syncedSignal is a channel that, if set, will be closed when the
377
        // GossipSyncer reaches its terminal chansSynced state.
378
        syncedSignal chan struct{}
379

380
        // syncerSema is used to more finely control the syncer's ability to
381
        // respond to gossip timestamp range messages.
382
        syncerSema chan struct{}
383

384
        sync.Mutex
385

386
        // cg is a helper that encapsulates a wait group and quit channel and
387
        // allows contexts that either block or cancel on those depending on
388
        // the use case.
389
        cg *fn.ContextGuard
390
}
391

392
// newGossipSyncer returns a new instance of the GossipSyncer populated using
393
// the passed config.
394
func newGossipSyncer(cfg gossipSyncerCfg, sema chan struct{}) *GossipSyncer {
52✔
395
        return &GossipSyncer{
52✔
396
                cfg:                cfg,
52✔
397
                syncTransitionReqs: make(chan *syncTransitionReq),
52✔
398
                historicalSyncReqs: make(chan *historicalSyncReq),
52✔
399
                gossipMsgs:         make(chan lnwire.Message, syncerBufferSize),
52✔
400
                queryMsgs:          make(chan lnwire.Message, syncerBufferSize),
52✔
401
                syncerSema:         sema,
52✔
402
                cg:                 fn.NewContextGuard(),
52✔
403
        }
52✔
404
}
52✔
405

406
// Start starts the GossipSyncer and any goroutines that it needs to carry out
407
// its duties.
408
func (g *GossipSyncer) Start() {
38✔
409
        g.started.Do(func() {
76✔
410
                log.Debugf("Starting GossipSyncer(%x)", g.cfg.peerPub[:])
38✔
411

38✔
412
                ctx, _ := g.cg.Create(context.Background())
38✔
413

38✔
414
                // TODO(conner): only spawn channelGraphSyncer if remote
38✔
415
                // supports gossip queries, and only spawn replyHandler if we
38✔
416
                // advertise support
38✔
417
                if !g.cfg.noSyncChannels {
75✔
418
                        g.cg.WgAdd(1)
37✔
419
                        go g.channelGraphSyncer(ctx)
37✔
420
                }
37✔
421
                if !g.cfg.noReplyQueries {
75✔
422
                        g.cg.WgAdd(1)
37✔
423
                        go g.replyHandler(ctx)
37✔
424
                }
37✔
425
        })
426
}
427

428
// Stop signals the GossipSyncer for a graceful exit, then waits until it has
429
// exited.
430
func (g *GossipSyncer) Stop() {
35✔
431
        g.stopped.Do(func() {
70✔
432
                log.Debugf("Stopping GossipSyncer(%x)", g.cfg.peerPub[:])
35✔
433
                defer log.Debugf("GossipSyncer(%x) stopped", g.cfg.peerPub[:])
35✔
434

35✔
435
                g.cg.Quit()
35✔
436
        })
35✔
437
}
438

439
// handleSyncingChans handles the state syncingChans for the GossipSyncer. When
440
// in this state, we will send a QueryChannelRange msg to our peer and advance
441
// the syncer's state to waitingQueryRangeReply.
442
func (g *GossipSyncer) handleSyncingChans(ctx context.Context) {
23✔
443
        // Prepare the query msg.
23✔
444
        queryRangeMsg, err := g.genChanRangeQuery(
23✔
445
                ctx, g.genHistoricalChanRangeQuery,
23✔
446
        )
23✔
447
        if err != nil {
23✔
448
                log.Errorf("Unable to gen chan range query: %v", err)
×
449
                return
×
450
        }
×
451

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

23✔
461
        // Send the msg to the remote peer, which is non-blocking as
23✔
462
        // `sendToPeer` only queues the msg in Brontide.
23✔
463
        err = g.cfg.sendToPeer(ctx, queryRangeMsg)
23✔
464
        if err != nil {
23✔
465
                log.Errorf("Unable to send chan range query: %v", err)
×
466
                return
×
467
        }
×
468

469
        // With the message sent successfully, we'll transition into the next
470
        // state where we wait for their reply.
471
        g.setSyncState(waitingQueryRangeReply)
23✔
472
}
473

474
// channelGraphSyncer is the main goroutine responsible for ensuring that we
475
// properly channel graph state with the remote peer, and also that we only
476
// send them messages which actually pass their defined update horizon.
477
func (g *GossipSyncer) channelGraphSyncer(ctx context.Context) {
37✔
478
        defer g.cg.WgDone()
37✔
479

37✔
480
        for {
246✔
481
                state := g.syncState()
209✔
482
                syncType := g.SyncType()
209✔
483

209✔
484
                log.Debugf("GossipSyncer(%x): state=%v, type=%v",
209✔
485
                        g.cfg.peerPub[:], state, syncType)
209✔
486

209✔
487
                switch state {
209✔
488
                // When we're in this state, we're trying to synchronize our
489
                // view of the network with the remote peer. We'll kick off
490
                // this sync by asking them for the set of channels they
491
                // understand, as we'll as responding to any other queries by
492
                // them.
493
                case syncingChans:
23✔
494
                        g.handleSyncingChans(ctx)
23✔
495

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

525
                                log.Warnf("Unexpected message: %T in state=%v",
×
526
                                        msg, state)
×
527

528
                        case <-g.cg.Done():
×
529
                                return
×
530

531
                        case <-ctx.Done():
5✔
532
                                return
5✔
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:
6✔
539
                        // First, we'll attempt to continue our channel
6✔
540
                        // synchronization by continuing to send off another
6✔
541
                        // query chunk.
6✔
542
                        done := g.synchronizeChanIDs(ctx)
6✔
543

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

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

4✔
554
                        // Ensure that the sync manager becomes aware that the
4✔
555
                        // historical sync completed so synced_to_graph is
4✔
556
                        // updated over rpc.
4✔
557
                        g.cfg.markGraphSynced()
4✔
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:
5✔
564
                        // Once we've sent off our query, we'll wait for either
5✔
565
                        // an ending reply, or just another query from the
5✔
566
                        // remote peer.
5✔
567
                        select {
5✔
568
                        case msg := <-g.gossipMsgs:
5✔
569
                                // If this is the final reply to one of our
5✔
570
                                // queries, then we'll loop back into our query
5✔
571
                                // state to send of the remaining query chunks.
5✔
572
                                _, ok := msg.(*lnwire.ReplyShortChanIDsEnd)
5✔
573
                                if ok {
10✔
574
                                        g.setSyncState(queryNewChannels)
5✔
575
                                        continue
5✔
576
                                }
577

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

581
                        case <-g.cg.Done():
×
582
                                return
×
583

584
                        case <-ctx.Done():
×
585
                                return
×
586
                        }
587

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

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

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

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

627
                        case req := <-g.historicalSyncReqs:
19✔
628
                                g.handleHistoricalSync(req)
19✔
629

630
                        case <-g.cg.Done():
1✔
631
                                return
1✔
632

633
                        case <-ctx.Done():
28✔
634
                                return
28✔
635
                        }
636
                }
637
        }
638
}
639

640
// replyHandler is an event loop whose sole purpose is to reply to the remote
641
// peers queries. Our replyHandler will respond to messages generated by their
642
// channelGraphSyncer, and vice versa. Each party's channelGraphSyncer drives
643
// the other's replyHandler, allowing the replyHandler to operate independently
644
// from the state machine maintained on the same node.
645
//
646
// NOTE: This method MUST be run as a goroutine.
647
func (g *GossipSyncer) replyHandler(ctx context.Context) {
37✔
648
        defer g.cg.WgDone()
37✔
649

37✔
650
        for {
79✔
651
                select {
42✔
652
                case msg := <-g.queryMsgs:
8✔
653
                        err := g.replyPeerQueries(ctx, msg)
8✔
654
                        switch {
8✔
655
                        case err == ErrGossipSyncerExiting:
×
656
                                return
×
657

658
                        case err == lnpeer.ErrPeerExiting:
×
659
                                return
×
660

661
                        case err != nil:
×
662
                                log.Errorf("Unable to reply to peer "+
×
663
                                        "query: %v", err)
×
664
                        }
665

UNCOV
666
                case <-g.cg.Done():
×
UNCOV
667
                        return
×
668

669
                case <-ctx.Done():
34✔
670
                        return
34✔
671
                }
672
        }
673
}
674

675
// sendGossipTimestampRange constructs and sets a GossipTimestampRange for the
676
// syncer and sends it to the remote peer.
677
func (g *GossipSyncer) sendGossipTimestampRange(ctx context.Context,
678
        firstTimestamp time.Time, timestampRange uint32) error {
31✔
679

31✔
680
        endTimestamp := firstTimestamp.Add(
31✔
681
                time.Duration(timestampRange) * time.Second,
31✔
682
        )
31✔
683

31✔
684
        log.Infof("GossipSyncer(%x): applying gossipFilter(start=%v, end=%v)",
31✔
685
                g.cfg.peerPub[:], firstTimestamp, endTimestamp)
31✔
686

31✔
687
        localUpdateHorizon := &lnwire.GossipTimestampRange{
31✔
688
                ChainHash:      g.cfg.chainHash,
31✔
689
                FirstTimestamp: uint32(firstTimestamp.Unix()),
31✔
690
                TimestampRange: timestampRange,
31✔
691
        }
31✔
692

31✔
693
        if err := g.cfg.sendToPeer(ctx, localUpdateHorizon); err != nil {
31✔
694
                return err
×
695
        }
×
696

697
        if firstTimestamp == zeroTimestamp && timestampRange == 0 {
33✔
698
                g.localUpdateHorizon = nil
2✔
699
        } else {
31✔
700
                g.localUpdateHorizon = localUpdateHorizon
29✔
701
        }
29✔
702

703
        return nil
31✔
704
}
705

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

4✔
720
                return true
4✔
721
        }
4✔
722

723
        // Otherwise, we'll issue our next chunked query to receive replies
724
        // for.
725
        var queryChunk []lnwire.ShortChannelID
8✔
726

8✔
727
        // If the number of channels to query for is less than the chunk size,
8✔
728
        // then we can issue a single query.
8✔
729
        if int32(len(g.newChansToQuery)) < g.cfg.batchSize {
13✔
730
                queryChunk = g.newChansToQuery
5✔
731
                g.newChansToQuery = nil
5✔
732

5✔
733
        } else {
8✔
734
                // Otherwise, we'll need to only query for the next chunk.
3✔
735
                // We'll slice into our query chunk, then slide down our main
3✔
736
                // pointer down by the chunk size.
3✔
737
                queryChunk = g.newChansToQuery[:g.cfg.batchSize]
3✔
738
                g.newChansToQuery = g.newChansToQuery[g.cfg.batchSize:]
3✔
739
        }
3✔
740

741
        log.Infof("GossipSyncer(%x): querying for %v new channels",
8✔
742
                g.cfg.peerPub[:], len(queryChunk))
8✔
743

8✔
744
        // Change the state before sending the query msg.
8✔
745
        g.setSyncState(waitingQueryChanReply)
8✔
746

8✔
747
        // With our chunk obtained, we'll send over our next query, then return
8✔
748
        // false indicating that we're net yet fully synced.
8✔
749
        err := g.cfg.sendToPeer(ctx, &lnwire.QueryShortChanIDs{
8✔
750
                ChainHash:    g.cfg.chainHash,
8✔
751
                EncodingType: lnwire.EncodingSortedPlain,
8✔
752
                ShortChanIDs: queryChunk,
8✔
753
        })
8✔
754
        if err != nil {
8✔
755
                log.Errorf("Unable to sync chan IDs: %v", err)
×
756
        }
×
757

758
        return false
8✔
759
}
760

761
// isLegacyReplyChannelRange determines where a ReplyChannelRange message is
762
// considered legacy. There was a point where lnd used to include the same query
763
// over multiple replies, rather than including the portion of the query the
764
// reply is handling. We'll use this as a way of detecting whether we are
765
// communicating with a legacy node so we can properly sync with them.
766
func isLegacyReplyChannelRange(query *lnwire.QueryChannelRange,
767
        reply *lnwire.ReplyChannelRange) bool {
253✔
768

253✔
769
        return (reply.ChainHash == query.ChainHash &&
253✔
770
                reply.FirstBlockHeight == query.FirstBlockHeight &&
253✔
771
                reply.NumBlocks == query.NumBlocks)
253✔
772
}
253✔
773

774
// processChanRangeReply is called each time the GossipSyncer receives a new
775
// reply to the initial range query to discover new channels that it didn't
776
// previously know of.
777
func (g *GossipSyncer) processChanRangeReply(_ context.Context,
778
        msg *lnwire.ReplyChannelRange) error {
128✔
779

128✔
780
        // isStale returns whether the timestamp is too far into the past.
128✔
781
        isStale := func(timestamp time.Time) bool {
161✔
782
                return time.Since(timestamp) > graph.DefaultChannelPruneExpiry
33✔
783
        }
33✔
784

785
        // isSkewed returns whether the timestamp is too far into the future.
786
        isSkewed := func(timestamp time.Time) bool {
151✔
787
                return time.Until(timestamp) > graph.DefaultChannelPruneExpiry
23✔
788
        }
23✔
789

790
        // If we're not communicating with a legacy node, we'll apply some
791
        // further constraints on their reply to ensure it satisfies our query.
792
        if !isLegacyReplyChannelRange(g.curQueryRangeMsg, msg) {
238✔
793
                // The first block should be within our original request.
110✔
794
                if msg.FirstBlockHeight < g.curQueryRangeMsg.FirstBlockHeight {
110✔
795
                        return fmt.Errorf("reply includes channels for height "+
×
796
                                "%v prior to query %v", msg.FirstBlockHeight,
×
797
                                g.curQueryRangeMsg.FirstBlockHeight)
×
798
                }
×
799

800
                // The last block should also be. We don't need to check the
801
                // intermediate ones because they should already be in sorted
802
                // order.
803
                replyLastHeight := msg.LastBlockHeight()
110✔
804
                queryLastHeight := g.curQueryRangeMsg.LastBlockHeight()
110✔
805
                if replyLastHeight > queryLastHeight {
110✔
806
                        return fmt.Errorf("reply includes channels for height "+
×
807
                                "%v after query %v", replyLastHeight,
×
808
                                queryLastHeight)
×
809
                }
×
810

811
                // If we've previously received a reply for this query, look at
812
                // its last block to ensure the current reply properly follows
813
                // it.
814
                if g.prevReplyChannelRange != nil {
215✔
815
                        prevReply := g.prevReplyChannelRange
105✔
816
                        prevReplyLastHeight := prevReply.LastBlockHeight()
105✔
817

105✔
818
                        // The current reply can either start from the previous
105✔
819
                        // reply's last block, if there are still more channels
105✔
820
                        // for the same block, or the block after.
105✔
821
                        if msg.FirstBlockHeight != prevReplyLastHeight &&
105✔
822
                                msg.FirstBlockHeight != prevReplyLastHeight+1 {
105✔
823

×
824
                                return fmt.Errorf("first block of reply %v "+
×
825
                                        "does not continue from last block of "+
×
826
                                        "previous %v", msg.FirstBlockHeight,
×
827
                                        prevReplyLastHeight)
×
828
                        }
×
829
                }
830
        }
831

832
        g.prevReplyChannelRange = msg
128✔
833

128✔
834
        for i, scid := range msg.ShortChanIDs {
258✔
835
                info := graphdb.NewChannelUpdateInfo(
130✔
836
                        scid, time.Time{}, time.Time{},
130✔
837
                )
130✔
838

130✔
839
                if len(msg.Timestamps) != 0 {
145✔
840
                        t1 := time.Unix(int64(msg.Timestamps[i].Timestamp1), 0)
15✔
841
                        info.Node1UpdateTimestamp = t1
15✔
842

15✔
843
                        t2 := time.Unix(int64(msg.Timestamps[i].Timestamp2), 0)
15✔
844
                        info.Node2UpdateTimestamp = t2
15✔
845

15✔
846
                        // Sort out all channels with outdated or skewed
15✔
847
                        // timestamps. Both timestamps need to be out of
15✔
848
                        // boundaries for us to skip the channel and not query
15✔
849
                        // it later on.
15✔
850
                        switch {
15✔
851
                        case isStale(info.Node1UpdateTimestamp) &&
852
                                isStale(info.Node2UpdateTimestamp):
2✔
853

2✔
854
                                continue
2✔
855

856
                        case isSkewed(info.Node1UpdateTimestamp) &&
857
                                isSkewed(info.Node2UpdateTimestamp):
2✔
858

2✔
859
                                continue
2✔
860

861
                        case isStale(info.Node1UpdateTimestamp) &&
862
                                isSkewed(info.Node2UpdateTimestamp):
2✔
863

2✔
864
                                continue
2✔
865

866
                        case isStale(info.Node2UpdateTimestamp) &&
867
                                isSkewed(info.Node1UpdateTimestamp):
2✔
868

2✔
869
                                continue
2✔
870
                        }
871
                }
872

873
                g.bufferedChanRangeReplies = append(
122✔
874
                        g.bufferedChanRangeReplies, info,
122✔
875
                )
122✔
876
        }
877

878
        switch g.cfg.encodingType {
128✔
879
        case lnwire.EncodingSortedPlain:
128✔
880
                g.numChanRangeRepliesRcvd++
128✔
881
        case lnwire.EncodingSortedZlib:
×
882
                g.numChanRangeRepliesRcvd += maxQueryChanRangeRepliesZlibFactor
×
883
        default:
×
884
                return fmt.Errorf("unhandled encoding type %v", g.cfg.encodingType)
×
885
        }
886

887
        log.Infof("GossipSyncer(%x): buffering chan range reply of size=%v",
128✔
888
                g.cfg.peerPub[:], len(msg.ShortChanIDs))
128✔
889

128✔
890
        // If this isn't the last response and we can continue to receive more,
128✔
891
        // then we can exit as we've already buffered the latest portion of the
128✔
892
        // streaming reply.
128✔
893
        maxReplies := g.cfg.maxQueryChanRangeReplies
128✔
894
        switch {
128✔
895
        // If we're communicating with a legacy node, we'll need to look at the
896
        // complete field.
897
        case isLegacyReplyChannelRange(g.curQueryRangeMsg, msg):
18✔
898
                if msg.Complete == 0 && g.numChanRangeRepliesRcvd < maxReplies {
21✔
899
                        return nil
3✔
900
                }
3✔
901

902
        // Otherwise, we'll look at the reply's height range.
903
        default:
110✔
904
                replyLastHeight := msg.LastBlockHeight()
110✔
905
                queryLastHeight := g.curQueryRangeMsg.LastBlockHeight()
110✔
906

110✔
907
                // TODO(wilmer): This might require some padding if the remote
110✔
908
                // node is not aware of the last height we sent them, i.e., is
110✔
909
                // behind a few blocks from us.
110✔
910
                if replyLastHeight < queryLastHeight &&
110✔
911
                        g.numChanRangeRepliesRcvd < maxReplies {
215✔
912

105✔
913
                        return nil
105✔
914
                }
105✔
915
        }
916

917
        log.Infof("GossipSyncer(%x): filtering through %v chans",
20✔
918
                g.cfg.peerPub[:], len(g.bufferedChanRangeReplies))
20✔
919

20✔
920
        // Otherwise, this is the final response, so we'll now check to see
20✔
921
        // which channels they know of that we don't.
20✔
922
        newChans, err := g.cfg.channelSeries.FilterKnownChanIDs(
20✔
923
                g.cfg.chainHash, g.bufferedChanRangeReplies,
20✔
924
                g.cfg.isStillZombieChannel,
20✔
925
        )
20✔
926
        if err != nil {
20✔
927
                return fmt.Errorf("unable to filter chan ids: %w", err)
×
928
        }
×
929

930
        // As we've received the entirety of the reply, we no longer need to
931
        // hold on to the set of buffered replies or the original query that
932
        // prompted the replies, so we'll let that be garbage collected now.
933
        g.curQueryRangeMsg = nil
20✔
934
        g.prevReplyChannelRange = nil
20✔
935
        g.bufferedChanRangeReplies = nil
20✔
936
        g.numChanRangeRepliesRcvd = 0
20✔
937

20✔
938
        // If there aren't any channels that we don't know of, then we can
20✔
939
        // switch straight to our terminal state.
20✔
940
        if len(newChans) == 0 {
37✔
941
                log.Infof("GossipSyncer(%x): remote peer has no new chans",
17✔
942
                        g.cfg.peerPub[:])
17✔
943

17✔
944
                g.setSyncState(chansSynced)
17✔
945

17✔
946
                // Ensure that the sync manager becomes aware that the
17✔
947
                // historical sync completed so synced_to_graph is updated over
17✔
948
                // rpc.
17✔
949
                g.cfg.markGraphSynced()
17✔
950
                return nil
17✔
951
        }
17✔
952

953
        // Otherwise, we'll set the set of channels that we need to query for
954
        // the next state, and also transition our state.
955
        g.newChansToQuery = newChans
6✔
956
        g.setSyncState(queryNewChannels)
6✔
957

6✔
958
        log.Infof("GossipSyncer(%x): starting query for %v new chans",
6✔
959
                g.cfg.peerPub[:], len(newChans))
6✔
960

6✔
961
        return nil
6✔
962
}
963

964
// genChanRangeQuery generates the initial message we'll send to the remote
965
// party when we're kicking off the channel graph synchronization upon
966
// connection. The historicalQuery boolean can be used to generate a query from
967
// the genesis block of the chain.
968
func (g *GossipSyncer) genChanRangeQuery(ctx context.Context,
969
        historicalQuery bool) (*lnwire.QueryChannelRange, error) {
27✔
970

27✔
971
        // First, we'll query our channel graph time series for its highest
27✔
972
        // known channel ID.
27✔
973
        newestChan, err := g.cfg.channelSeries.HighestChanID(
27✔
974
                ctx, g.cfg.chainHash,
27✔
975
        )
27✔
976
        if err != nil {
27✔
977
                return nil, err
×
978
        }
×
979

980
        // Once we have the chan ID of the newest, we'll obtain the block height
981
        // of the channel, then subtract our default horizon to ensure we don't
982
        // miss any channels. By default, we go back 1 day from the newest
983
        // channel, unless we're attempting a historical sync, where we'll
984
        // actually start from the genesis block instead.
985
        var startHeight uint32
27✔
986
        switch {
27✔
987
        case historicalQuery:
22✔
988
                fallthrough
22✔
989
        case newestChan.BlockHeight <= chanRangeQueryBuffer:
22✔
990
                startHeight = 0
22✔
991
        default:
5✔
992
                startHeight = newestChan.BlockHeight - chanRangeQueryBuffer
5✔
993
        }
994

995
        // Determine the number of blocks to request based on our best height.
996
        // We'll take into account any potential underflows and explicitly set
997
        // numBlocks to its minimum value of 1 if so.
998
        bestHeight := g.cfg.bestHeight()
27✔
999
        numBlocks := bestHeight - startHeight
27✔
1000
        if int64(numBlocks) < 1 {
27✔
1001
                numBlocks = 1
×
1002
        }
×
1003

1004
        log.Infof("GossipSyncer(%x): requesting new chans from height=%v "+
27✔
1005
                "and %v blocks after", g.cfg.peerPub[:], startHeight, numBlocks)
27✔
1006

27✔
1007
        // Finally, we'll craft the channel range query, using our starting
27✔
1008
        // height, then asking for all known channels to the foreseeable end of
27✔
1009
        // the main chain.
27✔
1010
        query := &lnwire.QueryChannelRange{
27✔
1011
                ChainHash:        g.cfg.chainHash,
27✔
1012
                FirstBlockHeight: startHeight,
27✔
1013
                NumBlocks:        numBlocks,
27✔
1014
        }
27✔
1015

27✔
1016
        if !g.cfg.noTimestampQueryOption {
46✔
1017
                query.QueryOptions = lnwire.NewTimestampQueryOption()
19✔
1018
        }
19✔
1019

1020
        g.curQueryRangeMsg = query
27✔
1021

27✔
1022
        return query, nil
27✔
1023
}
1024

1025
// replyPeerQueries is called in response to any query by the remote peer.
1026
// We'll examine our state and send back our best response.
1027
func (g *GossipSyncer) replyPeerQueries(ctx context.Context,
1028
        msg lnwire.Message) error {
8✔
1029

8✔
1030
        switch msg := msg.(type) {
8✔
1031

1032
        // In this state, we'll also handle any incoming channel range queries
1033
        // from the remote peer as they're trying to sync their state as well.
1034
        case *lnwire.QueryChannelRange:
6✔
1035
                return g.replyChanRangeQuery(ctx, msg)
6✔
1036

1037
        // If the remote peer skips straight to requesting new channels that
1038
        // they don't know of, then we'll ensure that we also handle this case.
1039
        case *lnwire.QueryShortChanIDs:
5✔
1040
                return g.replyShortChanIDs(ctx, msg)
5✔
1041

1042
        default:
×
1043
                return fmt.Errorf("unknown message: %T", msg)
×
1044
        }
1045
}
1046

1047
// replyChanRangeQuery will be dispatched in response to a channel range query
1048
// by the remote node. We'll query the channel time series for channels that
1049
// meet the channel range, then chunk our responses to the remote node. We also
1050
// ensure that our final fragment carries the "complete" bit to indicate the
1051
// end of our streaming response.
1052
func (g *GossipSyncer) replyChanRangeQuery(ctx context.Context,
1053
        query *lnwire.QueryChannelRange) error {
12✔
1054

12✔
1055
        // Before responding, we'll check to ensure that the remote peer is
12✔
1056
        // querying for the same chain that we're on. If not, we'll send back a
12✔
1057
        // response with a complete value of zero to indicate we're on a
12✔
1058
        // different chain.
12✔
1059
        if g.cfg.chainHash != query.ChainHash {
13✔
1060
                log.Warnf("Remote peer requested QueryChannelRange for "+
1✔
1061
                        "chain=%v, we're on chain=%v", query.ChainHash,
1✔
1062
                        g.cfg.chainHash)
1✔
1063

1✔
1064
                return g.cfg.sendToPeerSync(ctx, &lnwire.ReplyChannelRange{
1✔
1065
                        ChainHash:        query.ChainHash,
1✔
1066
                        FirstBlockHeight: query.FirstBlockHeight,
1✔
1067
                        NumBlocks:        query.NumBlocks,
1✔
1068
                        Complete:         0,
1✔
1069
                        EncodingType:     g.cfg.encodingType,
1✔
1070
                        ShortChanIDs:     nil,
1✔
1071
                })
1✔
1072
        }
1✔
1073

1074
        log.Infof("GossipSyncer(%x): filtering chan range: start_height=%v, "+
11✔
1075
                "num_blocks=%v", g.cfg.peerPub[:], query.FirstBlockHeight,
11✔
1076
                query.NumBlocks)
11✔
1077

11✔
1078
        // Check if the query asked for timestamps. We will only serve
11✔
1079
        // timestamps if this has not been disabled with
11✔
1080
        // noTimestampQueryOption.
11✔
1081
        withTimestamps := query.WithTimestamps() &&
11✔
1082
                !g.cfg.noTimestampQueryOption
11✔
1083

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

1095
        // TODO(roasbeef): means can't send max uint above?
1096
        //  * or make internal 64
1097

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

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

1115
                var timestamps lnwire.Timestamps
16✔
1116
                if withTimestamps {
19✔
1117
                        timestamps = make(lnwire.Timestamps, len(channelChunk))
3✔
1118
                }
3✔
1119

1120
                scids := make([]lnwire.ShortChannelID, len(channelChunk))
16✔
1121
                for i, info := range channelChunk {
33✔
1122
                        scids[i] = info.ShortChannelID
17✔
1123

17✔
1124
                        if !withTimestamps {
31✔
1125
                                continue
14✔
1126
                        }
1127

1128
                        timestamps[i].Timestamp1 = uint32(
3✔
1129
                                info.Node1UpdateTimestamp.Unix(),
3✔
1130
                        )
3✔
1131

3✔
1132
                        timestamps[i].Timestamp2 = uint32(
3✔
1133
                                info.Node2UpdateTimestamp.Unix(),
3✔
1134
                        )
3✔
1135
                }
1136

1137
                return g.cfg.sendToPeerSync(ctx, &lnwire.ReplyChannelRange{
16✔
1138
                        ChainHash:        query.ChainHash,
16✔
1139
                        NumBlocks:        numBlocks,
16✔
1140
                        FirstBlockHeight: firstHeight,
16✔
1141
                        Complete:         complete,
16✔
1142
                        EncodingType:     g.cfg.encodingType,
16✔
1143
                        ShortChanIDs:     scids,
16✔
1144
                        Timestamps:       timestamps,
16✔
1145
                })
16✔
1146
        }
1147

1148
        var (
11✔
1149
                firstHeight  = query.FirstBlockHeight
11✔
1150
                lastHeight   uint32
11✔
1151
                channelChunk []graphdb.ChannelUpdateInfo
11✔
1152
        )
11✔
1153

11✔
1154
        // chunkSize is the maximum number of SCIDs that we can safely put in a
11✔
1155
        // single message. If we also need to include timestamps though, then
11✔
1156
        // this number is halved since encoding two timestamps takes the same
11✔
1157
        // number of bytes as encoding an SCID.
11✔
1158
        chunkSize := g.cfg.chunkSize
11✔
1159
        if withTimestamps {
14✔
1160
                chunkSize /= 2
3✔
1161
        }
3✔
1162

1163
        for _, channelRange := range channelRanges {
28✔
1164
                channels := channelRange.Channels
17✔
1165
                numChannels := int32(len(channels))
17✔
1166
                numLeftToAdd := chunkSize - int32(len(channelChunk))
17✔
1167

17✔
1168
                // Include the current block in the ongoing chunk if it can fit
17✔
1169
                // and move on to the next block.
17✔
1170
                if numChannels <= numLeftToAdd {
29✔
1171
                        channelChunk = append(channelChunk, channels...)
12✔
1172
                        continue
12✔
1173
                }
1174

1175
                // Otherwise, we need to send our existing channel chunk as is
1176
                // as its own reply and start a new one for the current block.
1177
                // We'll mark the end of our current chunk as the height before
1178
                // the current block to ensure the whole query range is replied
1179
                // to.
1180
                log.Infof("GossipSyncer(%x): sending range chunk of size=%v",
5✔
1181
                        g.cfg.peerPub[:], len(channelChunk))
5✔
1182

5✔
1183
                lastHeight = channelRange.Height - 1
5✔
1184
                err := sendReplyForChunk(
5✔
1185
                        channelChunk, firstHeight, lastHeight, false,
5✔
1186
                )
5✔
1187
                if err != nil {
5✔
1188
                        return err
×
1189
                }
×
1190

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

5✔
1207
                // Sort the chunk once again if we had to shuffle it.
5✔
1208
                if exceedsChunkSize {
5✔
1209
                        sort.Slice(channelChunk, func(i, j int) bool {
×
1210
                                id1 := channelChunk[i].ShortChannelID.ToUint64()
×
1211
                                id2 := channelChunk[j].ShortChannelID.ToUint64()
×
1212

×
1213
                                return id1 < id2
×
1214
                        })
×
1215
                }
1216
        }
1217

1218
        // Send the remaining chunk as the final reply.
1219
        log.Infof("GossipSyncer(%x): sending final chan range chunk, size=%v",
11✔
1220
                g.cfg.peerPub[:], len(channelChunk))
11✔
1221

11✔
1222
        return sendReplyForChunk(
11✔
1223
                channelChunk, firstHeight, query.LastBlockHeight(), true,
11✔
1224
        )
11✔
1225
}
1226

1227
// replyShortChanIDs will be dispatched in response to a query by the remote
1228
// node for information concerning a set of short channel ID's. Our response
1229
// will be sent in a streaming chunked manner to ensure that we remain below
1230
// the current transport level message size.
1231
func (g *GossipSyncer) replyShortChanIDs(ctx context.Context,
1232
        query *lnwire.QueryShortChanIDs) error {
7✔
1233

7✔
1234
        // Before responding, we'll check to ensure that the remote peer is
7✔
1235
        // querying for the same chain that we're on. If not, we'll send back a
7✔
1236
        // response with a complete value of zero to indicate we're on a
7✔
1237
        // different chain.
7✔
1238
        if g.cfg.chainHash != query.ChainHash {
8✔
1239
                log.Warnf("Remote peer requested QueryShortChanIDs for "+
1✔
1240
                        "chain=%v, we're on chain=%v", query.ChainHash,
1✔
1241
                        g.cfg.chainHash)
1✔
1242

1✔
1243
                return g.cfg.sendToPeerSync(ctx, &lnwire.ReplyShortChanIDsEnd{
1✔
1244
                        ChainHash: query.ChainHash,
1✔
1245
                        Complete:  0,
1✔
1246
                })
1✔
1247
        }
1✔
1248

1249
        if len(query.ShortChanIDs) == 0 {
6✔
1250
                log.Infof("GossipSyncer(%x): ignoring query for blank short chan ID's",
×
1251
                        g.cfg.peerPub[:])
×
1252
                return nil
×
1253
        }
×
1254

1255
        log.Infof("GossipSyncer(%x): fetching chan anns for %v chans",
6✔
1256
                g.cfg.peerPub[:], len(query.ShortChanIDs))
6✔
1257

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

1270
        // Reply with any messages related to those channel ID's, we'll write
1271
        // each one individually and synchronously to throttle the sends and
1272
        // perform buffering of responses in the syncer as opposed to the peer.
1273
        for _, msg := range replyMsgs {
12✔
1274
                err := g.cfg.sendToPeerSync(ctx, msg)
6✔
1275
                if err != nil {
6✔
1276
                        return err
×
1277
                }
×
1278
        }
1279

1280
        // Regardless of whether we had any messages to reply with, send over
1281
        // the sentinel message to signal that the stream has terminated.
1282
        return g.cfg.sendToPeerSync(ctx, &lnwire.ReplyShortChanIDsEnd{
6✔
1283
                ChainHash: query.ChainHash,
6✔
1284
                Complete:  1,
6✔
1285
        })
6✔
1286
}
1287

1288
// ApplyGossipFilter applies a gossiper filter sent by the remote node to the
1289
// state machine. Once applied, we'll ensure that we don't forward any messages
1290
// to the peer that aren't within the time range of the filter.
1291
func (g *GossipSyncer) ApplyGossipFilter(ctx context.Context,
1292
        filter *lnwire.GossipTimestampRange) error {
6✔
1293

6✔
1294
        g.Lock()
6✔
1295

6✔
1296
        g.remoteUpdateHorizon = filter
6✔
1297

6✔
1298
        startTime := time.Unix(int64(g.remoteUpdateHorizon.FirstTimestamp), 0)
6✔
1299
        endTime := startTime.Add(
6✔
1300
                time.Duration(g.remoteUpdateHorizon.TimestampRange) * time.Second,
6✔
1301
        )
6✔
1302

6✔
1303
        g.Unlock()
6✔
1304

6✔
1305
        // If requested, don't reply with historical gossip data when the remote
6✔
1306
        // peer sets their gossip timestamp range.
6✔
1307
        if g.cfg.ignoreHistoricalFilters {
7✔
1308
                return nil
1✔
1309
        }
1✔
1310

1311
        select {
5✔
1312
        case <-g.syncerSema:
5✔
1313
        case <-g.cg.Done():
×
1314
                return ErrGossipSyncerExiting
×
1315
        case <-ctx.Done():
×
1316
                return ctx.Err()
×
1317
        }
1318

1319
        // We don't put this in a defer because if the goroutine is launched,
1320
        // it needs to be called when the goroutine is stopped.
1321
        returnSema := func() {
10✔
1322
                g.syncerSema <- struct{}{}
5✔
1323
        }
5✔
1324

1325
        // Now that the remote peer has applied their filter, we'll query the
1326
        // database for all the messages that are beyond this filter.
1327
        newUpdatestoSend, err := g.cfg.channelSeries.UpdatesInHorizon(
5✔
1328
                g.cfg.chainHash, startTime, endTime,
5✔
1329
        )
5✔
1330
        if err != nil {
5✔
1331
                returnSema()
×
1332
                return err
×
1333
        }
×
1334

1335
        log.Infof("GossipSyncer(%x): applying new remote update horizon: "+
5✔
1336
                "start=%v, end=%v, backlog_size=%v", g.cfg.peerPub[:],
5✔
1337
                startTime, endTime, len(newUpdatestoSend))
5✔
1338

5✔
1339
        // If we don't have any to send, then we can return early.
5✔
1340
        if len(newUpdatestoSend) == 0 {
9✔
1341
                returnSema()
4✔
1342
                return nil
4✔
1343
        }
4✔
1344

1345
        // We'll conclude by launching a goroutine to send out any updates.
1346
        g.cg.WgAdd(1)
4✔
1347
        go func() {
8✔
1348
                defer g.cg.WgDone()
4✔
1349
                defer returnSema()
4✔
1350

4✔
1351
                for _, msg := range newUpdatestoSend {
8✔
1352
                        err := g.cfg.sendToPeerSync(ctx, msg)
4✔
1353
                        switch {
4✔
1354
                        case err == ErrGossipSyncerExiting:
×
1355
                                return
×
1356

1357
                        case err == lnpeer.ErrPeerExiting:
×
1358
                                return
×
1359

1360
                        case err != nil:
×
1361
                                log.Errorf("Unable to send message for "+
×
1362
                                        "peer catch up: %v", err)
×
1363
                        }
1364
                }
1365
        }()
1366

1367
        return nil
4✔
1368
}
1369

1370
// FilterGossipMsgs takes a set of gossip messages, and only send it to a peer
1371
// iff the message is within the bounds of their set gossip filter. If the peer
1372
// doesn't have a gossip filter set, then no messages will be forwarded.
1373
func (g *GossipSyncer) FilterGossipMsgs(ctx context.Context,
1374
        msgs ...msgWithSenders) {
5✔
1375

5✔
1376
        // If the peer doesn't have an update horizon set, then we won't send
5✔
1377
        // it any new update messages.
5✔
1378
        if g.remoteUpdateHorizon == nil {
9✔
1379
                log.Tracef("GossipSyncer(%x): skipped due to nil "+
4✔
1380
                        "remoteUpdateHorizon", g.cfg.peerPub[:])
4✔
1381
                return
4✔
1382
        }
4✔
1383

1384
        // If we've been signaled to exit, or are exiting, then we'll stop
1385
        // short.
1386
        select {
4✔
1387
        case <-g.cg.Done():
×
1388
                return
×
1389
        case <-ctx.Done():
×
1390
                return
×
1391
        default:
4✔
1392
        }
1393

1394
        // TODO(roasbeef): need to ensure that peer still online...send msg to
1395
        // gossiper on peer termination to signal peer disconnect?
1396

1397
        var err error
4✔
1398

4✔
1399
        // Before we filter out the messages, we'll construct an index over the
4✔
1400
        // set of channel announcements and channel updates. This will allow us
4✔
1401
        // to quickly check if we should forward a chan ann, based on the known
4✔
1402
        // channel updates for a channel.
4✔
1403
        chanUpdateIndex := make(
4✔
1404
                map[lnwire.ShortChannelID][]*lnwire.ChannelUpdate1,
4✔
1405
        )
4✔
1406
        for _, msg := range msgs {
17✔
1407
                chanUpdate, ok := msg.msg.(*lnwire.ChannelUpdate1)
13✔
1408
                if !ok {
23✔
1409
                        continue
10✔
1410
                }
1411

1412
                chanUpdateIndex[chanUpdate.ShortChannelID] = append(
6✔
1413
                        chanUpdateIndex[chanUpdate.ShortChannelID], chanUpdate,
6✔
1414
                )
6✔
1415
        }
1416

1417
        // We'll construct a helper function that we'll us below to determine
1418
        // if a given messages passes the gossip msg filter.
1419
        g.Lock()
4✔
1420
        startTime := time.Unix(int64(g.remoteUpdateHorizon.FirstTimestamp), 0)
4✔
1421
        endTime := startTime.Add(
4✔
1422
                time.Duration(g.remoteUpdateHorizon.TimestampRange) * time.Second,
4✔
1423
        )
4✔
1424
        g.Unlock()
4✔
1425

4✔
1426
        passesFilter := func(timeStamp uint32) bool {
17✔
1427
                t := time.Unix(int64(timeStamp), 0)
13✔
1428
                return t.Equal(startTime) ||
13✔
1429
                        (t.After(startTime) && t.Before(endTime))
13✔
1430
        }
13✔
1431

1432
        msgsToSend := make([]lnwire.Message, 0, len(msgs))
4✔
1433
        for _, msg := range msgs {
17✔
1434
                // If the target peer is the peer that sent us this message,
13✔
1435
                // then we'll exit early as we don't need to filter this
13✔
1436
                // message.
13✔
1437
                if _, ok := msg.senders[g.cfg.peerPub]; ok {
16✔
1438
                        continue
3✔
1439
                }
1440

1441
                switch msg := msg.msg.(type) {
13✔
1442

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

1464
                        for _, chanUpdate := range chanUpdates {
14✔
1465
                                if passesFilter(chanUpdate.Timestamp) {
11✔
1466
                                        msgsToSend = append(msgsToSend, msg)
4✔
1467
                                        break
4✔
1468
                                }
1469
                        }
1470

1471
                        if len(chanUpdates) == 0 {
10✔
1472
                                msgsToSend = append(msgsToSend, msg)
3✔
1473
                        }
3✔
1474

1475
                // For each channel update, we'll only send if it the timestamp
1476
                // is between our time range.
1477
                case *lnwire.ChannelUpdate1:
6✔
1478
                        if passesFilter(msg.Timestamp) {
10✔
1479
                                msgsToSend = append(msgsToSend, msg)
4✔
1480
                        }
4✔
1481

1482
                // Similarly, we only send node announcements if the update
1483
                // timestamp ifs between our set gossip filter time range.
1484
                case *lnwire.NodeAnnouncement:
6✔
1485
                        if passesFilter(msg.Timestamp) {
10✔
1486
                                msgsToSend = append(msgsToSend, msg)
4✔
1487
                        }
4✔
1488
                }
1489
        }
1490

1491
        log.Tracef("GossipSyncer(%x): filtered gossip msgs: set=%v, sent=%v",
4✔
1492
                g.cfg.peerPub[:], len(msgs), len(msgsToSend))
4✔
1493

4✔
1494
        if len(msgsToSend) == 0 {
7✔
1495
                return
3✔
1496
        }
3✔
1497

1498
        if err = g.cfg.sendToPeer(ctx, msgsToSend...); err != nil {
4✔
1499
                log.Errorf("unable to send gossip msgs: %v", err)
×
1500
        }
×
1501

1502
}
1503

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

1512
        // Reply messages should only be expected in states where we're waiting
1513
        // for a reply.
1514
        case *lnwire.ReplyChannelRange, *lnwire.ReplyShortChanIDsEnd:
115✔
1515
                g.Lock()
115✔
1516
                syncState := g.syncState()
115✔
1517
                g.Unlock()
115✔
1518

115✔
1519
                if syncState != waitingQueryRangeReply &&
115✔
1520
                        syncState != waitingQueryChanReply {
116✔
1521

1✔
1522
                        return fmt.Errorf("unexpected msg %T received in "+
1✔
1523
                                "state %v", msg, syncState)
1✔
1524
                }
1✔
1525
                msgChan = g.gossipMsgs
114✔
1526

1527
        default:
×
1528
                msgChan = g.gossipMsgs
×
1529
        }
1530

1531
        select {
114✔
1532
        case msgChan <- msg:
114✔
1533
        case <-peerQuit:
×
1534
        case <-g.cg.Done():
×
1535
        }
1536

1537
        return nil
114✔
1538
}
1539

1540
// setSyncState sets the gossip syncer's state to the given state.
1541
func (g *GossipSyncer) setSyncState(state syncerState) {
97✔
1542
        atomic.StoreUint32(&g.state, uint32(state))
97✔
1543
}
97✔
1544

1545
// syncState returns the current syncerState of the target GossipSyncer.
1546
func (g *GossipSyncer) syncState() syncerState {
428✔
1547
        return syncerState(atomic.LoadUint32(&g.state))
428✔
1548
}
428✔
1549

1550
// ResetSyncedSignal returns a channel that will be closed in order to serve as
1551
// a signal for when the GossipSyncer has reached its chansSynced state.
1552
func (g *GossipSyncer) ResetSyncedSignal() chan struct{} {
17✔
1553
        g.Lock()
17✔
1554
        defer g.Unlock()
17✔
1555

17✔
1556
        syncedSignal := make(chan struct{})
17✔
1557

17✔
1558
        syncState := syncerState(atomic.LoadUint32(&g.state))
17✔
1559
        if syncState == chansSynced {
20✔
1560
                close(syncedSignal)
3✔
1561
                return syncedSignal
3✔
1562
        }
3✔
1563

1564
        g.syncedSignal = syncedSignal
15✔
1565
        return g.syncedSignal
15✔
1566
}
1567

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

1586
        select {
17✔
1587
        case err := <-errChan:
17✔
1588
                return err
17✔
1589
        case <-g.cg.Done():
×
1590
                return ErrGossipSyncerExiting
×
1591
        }
1592
}
1593

1594
// handleSyncTransition handles a new sync type transition request.
1595
//
1596
// NOTE: The gossip syncer might have another sync state as a result of this
1597
// transition.
1598
func (g *GossipSyncer) handleSyncTransition(ctx context.Context,
1599
        req *syncTransitionReq) error {
17✔
1600

17✔
1601
        // Return early from any NOP sync transitions.
17✔
1602
        syncType := g.SyncType()
17✔
1603
        if syncType == req.newSyncType {
17✔
1604
                return nil
×
1605
        }
×
1606

1607
        log.Debugf("GossipSyncer(%x): transitioning from %v to %v",
17✔
1608
                g.cfg.peerPub, syncType, req.newSyncType)
17✔
1609

17✔
1610
        var (
17✔
1611
                firstTimestamp time.Time
17✔
1612
                timestampRange uint32
17✔
1613
        )
17✔
1614

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

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

1630
        default:
×
1631
                return fmt.Errorf("unhandled sync transition %v",
×
1632
                        req.newSyncType)
×
1633
        }
1634

1635
        err := g.sendGossipTimestampRange(ctx, firstTimestamp, timestampRange)
17✔
1636
        if err != nil {
17✔
1637
                return fmt.Errorf("unable to send local update horizon: %w",
×
1638
                        err)
×
1639
        }
×
1640

1641
        g.setSyncType(req.newSyncType)
17✔
1642

17✔
1643
        return nil
17✔
1644
}
1645

1646
// setSyncType sets the gossip syncer's sync type to the given type.
1647
func (g *GossipSyncer) setSyncType(syncType SyncerType) {
70✔
1648
        atomic.StoreUint32(&g.syncType, uint32(syncType))
70✔
1649
}
70✔
1650

1651
// SyncType returns the current SyncerType of the target GossipSyncer.
1652
func (g *GossipSyncer) SyncType() SyncerType {
298✔
1653
        return SyncerType(atomic.LoadUint32(&g.syncType))
298✔
1654
}
298✔
1655

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

19✔
1664
        select {
19✔
1665
        case g.historicalSyncReqs <- &historicalSyncReq{
1666
                doneChan: done,
1667
        }:
19✔
1668
        case <-time.After(syncTransitionTimeout):
×
1669
                return ErrSyncTransitionTimeout
×
1670
        case <-g.cg.Done():
×
1671
                return ErrGossiperShuttingDown
×
1672
        }
1673

1674
        select {
19✔
1675
        case <-done:
19✔
1676
                return nil
19✔
1677
        case <-g.cg.Done():
×
1678
                return ErrGossiperShuttingDown
×
1679
        }
1680
}
1681

1682
// handleHistoricalSync handles a request to the gossip syncer to perform a
1683
// historical sync.
1684
func (g *GossipSyncer) handleHistoricalSync(req *historicalSyncReq) {
19✔
1685
        // We'll go back to our initial syncingChans state in order to request
19✔
1686
        // the remote peer to give us all of the channel IDs they know of
19✔
1687
        // starting from the genesis block.
19✔
1688
        g.genHistoricalChanRangeQuery = true
19✔
1689
        g.setSyncState(syncingChans)
19✔
1690
        close(req.doneChan)
19✔
1691
}
19✔
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