Skip to content

Commit

Permalink
feat(cannon): Add additonal logging to derivers waiting for activation (
Browse files Browse the repository at this point in the history
#269)

* feat(cannon): Refresh spec every epoch

* feat(cannon): Add additonal logging for derviers waiting to be activated
  • Loading branch information
samcm authored Jan 12, 2024
1 parent f1fdc94 commit 7d9507e
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions 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,18 +600,40 @@ 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
}

if !fork.Active(phase0.Slot(slot.Number()), spec.SlotsPerEpoch) {
// Sleep until the next epochl and then retrty
c.log.Debug("Derived epoch is not active yet, sleeping until next epoch")
currentEpoch := c.beacon.Metadata().Wallclock().Epochs().Current()

epoch := c.beacon.Metadata().Wallclock().Epochs().Current()
activationForkEpoch := c.beacon.Node().Wallclock().Epochs().FromNumber(uint64(fork.Epoch))

time.Sleep(time.Until(epoch.TimeWindow().End()))
sleepFor := time.Until(activationForkEpoch.TimeWindow().End())

if activationForkEpoch.Number()-currentEpoch.Number() > 100000 {
// If the fork epoch is over 100k epochs away we are most likely dealing with a
// placeholder fork epoch. We should sleep until the end of the current fork epoch and then
// wait for the spec to refresh. This gives the beacon node a chance to give us the real
// fork epoch once its scheduled.
sleepFor = time.Until(currentEpoch.TimeWindow().End())
}

c.log.
WithField("current_epoch", currentEpoch.Number()).
WithField("activation_fork_name", d.ActivationFork()).
WithField("activation_fork_epoch", fork.Epoch).
WithField("estimated_time_until_fork", time.Until(
activationForkEpoch.TimeWindow().Start(),
)).
WithField("check_again_in", sleepFor).
Warn("Deriver required fork is not active yet")

time.Sleep(sleepFor)

continue
}
Expand Down

0 comments on commit 7d9507e

Please sign in to comment.