From 58b8c31c932c16de4076076305c715c869b8e95b Mon Sep 17 00:00:00 2001 From: Nishant Das Date: Sat, 16 Mar 2024 00:46:26 +0800 Subject: [PATCH] mark in progress (#13750) --- beacon-chain/cache/skip_slot_cache.go | 8 ------- beacon-chain/cache/skip_slot_cache_test.go | 26 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/beacon-chain/cache/skip_slot_cache.go b/beacon-chain/cache/skip_slot_cache.go index 0b230ecb8..4e9538b19 100644 --- a/beacon-chain/cache/skip_slot_cache.go +++ b/beacon-chain/cache/skip_slot_cache.go @@ -109,10 +109,6 @@ func (c *SkipSlotCache) Get(ctx context.Context, r [32]byte) (state.BeaconState, // MarkInProgress a request so that any other similar requests will block on // Get until MarkNotInProgress is called. func (c *SkipSlotCache) MarkInProgress(r [32]byte) error { - if c.disabled { - return nil - } - c.lock.Lock() defer c.lock.Unlock() @@ -126,10 +122,6 @@ func (c *SkipSlotCache) MarkInProgress(r [32]byte) error { // MarkNotInProgress will release the lock on a given request. This should be // called after put. func (c *SkipSlotCache) MarkNotInProgress(r [32]byte) { - if c.disabled { - return - } - c.lock.Lock() defer c.lock.Unlock() diff --git a/beacon-chain/cache/skip_slot_cache_test.go b/beacon-chain/cache/skip_slot_cache_test.go index c2ad84f15..c13cce3b7 100644 --- a/beacon-chain/cache/skip_slot_cache_test.go +++ b/beacon-chain/cache/skip_slot_cache_test.go @@ -2,6 +2,7 @@ package cache_test import ( "context" + "sync" "testing" "github.com/prysmaticlabs/prysm/v5/beacon-chain/cache" @@ -35,3 +36,28 @@ func TestSkipSlotCache_RoundTrip(t *testing.T) { require.NoError(t, err) assert.DeepEqual(t, res.ToProto(), s.ToProto(), "Expected equal protos to return from cache") } + +func TestSkipSlotCache_DisabledAndEnabled(t *testing.T) { + ctx := context.Background() + c := cache.NewSkipSlotCache() + + r := [32]byte{'a'} + c.Disable() + + require.NoError(t, c.MarkInProgress(r)) + + c.Enable() + wg := new(sync.WaitGroup) + wg.Add(1) + go func() { + // Get call will only terminate when + // it is not longer in progress. + obj, err := c.Get(ctx, r) + require.NoError(t, err) + require.IsNil(t, obj) + wg.Done() + }() + + c.MarkNotInProgress(r) + wg.Wait() +}