Skip to content

Commit 0f5da4f

Browse files
committed
fix(block-producer-stats): Improve the logic that checks if a block being applied is ours
1 parent 26ce803 commit 0f5da4f

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

node/src/stats/stats_block_producer.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ impl BlockProducerStats {
261261
}
262262

263263
pub fn block_apply_start(&mut self, time: redux::Timestamp, hash: &BlockHash) {
264-
if !self.is_our_block(hash) {
264+
if !self.is_our_just_produced_block(hash) {
265265
return;
266266
}
267267

@@ -315,11 +315,20 @@ impl BlockProducerStats {
315315
});
316316
}
317317

318-
pub fn is_our_block(&self, hash: &BlockHash) -> bool {
319-
self.attempts
320-
.back()
321-
.and_then(|v| v.block.as_ref())
322-
.map_or(false, |b| &b.hash == hash)
318+
/// Returns `true` if this is a block we just produced
319+
pub fn is_our_just_produced_block(&self, hash: &BlockHash) -> bool {
320+
// For the block to be ours:
321+
// - we must have an attempt to produce a block
322+
// - we must have just produced the proof for that block
323+
// - the hash must match
324+
if let Some(attempt) = self.attempts.back() {
325+
match (&attempt.status, attempt.block.as_ref()) {
326+
(BlockProductionStatus::ProofCreateSuccess, Some(block)) => &block.hash == hash,
327+
_ => false,
328+
}
329+
} else {
330+
false
331+
}
323332
}
324333
}
325334

node/src/transition_frontier/sync/transition_frontier_sync_effects.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ impl TransitionFrontierSyncAction {
253253
stats.block_producer().block_apply_start(meta.time(), &hash);
254254
// TODO(tizoc): try a better approach that doesn't need
255255
// to make use of the collected stats.
256-
is_our_block = stats.block_producer().is_our_block(&hash);
256+
is_our_block = stats.block_producer().is_our_just_produced_block(&hash);
257257
} else {
258258
is_our_block = false;
259259
}

0 commit comments

Comments
 (0)