mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-19 11:20:45 +00:00
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
This commit is contained in:
parent
7a0e89b4f4
commit
85a1e132a9
4 changed files with 26 additions and 10 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue