Skip to content

Commit

Permalink
Merge pull request #47 from samcm/fix/finality-checkpoints
Browse files Browse the repository at this point in the history
fix(consensus): Fetch finality checkpoints on a loop
  • Loading branch information
samcm authored Sep 9, 2022
2 parents e302ec5 + bd438cc commit ad52b02
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/exporter/consensus/beacon/state/fork_epoch.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type ForkEpoch struct {

// Active returns true if the fork is active at the given slot.
func (f *ForkEpoch) Active(slot, slotsPerEpoch phase0.Slot) bool {
return phase0.Epoch(int(slot)/int(slotsPerEpoch)) > f.Epoch
return phase0.Epoch(int(slot)/int(slotsPerEpoch)) >= f.Epoch
}

// ForkEpochs is a list of forks that activate at specific epochs.
Expand Down
13 changes: 10 additions & 3 deletions pkg/exporter/consensus/jobs/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,14 @@ func (b *Beacon) Start(ctx context.Context) error {
select {
case <-ctx.Done():
return ctx.Err()
case <-time.After(time.Second * 5):
case <-time.After(time.Second * 60):
b.tick(ctx)
}
}
}

func (b *Beacon) tick(ctx context.Context) {

b.updateFinalizedCheckpoint(ctx)
}

func (b *Beacon) setupSubscriptions(ctx context.Context) error {
Expand All @@ -233,7 +233,14 @@ func (b *Beacon) setupSubscriptions(ctx context.Context) error {
return err
}

if _, err := b.beaconNode.OnFinalizedCheckpoint(ctx, b.handleFinalizedCheckpointEvent); err != nil {
if _, err := b.beaconNode.OnFinalizedCheckpoint(ctx, func(ctx context.Context, ev *v1.FinalizedCheckpointEvent) error {
// Sleep for 3 seconds to allow the beacon node to process the finalized checkpoint.
time.Sleep(3 * time.Second)

b.updateFinalizedCheckpoint(ctx)

return nil
}); err != nil {
return err
}

Expand Down

0 comments on commit ad52b02

Please sign in to comment.