Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(store): Add HasQ4ByHash method on store #4035

Merged
merged 4 commits into from
Jan 28, 2025
Merged
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
7 changes: 6 additions & 1 deletion core/exchange_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func TestExchange_StoreHistoricIfArchival(t *testing.T) {
headers, err := ce.GetRangeByHeight(ctx, genHeader, 30)
require.NoError(t, err)

// ensure all "historic" EDSs were stored
// ensure all "historic" EDSs were stored but not the .q4 files
for _, h := range headers {
has, err := store.HasByHeight(ctx, h.Height())
require.NoError(t, err)
Expand All @@ -159,6 +159,11 @@ func TestExchange_StoreHistoricIfArchival(t *testing.T) {
has, err = store.HasByHash(ctx, h.DAH.Hash())
require.NoError(t, err)
assert.True(t, has)

// ensure .q4 file was not stored
has, err = store.HasQ4ByHash(ctx, h.DAH.Hash())
require.NoError(t, err)
assert.False(t, has)
}
}

Expand Down
5 changes: 5 additions & 0 deletions core/listener_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ func TestListener_DoesNotStoreHistoric(t *testing.T) {
has, err := store.HasByHash(ctx, hash)
require.NoError(t, err)
assert.False(t, has)

// ensure .q4 file was not stored
has, err = store.HasQ4ByHash(ctx, hash)
require.NoError(t, err)
assert.False(t, has)
}
}

Expand Down
9 changes: 9 additions & 0 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,15 @@ func (s *Store) hasByHeight(height uint64) (bool, error) {
return exists(pathODS)
}

func (s *Store) HasQ4ByHash(_ context.Context, datahash share.DataHash) (bool, error) {
lock := s.stripLock.byHash(datahash)
lock.RLock()
defer lock.RUnlock()

pathQ4File := s.hashToPath(datahash, q4FileExt)
return exists(pathQ4File)
}

func (s *Store) RemoveODSQ4(ctx context.Context, height uint64, datahash share.DataHash) error {
lock := s.stripLock.byHashAndHeight(datahash, height)
lock.lock()
Expand Down
28 changes: 28 additions & 0 deletions store/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

libshare "github.com/celestiaorg/go-square/v2/share"
Expand Down Expand Up @@ -268,6 +269,33 @@ func TestEDSStore(t *testing.T) {
})
}

t.Run("HasQ4", func(t *testing.T) {
dir := t.TempDir()
edsStore, err := NewStore(paramsNoCache(), dir)
require.NoError(t, err)

square, roots := randomEDS(t)
randHeight := uint64(8)

has, err := edsStore.HasQ4ByHash(ctx, roots.Hash())
require.NoError(t, err)
assert.False(t, has)

err = edsStore.PutODSQ4(ctx, roots, randHeight, square)
require.NoError(t, err)

has, err = edsStore.HasQ4ByHash(ctx, roots.Hash())
require.NoError(t, err)
assert.True(t, has)

err = edsStore.RemoveQ4(ctx, randHeight, roots.Hash())
require.NoError(t, err)

has, err = edsStore.HasQ4ByHash(ctx, roots.Hash())
require.NoError(t, err)
assert.False(t, has)
})

t.Run("Does not exist", func(t *testing.T) {
dir := t.TempDir()
edsStore, err := NewStore(paramsNoCache(), dir)
Expand Down
Loading