@@ -516,23 +516,33 @@ pub async fn update_scores(pool: &SqlitePool, config: &Config) -> Result<()> {
516516 GROUP BY public_key_id
517517 ),
518518 HeartbeatCounts AS (
519- SELECT hp.public_key_id, COUNT(DISTINCT hp.window_id) as heartbeats
519+ SELECT
520+ hp.public_key_id,
521+ COUNT(DISTINCT hp.window_id) as heartbeats,
522+ MAX(hp.heartbeat_time) as last_heartbeat
520523 FROM heartbeat_presence hp
521524 JOIN ValidWindows vw ON vw.id = hp.window_id
522525 GROUP BY hp.public_key_id
523526 )
524- INSERT INTO submitter_scores (public_key_id, score, blocks_produced)
527+ INSERT INTO submitter_scores (
528+ public_key_id,
529+ score,
530+ blocks_produced,
531+ last_heartbeat
532+ )
525533 SELECT
526534 pk.id,
527535 COALESCE(hc.heartbeats, 0) as score,
528- COALESCE(bc.blocks, 0) as blocks_produced
536+ COALESCE(bc.blocks, 0) as blocks_produced,
537+ COALESCE(hc.last_heartbeat, 0) as last_heartbeat
529538 FROM public_keys pk
530539 LEFT JOIN HeartbeatCounts hc ON hc.public_key_id = pk.id
531540 LEFT JOIN BlockCounts bc ON bc.public_key_id = pk.id
532541 WHERE hc.heartbeats > 0 OR bc.blocks > 0
533542 ON CONFLICT(public_key_id) DO UPDATE SET
534543 score = excluded.score,
535544 blocks_produced = excluded.blocks_produced,
545+ last_heartbeat = excluded.last_heartbeat,
536546 last_updated = strftime('%s', 'now')
537547 "# ,
538548 window_start,
@@ -580,7 +590,8 @@ pub async fn view_scores(pool: &SqlitePool, config: &Config) -> Result<()> {
580590 pk.public_key,
581591 ss.score,
582592 ss.blocks_produced,
583- datetime(ss.last_updated, 'unixepoch') as last_updated
593+ datetime(ss.last_updated, 'unixepoch') as last_updated,
594+ datetime(ss.last_heartbeat, 'unixepoch') as last_heartbeat
584595 FROM submitter_scores ss
585596 JOIN public_keys pk ON pk.id = ss.public_key_id
586597 ORDER BY ss.score DESC, ss.blocks_produced DESC
@@ -594,19 +605,20 @@ pub async fn view_scores(pool: &SqlitePool, config: &Config) -> Result<()> {
594605 println ! ( "\n Submitter Scores:" ) ;
595606 println ! ( "--------------------------------------------------------" ) ;
596607 println ! (
597- "Public Key | Score | Blocks | Current Max | Total Max | Last Updated"
608+ "Public Key | Score | Blocks | Current Max | Total Max | Last Updated | Last Heartbeat "
598609 ) ;
599610 println ! ( "--------------------------------------------------------" ) ;
600611
601612 for row in scores {
602613 println ! (
603- "{:<40} | {:>5} | {:>6} | {:>11} | {:>9} | {}" ,
614+ "{:<40} | {:>5} | {:>6} | {:>11} | {:>9} | {} | {} " ,
604615 row. public_key,
605616 row. score,
606617 row. blocks_produced,
607618 max_scores. current,
608619 max_scores. total,
609- row. last_updated. unwrap_or_default( )
620+ row. last_updated. unwrap_or_default( ) ,
621+ row. last_heartbeat. unwrap_or_default( )
610622 ) ;
611623 }
612624
0 commit comments