Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/scheduler: tweak clock sync #778

Merged
merged 3 commits into from
Jul 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions core/scheduler/clocksync.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ func newClockSyncer(ctx context.Context, eventsProvider eth2client.EventsProvide
newOffset := clock.Since(startTime)

offsets = append(offsets, newOffset)
if len(offsets) < offsetCount {
return
}

offsets = offsets[len(offsets)-offsetCount:] // Trim buffer to max offsetCount items.
if len(offsets) > offsetCount {
offsets = offsets[len(offsets)-offsetCount:] // Trim buffer to max offsetCount items.
}

clone := append([]time.Duration(nil), offsets...)
sort.Slice(clone, func(i, j int) bool {
Expand Down
12 changes: 3 additions & 9 deletions core/scheduler/clocksync_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,14 @@ func TestClockSync(t *testing.T) {

var slot int

// Offset is zero until min 10 events
for i := 0; i < offsetCount-1; i++ {
// Offset is smallOffset
for i := 0; i < offsetCount; i++ {
clock.Advance(slotDuration)
slot++
provider.Push(slot)
require.Zero(t, syncOffset())
require.Equal(t, smallOffset, syncOffset())
}

clock.Advance(slotDuration)
slot++
provider.Push(slot)

require.Equal(t, smallOffset, syncOffset())

// Increase offset
clock.Advance(smallOffset)

Expand Down
2 changes: 1 addition & 1 deletion core/scheduler/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var (
syncMedianGauge = promauto.NewGauge(prometheus.GaugeOpts{
Namespace: "core",
Subsystem: "scheduler",
Name: "clock_sync_median_seconds",
Name: "beacon_node_offset_seconds",
Help: "The beacon node clock sync median offset in seconds",
})
)
Expand Down
3 changes: 2 additions & 1 deletion core/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@ func newSlotTicker(ctx context.Context, eth2Cl eth2Provider, clock clockwork.Clo
// Add offset to start time to account for beacon node clock skew.
delay += syncOffset()
}
if height/10 == 0 { // Log offset every minute or so.

if height%10 == 0 { // Log offset every minute or so.
log.Debug(ctx, "Beacon node clock sync: remote vs local next slot event",
z.Any("offset", syncOffset()),
z.Any("beacon_clock_sync_enabled", featureset.Enabled(featureset.BeaconClockSync)))
Expand Down
2 changes: 1 addition & 1 deletion testutil/compose/define.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func buildLocal(ctx context.Context, dir string) error {
log.Info(ctx, "Building local charon binary", z.Str("repo", repo), z.Str("target", target))

cmd := exec.CommandContext(ctx, "go", "build", "-o", target)
cmd.Env = append(os.Environ(), "GOOS=linux", "GOARCH=amd64")
cmd.Env = append(os.Environ(), "GOOS=linux", "GOARCH=amd64", "CGO_ENABLED=0")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussion: why do we need to set CGO_ENABLED flag here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when building go programs, it is best practice to explicitly disable CGO if not required, otherwise some C libraries and stuff is included in the build which can impact compatibility.

cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Dir = repo
Expand Down
73 changes: 68 additions & 5 deletions testutil/compose/static/grafana/dash_simnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"iteration": 1649349193420,
"iteration": 1657289866291,
"links": [],
"liveNow": false,
"panels": [
Expand Down Expand Up @@ -177,6 +177,69 @@
],
"type": "table"
},
{
"description": "Difference of local vs remote next slot event",
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "red",
"value": 80
}
]
},
"unit": "s"
},
"overrides": []
},
"gridPos": {
"h": 4,
"w": 3,
"x": 8,
"y": 1
},
"id": 21,
"options": {
"colorMode": "value",
"graphMode": "area",
"justifyMode": "auto",
"orientation": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": false
},
"textMode": "auto"
},
"pluginVersion": "8.4.4",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "PBFA97CFB590B2093"
},
"exemplar": true,
"expr": "core_scheduler_beacon_node_offset_seconds{job=\"$node\"}",
"interval": "",
"legendFormat": "",
"refId": "A"
}
],
"title": "Beacon Clock Sync",
"type": "stat"
},
{
"fieldConfig": {
"defaults": {
Expand Down Expand Up @@ -230,8 +293,8 @@
},
"gridPos": {
"h": 4,
"w": 8,
"x": 8,
"w": 7,
"x": 11,
"y": 1
},
"id": 13,
Expand Down Expand Up @@ -315,8 +378,8 @@
},
"gridPos": {
"h": 4,
"w": 8,
"x": 16,
"w": 6,
"x": 18,
"y": 1
},
"id": 14,
Expand Down