@@ -516,23 +516,33 @@ pub async fn update_scores(pool: &SqlitePool, config: &Config) -> Result<()> {
516
516
GROUP BY public_key_id
517
517
),
518
518
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
520
523
FROM heartbeat_presence hp
521
524
JOIN ValidWindows vw ON vw.id = hp.window_id
522
525
GROUP BY hp.public_key_id
523
526
)
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
+ )
525
533
SELECT
526
534
pk.id,
527
535
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
529
538
FROM public_keys pk
530
539
LEFT JOIN HeartbeatCounts hc ON hc.public_key_id = pk.id
531
540
LEFT JOIN BlockCounts bc ON bc.public_key_id = pk.id
532
541
WHERE hc.heartbeats > 0 OR bc.blocks > 0
533
542
ON CONFLICT(public_key_id) DO UPDATE SET
534
543
score = excluded.score,
535
544
blocks_produced = excluded.blocks_produced,
545
+ last_heartbeat = excluded.last_heartbeat,
536
546
last_updated = strftime('%s', 'now')
537
547
"# ,
538
548
window_start,
@@ -580,7 +590,8 @@ pub async fn view_scores(pool: &SqlitePool, config: &Config) -> Result<()> {
580
590
pk.public_key,
581
591
ss.score,
582
592
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
584
595
FROM submitter_scores ss
585
596
JOIN public_keys pk ON pk.id = ss.public_key_id
586
597
ORDER BY ss.score DESC, ss.blocks_produced DESC
@@ -594,19 +605,20 @@ pub async fn view_scores(pool: &SqlitePool, config: &Config) -> Result<()> {
594
605
println ! ( "\n Submitter Scores:" ) ;
595
606
println ! ( "--------------------------------------------------------" ) ;
596
607
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 "
598
609
) ;
599
610
println ! ( "--------------------------------------------------------" ) ;
600
611
601
612
for row in scores {
602
613
println ! (
603
- "{:<40} | {:>5} | {:>6} | {:>11} | {:>9} | {}" ,
614
+ "{:<40} | {:>5} | {:>6} | {:>11} | {:>9} | {} | {} " ,
604
615
row. public_key,
605
616
row. score,
606
617
row. blocks_produced,
607
618
max_scores. current,
608
619
max_scores. total,
609
- row. last_updated. unwrap_or_default( )
620
+ row. last_updated. unwrap_or_default( ) ,
621
+ row. last_heartbeat. unwrap_or_default( )
610
622
) ;
611
623
}
612
624
0 commit comments