Skip to content

Commit 0891111

Browse files
nits
1 parent 780d21b commit 0891111

1 file changed

Lines changed: 14 additions & 30 deletions

File tree

chain/src/indexer/backfiller/state.rs

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ pub struct State {
5757
uploaded: PrioritySet<Digest, u64>,
5858
// Conservative height watermark derived from contiguous queue-floor
5959
// progress. Heights below this can be forgotten from the uploaded set.
60-
acked_through: Option<u64>,
60+
acked_through: u64,
6161
// Highest finalized height observed from the live application stream.
62-
latest_finalized: Option<u64>,
62+
latest_finalized: u64,
6363
// Blocks cached for the live certificate upload path and the backfiller.
6464
cached_blocks: BTreeMap<Digest, Block>,
6565
// Number of in-flight certificate uploads per digest so the backfiller can
@@ -71,8 +71,8 @@ impl State {
7171
pub fn new() -> Self {
7272
Self {
7373
uploaded: PrioritySet::new(),
74-
acked_through: None,
75-
latest_finalized: None,
74+
acked_through: 0,
75+
latest_finalized: 0,
7676
cached_blocks: BTreeMap::new(),
7777
certificate_uploads: BTreeMap::new(),
7878
}
@@ -96,10 +96,7 @@ impl State {
9696
}
9797

9898
pub fn advance_queue_floor(&mut self, height: u64) {
99-
self.acked_through = Some(
100-
self.acked_through
101-
.map_or(height, |current| current.max(height)),
102-
);
99+
self.acked_through = self.acked_through.max(height);
103100
self.prune();
104101
}
105102

@@ -148,40 +145,27 @@ impl State {
148145
}
149146

150147
fn observe_finalization(&mut self, height: u64) {
151-
self.latest_finalized = Some(
152-
self.latest_finalized
153-
.map_or(height, |latest| latest.max(height)),
154-
);
148+
self.latest_finalized = self.latest_finalized.max(height);
155149
self.prune();
156150
}
157151

158152
fn prune(&mut self) {
159-
if let Some(prune_before) = self.acked_through {
160-
while let Some((_, &height)) = self.uploaded.peek() {
161-
if height >= prune_before {
162-
break;
163-
}
164-
self.uploaded.pop();
153+
while let Some((_, &height)) = self.uploaded.peek() {
154+
if height >= self.acked_through {
155+
break;
165156
}
157+
self.uploaded.pop();
166158
}
167159

168-
let mut cached_prune_before: Option<u64> = None;
160+
let mut cached_prune_before = self.latest_finalized;
169161
for digest in self.certificate_uploads.keys() {
170162
let Some(block) = self.cached_blocks.get(digest) else {
171163
continue;
172164
};
173-
cached_prune_before = Some(cached_prune_before.map_or(block.height.get(), |current| {
174-
current.min(block.height.get())
175-
}));
176-
}
177-
if cached_prune_before.is_none() {
178-
cached_prune_before = self.latest_finalized;
179-
}
180-
181-
if let Some(prune_before) = cached_prune_before {
182-
self.cached_blocks
183-
.retain(|_, block| block.height.get() >= prune_before);
165+
cached_prune_before = cached_prune_before.min(block.height.get());
184166
}
167+
self.cached_blocks
168+
.retain(|_, block| block.height.get() >= cached_prune_before);
185169
}
186170
}
187171

0 commit comments

Comments
 (0)