From 3ee062b86315823dd775453ad320b8be892c7df3 Mon Sep 17 00:00:00 2001 From: Harold Brenes Date: Thu, 15 Sep 2022 14:26:53 -0500 Subject: [PATCH] Short-circuit C2 table loading at first encounter of lesser C2 entry. This prevents DiskProver from loading dead-space into memory when reading C2. --- src/prover_disk.hpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/prover_disk.hpp b/src/prover_disk.hpp index a38f85f0f..68808abc2 100644 --- a/src/prover_disk.hpp +++ b/src/prover_disk.hpp @@ -110,10 +110,21 @@ class DiskProver { // The list of C2 entries is small enough to keep in memory. When proving, we can // read from disk the C1 and C3 entries. + uint64_t prev_c2_f7 = 0; auto* c2_buf = new uint8_t[c2_size]; for (uint32_t i = 0; i < c2_entries - 1; i++) { SafeRead(disk_file, c2_buf, c2_size); - this->C2.push_back(Bits(c2_buf, c2_size, c2_size * 8).Slice(0, k).GetValue()); + + const uint64_t f7 = Bits(c2_buf, c2_size, c2_size * 8).Slice(0, k).GetValue(); + + // Short-circuit reading of the C2 table as soon as we encounter an f7 entry whose + // value is lesser than the previous f7 read. This ensures that we don't read + // empty space from C2 tables that are written with file system block-alignment (like bladebit v1 does). + if (f7 < prev_c2_f7) + break; + + this->C2.push_back(f7); + prev_c2_f7 = f7; } delete[] c2_buf;