Skip to content

Commit 79204ae

Browse files
committed
fixes
1 parent 9a157c0 commit 79204ae

2 files changed

Lines changed: 16 additions & 5 deletions

File tree

block/internal/cache/generic_cache.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,14 @@ func (c *Cache[T]) setDAIncluded(hash string, daHeight uint64, blockHeight uint6
9797
c.hashByHeight.Store(blockHeight, hash)
9898

9999
// Update max DA height if necessary
100-
current := c.maxDAHeight.Load()
101-
if daHeight > current {
102-
c.maxDAHeight.Store(daHeight)
100+
for {
101+
current := c.maxDAHeight.Load()
102+
if daHeight <= current {
103+
return
104+
}
105+
if c.maxDAHeight.CompareAndSwap(current, daHeight) {
106+
return
107+
}
103108
}
104109
}
105110

block/internal/syncing/p2p_handler.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ func NewP2PHandler(
5050

5151
// SetProcessedHeight updates the highest processed block height.
5252
func (h *P2PHandler) SetProcessedHeight(height uint64) {
53-
if height > h.processedHeight.Load() {
54-
h.processedHeight.Store(height)
53+
for {
54+
current := h.processedHeight.Load()
55+
if height <= current {
56+
return
57+
}
58+
if h.processedHeight.CompareAndSwap(current, height) {
59+
return
60+
}
5561
}
5662
}
5763

0 commit comments

Comments
 (0)