@@ -76,8 +76,7 @@ type Syncer struct {
7676 wg sync.WaitGroup
7777
7878 // P2P wait coordination
79- p2pWaitMu sync.Mutex
80- p2pWaitState p2pWaitState
79+ p2pWaitState atomic.Value // stores p2pWaitState
8180}
8281
8382// NewSyncer creates a new block syncer
@@ -257,10 +256,6 @@ func (s *Syncer) startSyncWorkers() {
257256 go s .p2pWorkerLoop ()
258257}
259258
260- const (
261- futureHeightBackoff = 6 * time .Second // current celestia block time
262- )
263-
264259func (s * Syncer ) daWorkerLoop () {
265260 defer s .wg .Done ()
266261
@@ -277,7 +272,7 @@ func (s *Syncer) daWorkerLoop() {
277272 var backoff time.Duration
278273 if err == nil {
279274 // No error, means we are caught up.
280- backoff = futureHeightBackoff
275+ backoff = s . config . DA . BlockTime . Duration
281276 } else {
282277 // Error, back off for a shorter duration.
283278 backoff = s .config .DA .BlockTime .Duration
@@ -772,20 +767,21 @@ type p2pWaitState struct {
772767}
773768
774769func (s * Syncer ) setP2PWaitState (height uint64 , cancel context.CancelFunc ) {
775- s .p2pWaitMu .Lock ()
776- defer s .p2pWaitMu .Unlock ()
777- s .p2pWaitState = p2pWaitState {
778- height : height ,
779- cancel : cancel ,
780- }
770+ s .p2pWaitState .Store (p2pWaitState {height : height , cancel : cancel })
781771}
782772
783773func (s * Syncer ) cancelP2PWait (height uint64 ) {
784- s .p2pWaitMu .Lock ()
785- defer s .p2pWaitMu .Unlock ()
774+ val := s .p2pWaitState .Load ()
775+ if val == nil {
776+ return
777+ }
778+ state , ok := val .(p2pWaitState )
779+ if ! ok || state .cancel == nil {
780+ return
781+ }
786782
787- if s . p2pWaitState . cancel != nil && ( height == 0 || s . p2pWaitState . height <= height ) {
788- s .p2pWaitState .cancel ( )
789- s . p2pWaitState = p2pWaitState {}
783+ if height == 0 || state . height <= height {
784+ s .p2pWaitState .Store ( p2pWaitState {} )
785+ state . cancel ()
790786 }
791787}
0 commit comments