Fix: Fresh block timestamps + sensible recommit bounds for PoW mining #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 = 5smaxRecommitInterval = 2mRecommit = 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:
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 ofnewTxs). This caps header staleness toRecommit.Patch (key logic in
newWorkLoop):2) Sensible recommit bounds
We clamp the auto-tuned recommit interval to:
Rationale:
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
intervalAdjustRatioandintervalAdjustBiasmath).Backward compatibility
Operator guidance (pools & miners)
Recommitto 20s (typical range 10–30s).Expected impact
Metrics to watch