Skip to content

Commit

Permalink
fetch general data on boot
Browse files Browse the repository at this point in the history
  • Loading branch information
samcm committed Jul 12, 2022
1 parent 4220717 commit 7d3b818
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
6 changes: 6 additions & 0 deletions pkg/exporter/consensus/beacon/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type Node interface {
GetSyncState(ctx context.Context) (*v1.SyncState, error)
// GetGenesis returns the genesis for the node.
GetGenesis(ctx context.Context) (*v1.Genesis, error)
// GetNodeVersion returns the node version.
GetNodeVersion(ctx context.Context) (string, error)

// Subscriptions
// - Proxied Beacon events
Expand Down Expand Up @@ -191,6 +193,10 @@ func (n *node) GetGenesis(ctx context.Context) (*v1.Genesis, error) {
return n.genesis, nil
}

func (n *node) GetNodeVersion(ctx context.Context) (string, error) {
return n.nodeVersion, nil
}

func (n *node) bootstrap(ctx context.Context) error {
if err := n.initializeState(ctx); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion pkg/exporter/consensus/beacon/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func (c *Container) checkForNewCurrentEpochAndSlot(ctx context.Context) error {
// We can't safely check if the previous slot was missed if
// we potentially started up _after_ the slot had started.
// So we'll just not bother checking in that case.
if time.Since(c.startedAt) > (c.spec.SecondsPerSlot * 2) {
if time.Since(c.startedAt) > (c.spec.SecondsPerSlot * 3) {
if err := c.checkForEmptySlot(ctx, previousSlot); err != nil {
c.log.WithError(err).Error("Failed to check for empty slot")
}
Expand Down
28 changes: 23 additions & 5 deletions pkg/exporter/consensus/jobs/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ func (g *General) Name() string {

func (g *General) Start(ctx context.Context) error {
if _, err := g.beacon.OnNodeVersionUpdated(ctx, func(ctx context.Context, event *beacon.NodeVersionUpdatedEvent) error {
g.log.WithField("version", event.Version).Debug("Got node version")

g.NodeVersion.Reset()
g.NodeVersion.WithLabelValues(event.Version).Set(1)

g.observeNodeVersion(ctx, event.Version)
return nil
}); err != nil {
return err
Expand All @@ -85,5 +81,27 @@ func (g *General) Start(ctx context.Context) error {
return err
}

if err := g.initialFetch(ctx); err != nil {
return err
}

return nil
}

func (g *General) initialFetch(ctx context.Context) error {
version, err := g.beacon.GetNodeVersion(ctx)
if err != nil {
return err
}

g.observeNodeVersion(ctx, version)

return nil
}

func (g *General) observeNodeVersion(ctx context.Context, version string) {
g.log.WithField("version", version).Debug("Got node version")

g.NodeVersion.Reset()
g.NodeVersion.WithLabelValues(version).Set(1)
}

0 comments on commit 7d3b818

Please sign in to comment.