Skip to content

Commit 54c5266

Browse files
committed
adding the division precheck
Signed-off-by: Atanas Atanasov <a.v.atanasov98@gmail.com>
1 parent 52bf262 commit 54c5266

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

block-node/block-providers/files.historic/src/main/java/org/hiero/block/node/blocks/files/historic/BlocksFilesHistoricPlugin.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,19 @@ private void attemptZipping() {
228228
// multiple batches of blocks available for zipping potentially, so we
229229
// need to queue them all up
230230
while (historicalAvailable.max() >= maxBlockNumber) {
231-
if (historicalAvailable.contains(minBlockNumber, maxBlockNumber)) {
231+
// since we know that we have a power of 10 number of blocks per zip file,
232+
// we know our batch always starts with a number that is a multiple of
233+
// numberOfBlocksPerZipFile, so we can check if the start is valid
234+
// if the start is not valid, we will skip this batch and when we have
235+
// enough blocks available, for the next one, we will start that and
236+
// then the min will be updated, missed batches will be handled
237+
// in another fashion
238+
final boolean isValidStart = minBlockNumber % numberOfBlocksPerZipFile == 0;
239+
// we can do a quick pre-check to see if the blocks are available
240+
// this pre-check asserts the min and max are contained however,
241+
// not the whole range, this will be asserted when we gather the batch
242+
final boolean blocksAvailablePreCheck = historicalAvailable.contains(minBlockNumber, maxBlockNumber);
243+
if (isValidStart && blocksAvailablePreCheck) {
232244
final LongRange batchRange = new LongRange(minBlockNumber, maxBlockNumber);
233245
// move the batch of blocks to a zip file
234246
startMovingBatchOfBlocksToZipFile(batchRange);

0 commit comments

Comments
 (0)