mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-23 11:57:18 +00:00
QSP-49 Recalibrate Roughtime (#6393)
* roughtime recalibrate * recalibrate roughtime Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
parent
5fdf6310f7
commit
90bfc9a395
@ -6,6 +6,7 @@ go_library(
|
||||
importpath = "github.com/prysmaticlabs/prysm/shared/roughtime",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//shared/runutil:go_default_library",
|
||||
"@com_github_cloudflare_roughtime//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
],
|
||||
|
@ -2,12 +2,18 @@
|
||||
package roughtime
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
rt "github.com/cloudflare/roughtime"
|
||||
"github.com/prysmaticlabs/prysm/shared/runutil"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
// RecalibrationInterval for roughtime and system time differences. Set
|
||||
// as a default of once per hour.
|
||||
const RecalibrationInterval = time.Hour
|
||||
|
||||
// offset is the difference between the system time and the time returned by
|
||||
// the roughtime server
|
||||
var offset time.Duration
|
||||
@ -15,10 +21,13 @@ var offset time.Duration
|
||||
var log = logrus.WithField("prefix", "roughtime")
|
||||
|
||||
func init() {
|
||||
recalibrateRoughtime()
|
||||
runutil.RunEvery(context.Background(), RecalibrationInterval, recalibrateRoughtime)
|
||||
}
|
||||
|
||||
func recalibrateRoughtime() {
|
||||
t0 := time.Now()
|
||||
|
||||
results := rt.Do(rt.Ecosystem, rt.DefaultQueryAttempts, rt.DefaultQueryTimeout, nil)
|
||||
|
||||
// Compute the average difference between the system's time and the
|
||||
// Roughtime responses from the servers, rejecting responses whose radii
|
||||
// are larger than 2 seconds.
|
||||
|
Loading…
Reference in New Issue
Block a user