Skip to content

Conversation

@andrepatta
Copy link
Contributor

@andrepatta andrepatta commented Nov 3, 2025

Summary

This PR makes miner templates always refresh the header timestamp and rebuild on the timer, preventing blocks from being found with stale timestamps (e.g., “found now, header time from 40 minutes ago”).
It also standardizes recommit bounds to keep templates fresh without excessive churn:

  • minRecommitInterval = 5s
  • maxRecommitInterval = 2m
  • Recommended default Recommit = 20s (operational knob; pools may choose 10–30s)

Motivation

Some pools were hashing on the same old block template for long periods. When a nonce was finally found, the block carried a stale header timestamp, which:

  • Confused difficulty adjustment by making inter-block times appear shorter than reality.
  • Missed new transactions / tips that arrived after the template was built.
  • Produced poor UX on explorers (large gaps vs. “old” header times).

What changed

1) Always refresh timestamp and rebuild on timer

We now update timestamp = time.Now().Unix() right before committing a new template on the timer tick, and always resubmit on that tick (independent of newTxs). This caps header staleness to Recommit.

Patch (key logic in newWorkLoop):

case <-timer.C:
-   // If sealing is running resubmit a new work cycle periodically to pull in
-   // higher priced transactions. Disable this overhead for pending blocks.
-   if w.isRunning() && (w.chainConfig.Clique == nil || w.chainConfig.Clique.Period > 0) {
-       // Short circuit if no new transaction arrives.
-       if atomic.LoadInt32(&w.newTxs) == 0 {
-           timer.Reset(recommit)
-           continue
-       }
-       commit(true, commitInterruptResubmit)
-   }
+   // Periodically rebuild sealing work so the header timestamp stays fresh,
+   // even if no new transactions arrived.
+   if w.isRunning() && (w.chainConfig.Clique == nil || w.chainConfig.Clique.Period > 0) {
+       timestamp = time.Now().Unix()          // refresh right before commit
+       commit(true, commitInterruptResubmit)  // always rebuild on timer
+   }

2) Sensible recommit bounds

We clamp the auto-tuned recommit interval to:

const (
   minRecommitInterval = 5 * time.Second
   maxRecommitInterval = 2 * time.Minute
)

Rationale:

  • Min 5s: keeps timestamps accurate and responsive to fees without thrashing.
  • Max 2m: caps worst-case staleness to ≤20% of a 10-minute block target.

3) Tests updated for new bounds

The interval-adjust test expected a 1s/3s baseline. It now expects 5s clamping and computes subsequent steps from that baseline (still using the same intervalAdjustRatio and intervalAdjustBias math).

Backward compatibility

  • Consensus-safe: No protocol or block format changes. This only affects local miner behavior.
  • Nodes without this patch remain compatible; they may simply keep hashing older templates longer.

Operator guidance (pools & miners)

  • Set default Recommit to 20s (typical range 10–30s).
  • Keep NTP in sync.
  • Pools should broadcast periodic clean jobs to downstream miners on a similar cadence (e.g., 15–30s) to prevent remote hashing on stale templates.

Expected impact

  • Block times should decrease (speed up toward target) over the next DAA window because timestamps become accurate again (no “fast-block” illusion driving difficulty too high).
  • Fee capture improves—newer, higher-tip transactions get included more promptly.
  • Explorer UX improves—header times align with observed times.

Metrics to watch

  • Template age (time since last rebuild)
  • Median header inter-block time vs. wall-clock
  • Average tx inclusion delay and fee capture
  • Recommit frequency (auto-tuner movements within [5s, 2m])

@andrepatta andrepatta merged commit 647b200 into main Nov 3, 2025
3 checks passed
@andrepatta andrepatta deleted the fix_recommit_interval branch November 3, 2025 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants