Skip to content

Conversation

@gzliudan
Copy link
Collaborator

Proposed changes

recompute timestamp after sleep

Types of changes

What types of changes does your code introduce to XDC network?
Put an in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)
  • Regular KTLO or any of the maintaince work. e.g code style
  • CICD Improvement

Impacted Components

Which part of the codebase this PR will touch base on,

Put an in the boxes that apply

  • Consensus
  • Account
  • Network
  • Geth
  • Smart Contract
  • External components
  • Not sure (Please specify below)

Checklist

Put an in the boxes once you have confirmed below actions (or provide reasons on not doing so) that

  • This PR has sufficient test coverage (unit/integration test) OR I have provided reason in the PR description for not having test coverage
  • Provide an end-to-end test plan in the PR description on how to manually test it on the devnet/testnet.
  • Tested the backwards compatibility.
  • Tested with XDC nodes running this version co-exist with those running the previous version.
  • Relevant documentation has been updated as part of this PR
  • N/A

Copilot AI review requested due to automatic review settings February 11, 2026 11:00
@coderabbitai
Copy link

coderabbitai bot commented Feb 11, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates mining work creation to recompute the candidate block timestamp after any sleep, aiming to avoid stale timestamps when the parent block changes.

Changes:

  • Recalculates tstart/tstamp after re-checking the parent block (post-sleep) in commitNewWork.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

tstamp = tstart.Unix()
if parent.Time() >= uint64(tstamp) {
tstamp = int64(parent.Time() + 1)
}
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After re-checking parent post-sleep, tstamp is recomputed but the "Mining too far in the future" guard is not re-applied. If the canonical parent advances to a block with a higher parent.Time() while sleeping, this can set header.Time far ahead of wall clock time without waiting again. Consider re-running the future-time wait logic after this recalculation (or moving the sleep until after the final parent selection).

Suggested change
}
}
// Ensure we are still not mining too far in the future with the updated parent.
if now := time.Now().Unix(); tstamp > now {
wait := time.Duration(tstamp-now) * time.Second
log.Info("Mining too far in the future", "wait", common.PrettyDuration(wait))
time.Sleep(wait)
}

Copilot uses AI. Check for mistakes.
Comment on lines +736 to +737
tstart = time.Now()
tstamp = tstart.Unix()
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tstart is later used for commit/finalize/total timing metrics, but it gets reassigned here. This changes the meaning of the logged durations (they will no longer include any pre-lock work/sleep) and is likely unintended given the PR scope. Consider keeping the original tstart for metrics and using a separate variable when recomputing the timestamp.

Suggested change
tstart = time.Now()
tstamp = tstart.Unix()
now := time.Now()
tstamp = now.Unix()

Copilot uses AI. Check for mistakes.
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.

1 participant