@@ -246,7 +246,14 @@ func (b *Bootstrap) StartAPIServer(ctx context.Context) error {
246246 return fmt .Errorf ("failed to create rate limiter: %w" , err )
247247 }
248248
249- blockchainAPI , err := api .NewBlockChainAPI (
249+ // get the height from which the indexing resumed since the last restart,
250+ // this is needed for the `eth_syncing` endpoint.
251+ indexingResumedHeight , err := b .storages .Blocks .LatestEVMHeight ()
252+ if err != nil {
253+ return fmt .Errorf ("failed to retrieve the indexing resumed height: %w" , err )
254+ }
255+
256+ blockchainAPI := api .NewBlockChainAPI (
250257 b .logger ,
251258 b .config ,
252259 evm ,
@@ -255,10 +262,8 @@ func (b *Bootstrap) StartAPIServer(ctx context.Context) error {
255262 b .storages .Receipts ,
256263 ratelimiter ,
257264 b .collector ,
265+ indexingResumedHeight ,
258266 )
259- if err != nil {
260- return err
261- }
262267
263268 streamAPI := api .NewStreamAPI (
264269 b .logger ,
@@ -577,14 +582,16 @@ func Run(ctx context.Context, cfg *config.Config, ready component.ReadyFunc) err
577582 return err
578583 }
579584
580- if err := boot .StartEventIngestion (ctx ); err != nil {
581- return fmt .Errorf ("failed to start event ingestion engine: %w" , err )
582- }
583-
585+ // Start the API Server first, to avoid any races with incoming
586+ // EVM events, that might affect the starting state.
584587 if err := boot .StartAPIServer (ctx ); err != nil {
585588 return fmt .Errorf ("failed to start API server: %w" , err )
586589 }
587590
591+ if err := boot .StartEventIngestion (ctx ); err != nil {
592+ return fmt .Errorf ("failed to start event ingestion engine: %w" , err )
593+ }
594+
588595 if err := boot .StartMetricsServer (ctx ); err != nil {
589596 return fmt .Errorf ("failed to start metrics server: %w" , err )
590597 }
0 commit comments