Skip to content

Commit

Permalink
Short-circuit C2 table loading at first encounter of lesser C2 entry.
Browse files Browse the repository at this point in the history
This prevents DiskProver from loading dead-space into memory when reading C2.
  • Loading branch information
haorldbchi committed Sep 15, 2022
1 parent e015ab0 commit 3ee062b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/prover_disk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 3ee062b

Please sign in to comment.