Skip to content

Commit

Permalink
Merge pull request #19 from samcm/feat/finality
Browse files Browse the repository at this point in the history
feat(consensus): Expose finality checkpoints
  • Loading branch information
samcm authored Jun 3, 2022
2 parents 647be21 + 8a3f7b9 commit 13d2818
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 18 deletions.
71 changes: 53 additions & 18 deletions pkg/exporter/consensus/jobs/general.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import (

// General reports general information about the node.
type General struct {
client eth2client.Service
log logrus.FieldLogger
Slots prometheus.GaugeVec
NodeVersion prometheus.GaugeVec
ReOrgs prometheus.Counter
ReOrgDepth prometheus.Counter
client eth2client.Service
log logrus.FieldLogger
Slots prometheus.GaugeVec
NodeVersion prometheus.GaugeVec
ReOrgs prometheus.Counter
ReOrgDepth prometheus.Counter
FinalityCheckpoints prometheus.GaugeVec
}

const (
Expand Down Expand Up @@ -70,6 +71,18 @@ func NewGeneralJob(client eth2client.Service, log logrus.FieldLogger, namespace
ConstLabels: constLabels,
},
),
FinalityCheckpoints: *prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: namespace,
Name: "finality_checkpoint_epochs",
Help: "That epochs of the finality checkpoints.",
ConstLabels: constLabels,
},
[]string{
"state_id",
"checkpoint",
},
),
}
}

Expand Down Expand Up @@ -144,20 +157,16 @@ func (g *General) tick(ctx context.Context) {
g.log.WithError(err).Error("Failed to get node version")
}

if err := g.GetBeaconSlot(ctx, "head"); err != nil {
g.log.WithError(err).Error("Failed to get beacon slot: head")
}

if err := g.GetBeaconSlot(ctx, "genesis"); err != nil {
g.log.WithError(err).Error("Failed to get beacon slot: genesis")
}
checkpoints := []string{"head", "justified", "finalized"}

if err := g.GetBeaconSlot(ctx, "justified"); err != nil {
g.log.WithError(err).Error("Failed to get beacon slot: justified")
}
for _, checkpoint := range checkpoints {
if err := g.GetBeaconSlot(ctx, checkpoint); err != nil {
g.log.WithError(err).Error("Failed to get beacon slot: ", checkpoint)
}

if err := g.GetBeaconSlot(ctx, "finalized"); err != nil {
g.log.WithError(err).Error("Failed to get beacon slot: finalized")
if err := g.GetFinality(ctx, checkpoint); err != nil {
g.log.WithError(err).Error("Failed to get finality checkpoint: ", checkpoint)
}
}
}

Expand Down Expand Up @@ -208,3 +217,29 @@ func (g *General) GetBeaconSlot(ctx context.Context, identifier string) error {
func (g *General) ObserveSlot(identifier string, slot uint64) {
g.Slots.WithLabelValues(identifier).Set(float64(slot))
}

func (g *General) GetFinality(ctx context.Context, stateID string) error {
provider, isProvider := g.client.(eth2client.FinalityProvider)
if !isProvider {
return errors.New("client does not implement eth2client.FinalityProvider")
}

finality, err := provider.Finality(ctx, stateID)
if err != nil {
return err
}

g.FinalityCheckpoints.
WithLabelValues(stateID, "previous_justified").
Set(float64(finality.PreviousJustified.Epoch))

g.FinalityCheckpoints.
WithLabelValues(stateID, "justified").
Set(float64(finality.Justified.Epoch))

g.FinalityCheckpoints.
WithLabelValues(stateID, "finalized").
Set(float64(finality.Finalized.Epoch))

return nil
}
1 change: 1 addition & 0 deletions pkg/exporter/consensus/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func NewMetrics(client eth2client.Service, log logrus.FieldLogger, nodeName, nam
prometheus.MustRegister(m.generalMetrics.NodeVersion)
prometheus.MustRegister(m.generalMetrics.ReOrgs)
prometheus.MustRegister(m.generalMetrics.ReOrgDepth)
prometheus.MustRegister(m.generalMetrics.FinalityCheckpoints)

prometheus.MustRegister(m.syncMetrics.Percentage)
prometheus.MustRegister(m.syncMetrics.EstimatedHighestSlot)
Expand Down

0 comments on commit 13d2818

Please sign in to comment.