From 344df03c6cdc4078dc39e7ccfeeef764a9d537aa Mon Sep 17 00:00:00 2001 From: Andrew Ayer Date: Tue, 6 May 2025 14:58:23 -0400 Subject: [PATCH] Avoid generating download batches with an invalid range Previously, if we rounded down the tree size to avoid downloading a partial tile, but the log position was already within the partial tile (which can happen with a brand new log and -start_at_end), we'd generate a download batch where end < begin, which caused all sorts of problems. --- monitor/monitor.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/monitor/monitor.go b/monitor/monitor.go index 8b8cbd4..3e03f6b 100644 --- a/monitor/monitor.go +++ b/monitor/monitor.go @@ -374,6 +374,10 @@ func generateBatches(ctx context.Context, ctlog *loglist.Log, position uint64, n // Round down to the tile boundary to avoid downloading a partial tile that was recently discovered // In a future invocation of this function, either enough time will have passed that this code path will be skipped, or the log will have grown and treeSize will be rounded to a larger tile boundary treeSize -= treeSize % ctclient.StaticTileWidth + if treeSize < position { + // This can arise with a brand new log when config.StartAtEnd is true + return position, number, nil + } } for { batch := &batch{