From bfe7a6c3dc18aff7d2ae3a39c386a3cb6f24a298 Mon Sep 17 00:00:00 2001 From: CPerezz Date: Wed, 21 Jan 2026 23:14:45 +0100 Subject: [PATCH] fix(metrics): use float64 for sub-millisecond timing precision Convert timing fields from int64 to float64 to preserve sub-millisecond precision in slow block JSON output. Previously, durations under 1ms would truncate to 0 due to integer division. Changes: - slowBlockTime struct fields: int64 -> float64 - Add durationToMs() helper for nanosecond to float ms conversion - Update test assertions for float comparisons --- core/blockchain_stats_test.go | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/core/blockchain_stats_test.go b/core/blockchain_stats_test.go index 25412a913e..97258f6607 100644 --- a/core/blockchain_stats_test.go +++ b/core/blockchain_stats_test.go @@ -58,8 +58,12 @@ func TestLogSlowBlockJSON(t *testing.T) { AccountCacheMiss: 6, StorageCacheHit: 0, StorageCacheMiss: 11, - ContractCodeHit: 4, - ContractCodeMiss: 0, + CodeStats: state.ContractCodeReaderStats{ + CacheHit: 4, + CacheMiss: 0, + CacheHitBytes: 102400, // ~100KB served from cache + CacheMissBytes: 0, + }, }, } @@ -110,11 +114,11 @@ func TestLogSlowBlockJSON(t *testing.T) { if logEntry.Block.GasUsed != 21000000 { t.Errorf("Expected gas used 21000000, got %d", logEntry.Block.GasUsed) } - if logEntry.Timing.ExecutionMs != 500 { - t.Errorf("Expected execution_ms 500, got %d", logEntry.Timing.ExecutionMs) + if logEntry.Timing.ExecutionMs != 500.0 { + t.Errorf("Expected execution_ms 500.0, got %v", logEntry.Timing.ExecutionMs) } - if logEntry.Timing.TotalMs != 1200 { - t.Errorf("Expected total_ms 1200, got %d", logEntry.Timing.TotalMs) + if logEntry.Timing.TotalMs != 1200.0 { + t.Errorf("Expected total_ms 1200.0, got %v", logEntry.Timing.TotalMs) } if logEntry.StateReads.Accounts != 100 { t.Errorf("Expected accounts 100, got %d", logEntry.StateReads.Accounts) @@ -157,6 +161,13 @@ func TestLogSlowBlockJSON(t *testing.T) { if logEntry.Cache.Code.HitRate != 100.0 { t.Errorf("Expected code cache hit_rate 100.0, got %f", logEntry.Cache.Code.HitRate) } + // Verify new byte-level cache statistics + if logEntry.Cache.Code.HitBytes != 102400 { + t.Errorf("Expected code cache hit_bytes 102400, got %d", logEntry.Cache.Code.HitBytes) + } + if logEntry.Cache.Code.MissBytes != 0 { + t.Errorf("Expected code cache miss_bytes 0, got %d", logEntry.Cache.Code.MissBytes) + } t.Logf("Parsed JSON:\n%+v", logEntry) }