mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Remove Roughtime Usage From Prysm (#7299)
* remove roughtime * Merge branch 'master' into removeRoughtime * Merge refs/heads/master into removeRoughtime
This commit is contained in:
12
deps.bzl
12
deps.bzl
@@ -303,12 +303,6 @@ def prysm_deps():
|
||||
sum = "h1:ta993UF76GwbvJcIo3Y68y/M3WxlpEHPWIGDkJYwzJI=",
|
||||
version = "v0.3.4",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_cloudflare_cloudflare_go",
|
||||
importpath = "github.com/cloudflare/cloudflare-go",
|
||||
sum = "h1:J82+/8rub3qSy0HxEnoYD8cs+HDlHWYrqYXe2Vqxluk=",
|
||||
version = "v0.10.2-0.20190916151808-a80f83b9add9",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_cncf_udpa_go",
|
||||
importpath = "github.com/cncf/udpa/go",
|
||||
@@ -1895,12 +1889,6 @@ def prysm_deps():
|
||||
sum = "h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4=",
|
||||
version = "v2.2.0",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_github_cloudflare_roughtime",
|
||||
importpath = "github.com/cloudflare/roughtime",
|
||||
sum = "h1:jeSxE3fepJdhASERvBHI6RFkMhISv6Ir2JUybYLIVXs=",
|
||||
version = "v0.0.0-20200205191924-a69ef1dab727",
|
||||
)
|
||||
go_repository(
|
||||
name = "com_googlesource_roughtime_roughtime_git",
|
||||
build_file_generation = "on",
|
||||
|
||||
1
go.mod
1
go.mod
@@ -11,7 +11,6 @@ require (
|
||||
github.com/bazelbuild/rules_go v0.23.2
|
||||
github.com/btcsuite/btcd v0.20.1-beta
|
||||
github.com/cespare/cp v1.1.1 // indirect
|
||||
github.com/cloudflare/roughtime v0.0.0-20200205191924-a69ef1dab727
|
||||
github.com/confluentinc/confluent-kafka-go v1.4.2 // indirect
|
||||
github.com/d4l3k/messagediff v1.2.1 // indirect
|
||||
github.com/davidlazar/go-crypto v0.0.0-20200604182044-b73af7476f6c // indirect
|
||||
|
||||
5
go.sum
5
go.sum
@@ -136,8 +136,6 @@ github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1 h1:q763qf9huN11kDQavWs
|
||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/cloudflare/cloudflare-go v0.10.2-0.20190916151808-a80f83b9add9/go.mod h1:1MxXX1Ux4x6mqPmjkUgTP1CdXIBXKX7T+Jk9Gxrmx+U=
|
||||
github.com/cloudflare/roughtime v0.0.0-20200205191924-a69ef1dab727 h1:jeSxE3fepJdhASERvBHI6RFkMhISv6Ir2JUybYLIVXs=
|
||||
github.com/cloudflare/roughtime v0.0.0-20200205191924-a69ef1dab727/go.mod h1:cwyC+0SF0JfJKP8WehRwgHf2xuy8/DkUhZKxmYwND+w=
|
||||
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
|
||||
github.com/confluentinc/confluent-kafka-go v1.4.2 h1:13EK9RTujF7lVkvHQ5Hbu6bM+Yfrq8L0MkJNnjHSd4Q=
|
||||
github.com/confluentinc/confluent-kafka-go v1.4.2/go.mod h1:u2zNLny2xq+5rWeTQjFHbDzzNuba4P1vo31r9r4uAdg=
|
||||
@@ -1219,7 +1217,6 @@ golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8U
|
||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190618222545-ea8f1a30c443/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191105034135-c7e5f84aec59/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20191219195013-becbf705a915/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
@@ -1582,8 +1579,6 @@ k8s.io/kube-openapi v0.0.0-20200410145947-61e04a5be9a6/go.mod h1:GRQhZsXIAJ1xR0C
|
||||
k8s.io/utils v0.0.0-20200324210504-a9aa75ae1b89/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
|
||||
k8s.io/utils v0.0.0-20200520001619-278ece378a50 h1:ZtTUW5+ZWaoqjR3zOpRa7oFJ5d4aA22l4me/xArfOIc=
|
||||
k8s.io/utils v0.0.0-20200520001619-278ece378a50/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
|
||||
roughtime.googlesource.com/roughtime.git v0.0.0-20190418172256-51f6971f5f06 h1:Cmz+zn5wHFlBz3sPMsCzjmsn4zKLMMRRxhqnlKQ/zfI=
|
||||
roughtime.googlesource.com/roughtime.git v0.0.0-20190418172256-51f6971f5f06/go.mod h1:WmkBL5E0uicsLz5cgYSokPuZcXspS1pFFgEqotqNngk=
|
||||
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
|
||||
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
|
||||
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
|
||||
|
||||
@@ -64,7 +64,6 @@ type Flags struct {
|
||||
EnableEth1DataMajorityVote bool // EnableEth1DataMajorityVote uses the Voting With The Majority algorithm to vote for eth1data.
|
||||
EnableAttBroadcastDiscoveryAttempts bool // EnableAttBroadcastDiscoveryAttempts allows the p2p service to attempt to ensure a subnet peer is present before broadcasting an attestation.
|
||||
EnablePeerScorer bool // EnablePeerScorer enables experimental peer scoring in p2p.
|
||||
EnableRoughtime bool // EnableRoughtime is an opt-in flag for enabling hourly syncing with roughtime. Default is to not sync.
|
||||
|
||||
// DisableForkChoice disables using LMD-GHOST fork choice to update
|
||||
// the head of the chain based on attestations and instead accepts any valid received block
|
||||
@@ -263,10 +262,6 @@ func ConfigureBeaconChain(ctx *cli.Context) {
|
||||
log.Warn("Enabling peer scoring in P2P")
|
||||
cfg.EnablePeerScorer = true
|
||||
}
|
||||
if ctx.Bool(enableRoughtime.Name) {
|
||||
log.Warn("Enabling roughtime sync")
|
||||
cfg.EnableRoughtime = true
|
||||
}
|
||||
cfg.UseCheckPointInfoCache = true
|
||||
if ctx.Bool(disableCheckPtInfoCache.Name) {
|
||||
log.Warn("Disabling advanced check point info cache")
|
||||
|
||||
@@ -169,10 +169,6 @@ var (
|
||||
Name: "enable-peer-scorer",
|
||||
Usage: "Enable experimental P2P peer scorer",
|
||||
}
|
||||
enableRoughtime = &cli.BoolFlag{
|
||||
Name: "enable-roughtime",
|
||||
Usage: "Enables periodic roughtime syncs.",
|
||||
}
|
||||
disableCheckPtInfoCache = &cli.BoolFlag{
|
||||
Name: "disable-check-point-cache",
|
||||
Usage: "Disables check point info caching",
|
||||
@@ -566,6 +562,11 @@ var (
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
deprecatedEnableRoughtime = &cli.BoolFlag{
|
||||
Name: "enable-roughtime",
|
||||
Usage: deprecatedUsage,
|
||||
Hidden: true,
|
||||
}
|
||||
)
|
||||
|
||||
var deprecatedFlags = []cli.Flag{
|
||||
@@ -644,6 +645,7 @@ var deprecatedFlags = []cli.Flag{
|
||||
deprecatedEnableFinalizedDepositsCache,
|
||||
deprecatedCheckptInfoCache,
|
||||
deprecatedBatchBlockVerify,
|
||||
deprecatedEnableRoughtime,
|
||||
}
|
||||
|
||||
// ValidatorFlags contains a list of all the feature flags that apply to the validator client.
|
||||
@@ -703,7 +705,6 @@ var BeaconChainFlags = append(deprecatedFlags, []cli.Flag{
|
||||
enableEth1DataMajorityVote,
|
||||
enableAttBroadcastDiscoveryAttempts,
|
||||
enablePeerScorer,
|
||||
enableRoughtime,
|
||||
disableCheckPtInfoCache,
|
||||
}...)
|
||||
|
||||
|
||||
@@ -5,11 +5,4 @@ go_library(
|
||||
srcs = ["roughtime.go"],
|
||||
importpath = "github.com/prysmaticlabs/prysm/shared/roughtime",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//shared/featureconfig: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",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -1,121 +1,21 @@
|
||||
// Package roughtime is a wrapper for a roughtime clock source.
|
||||
// Package roughtime is a soon to be deprecated wrapper for the local clock time.
|
||||
package roughtime
|
||||
|
||||
import (
|
||||
"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/featureconfig"
|
||||
"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
|
||||
|
||||
var log = logrus.WithField("prefix", "roughtime")
|
||||
|
||||
var offsetHistogram = promauto.NewHistogram(prometheus.HistogramOpts{
|
||||
Name: "roughtime_offset_nsec",
|
||||
Help: "The absolute value delta between roughtime computed clock time and the system clock time.",
|
||||
Buckets: []float64{
|
||||
float64(50 * time.Millisecond),
|
||||
float64(100 * time.Millisecond),
|
||||
float64(500 * time.Millisecond),
|
||||
float64(1 * time.Second),
|
||||
float64(2 * time.Second),
|
||||
float64(10 * time.Second),
|
||||
},
|
||||
})
|
||||
|
||||
var offsetsRejected = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Name: "roughtime_offsets_rejected",
|
||||
Help: "The number of times that roughtime results could not be verified and the returned offset was rejected",
|
||||
})
|
||||
|
||||
func init() {
|
||||
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() {
|
||||
if !featureconfig.Get().EnableRoughtime {
|
||||
return
|
||||
}
|
||||
|
||||
t0 := time.Now()
|
||||
results := rt.Do(rt.Ecosystem, rt.DefaultQueryAttempts, rt.DefaultQueryTimeout, nil)
|
||||
|
||||
// Log Debug Results.
|
||||
for _, res := range results {
|
||||
if res.Error() != nil {
|
||||
log.Errorf("Could not get rough time result: %v", res.Error())
|
||||
continue
|
||||
}
|
||||
log.WithFields(logrus.Fields{
|
||||
"Server Name": res.Server.Name,
|
||||
"Midpoint": res.Midpoint,
|
||||
"Delay": res.Delay,
|
||||
"Radius": res.Roughtime.Radius,
|
||||
}).Debug("Response received from roughtime server")
|
||||
}
|
||||
// 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.
|
||||
newOffset, err := rt.AvgDeltaWithRadiusThresh(results, t0, 2*time.Second)
|
||||
if err != nil {
|
||||
log.WithError(err).Error("Failed to calculate roughtime offset")
|
||||
}
|
||||
offsetHistogram.Observe(math.Abs(float64(newOffset)))
|
||||
if newOffset > 2*time.Second {
|
||||
log.WithField("offset", newOffset).Warn("Roughtime reports your clock is off by more than 2 seconds")
|
||||
}
|
||||
|
||||
chain := rt.NewChain(results)
|
||||
ok, err := chain.Verify(nil)
|
||||
if err != nil || !ok {
|
||||
log.WithError(err).WithField("offset", newOffset).Error("Could not verify roughtime responses, not accepting roughtime offset")
|
||||
offsetsRejected.Inc()
|
||||
return
|
||||
}
|
||||
|
||||
log.Debugf("New calculated roughtime offset is %d ns", newOffset.Nanoseconds())
|
||||
offset = newOffset
|
||||
}
|
||||
|
||||
// Since returns the duration since t, based on the roughtime response
|
||||
// Since returns the duration since t.
|
||||
func Since(t time.Time) time.Duration {
|
||||
return Now().Sub(t)
|
||||
}
|
||||
|
||||
// Until returns the duration until t, based on the roughtime response
|
||||
// Until returns the duration until t.
|
||||
func Until(t time.Time) time.Duration {
|
||||
return t.Sub(Now())
|
||||
}
|
||||
|
||||
// Now returns the current local time given the roughtime offset.
|
||||
// Now returns the current local time.
|
||||
func Now() time.Time {
|
||||
if featureconfig.Get().EnableRoughtime {
|
||||
return time.Now().Add(offset)
|
||||
}
|
||||
return time.Now()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user