Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions pkg/assertoor/coordinator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
Expand All @@ -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)
}

Expand Down
15 changes: 14 additions & 1 deletion pkg/clients/consensus/blockcache.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,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 {
Expand Down Expand Up @@ -185,7 +193,12 @@ func (cache *BlockCache) InitWallclock() {
return
}

cache.wallclock = ethwallclock.NewEthereumBeaconChain(cache.genesis.GenesisTime, specs.SecondsPerSlot, specs.SlotsPerEpoch)
if specs.SlotDurationMs == 0 || specs.SlotsPerEpoch == 0 {
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(&current)
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/clients/consensus/chainspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down
Loading