Skip to content

Commit 4b8633c

Browse files
committed
fix(hearbeats): Catchup syncs should mark precense too for the 5 height tolerance to work
1 parent 1ca3d81 commit 4b8633c

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

tools/heartbeats-processor/src/local_db.rs

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,11 @@ pub async fn process_heartbeats(
391391

392392
let best_tip = entry.best_tip_block();
393393
let public_key_id = *public_key_map.get(&entry.submitter).unwrap();
394+
let has_presence =
395+
(entry.is_synced() || entry.is_catchup()) && best_tip.is_some();
394396

395397
// Record presence only if node is synced and has a best tip
396-
if entry.is_synced() && best_tip.is_some() {
398+
if has_presence {
397399
presence_batch.push(HeartbeatPresence {
398400
window_id: window.id.unwrap(),
399401
public_key_id,
@@ -448,15 +450,25 @@ pub async fn process_heartbeats(
448450
continue;
449451
}
450452

451-
seen_blocks.insert(key.clone(), entry.create_time);
452-
produced_blocks_batch.push(ProducedBlock {
453-
window_id: window.id.unwrap(),
454-
public_key_id,
455-
block_hash: block_info.hash,
456-
block_height: block_info.height,
457-
block_global_slot: block_info.global_slot,
458-
block_data: block_info.base64_encoded_header,
459-
});
453+
if has_presence {
454+
seen_blocks.insert(key.clone(), entry.create_time);
455+
produced_blocks_batch.push(ProducedBlock {
456+
window_id: window.id.unwrap(),
457+
public_key_id,
458+
block_hash: block_info.hash,
459+
block_height: block_info.height,
460+
block_global_slot: block_info.global_slot,
461+
block_data: block_info.base64_encoded_header,
462+
});
463+
} else {
464+
println!(
465+
"WARNING: Block produced by unsynced node: {} (height: {}, producer: {})",
466+
block_info.hash, block_info.height, entry.submitter
467+
);
468+
println!("Submitter: {:?}", entry.submitter);
469+
println!("Sync status: {}", entry.sync_phase().unwrap_or_default());
470+
println!("Best tip: {:?}", entry.best_tip_block().map(|b| b.hash));
471+
}
460472
}
461473
Some((_block_info, Err(e))) => {
462474
println!(

tools/heartbeats-processor/src/remote_db.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,34 @@ impl HeartbeatEntry {
113113
})
114114
}
115115

116+
#[allow(dead_code)]
116117
pub fn sync_status(&self) -> Option<String> {
117118
self.transition_frontier()
118119
.and_then(|tf| tf.get("sync"))
119120
.and_then(|sync| sync.get("status"))
120121
.map(|status| status.as_str().unwrap().to_string())
121122
}
122123

124+
pub fn sync_phase(&self) -> Option<String> {
125+
self.transition_frontier()
126+
.and_then(|tf| tf.get("sync"))
127+
.and_then(|sync| sync.get("phase"))
128+
.map(|phase| phase.as_str().unwrap().to_string())
129+
}
130+
123131
pub fn is_synced(&self) -> bool {
124-
self.sync_status()
132+
self.sync_phase()
125133
.as_ref()
126134
.map(|status| status == "Synced")
127135
.unwrap_or(false)
128136
}
137+
138+
pub fn is_catchup(&self) -> bool {
139+
self.sync_phase()
140+
.as_ref()
141+
.map(|status| status == "Catchup")
142+
.unwrap_or(false)
143+
}
129144
}
130145

131146
#[derive(Debug, Serialize, Deserialize)]

0 commit comments

Comments
 (0)