From 85a1e132a97ab7a36af3b4c1e674b6975481f24d Mon Sep 17 00:00:00 2001 From: CPerezz Date: Sun, 25 Jan 2026 11:33:57 +0100 Subject: [PATCH] core: fix slow block flag to be disabled by default Previously, --debug.logslowblock defaulted to 2 seconds (enabled) and setting 0 would disable logging. This was confusing. Now: - Disabled by default (flag must be explicitly set) - Value 0 logs ALL blocks - Positive value filters by execution time threshold --- cmd/utils/flags.go | 12 ++++++++---- core/blockchain.go | 3 ++- core/blockchain_stats_test.go | 14 ++++++++++++-- eth/ethconfig/config.go | 7 ++++--- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 844397b734..98e3c6171c 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -692,8 +692,8 @@ var ( } LogSlowBlockFlag = &cli.DurationFlag{ Name: "debug.logslowblock", - Usage: "Block execution time threshold beyond which detailed statistics will be logged (0 means disable)", - Value: ethconfig.Defaults.SlowBlockThreshold, + Usage: "Block execution time threshold beyond which detailed statistics will be logged (0 logs all blocks)", + Value: 0, Category: flags.LoggingCategory, } @@ -2351,8 +2351,12 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh // Enable state size tracking if enabled StateSizeTracking: ctx.Bool(StateSizeTrackingFlag.Name), - // Configure the slow block statistic logger - SlowBlockThreshold: ctx.Duration(LogSlowBlockFlag.Name), + // Configure the slow block statistic logger (disabled by default) + SlowBlockThreshold: ethconfig.Defaults.SlowBlockThreshold, + } + // Only enable slow block logging if the flag was explicitly set + if ctx.IsSet(LogSlowBlockFlag.Name) { + options.SlowBlockThreshold = ctx.Duration(LogSlowBlockFlag.Name) } if options.ArchiveMode && !options.Preimages { options.Preimages = true diff --git a/core/blockchain.go b/core/blockchain.go index 240e20aff1..8cfeabe8a2 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -214,7 +214,8 @@ type BlockChainConfig struct { StateSizeTracking bool // SlowBlockThreshold is the block execution time threshold beyond which - // detailed statistics will be logged. + // detailed statistics will be logged. Negative value means disabled (default), + // zero logs all blocks, positive value filters blocks by execution time. SlowBlockThreshold time.Duration } diff --git a/core/blockchain_stats_test.go b/core/blockchain_stats_test.go index 80abb5b323..580c472918 100644 --- a/core/blockchain_stats_test.go +++ b/core/blockchain_stats_test.go @@ -266,10 +266,20 @@ func TestLogSlowBlockThreshold(t *testing.T) { // Reset buffer buf.Reset() - // Test with zero threshold (disabled) + // Test with zero threshold (logs all blocks) stats.logSlow(block, 0) + if buf.Len() == 0 { + t.Errorf("Expected output for zero threshold (logs all), got nothing") + } + + // Reset buffer + buf.Reset() + + // Test with negative threshold (disabled) + stats.logSlow(block, -1) + if buf.Len() > 0 { - t.Errorf("Expected no output for zero threshold, got: %s", buf.String()) + t.Errorf("Expected no output for negative threshold (disabled), got: %s", buf.String()) } } diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index e58c4b884a..8aa6e4ef09 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -75,7 +75,7 @@ var Defaults = Config{ RPCTxFeeCap: 1, // 1 ether TxSyncDefaultTimeout: 20 * time.Second, TxSyncMaxTimeout: 1 * time.Minute, - SlowBlockThreshold: time.Second * 2, + SlowBlockThreshold: -1, // Disabled by default; set via --debug.logslowblock flag RangeLimit: 0, } @@ -130,8 +130,9 @@ type Config struct { // presence of these blocks for every new peer connection. RequiredBlocks map[uint64]common.Hash `toml:"-"` - // SlowBlockThreshold is the block execution speed threshold (Mgas/s) - // below which detailed statistics are logged. + // SlowBlockThreshold is the block execution time threshold beyond which + // detailed statistics are logged. Negative means disabled (default), zero + // logs all blocks, positive filters by execution time. SlowBlockThreshold time.Duration `toml:",omitempty"` // Database options