diff --git a/mod/execution/pkg/client/client.go b/mod/execution/pkg/client/client.go index 317408aa8d..8c86272981 100644 --- a/mod/execution/pkg/client/client.go +++ b/mod/execution/pkg/client/client.go @@ -102,12 +102,19 @@ func New[ExecutionPayloadDenebT engineprimitives.ExecutionPayload]( } } -// Name returns the name of the engine client. -func (s *EngineClient[ExecutionPayloadDenebT]) Name() string { - return "EngineClient" +func (s *EngineClient[ExecutionPayloadDenebT]) StartWithIPC( + ctx context.Context, +) error { + if err := s.initializeConnection(ctx); err != nil { + return err + } + if s.cfg.RPCDialURL.IsIPC() { + s.startIPCServer(ctx) + } + return nil } -// Start starts the engine client. +// StartWithHTTP starts the engine client. func (s *EngineClient[ExecutionPayloadDenebT]) Start( ctx context.Context, ) error { @@ -125,13 +132,6 @@ func (s *EngineClient[ExecutionPayloadDenebT]) Start( go s.jwtRefreshLoop(ctx) }() } - - // If we are running in IPC mode, we will need start the IPC server - // as well. - if s.cfg.RPCDialURL.IsIPC() { - s.startIPCServer(ctx) - } - return s.initializeConnection(ctx) } @@ -180,17 +180,6 @@ func (s *EngineClient[ExecutionPayloadDenebT]) VerifyChainID( ) } - // Log the chain ID. - s.logger.Info( - "connected to execution client πŸ”Œ", - "dial_url", - s.cfg.RPCDialURL.String(), - "chain_id", - chainID.Uint64(), - "required_chain_id", - s.eth1ChainID, - ) - return nil } @@ -200,12 +189,16 @@ func (s *EngineClient[ExecutionPayloadDenebT]) initializeConnection( ctx context.Context, ) error { // Initialize the connection to the execution client. + var ( + err error + chainID *big.Int + ) for { s.logger.Info( "waiting for execution client to start πŸΊπŸ•”", "dial_url", s.cfg.RPCDialURL, ) - if err := s.dialExecutionRPCClient(ctx); err != nil { + if err = s.setupExecutionClientConnection(ctx); err != nil { s.statusErrMu.Lock() s.statusErr = err s.statusErrMu.Unlock() @@ -214,6 +207,41 @@ func (s *EngineClient[ExecutionPayloadDenebT]) initializeConnection( } break } + // Get the chain ID from the execution client. + chainID, err = s.ChainID(ctx) + if err != nil { + s.logger.Error("failed to get chain ID", "err", err) + return err + } + + // Log the chain ID. + s.logger.Info( + "connected to execution client πŸ”Œ", + "dial_url", + s.cfg.RPCDialURL.String(), + "chain_id", + chainID.Uint64(), + "required_chain_id", + s.eth1ChainID, + ) + + // Exchange capabilities with the execution client. + if _, err = s.ExchangeCapabilities(ctx); err != nil { + s.logger.Error("failed to exchange capabilities", "err", err) + return err + } + return nil +} + +// setupExecutionClientConnections dials the execution client and +// ensures the chain ID is correct. +func (s *EngineClient[ExecutionPayloadDenebT]) setupExecutionClientConnection( + ctx context.Context, +) error { + // Dial the execution client. + if err := s.dialExecutionRPCClient(ctx); err != nil { + return err + } // Ensure the execution client is connected to the correct chain. if err := s.VerifyChainID(ctx); err != nil { @@ -224,12 +252,6 @@ func (s *EngineClient[ExecutionPayloadDenebT]) initializeConnection( } return err } - - // Exchange capabilities with the execution client. - if _, err := s.ExchangeCapabilities(ctx); err != nil { - s.logger.Error("failed to exchange capabilities", "err", err) - return err - } return nil } @@ -332,8 +354,14 @@ func (s *EngineClient[ExecutionPayloadDenebT]) buildJWTHeader() (http.Header, er return header, nil } +func (s *EngineClient[ExecutionPayloadDenebT]) Name() string { + return "EngineClient" +} + // ================================ IPC ================================ +// + func (s *EngineClient[ExecutionPayloadDenebT]) startIPCServer( ctx context.Context, ) {