Skip to content

Commit fd73169

Browse files
committed
updates
1 parent 7e82b89 commit fd73169

3 files changed

Lines changed: 10 additions & 14 deletions

File tree

block/internal/cache/generic_cache.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,13 @@ type snapshotEntry struct {
3232
const snapshotEntrySize = 16 // bytes per snapshotEntry
3333

3434
// Cache tracks seen blocks and DA inclusion status using bounded LRU caches.
35-
//
36-
// Persistence: on every DA inclusion mutation a single snapshot key
37-
// (storeKeyPrefix+"__snap") is rewritten with all current in-flight
38-
// [blockHeight, daHeight] pairs. RestoreFromStore reads that one key on
39-
// startup — O(1) regardless of chain length.
40-
//
41-
// After a restart, real content hashes are not available until the DA
42-
// retriever re-fires. In the meantime, placeholder keys indexed by height
43-
// allow lookups to succeed via getDAIncludedByHeight.
4435
type Cache[T any] struct {
36+
// itemsByHeight stores items keyed by uint64 height.
37+
// Mutex needed for atomic get-and-remove in getNextItem.
4538
itemsByHeight *lru.Cache[uint64, *T]
4639
itemsByHeightMu sync.Mutex
4740

41+
// hashes tracks whether a given hash has been seen
4842
hashes *lru.Cache[string, bool]
4943

5044
// daIncluded maps hash → daHeight. Hash may be a real content hash or a
@@ -57,9 +51,11 @@ type Cache[T any] struct {
5751
hashByHeight *lru.Cache[uint64, string]
5852
hashByHeightMu sync.Mutex
5953

54+
// maxDAHeight tracks the maximum DA height seen
6055
maxDAHeight *atomic.Uint64
6156

62-
store store.Store // nil = ephemeral, no persistence
57+
store store.Store // nil = ephemeral, no persistence
58+
// storeKeyPrefix is the prefix used for store keys
6359
storeKeyPrefix string
6460
}
6561

block/internal/cache/manager.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ type CacheManager interface {
4646
IsDataSeen(hash string) bool
4747
SetDataSeen(hash string, blockHeight uint64)
4848
GetDataDAIncluded(hash string) (uint64, bool)
49-
// GetDataDAIncludedByHeight is the data equivalent of GetHeaderDAIncludedByHeight.
5049
GetDataDAIncludedByHeight(blockHeight uint64) (uint64, bool)
5150
SetDataDAIncluded(hash string, daHeight uint64, blockHeight uint64)
5251
RemoveDataDAIncluded(hash string)
@@ -204,7 +203,9 @@ func (m *implementation) IsTxSeen(hash string) bool {
204203
}
205204

206205
func (m *implementation) SetTxSeen(hash string) {
206+
// Use 0 as height since transactions don't have a block height yet
207207
m.txCache.setSeen(hash, 0)
208+
// Track timestamp for cleanup purposes
208209
m.txTimestamps.Store(hash, time.Now())
209210
}
210211

@@ -383,6 +384,7 @@ func (m *implementation) ClearFromStore() error {
383384
m.txCache = NewCache[struct{}](nil, "")
384385
m.pendingEventsCache = NewCache[common.DAHeightEvent](nil, "")
385386

387+
// Initialize DA height from store metadata to ensure DaHeight() is never 0.
386388
m.initDAHeightFromStore(ctx)
387389

388390
return nil

block/internal/cache/manager_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,12 @@ func TestManager_SaveAndRestoreFromStore(t *testing.T) {
114114
// Simulate the submitter: write per-height DA mappings (normally done by
115115
// setNodeHeightToDAHeight) and mark height 1 as finalized.
116116
// Heights 1 and 2 are both submitted to DA; height 1 is finalized, height 2 is in-flight.
117-
writeHeightDAMeta := func(height, daH uint64, headerKey, dataKey string) {
117+
writeHeightDAMeta := func(height, daH uint64, _, _ string) {
118118
b := make([]byte, 8)
119119
binary.LittleEndian.PutUint64(b, daH)
120120
require.NoError(t, st.SetMetadata(ctx, pkgstore.GetHeightToDAHeightHeaderKey(height), b))
121121
binary.LittleEndian.PutUint64(b, daH)
122122
require.NoError(t, st.SetMetadata(ctx, pkgstore.GetHeightToDAHeightDataKey(height), b))
123-
_ = headerKey
124-
_ = dataKey
125123
}
126124
writeHeightDAMeta(1, 100, "", "")
127125
writeHeightDAMeta(2, 101, "", "")

0 commit comments

Comments
 (0)