Skip to content

Commit 889da9a

Browse files
authored
chore: missed feedback from #3204 (#3206)
1 parent 763e8c6 commit 889da9a

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

block/internal/cache/generic_cache.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const snapshotEntrySize = 16 // bytes per snapshotEntry
2424

2525
// Cache tracks seen blocks and DA inclusion status.
2626
type Cache struct {
27-
mu sync.Mutex
27+
mu sync.RWMutex
2828

2929
hashes map[string]bool
3030
daIncluded map[string]uint64
@@ -53,8 +53,8 @@ func NewCache(s store.Store, keyPrefix string) *Cache {
5353
}
5454

5555
func (c *Cache) isSeen(hash string) bool {
56-
c.mu.Lock()
57-
defer c.mu.Unlock()
56+
c.mu.RLock()
57+
defer c.mu.RUnlock()
5858
return c.hashes[hash]
5959
}
6060

@@ -72,15 +72,15 @@ func (c *Cache) removeSeen(hash string) {
7272
}
7373

7474
func (c *Cache) getDAIncluded(hash string) (uint64, bool) {
75-
c.mu.Lock()
76-
defer c.mu.Unlock()
75+
c.mu.RLock()
76+
defer c.mu.RUnlock()
7777
v, ok := c.daIncluded[hash]
7878
return v, ok
7979
}
8080

8181
func (c *Cache) getDAIncludedByHeight(blockHeight uint64) (uint64, bool) {
82-
c.mu.Lock()
83-
defer c.mu.Unlock()
82+
c.mu.RLock()
83+
defer c.mu.RUnlock()
8484
hash, ok := c.hashByHeight[blockHeight]
8585
if !ok {
8686
return 0, false
@@ -138,8 +138,8 @@ func (c *Cache) deleteAllForHeight(height uint64) {
138138
}
139139

140140
func (c *Cache) daIncludedLen() int {
141-
c.mu.Lock()
142-
defer c.mu.Unlock()
141+
c.mu.RLock()
142+
defer c.mu.RUnlock()
143143
return len(c.daIncluded)
144144
}
145145

@@ -150,7 +150,7 @@ func (c *Cache) persistSnapshot(ctx context.Context) error {
150150
return nil
151151
}
152152

153-
c.mu.Lock()
153+
c.mu.RLock()
154154
entries := make([]snapshotEntry, 0, len(c.hashByHeight))
155155
for h, hash := range c.hashByHeight {
156156
daH, ok := c.daIncluded[hash]
@@ -159,7 +159,7 @@ func (c *Cache) persistSnapshot(ctx context.Context) error {
159159
}
160160
entries = append(entries, snapshotEntry{blockHeight: h, daHeight: daH})
161161
}
162-
c.mu.Unlock()
162+
c.mu.RUnlock()
163163

164164
return c.store.SetMetadata(ctx, c.snapshotKey(), encodeSnapshot(entries))
165165
}

pkg/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ func AddFlags(cmd *cobra.Command) {
567567
})
568568

569569
// Add base flags
570-
cmd.Flags().String(FlagDBPath, def.DBPath, "path for for node database")
570+
cmd.Flags().String(FlagDBPath, def.DBPath, "path for node database")
571571
cmd.Flags().Bool(FlagClearCache, def.ClearCache, "clear the cache")
572572

573573
// Node configuration flags

0 commit comments

Comments
 (0)