Skip to content

Commit ec3fd4b

Browse files
authored
Merge pull request #679 from onflow/mpeter/fix-eth-syncing-starting-height
Fix race for `startingBlock` field of `eth_syncing` endpoint
2 parents 528bd94 + d8fa7a2 commit ec3fd4b

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

api/api.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,8 @@ func NewBlockChainAPI(
170170
receipts storage.ReceiptIndexer,
171171
ratelimiter limiter.Store,
172172
collector metrics.Collector,
173-
) (*BlockChainAPI, error) {
174-
// get the height from which the indexing resumed since the last restart, this is needed for syncing status.
175-
indexingResumedHeight, err := blocks.LatestEVMHeight()
176-
if err != nil {
177-
return nil, fmt.Errorf("failed to retrieve the indexing resumed height: %w", err)
178-
}
179-
173+
indexingResumedHeight uint64,
174+
) *BlockChainAPI {
180175
return &BlockChainAPI{
181176
logger: logger,
182177
config: config,
@@ -187,7 +182,7 @@ func NewBlockChainAPI(
187182
indexingResumedHeight: indexingResumedHeight,
188183
limiter: ratelimiter,
189184
collector: collector,
190-
}, nil
185+
}
191186
}
192187

193188
// BlockNumber returns the block number of the chain head.

bootstrap/bootstrap.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)