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:
Raul Jordan 2020-06-25 09:02:54 -05:00 committed by GitHub
parent 5fdf6310f7
commit 90bfc9a395
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -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",
],

View File

@ -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.