Merge pull request #2905 from cfromknecht/split-chunk-size

discovery: make batch size distinct from chunk size, reduce to 500
This commit is contained in:
Olaoluwa Osuntokun 2019-04-09 19:27:20 -07:00 committed by GitHub
commit 3e5a6f1022
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

@ -628,6 +628,7 @@ func (m *SyncManager) InitSyncState(peer lnpeer.Peer) {
channelSeries: m.cfg.ChanSeries, channelSeries: m.cfg.ChanSeries,
encodingType: encoding, encodingType: encoding,
chunkSize: encodingTypeToChunkSize[encoding], chunkSize: encodingTypeToChunkSize[encoding],
batchSize: requestBatchSize,
sendToPeer: func(msgs ...lnwire.Message) error { sendToPeer: func(msgs ...lnwire.Message) error {
return peer.SendMessageLazy(false, msgs...) return peer.SendMessageLazy(false, msgs...)
}, },

@ -128,6 +128,10 @@ const (
// syncTransitionTimeout is the default timeout in which we'll wait up // syncTransitionTimeout is the default timeout in which we'll wait up
// to when attempting to perform a sync transition. // to when attempting to perform a sync transition.
syncTransitionTimeout = 5 * time.Second syncTransitionTimeout = 5 * time.Second
// requestBatchSize is the maximum number of channels we will query the
// remote peer for in a QueryShortChanIDs message.
requestBatchSize = 500
) )
var ( var (
@ -183,6 +187,10 @@ type gossipSyncerCfg struct {
// encoding type that we can fit into a single message safely. // encoding type that we can fit into a single message safely.
chunkSize int32 chunkSize int32
// batchSize is the max number of channels the syncer will query from
// the remote node in a single QueryShortChanIDs request.
batchSize int32
// sendToPeer is a function closure that should send the set of // sendToPeer is a function closure that should send the set of
// targeted messages to the peer we've been assigned to sync the graph // targeted messages to the peer we've been assigned to sync the graph
// state from. // state from.
@ -570,7 +578,7 @@ func (g *GossipSyncer) synchronizeChanIDs() (bool, error) {
// If the number of channels to query for is less than the chunk size, // If the number of channels to query for is less than the chunk size,
// then we can issue a single query. // then we can issue a single query.
if int32(len(g.newChansToQuery)) < g.cfg.chunkSize { if int32(len(g.newChansToQuery)) < g.cfg.batchSize {
queryChunk = g.newChansToQuery queryChunk = g.newChansToQuery
g.newChansToQuery = nil g.newChansToQuery = nil
@ -578,8 +586,8 @@ func (g *GossipSyncer) synchronizeChanIDs() (bool, error) {
// Otherwise, we'll need to only query for the next chunk. // Otherwise, we'll need to only query for the next chunk.
// We'll slice into our query chunk, then slide down our main // We'll slice into our query chunk, then slide down our main
// pointer down by the chunk size. // pointer down by the chunk size.
queryChunk = g.newChansToQuery[:g.cfg.chunkSize] queryChunk = g.newChansToQuery[:g.cfg.batchSize]
g.newChansToQuery = g.newChansToQuery[g.cfg.chunkSize:] g.newChansToQuery = g.newChansToQuery[g.cfg.batchSize:]
} }
log.Infof("GossipSyncer(%x): querying for %v new channels", log.Infof("GossipSyncer(%x): querying for %v new channels",

@ -125,6 +125,7 @@ func newTestSyncer(hID lnwire.ShortChannelID,
channelSeries: newMockChannelGraphTimeSeries(hID), channelSeries: newMockChannelGraphTimeSeries(hID),
encodingType: encodingType, encodingType: encodingType,
chunkSize: chunkSize, chunkSize: chunkSize,
batchSize: chunkSize,
sendToPeer: func(msgs ...lnwire.Message) error { sendToPeer: func(msgs ...lnwire.Message) error {
msgChan <- msgs msgChan <- msgs
return nil return nil