Skip to content

Commit

Permalink
Merge branch 'main' into issue-4066
Browse files Browse the repository at this point in the history
  • Loading branch information
crStiv authored Jan 30, 2025
2 parents 832e635 + 87bc6c8 commit 0f2da20
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
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
4 changes: 2 additions & 2 deletions nodebuilder/pruner/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ If you want to retain history beyond the sampling window, please pass the --arch

// Warn the user if pruning is disabled and archival is not enabled for Full and Bridge nodes
if !archivalChanged && (tp == node.Full || tp == node.Bridge) {
log.Warn(`WARNING: Pruning is disabled.
Pruning will become the default mode for all nodes.
log.Warn(`WARNING: Node is now running in ARCHIVAL mode.
PRUNING mode will become the default for all nodes.
If you want to retain history beyond the sampling window, please pass the --archival flag.`)
}
}
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

0 comments on commit 0f2da20

Please sign in to comment.