@@ -331,79 +331,69 @@ pub async fn process_heartbeats(
331331 processed_heartbeats. insert ( idx) ;
332332
333333 let best_tip = entry. best_tip_block ( ) ;
334+ let public_key_id = * public_key_map. get ( & entry. submitter ) . unwrap ( ) ;
334335
336+ // Record presence only if node is synced and has a best tip
335337 if entry. is_synced ( ) && best_tip. is_some ( ) {
336- if let Some ( & public_key_id) = public_key_map. get ( & entry. submitter ) {
337- presence_batch. push ( HeartbeatPresence {
338+ presence_batch. push ( HeartbeatPresence {
339+ window_id : window. id . unwrap ( ) ,
340+ public_key_id,
341+ best_tip : best_tip. unwrap ( ) , // Cannot fail due to the above check
342+ heartbeat_time : to_unix_timestamp ( entry. create_time ) ,
343+ } ) ;
344+ presence_count += 1 ;
345+ } else {
346+ skipped_count += 1 ;
347+ }
348+
349+ // Process produced blocks regardless of sync status
350+ match entry
351+ . last_produced_block_info ( )
352+ . map ( |bi| ( bi. clone ( ) , bi. block_header_decoded ( ) ) )
353+ {
354+ None => ( ) , // No block to process
355+ Some ( ( block_info, Ok ( block_header) ) ) => {
356+ let key = ( public_key_id, block_info. hash . clone ( ) ) ;
357+
358+ if let Some ( first_seen) = seen_blocks. get ( & key) {
359+ blocks_duplicate += 1 ;
360+ println ! (
361+ "Duplicate block detected: {} (height: {}, producer: {}, peer_id: {}) [first seen at {}, now at {}]" ,
362+ key. 1 ,
363+ block_info. height,
364+ entry. submitter,
365+ entry. peer_id( ) . unwrap_or_else( || "unknown" . to_string( ) ) ,
366+ first_seen,
367+ entry. create_time
368+ ) ;
369+ continue ;
370+ }
371+
372+ // Verify block proof
373+ if !verify_block ( & block_header, & verifier_index, & verifier_srs) {
374+ println ! (
375+ "WARNING: Invalid block proof: {} (height: {}, producer: {})" ,
376+ block_info. hash, block_info. height, entry. submitter
377+ ) ;
378+ continue ;
379+ }
380+
381+ seen_blocks. insert ( key. clone ( ) , entry. create_time ) ;
382+ produced_blocks_batch. push ( ProducedBlock {
338383 window_id : window. id . unwrap ( ) ,
339384 public_key_id,
340- best_tip : best_tip. unwrap ( ) , // Cannot fail due to the above check
341- heartbeat_time : to_unix_timestamp ( entry. create_time ) ,
385+ block_hash : block_info. hash ,
386+ block_height : block_info. height ,
387+ block_global_slot : block_info. global_slot ,
388+ block_data : block_info. base64_encoded_header ,
342389 } ) ;
343- presence_count += 1 ;
344-
345- // Add produced block if it exists
346- match entry
347- . last_produced_block_info ( )
348- . map ( |bi| ( bi. clone ( ) , bi. block_header_decoded ( ) ) )
349- {
350- None => ( ) , // No block to process
351- Some ( ( block_info, Ok ( block_header) ) ) => {
352- let key = ( public_key_id, block_info. hash . clone ( ) ) ;
353-
354- if let Some ( first_seen) = seen_blocks. get ( & key) {
355- blocks_duplicate += 1 ;
356- println ! (
357- "Duplicate block detected: {} (height: {}, producer: {}, peer_id: {}) [first seen at {}, now at {}]" ,
358- key. 1 ,
359- block_info. height,
360- entry. submitter,
361- entry. peer_id( ) . unwrap_or_else( || "unknown" . to_string( ) ) ,
362- first_seen,
363- entry. create_time
364- ) ;
365- continue ;
366- }
367-
368- // Verify block proof
369- if !verify_block ( & block_header, & verifier_index, & verifier_srs)
370- {
371- println ! (
372- "WARNING: Invalid block proof: {} (height: {}, producer: {})" ,
373- block_info. hash, block_info. height, entry. submitter
374- ) ;
375- continue ;
376- }
377-
378- seen_blocks. insert ( key. clone ( ) , entry. create_time ) ;
379- produced_blocks_batch. push ( ProducedBlock {
380- window_id : window. id . unwrap ( ) ,
381- public_key_id,
382- block_hash : block_info. hash ,
383- block_height : block_info. height ,
384- block_global_slot : block_info. global_slot ,
385- block_data : block_info. base64_encoded_header ,
386- } ) ;
387- }
388- Some ( ( _block_info, Err ( e) ) ) => {
389- println ! (
390- "WARNING: Failed to decode block from {}: {}" ,
391- entry. submitter, e
392- )
393- }
394- }
395390 }
396- } else {
397- if let Some ( block_info) = entry. last_produced_block_info ( ) {
391+ Some ( ( _block_info, Err ( e) ) ) => {
398392 println ! (
399- "Skipping unsynced block: {} (height: {}, producer: {}, peer_id: {})" ,
400- block_info. hash,
401- block_info. height,
402- entry. submitter,
403- entry. peer_id( ) . unwrap_or_else( || "unknown" . to_string( ) )
404- ) ;
393+ "WARNING: Failed to decode block from {}: {}" ,
394+ entry. submitter, e
395+ )
405396 }
406- skipped_count += 1 ;
407397 }
408398 }
409399 }
0 commit comments