@@ -161,11 +161,17 @@ func (s *Syncer) SetBlockSyncer(bs BlockSyncer) {
161161}
162162
163163// Start begins the syncing component
164- func (s * Syncer ) Start (ctx context.Context ) error {
164+ func (s * Syncer ) Start (ctx context.Context ) ( err error ) {
165165 ctx , cancel := context .WithCancel (ctx )
166166 s .ctx , s .cancel = ctx , cancel
167167
168- if err := s .initializeState (); err != nil {
168+ defer func () {
169+ if err != nil {
170+ _ = s .Stop ()
171+ }
172+ }()
173+
174+ if err = s .initializeState (); err != nil {
169175 return fmt .Errorf ("failed to initialize syncer state: %w" , err )
170176 }
171177
@@ -177,14 +183,16 @@ func (s *Syncer) Start(ctx context.Context) error {
177183
178184 s .fiRetriever = da .NewForcedInclusionRetriever (s .daClient , s .logger , s .config , s .genesis .DAStartHeight , s .genesis .DAEpochForcedInclusion )
179185 s .p2pHandler = NewP2PHandler (s .headerStore , s .dataStore , s .cache , s .genesis , s .logger )
180- if currentHeight , err := s .store .Height (ctx ); err != nil {
181- s .logger .Error ().Err (err ).Msg ("failed to set initial processed height for p2p handler" )
186+
187+ currentHeight , initErr := s .store .Height (ctx )
188+ if initErr != nil {
189+ s .logger .Error ().Err (initErr ).Msg ("failed to set initial processed height for p2p handler" )
182190 } else {
183191 s .p2pHandler .SetProcessedHeight (currentHeight )
184192 }
185193
186194 if s .raftRetriever != nil {
187- if err : = s .raftRetriever .Start (ctx ); err != nil {
195+ if err = s .raftRetriever .Start (ctx ); err != nil {
188196 return fmt .Errorf ("start raft retriever: %w" , err )
189197 }
190198 }
@@ -207,9 +215,7 @@ func (s *Syncer) Start(ctx context.Context) error {
207215 StartDAHeight : s .daRetrieverHeight .Load (),
208216 DABlockTime : s .config .DA .BlockTime .Duration ,
209217 })
210- if err := s .daFollower .Start (ctx ); err != nil {
211- s .cancel ()
212- s .wg .Wait ()
218+ if err = s .daFollower .Start (ctx ); err != nil {
213219 return fmt .Errorf ("failed to start DA follower: %w" , err )
214220 }
215221
0 commit comments