Compare commits

...

1 Commits

Author SHA1 Message Date
Potuz
cc0f1d0f6d Only start from the skipped slot cache if better
ProcessSlots takes a state from the skipped slot cache and assumes that it's better than the passed current state.

If the incoming state.Slot() is higher than the skipped slot cache, then the highest slot is set to be the cache, we process slots again for the same state and then we put back to the cache.
2024-03-12 11:35:41 -03:00

View File

@@ -211,9 +211,12 @@ func ProcessSlots(ctx context.Context, state state.BeaconState, slot primitives.
if err != nil {
return nil, err
}
if cachedState != nil && !cachedState.IsNil() && cachedState.Slot() < slot {
highestSlot = cachedState.Slot()
cachedSlot := primitives.Slot(0)
if cachedState != nil {
cachedSlot = cachedState.Slot()
}
if cachedState != nil && !cachedState.IsNil() && cachedSlot <= slot && cachedSlot > highestSlot {
highestSlot = cachedSlot
state = cachedState
}
if err := SkipSlotCache.MarkInProgress(key); errors.Is(err, cache.ErrAlreadyInProgress) {
@@ -221,8 +224,10 @@ func ProcessSlots(ctx context.Context, state state.BeaconState, slot primitives.
if err != nil {
return nil, err
}
if cachedState != nil && !cachedState.IsNil() && cachedState.Slot() < slot {
highestSlot = cachedState.Slot()
if cachedState != nil {
cachedSlot = cachedState.Slot()
}
if cachedState != nil && !cachedState.IsNil() && cachedSlot <= slot && cachedSlot > highestSlot {
state = cachedState
}
} else if err != nil {
@@ -236,7 +241,7 @@ func ProcessSlots(ctx context.Context, state state.BeaconState, slot primitives.
if ctx.Err() != nil {
tracing.AnnotateError(span, ctx.Err())
// Cache last best value.
if highestSlot < state.Slot() {
if cachedSlot < state.Slot() {
if SkipSlotCache.Put(ctx, key, state); err != nil {
log.WithError(err).Error("Failed to put skip slot cache value")
}
@@ -277,7 +282,7 @@ func ProcessSlots(ctx context.Context, state state.BeaconState, slot primitives.
}
}
if highestSlot < state.Slot() {
if cachedSlot < state.Slot() {
SkipSlotCache.Put(ctx, key, state)
}