Skip to content

Commit bfc0701

Browse files
committed
clean-up
1 parent 915842e commit bfc0701

File tree

5 files changed

+2
-163
lines changed

5 files changed

+2
-163
lines changed

pkg/store/data_store_adapter.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -400,35 +400,3 @@ func (a *DataStoreAdapter) DeleteRange(ctx context.Context, from, to uint64) err
400400
func (a *DataStoreAdapter) OnDelete(fn func(context.Context, uint64) error) {
401401
a.onDeleteFn = fn
402402
}
403-
404-
// RefreshHeight updates the cached height from the underlying store.
405-
// This should be called after the syncer processes a new block.
406-
func (a *DataStoreAdapter) RefreshHeight(ctx context.Context) error {
407-
h, err := a.store.Height(ctx)
408-
if err != nil {
409-
return err
410-
}
411-
a.height.Store(h)
412-
413-
// Clean up pending data that is now in store
414-
for _, height := range a.pendingData.Keys() {
415-
if height <= h {
416-
a.pendingData.Remove(height)
417-
}
418-
}
419-
420-
return nil
421-
}
422-
423-
// SetHeight updates the cached height.
424-
// This is useful when the syncer knows the new height after processing a block.
425-
func (a *DataStoreAdapter) SetHeight(height uint64) {
426-
a.height.Store(height)
427-
428-
// Clean up pending data at or below this height
429-
for _, h := range a.pendingData.Keys() {
430-
if h <= height {
431-
a.pendingData.Remove(h)
432-
}
433-
}
434-
}

pkg/store/data_store_adapter_test.go

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -380,51 +380,6 @@ func TestDataStoreAdapter_OnDelete(t *testing.T) {
380380
assert.Equal(t, []uint64{1, 2}, deletedHeights)
381381
}
382382

383-
func TestDataStoreAdapter_RefreshHeight(t *testing.T) {
384-
t.Parallel()
385-
ctx := context.Background()
386-
387-
ds, err := NewTestInMemoryKVStore()
388-
require.NoError(t, err)
389-
store := New(ds)
390-
adapter := NewDataStoreAdapter(store)
391-
392-
// Save a block directly to the underlying store
393-
h1, d1 := types.GetRandomBlock(1, 1, "test-chain")
394-
batch, err := store.NewBatch(ctx)
395-
require.NoError(t, err)
396-
require.NoError(t, batch.SaveBlockData(h1, d1, &types.Signature{}))
397-
require.NoError(t, batch.SetHeight(1))
398-
require.NoError(t, batch.Commit())
399-
400-
// RefreshHeight should update from store and clean pending
401-
err = adapter.RefreshHeight(ctx)
402-
require.NoError(t, err)
403-
assert.Equal(t, uint64(1), adapter.Height())
404-
}
405-
406-
func TestDataStoreAdapter_SetHeight(t *testing.T) {
407-
t.Parallel()
408-
ctx := context.Background()
409-
410-
ds, err := NewTestInMemoryKVStore()
411-
require.NoError(t, err)
412-
store := New(ds)
413-
adapter := NewDataStoreAdapter(store)
414-
415-
// Add some pending data
416-
_, d1 := types.GetRandomBlock(1, 1, "test-chain")
417-
_, d2 := types.GetRandomBlock(2, 1, "test-chain")
418-
require.NoError(t, adapter.Append(ctx, d1, d2))
419-
420-
// SetHeight should update height and clean pending at or below
421-
adapter.SetHeight(1)
422-
assert.Equal(t, uint64(1), adapter.Height())
423-
424-
// Height 2 should still be in pending
425-
assert.True(t, adapter.HasAt(ctx, 2))
426-
}
427-
428383
func TestDataStoreAdapter_AppendSkipsExisting(t *testing.T) {
429384
t.Parallel()
430385
ctx := context.Background()

pkg/store/header_store_adapter.go

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@ import (
1212
"github.com/evstack/ev-node/types"
1313
)
1414

15-
const (
16-
// defaultPendingCacheSize is the default size for the pending headers/data LRU cache.
17-
// This should be large enough to handle P2P sync bursts but bounded to prevent memory issues.
18-
defaultPendingCacheSize = 1000
19-
)
15+
// defaultPendingCacheSize is the default size for the pending headers/data LRU cache.
16+
const defaultPendingCacheSize = 1000
2017

2118
// HeaderStoreAdapter wraps Store to implement header.Store[*types.SignedHeader].
2219
// This allows the ev-node store to be used directly by go-header's P2P infrastructure,
@@ -407,38 +404,6 @@ func (a *HeaderStoreAdapter) OnDelete(fn func(context.Context, uint64) error) {
407404
a.onDeleteFn = fn
408405
}
409406

410-
// RefreshHeight updates the cached height from the underlying store.
411-
// This should be called after the syncer processes a new block.
412-
func (a *HeaderStoreAdapter) RefreshHeight(ctx context.Context) error {
413-
h, err := a.store.Height(ctx)
414-
if err != nil {
415-
return err
416-
}
417-
a.height.Store(h)
418-
419-
// Clean up pending headers that are now in store
420-
for _, height := range a.pendingHeaders.Keys() {
421-
if height <= h {
422-
a.pendingHeaders.Remove(height)
423-
}
424-
}
425-
426-
return nil
427-
}
428-
429-
// SetHeight updates the cached height.
430-
// This is useful when the syncer knows the new height after processing a block.
431-
func (a *HeaderStoreAdapter) SetHeight(height uint64) {
432-
a.height.Store(height)
433-
434-
// Clean up pending headers at or below this height
435-
for _, h := range a.pendingHeaders.Keys() {
436-
if h <= height {
437-
a.pendingHeaders.Remove(h)
438-
}
439-
}
440-
}
441-
442407
// bytesEqual compares two byte slices for equality.
443408
func bytesEqual(a, b []byte) bool {
444409
if len(a) != len(b) {

pkg/store/header_store_adapter_test.go

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -379,53 +379,6 @@ func TestHeaderStoreAdapter_OnDelete(t *testing.T) {
379379
assert.Equal(t, []uint64{1, 2}, deletedHeights)
380380
}
381381

382-
func TestHeaderStoreAdapter_RefreshHeight(t *testing.T) {
383-
t.Parallel()
384-
ctx := context.Background()
385-
386-
ds, err := NewTestInMemoryKVStore()
387-
require.NoError(t, err)
388-
store := New(ds)
389-
adapter := NewHeaderStoreAdapter(store)
390-
391-
// Save a block directly to the underlying store
392-
h1, d1 := types.GetRandomBlock(1, 1, "test-chain")
393-
batch, err := store.NewBatch(ctx)
394-
require.NoError(t, err)
395-
require.NoError(t, batch.SaveBlockData(h1, d1, &types.Signature{}))
396-
require.NoError(t, batch.SetHeight(1))
397-
require.NoError(t, batch.Commit())
398-
399-
// RefreshHeight should update from store and clean pending
400-
err = adapter.RefreshHeight(ctx)
401-
require.NoError(t, err)
402-
assert.Equal(t, uint64(1), adapter.Height())
403-
}
404-
405-
func TestHeaderStoreAdapter_SetHeight(t *testing.T) {
406-
t.Parallel()
407-
ctx := context.Background()
408-
409-
ds, err := NewTestInMemoryKVStore()
410-
require.NoError(t, err)
411-
store := New(ds)
412-
adapter := NewHeaderStoreAdapter(store)
413-
414-
// Add some pending headers
415-
h1, _ := types.GetRandomBlock(1, 1, "test-chain")
416-
h2, _ := types.GetRandomBlock(2, 1, "test-chain")
417-
require.NoError(t, adapter.Append(ctx, h1, h2))
418-
419-
// SetHeight should update height and clean pending at or below
420-
adapter.SetHeight(1)
421-
assert.Equal(t, uint64(1), adapter.Height())
422-
423-
// Height 1 should be cleaned from pending
424-
// (but since we don't have store data, HasAt returns false now for pending)
425-
// Height 2 should still be in pending
426-
assert.True(t, adapter.HasAt(ctx, 2))
427-
}
428-
429382
func TestHeaderStoreAdapter_AppendSkipsExisting(t *testing.T) {
430383
t.Parallel()
431384
ctx := context.Background()

pkg/sync/sync_service.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ func (syncService *SyncService[H]) Store() header.Store[H] {
189189
}
190190

191191
// WriteToStoreAndBroadcast broadcasts provided header or block to P2P network.
192-
// Note: With the store adapter approach, actual storage is handled by the syncer
193-
// writing to the ev-node store. This method primarily handles P2P broadcasting.
194192
func (syncService *SyncService[H]) WriteToStoreAndBroadcast(ctx context.Context, headerOrData H, opts ...pubsub.PubOpt) error {
195193
if syncService.genesis.InitialHeight == 0 {
196194
return fmt.Errorf("invalid initial height; cannot be zero")

0 commit comments

Comments
 (0)