Skip to content

Commit

Permalink
feat(cannon): Refresh spec every epoch
Browse files Browse the repository at this point in the history
  • Loading branch information
samcm committed Jan 12, 2024
1 parent f1fdc94 commit f983937
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion pkg/cannon/cannon.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/beevik/ntp"
"github.com/ethpandaops/ethwallclock"
aBlockprint "github.com/ethpandaops/xatu/pkg/cannon/blockprint"
"github.com/ethpandaops/xatu/pkg/cannon/coordinator"
"github.com/ethpandaops/xatu/pkg/cannon/deriver"
Expand Down Expand Up @@ -551,6 +552,14 @@ func (c *Cannon) startBeaconBlockProcessor(ctx context.Context) error {

c.eventDerivers = eventDerivers

// Refresh the spec every epoch
c.beacon.Metadata().Wallclock().OnEpochChanged(func(current ethwallclock.Epoch) {
_, err := c.beacon.Node().FetchSpec(ctx)
if err != nil {
c.log.WithError(err).Error("Failed to refresh spec")
}
})

for _, deriver := range c.eventDerivers {
d := deriver

Expand Down Expand Up @@ -591,7 +600,9 @@ func (c *Cannon) startDeriverWhenReady(ctx context.Context, d deriver.EventDeriv
if err != nil {
c.log.WithError(err).Errorf("unknown activation fork: %s", d.ActivationFork())

time.Sleep(5 * time.Second)
epoch := c.beacon.Metadata().Wallclock().Epochs().Current()

time.Sleep(time.Until(epoch.TimeWindow().End()))

continue
}
Expand Down

0 comments on commit f983937

Please sign in to comment.