Skip to content

Commit 642cf03

Browse files
committed
fix compare and set
1 parent b7b9b98 commit 642cf03

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

sequencing/sequencer.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"errors"
99
"fmt"
1010
"sync"
11+
"sync/atomic"
1112
"time"
1213

1314
"github.com/dgraph-io/badger/v3"
@@ -359,8 +360,14 @@ func (c *Sequencer) Close() error {
359360
// Initially the max size is set to the max blob size returned by the DA layer
360361
// This can be overwritten by the execution client if it can only handle smaller size
361362
func (c *Sequencer) CompareAndSetMaxSize(size uint64) {
362-
if size < c.maxSize {
363-
c.maxSize = size
363+
for {
364+
current := atomic.LoadUint64(&c.maxSize)
365+
if size >= current {
366+
return
367+
}
368+
if atomic.CompareAndSwapUint64(&c.maxSize, current, size) {
369+
return
370+
}
364371
}
365372
}
366373

0 commit comments

Comments
 (0)