Skip to content

Commit

Permalink
Dmytro's comments
Browse files Browse the repository at this point in the history
  • Loading branch information
huangzhen1997 committed Sep 19, 2024
1 parent 6a45eee commit d8e5911
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .changeset/happy-feet-rhyme.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
---

This PR introduce few changes:
- Add a new flag support called `NewHeadsPollInterval` (0 by default indicate disabled), which is an interval for polling new block periodically using http client rather than subscribe to ws feed.
- Add a new config option `EVM.NodePool.NewHeadsPollInterval` (0 by default indicate disabled), which is an interval for polling new block periodically using http client rather than subscribe to ws feed.
- Updated new head handler for polling new head over http, and register the subscription in node lifecycle logic.
- If the polling new heads is enabled, WS new heads subscription will be replaced with the new http based polling.

Expand Down
23 changes: 2 additions & 21 deletions core/chains/evm/client/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,6 @@ func (r *rpcClient) SubscribeToHeads(ctx context.Context) (ch <-chan *evmtypes.H
lggr := r.newRqLggr().With("args", args)

// if new head based on http polling is enabled, we will replace it for WS newHead subscription
lggr.Infof("the newHeadsPollInterval is %v", r.newHeadsPollInterval.String())
if r.newHeadsPollInterval > 0 {
interval := r.newHeadsPollInterval
timeout := interval
Expand All @@ -536,7 +535,7 @@ func (r *rpcClient) SubscribeToHeads(ctx context.Context) (ch <-chan *evmtypes.H
return nil, nil, err
}

lggr.Infof("Polling new heads over http ")
lggr.Debugf("Polling new heads over http")
return channel, &poller, nil
}

Expand Down Expand Up @@ -713,25 +712,7 @@ func (r *rpcClient) LatestFinalizedBlock(ctx context.Context) (head *evmtypes.He
}

func (r *rpcClient) LatestBlock(ctx context.Context) (head *evmtypes.Head, err error) {
// capture chStopInFlight to ensure we are not updating chainInfo with observations related to previous life cycle
ctx, cancel, chStopInFlight, _, _ := r.acquireQueryCtx(ctx, r.rpcTimeout)
defer cancel()

// TODO any special treatment for some chains ?
err = r.ethGetBlockByNumber(ctx, rpc.LatestBlockNumber.String(), &head)
if err != nil {
return
}

if head == nil {
err = r.wrapRPCClientError(ethereum.NotFound)
return
}

head.EVMChainID = ubig.New(r.chainID)

r.onNewHead(ctx, chStopInFlight, head)
return
return r.BlockByNumber(ctx, nil)
}

func (r *rpcClient) astarLatestFinalizedBlock(ctx context.Context, result interface{}) (err error) {
Expand Down
5 changes: 3 additions & 2 deletions core/web/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ func metricRoutes(r *gin.RouterGroup, includeHeap bool) {
pprofGroup.GET("/allocs", ginHandlerFromHTTP(pprof.Handler("allocs").ServeHTTP))
pprofGroup.GET("/block", ginHandlerFromHTTP(pprof.Handler("block").ServeHTTP))
pprofGroup.GET("/goroutine", ginHandlerFromHTTP(pprof.Handler("goroutine").ServeHTTP))
pprofGroup.GET("/heap", ginHandlerFromHTTP(pprof.Handler("heap").ServeHTTP))

if includeHeap {
pprofGroup.GET("/heap", ginHandlerFromHTTP(pprof.Handler("heap").ServeHTTP))
}
pprofGroup.GET("/mutex", ginHandlerFromHTTP(pprof.Handler("mutex").ServeHTTP))
pprofGroup.GET("/threadcreate", ginHandlerFromHTTP(pprof.Handler("threadcreate").ServeHTTP))
}
Expand Down

0 comments on commit d8e5911

Please sign in to comment.