Skip to content

Commit

Permalink
Merge pull request #679 from onflow/mpeter/fix-eth-syncing-starting-h…
Browse files Browse the repository at this point in the history
…eight

Fix race for `startingBlock` field of `eth_syncing` endpoint
  • Loading branch information
m-Peter authored Nov 27, 2024
2 parents 528bd94 + d8fa7a2 commit ec3fd4b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
11 changes: 3 additions & 8 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,8 @@ func NewBlockChainAPI(
receipts storage.ReceiptIndexer,
ratelimiter limiter.Store,
collector metrics.Collector,
) (*BlockChainAPI, error) {
// get the height from which the indexing resumed since the last restart, this is needed for syncing status.
indexingResumedHeight, err := blocks.LatestEVMHeight()
if err != nil {
return nil, fmt.Errorf("failed to retrieve the indexing resumed height: %w", err)
}

indexingResumedHeight uint64,
) *BlockChainAPI {
return &BlockChainAPI{
logger: logger,
config: config,
Expand All @@ -187,7 +182,7 @@ func NewBlockChainAPI(
indexingResumedHeight: indexingResumedHeight,
limiter: ratelimiter,
collector: collector,
}, nil
}
}

// BlockNumber returns the block number of the chain head.
Expand Down
23 changes: 15 additions & 8 deletions bootstrap/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,14 @@ func (b *Bootstrap) StartAPIServer(ctx context.Context) error {
return fmt.Errorf("failed to create rate limiter: %w", err)
}

blockchainAPI, err := api.NewBlockChainAPI(
// get the height from which the indexing resumed since the last restart,
// this is needed for the `eth_syncing` endpoint.
indexingResumedHeight, err := b.storages.Blocks.LatestEVMHeight()
if err != nil {
return fmt.Errorf("failed to retrieve the indexing resumed height: %w", err)
}

blockchainAPI := api.NewBlockChainAPI(
b.logger,
b.config,
evm,
Expand All @@ -255,10 +262,8 @@ func (b *Bootstrap) StartAPIServer(ctx context.Context) error {
b.storages.Receipts,
ratelimiter,
b.collector,
indexingResumedHeight,
)
if err != nil {
return err
}

streamAPI := api.NewStreamAPI(
b.logger,
Expand Down Expand Up @@ -577,14 +582,16 @@ func Run(ctx context.Context, cfg *config.Config, ready component.ReadyFunc) err
return err
}

if err := boot.StartEventIngestion(ctx); err != nil {
return fmt.Errorf("failed to start event ingestion engine: %w", err)
}

// Start the API Server first, to avoid any races with incoming
// EVM events, that might affect the starting state.
if err := boot.StartAPIServer(ctx); err != nil {
return fmt.Errorf("failed to start API server: %w", err)
}

if err := boot.StartEventIngestion(ctx); err != nil {
return fmt.Errorf("failed to start event ingestion engine: %w", err)
}

if err := boot.StartMetricsServer(ctx); err != nil {
return fmt.Errorf("failed to start metrics server: %w", err)
}
Expand Down

0 comments on commit ec3fd4b

Please sign in to comment.