Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions discovery/sync_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,13 +660,11 @@ func (m *SyncManager) createGossipSyncer(peer lnpeer.Peer) *GossipSyncer {
nodeID := route.Vertex(peer.PubKey())
log.Infof("Creating new GossipSyncer for peer=%x", nodeID[:])

encoding := lnwire.EncodingSortedPlain
s := newGossipSyncer(gossipSyncerCfg{
chainHash: m.cfg.ChainHash,
peerPub: nodeID,
channelSeries: m.cfg.ChanSeries,
encodingType: encoding,
chunkSize: encodingTypeToChunkSize[encoding],
chunkSize: defaultChunkSize,
batchSize: requestBatchSize,
sendMsg: func(ctx context.Context, sync bool,
msgs ...lnwire.Message) error {
Expand Down
32 changes: 9 additions & 23 deletions discovery/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,9 @@ const (
// process for a single QueryChannelRange request.
maxQueryChanRangeReplies = 500

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

// maxChanRangeReplySCIDs is the maximum number of short channel IDs
// we'll process for a single QueryChannelRange request.
maxChanRangeReplySCIDs = 100_000

// chanRangeQueryBuffer is the number of blocks back that we'll go when
// asking the remote peer for their any channels they know of beyond
// our highest known channel ID.
Expand All @@ -189,18 +184,15 @@ const (
// remote peer for in a QueryShortChanIDs message.
requestBatchSize = 500

// defaultChunkSize is the max number of short chan IDs using plain
// encoding that we can fit into a single message safely.
defaultChunkSize = 8000

// syncerBufferSize is the size of the syncer's buffers.
syncerBufferSize = 50
)

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

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

Expand Down Expand Up @@ -242,12 +234,8 @@ type gossipSyncerCfg struct {
// our queries and respond to the queries of the remote peer.
channelSeries ChannelGraphTimeSeries

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

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

// batchSize is the max number of channels the syncer will query from
Expand Down Expand Up @@ -1024,9 +1012,6 @@ func (g *GossipSyncer) bufferChanRangeReply(_ context.Context,
case lnwire.EncodingSortedPlain:
replyCount = 1

case lnwire.EncodingSortedZlib:
replyCount = maxQueryChanRangeRepliesZlibFactor

default:
return fmt.Errorf(
"unhandled encoding type %v", msg.EncodingType,
Expand Down Expand Up @@ -1099,6 +1084,7 @@ func (g *GossipSyncer) bufferChanRangeReply(_ context.Context,
)
}

g.numChanRangeRepliesRcvd++
log.Infof("GossipSyncer(%x): buffering chan range reply of size=%v",
g.cfg.peerPub[:], len(msg.ShortChanIDs))

Expand Down Expand Up @@ -1288,7 +1274,7 @@ func (g *GossipSyncer) replyChanRangeQuery(ctx context.Context,
FirstBlockHeight: query.FirstBlockHeight,
NumBlocks: query.NumBlocks,
Complete: 0,
EncodingType: g.cfg.encodingType,
EncodingType: lnwire.EncodingSortedPlain,
ShortChanIDs: nil,
})
}
Expand Down Expand Up @@ -1361,7 +1347,7 @@ func (g *GossipSyncer) replyChanRangeQuery(ctx context.Context,
NumBlocks: numBlocks,
FirstBlockHeight: firstHeight,
Complete: complete,
EncodingType: g.cfg.encodingType,
EncodingType: lnwire.EncodingSortedPlain,
ShortChanIDs: scids,
Timestamps: timestamps,
})
Expand Down
2 changes: 1 addition & 1 deletion discovery/syncer_atomic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestGossipSyncerSingleBacklogSend(t *testing.T) {
// Now we'll kick off the test by making a syncer that uses our blocking
// send function.
msgChan, syncer, chanSeries := newTestSyncer(
lnwire.NewShortChanIDFromInt(10), defaultEncoding,
lnwire.NewShortChanIDFromInt(10),
defaultChunkSize, true, true, true,
)

Expand Down
12 changes: 6 additions & 6 deletions discovery/syncer_queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestGossipSyncerQueueTimestampRange(t *testing.T) {
// Enable timestamp queries (third flag set to true).
msgChan, syncer, _ := newTestSyncer(
lnwire.ShortChannelID{BlockHeight: latestKnownHeight},
defaultEncoding, defaultChunkSize,
defaultChunkSize,
true, true, true,
)

Expand Down Expand Up @@ -68,7 +68,7 @@ func TestGossipSyncerQueueTimestampRangeFull(t *testing.T) {
// processed. Enable timestamp queries.
_, syncer, _ := newTestSyncer(
lnwire.ShortChannelID{BlockHeight: latestKnownHeight},
defaultEncoding, defaultChunkSize,
defaultChunkSize,
true, true, true,
)

Expand Down Expand Up @@ -104,7 +104,7 @@ func TestGossipSyncerQueueTimestampRangeConcurrent(t *testing.T) {
// Create and start a test syncer. Enable timestamp queries.
msgChan, syncer, _ := newTestSyncer(
lnwire.ShortChannelID{BlockHeight: latestKnownHeight},
defaultEncoding, defaultChunkSize,
defaultChunkSize,
true, true, true,
)
syncer.Start()
Expand Down Expand Up @@ -183,7 +183,7 @@ func TestGossipSyncerQueueShutdown(t *testing.T) {
// Create and start a test syncer. Enable timestamp queries.
_, syncer, _ := newTestSyncer(
lnwire.ShortChannelID{BlockHeight: latestKnownHeight},
defaultEncoding, defaultChunkSize,
defaultChunkSize,
true, true, true,
)
syncer.Start()
Expand Down Expand Up @@ -256,7 +256,7 @@ func TestGossipSyncerQueueInvariants(t *testing.T) {
// Create a test syncer. Enable timestamp queries.
msgChan, syncer, _ := newTestSyncer(
lnwire.ShortChannelID{BlockHeight: latestKnownHeight},
defaultEncoding, defaultChunkSize,
defaultChunkSize,
true, true, true,
)

Expand Down Expand Up @@ -366,7 +366,7 @@ func TestGossipSyncerQueueOrder(t *testing.T) {
// Enable timestamp queries.
msgChan, syncer, chanSeries := newTestSyncer(
lnwire.ShortChannelID{BlockHeight: latestKnownHeight},
defaultEncoding, defaultChunkSize,
defaultChunkSize,
true, true, true,
)

Expand Down
Loading