Skip to content

Implement NTP offset updates for block timestamps every minute#5028

Merged
Frozen merged 3 commits into
devfrom
feat/ntp-time-provider
Apr 16, 2026
Merged

Implement NTP offset updates for block timestamps every minute#5028
Frozen merged 3 commits into
devfrom
feat/ntp-time-provider

Conversation

@Frozen
Copy link
Copy Markdown
Collaborator

@Frozen Frozen commented Mar 28, 2026

This pull request introduces a new abstraction for time management in the Harmony node, allowing the system to use NTP-corrected time instead of relying solely on the local system clock. The changes provide a pluggable interface for time retrieval, integrate NTP time synchronization into the node setup, and propagate the use of this time source throughout the consensus and worker logic.

Key changes include:

NTP Time Abstraction and Implementation:

  • Added a new NTPTime interface and its implementations (LocalTime for local system time and ntpTimeImpl for NTP-synchronized time) in api/service/ntp, with logic to periodically synchronize time from an NTP server and provide the current corrected time. [1] [2]

Node Initialization and Registry Integration:

  • Modified node setup (cmd/harmony/main.go) to initialize and select the appropriate time provider (NTP or local) based on network type, and inject it into the node's registry. The NTP provider is run in the background to keep time updated. [1] [2] [3] [4] [5]
  • Updated the Registry struct to store the NTPTime provider and expose a Now() method for retrieving the current time, as well as a setter for the time provider. [1] [2] [3]

Consensus and Worker Usage:

  • Changed the consensus block proposing logic to use the registry's NTP-corrected time when updating the worker's environment.
  • Updated the Worker.UpdateCurrent method to accept the current time as a parameter, enabling the use of the NTP-corrected time for block timestamps.

Testing Adjustments:

  • Updated tests to pass the current time explicitly to Worker.UpdateCurrent, ensuring compatibility with the new interface. [1] [2] [3]

@Frozen Frozen self-assigned this Mar 28, 2026
@Frozen Frozen marked this pull request as ready for review March 28, 2026 06:06
@mur-me mur-me requested review from GheisMohammadi and mur-me April 15, 2026 15:36
Frozen and others added 3 commits April 15, 2026 14:21
…amps

- Add NTPTime interface and periodic offset refresh (every 1 minute) via Run()
- Store NTP time provider in Registry with Now() accessor
- Pass NTP-corrected time to Worker.UpdateCurrent() when proposing blocks
- Fix consensus_block_proposing.go to use registry.Now() for block timestamp
- Wire NTP provider in main.go with go impl.Run(ctx, time.Minute)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add NTPEpoch field to ChainConfig with EpochTBD in all network configs
- Add IsNTP(epoch) helper method
- Use NTP-corrected time in ProposeNewBlock only when IsNTP is active

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Frozen Frozen force-pushed the feat/ntp-time-provider branch from c36d812 to 8977653 Compare April 15, 2026 19:24
@Frozen Frozen merged commit 552ac1d into dev Apr 16, 2026
4 checks passed
@Frozen Frozen deleted the feat/ntp-time-provider branch April 27, 2026 22:12
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