Check roughtime more frequently when there is a large clock offset (#6879)

* recheck roughtime more frequently if we think our clock is far off
* Merge refs/heads/master into faster-roughtime-corrections
* gaz
* Merge refs/heads/master into faster-roughtime-corrections
* Merge refs/heads/master into faster-roughtime-corrections
* Merge refs/heads/master into faster-roughtime-corrections
This commit is contained in:
Preston Van Loon 2020-08-05 05:31:13 -07:00 committed by GitHub
parent e492343ffd
commit 0d118df034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 4 deletions

View File

@ -6,7 +6,6 @@ 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_prometheus_client_golang//prometheus:go_default_library",
"@com_github_prometheus_client_golang//prometheus/promauto:go_default_library",

View File

@ -2,14 +2,12 @@
package roughtime
import (
"context"
"math"
"time"
rt "github.com/cloudflare/roughtime"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/prysmaticlabs/prysm/shared/runutil"
"github.com/sirupsen/logrus"
)
@ -43,7 +41,19 @@ var offsetsRejected = promauto.NewCounter(prometheus.CounterOpts{
func init() {
recalibrateRoughtime()
runutil.RunEvery(context.Background(), RecalibrationInterval, recalibrateRoughtime)
go func() {
for {
wait := RecalibrationInterval
// recalibrate every minute if there is a large skew.
if offset > 2*time.Second {
wait = 1 * time.Minute
}
select {
case <-time.After(wait):
recalibrateRoughtime()
}
}
}()
}
func recalibrateRoughtime() {