@@ -47,8 +47,7 @@ type Syncer struct {
4747 options common.BlockOptions
4848
4949 // State management
50- lastState types.State
51- lastStateMtx * sync.RWMutex
50+ lastState * atomic.Pointer [types.State ]
5251
5352 // DA state
5453 daHeight uint64
@@ -90,20 +89,20 @@ func NewSyncer(
9089 errorCh chan <- error ,
9190) * Syncer {
9291 return & Syncer {
93- store : store ,
94- exec : exec ,
95- da : da ,
96- cache : cache ,
97- metrics : metrics ,
98- config : config ,
99- genesis : genesis ,
100- options : options ,
101- headerStore : headerStore ,
102- dataStore : dataStore ,
103- lastStateMtx : & sync. RWMutex {},
104- heightInCh : make (chan common.DAHeightEvent , 10_000 ),
105- errorCh : errorCh ,
106- logger : logger .With ().Str ("component" , "syncer" ).Logger (),
92+ store : store ,
93+ exec : exec ,
94+ da : da ,
95+ cache : cache ,
96+ metrics : metrics ,
97+ config : config ,
98+ genesis : genesis ,
99+ options : options ,
100+ headerStore : headerStore ,
101+ dataStore : dataStore ,
102+ lastState : & atomic. Pointer [types. State ] {},
103+ heightInCh : make (chan common.DAHeightEvent , 10_000 ),
104+ errorCh : errorCh ,
105+ logger : logger .With ().Str ("component" , "syncer" ).Logger (),
107106 }
108107}
109108
@@ -150,16 +149,21 @@ func (s *Syncer) Stop() error {
150149
151150// GetLastState returns the current state
152151func (s * Syncer ) GetLastState () types.State {
153- s .lastStateMtx .RLock ()
154- defer s .lastStateMtx .RUnlock ()
155- return s .lastState
152+ state := s .lastState .Load ()
153+ if state == nil {
154+ return types.State {}
155+ }
156+
157+ stateCopy := * state
158+ stateCopy .AppHash = bytes .Clone (state .AppHash )
159+ stateCopy .LastResultsHash = bytes .Clone (state .LastResultsHash )
160+
161+ return stateCopy
156162}
157163
158164// SetLastState updates the current state
159165func (s * Syncer ) SetLastState (state types.State ) {
160- s .lastStateMtx .Lock ()
161- defer s .lastStateMtx .Unlock ()
162- s .lastState = state
166+ s .lastState .Store (& state )
163167}
164168
165169// GetDAHeight returns the current DA height
0 commit comments