diff --git a/pkg/assertoor/coordinator.go b/pkg/assertoor/coordinator.go index e9f7999b..b725061a 100644 --- a/pkg/assertoor/coordinator.go +++ b/pkg/assertoor/coordinator.go @@ -366,10 +366,12 @@ func (c *Coordinator) runEpochGC(ctx context.Context) { var sleepTime time.Duration networkTime := time.Since(genesis.GenesisTime) + slotDuration := time.Duration(specs.SlotDurationMs) * time.Millisecond //nolint:gosec // G115: slot duration values won't overflow int64 + if networkTime < 0 { sleepTime = networkTime.Abs() } else { - currentSlot := uint64(networkTime / specs.SecondsPerSlot) //nolint:gosec // G115: networkTime is checked non-negative above + currentSlot := uint64(networkTime / slotDuration) //nolint:gosec // G115: networkTime is checked non-negative above currentEpoch := currentSlot / specs.SlotsPerEpoch currentSlotIndex := currentSlot % specs.SlotsPerEpoch nextGcSlot := uint64(0) @@ -385,10 +387,10 @@ func (c *Coordinator) runEpochGC(ctx context.Context) { select { case <-ctx.Done(): return - case <-time.After(specs.SecondsPerSlot / 2): + case <-time.After(slotDuration / 2): } - nextEpochDuration := time.Until(genesis.GenesisTime.Add(time.Duration((currentEpoch+1)*specs.SlotsPerEpoch) * specs.SecondsPerSlot)) //nolint:gosec // G115: epoch*slots product won't overflow + nextEpochDuration := time.Until(genesis.GenesisTime.Add(time.Duration((currentEpoch+1)*specs.SlotsPerEpoch) * slotDuration)) //nolint:gosec // G115: epoch*slots product won't overflow c.log.GetLogger().Infof("run GC (slot %v, %v sec before epoch %v)", currentSlot, nextEpochDuration.Seconds(), currentEpoch+1) runtime.GC() @@ -402,7 +404,7 @@ func (c *Coordinator) runEpochGC(ctx context.Context) { } } - nextRunTime := genesis.GenesisTime.Add(time.Duration(nextGcSlot) * specs.SecondsPerSlot) //nolint:gosec // G115: slot number won't overflow int64 + nextRunTime := genesis.GenesisTime.Add(time.Duration(nextGcSlot) * slotDuration) //nolint:gosec // G115: slot number won't overflow int64 sleepTime = time.Until(nextRunTime) } diff --git a/pkg/clients/consensus/blockcache.go b/pkg/clients/consensus/blockcache.go index fe74bb37..d904f72f 100644 --- a/pkg/clients/consensus/blockcache.go +++ b/pkg/clients/consensus/blockcache.go @@ -19,6 +19,7 @@ import ( ) type BlockCache struct { + logger logrus.FieldLogger followDistance uint32 specMutex sync.RWMutex @@ -56,6 +57,7 @@ func NewBlockCache(ctx context.Context, logger logrus.FieldLogger, followDistanc } cache := BlockCache{ + logger: logger, followDistance: followDistance, blockSlotMap: make(map[phase0.Slot][]*Block), blockRootMap: make(map[phase0.Root]*Block), @@ -145,6 +147,14 @@ func (cache *BlockCache) SetClientSpecs(specValues map[string]interface{}) error return err } + if specs.SlotDurationMs == 0 { + if secondsPerSlot, ok := specValues["SECONDS_PER_SLOT"]; ok { + if v, vOk := secondsPerSlot.(time.Duration); vOk { + specs.SlotDurationMs = uint64(v.Milliseconds()) //nolint:gosec // G115: SECONDS_PER_SLOT is always a small positive value + } + } + } + if cache.specs != nil { mismatches := cache.specs.CheckMismatch(&specs) if len(mismatches) > 0 { @@ -185,7 +195,13 @@ func (cache *BlockCache) InitWallclock() { return } - cache.wallclock = ethwallclock.NewEthereumBeaconChain(cache.genesis.GenesisTime, specs.SecondsPerSlot, specs.SlotsPerEpoch) + if specs.SlotDurationMs == 0 || specs.SlotsPerEpoch == 0 { + cache.logger.Errorf("cannot initialize wallclock: neither SLOT_DURATION_MS nor SECONDS_PER_SLOT are available from the beacon API (SlotDurationMs=%d, SlotsPerEpoch=%d)", specs.SlotDurationMs, specs.SlotsPerEpoch) + return + } + + slotDuration := time.Duration(specs.SlotDurationMs) * time.Millisecond //nolint:gosec // G115: slot duration values won't overflow int64 + cache.wallclock = ethwallclock.NewEthereumBeaconChain(cache.genesis.GenesisTime, slotDuration, specs.SlotsPerEpoch) cache.wallclock.OnEpochChanged(func(current ethwallclock.Epoch) { cache.wallclockEpochDispatcher.Fire(¤t) }) diff --git a/pkg/clients/consensus/chainspec.go b/pkg/clients/consensus/chainspec.go index 7de457cf..c855c2c5 100644 --- a/pkg/clients/consensus/chainspec.go +++ b/pkg/clients/consensus/chainspec.go @@ -25,7 +25,7 @@ type ChainSpec struct { BellatrixForkEpoch uint64 `yaml:"BELLATRIX_FORK_EPOCH"` CappellaForkVersion phase0.Version `yaml:"CAPELLA_FORK_VERSION"` CappellaForkEpoch uint64 `yaml:"CAPELLA_FORK_EPOCH"` - SecondsPerSlot time.Duration `yaml:"SECONDS_PER_SLOT"` + SlotDurationMs uint64 `yaml:"SLOT_DURATION_MS"` SlotsPerEpoch uint64 `yaml:"SLOTS_PER_EPOCH"` MaxCommitteesPerSlot uint64 `yaml:"MAX_COMMITTEES_PER_SLOT"` }