Implement NTP offset updates for block timestamps every minute#5028
Merged
Conversation
…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>
c36d812 to
8977653
Compare
mur-me
approved these changes
Apr 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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:
NTPTimeinterface and its implementations (LocalTimefor local system time andntpTimeImplfor NTP-synchronized time) inapi/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:
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]Registrystruct to store theNTPTimeprovider and expose aNow()method for retrieving the current time, as well as a setter for the time provider. [1] [2] [3]Consensus and Worker Usage:
Worker.UpdateCurrentmethod to accept the current time as a parameter, enabling the use of the NTP-corrected time for block timestamps.Testing Adjustments:
Worker.UpdateCurrent, ensuring compatibility with the new interface. [1] [2] [3]