Skip to content

Commit 1a36b73

Browse files
authored
Merge branch 'main' into marko/migration_docs
2 parents ca7d0b1 + 15afbee commit 1a36b73

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

pkg/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ const (
4545
FlagMaxPendingHeadersAndData = FlagPrefixEvnode + "node.max_pending_headers_and_data"
4646
// FlagLazyBlockTime is a flag for specifying the maximum interval between blocks in lazy aggregation mode
4747
FlagLazyBlockTime = FlagPrefixEvnode + "node.lazy_block_interval"
48+
// FlagReadinessWindowSeconds configures the time window (in seconds) used to calculate readiness threshold
49+
FlagReadinessWindowSeconds = FlagPrefixEvnode + "node.readiness_window_seconds"
4850
// FlagReadinessMaxBlocksBehind configures how many blocks behind best-known head is still considered ready
4951
FlagReadinessMaxBlocksBehind = FlagPrefixEvnode + "node.readiness_max_blocks_behind"
5052
// FlagClearCache is a flag for clearing the cache
@@ -198,6 +200,7 @@ type NodeConfig struct {
198200
TrustedHash string `mapstructure:"trusted_hash" yaml:"trusted_hash" comment:"Initial trusted hash used to bootstrap the header exchange service. Allows nodes to start synchronizing from a specific trusted point in the chain instead of genesis. When provided, the node will fetch the corresponding header/block from peers using this hash and use it as a starting point for synchronization. If not provided, the node will attempt to fetch the genesis block instead."`
199201

200202
// Readiness / health configuration
203+
ReadinessWindowSeconds uint64 `mapstructure:"readiness_window_seconds" yaml:"readiness_window_seconds" comment:"Time window in seconds used to calculate ReadinessMaxBlocksBehind based on block time. Default: 15 seconds."`
201204
ReadinessMaxBlocksBehind uint64 `mapstructure:"readiness_max_blocks_behind" yaml:"readiness_max_blocks_behind" comment:"How many blocks behind best-known head the node can be and still be considered ready. 0 means must be exactly at head."`
202205
}
203206

@@ -314,6 +317,7 @@ func AddFlags(cmd *cobra.Command) {
314317
cmd.Flags().Bool(FlagLazyAggregator, def.Node.LazyMode, "produce blocks only when transactions are available or after lazy block time")
315318
cmd.Flags().Uint64(FlagMaxPendingHeadersAndData, def.Node.MaxPendingHeadersAndData, "maximum headers or data pending DA confirmation before pausing block production (0 for no limit)")
316319
cmd.Flags().Duration(FlagLazyBlockTime, def.Node.LazyBlockInterval.Duration, "maximum interval between blocks in lazy aggregation mode")
320+
cmd.Flags().Uint64(FlagReadinessWindowSeconds, def.Node.ReadinessWindowSeconds, "time window in seconds for calculating readiness threshold based on block time (default: 15s)")
317321
cmd.Flags().Uint64(FlagReadinessMaxBlocksBehind, def.Node.ReadinessMaxBlocksBehind, "how many blocks behind best-known head the node can be and still be considered ready (0 = must be at head)")
318322

319323
// Data Availability configuration flags

pkg/config/config_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func TestAddFlags(t *testing.T) {
6262
assertFlagValue(t, flags, FlagLazyAggregator, DefaultConfig().Node.LazyMode)
6363
assertFlagValue(t, flags, FlagMaxPendingHeadersAndData, DefaultConfig().Node.MaxPendingHeadersAndData)
6464
assertFlagValue(t, flags, FlagLazyBlockTime, DefaultConfig().Node.LazyBlockInterval.Duration)
65+
assertFlagValue(t, flags, FlagReadinessWindowSeconds, DefaultConfig().Node.ReadinessWindowSeconds)
6566
assertFlagValue(t, flags, FlagReadinessMaxBlocksBehind, DefaultConfig().Node.ReadinessMaxBlocksBehind)
6667

6768
// DA flags
@@ -103,7 +104,7 @@ func TestAddFlags(t *testing.T) {
103104
assertFlagValue(t, flags, FlagRPCAddress, DefaultConfig().RPC.Address)
104105

105106
// Count the number of flags we're explicitly checking
106-
expectedFlagCount := 38 // Update this number if you add more flag checks above
107+
expectedFlagCount := 39 // Update this number if you add more flag checks above
107108

108109
// Get the actual number of flags (both regular and persistent)
109110
actualFlagCount := 0

pkg/config/defaults.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,23 @@ func DefaultRootDirWithName(appName string) string {
3636
return filepath.Join(home, "."+appName)
3737
}
3838

39+
// calculateReadinessMaxBlocksBehind calculates how many blocks represent the readiness window
40+
// based on the given block time and window duration in seconds. This allows for normal
41+
// batch-sync latency while detecting stuck nodes.
42+
func calculateReadinessMaxBlocksBehind(blockTime time.Duration, windowSeconds uint64) uint64 {
43+
if blockTime == 0 {
44+
return 30 // fallback to safe default if blockTime is not set
45+
}
46+
if windowSeconds == 0 {
47+
windowSeconds = 15 // fallback to default 15s window
48+
}
49+
return uint64(time.Duration(windowSeconds) * time.Second / blockTime)
50+
}
51+
3952
// DefaultConfig keeps default values of NodeConfig
4053
func DefaultConfig() Config {
54+
defaultBlockTime := DurationWrapper{1 * time.Second}
55+
defaultReadinessWindowSeconds := uint64(15)
4156
return Config{
4257
RootDir: DefaultRootDir,
4358
DBPath: "data",
@@ -47,12 +62,13 @@ func DefaultConfig() Config {
4762
},
4863
Node: NodeConfig{
4964
Aggregator: false,
50-
BlockTime: DurationWrapper{1 * time.Second},
65+
BlockTime: defaultBlockTime,
5166
LazyMode: false,
5267
LazyBlockInterval: DurationWrapper{60 * time.Second},
5368
Light: false,
5469
TrustedHash: "",
55-
ReadinessMaxBlocksBehind: 3,
70+
ReadinessWindowSeconds: defaultReadinessWindowSeconds,
71+
ReadinessMaxBlocksBehind: calculateReadinessMaxBlocksBehind(defaultBlockTime.Duration, defaultReadinessWindowSeconds),
5672
},
5773
DA: DAConfig{
5874
Address: "http://localhost:7980",

pkg/rpc/server/server_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,8 +409,8 @@ func TestHealthReadyEndpoint(t *testing.T) {
409409
}{
410410
{name: "at_head", local: 100, bestKnown: 100, peers: 1, expectedCode: http.StatusOK},
411411
{name: "within_1_block", local: 99, bestKnown: 100, peers: 1, expectedCode: http.StatusOK},
412-
{name: "within_3_blocks", local: 97, bestKnown: 100, peers: 1, expectedCode: http.StatusOK},
413-
{name: "just_over_3_blocks", local: 96, bestKnown: 100, peers: 1, expectedCode: http.StatusServiceUnavailable},
412+
{name: "within_15_blocks", local: 85, bestKnown: 100, peers: 1, expectedCode: http.StatusOK},
413+
{name: "just_over_15_blocks", local: 84, bestKnown: 100, peers: 1, expectedCode: http.StatusServiceUnavailable},
414414
{name: "local_ahead", local: 101, bestKnown: 100, peers: 1, expectedCode: http.StatusOK},
415415
{name: "no_blocks_yet", local: 0, bestKnown: 100, peers: 1, expectedCode: http.StatusServiceUnavailable},
416416
{name: "unknown_best_known", local: 100, bestKnown: 0, peers: 1, expectedCode: http.StatusServiceUnavailable},

0 commit comments

Comments
 (0)