Skip to content

Commit adddf8b

Browse files
committed
save only on exit
1 parent 8a1e535 commit adddf8b

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

block/internal/cache/generic_cache.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,6 @@ func (c *Cache[T]) setDAIncluded(hash string, daHeight uint64, blockHeight uint6
131131
c.daIncluded.Add(hash, daHeight)
132132
c.hashByHeight.Add(blockHeight, hash)
133133

134-
// Persist to store if configured
135-
if c.store != nil {
136-
key := c.storeKeyPrefix + hash
137-
value := make([]byte, 16) // 8 bytes for daHeight + 8 bytes for blockHeight
138-
binary.LittleEndian.PutUint64(value[0:8], daHeight)
139-
binary.LittleEndian.PutUint64(value[8:16], blockHeight)
140-
_ = c.store.SetMetadata(context.Background(), key, value)
141-
}
142-
143134
// Update max DA height if necessary
144135
c.setMaxDAHeight(daHeight)
145136
}

block/internal/cache/generic_cache_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,14 @@ func TestCache_MaxDAHeight_WithStore(t *testing.T) {
6161
t.Errorf("after setDAIncluded: daHeight = %d, want 200", got)
6262
}
6363

64+
err := c1.SaveToStore(ctx)
65+
require.NoError(t, err)
66+
6467
// Create new cache and restore from store
6568
c2 := NewCache[testItem](st, "test/da-included/")
6669

6770
// Restore with the known hashes
68-
err := c2.RestoreFromStore(ctx, []string{"hash1", "hash2", "hash3"})
71+
err = c2.RestoreFromStore(ctx, []string{"hash1", "hash2", "hash3"})
6972
require.NoError(t, err)
7073

7174
if got := c2.daHeight(); got != 200 {
@@ -93,14 +96,17 @@ func TestCache_WithStorePersistence(t *testing.T) {
9396

9497
c1 := NewCache[testItem](st, "test/")
9598

96-
// Set DA inclusion - this should persist to store immediately
99+
// Set DA inclusion
97100
c1.setDAIncluded("hash1", 100, 1)
98101
c1.setDAIncluded("hash2", 200, 2)
99102

103+
err := c1.SaveToStore(ctx)
104+
require.NoError(t, err)
105+
100106
// Create new cache with same store and restore
101107
c2 := NewCache[testItem](st, "test/")
102108

103-
err := c2.RestoreFromStore(ctx, []string{"hash1", "hash2", "hash3"})
109+
err = c2.RestoreFromStore(ctx, []string{"hash1", "hash2", "hash3"})
104110
require.NoError(t, err)
105111

106112
// hash1 and hash2 should be restored, hash3 should not exist

block/internal/cache/manager_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,9 @@ func TestManager_DAInclusionPersistence(t *testing.T) {
431431
// Verify DA height is tracked
432432
assert.Equal(t, uint64(101), m1.DaHeight())
433433

434+
err = m1.SaveToStore()
435+
require.NoError(t, err)
436+
434437
// Create new manager - DA inclusion should be restored
435438
m2, err := NewManager(cfg, st, zerolog.Nop())
436439
require.NoError(t, err)

0 commit comments

Comments
 (0)