Skip to content

Commit f4144ed

Browse files
committed
feat(heartbeats): Verify that produced blocks were produced at the expected time
1 parent 1bc1a4f commit f4144ed

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tools/heartbeats-processor/src/local_db.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,17 @@ pub async fn process_heartbeats(
369369
continue;
370370
}
371371

372+
// Verify that the block slot matches the expected one for the current time
373+
// TODO: maybe we can be a bit more lenient here?
374+
let expected_slot = global_slot_at_time(entry.create_time);
375+
if block_info.global_slot != expected_slot {
376+
println!(
377+
"WARNING: Invalid block slot: {} (height: {}, producer: {}, expected slot: {}, actual slot: {})",
378+
block_info.hash, block_info.height, entry.submitter, expected_slot, block_info.global_slot
379+
);
380+
continue;
381+
}
382+
372383
// Verify block proof
373384
if !verify_block(&block_header, &verifier_index, &verifier_srs) {
374385
println!(
@@ -775,3 +786,17 @@ pub async fn mark_disabled_windows(pool: &SqlitePool, config: &Config) -> Result
775786
}
776787
Ok(())
777788
}
789+
790+
fn global_slot_at_time(time: DateTime<Utc>) -> u32 {
791+
use chrono::FixedOffset;
792+
let slot_duration = 180_000;
793+
let genesis_state_timestamp =
794+
DateTime::<FixedOffset>::parse_from_rfc3339("2024-04-09T21:00:00Z")
795+
.unwrap()
796+
.to_utc();
797+
let slot_start_ms = genesis_state_timestamp.timestamp_millis() as u64;
798+
let time_ms = time.timestamp_millis() as u64;
799+
800+
let slot_diff = (time_ms - slot_start_ms) / slot_duration;
801+
slot_diff as u32
802+
}

0 commit comments

Comments
 (0)