Skip to content

Commit

Permalink
Revert "feat(client): Simplify startup process (#1201)"
Browse files Browse the repository at this point in the history
This reverts commit 7bcf086.
  • Loading branch information
itsdevbear committed May 28, 2024
1 parent 1645844 commit 589d2bf
Showing 1 changed file with 57 additions and 29 deletions.
86 changes: 57 additions & 29 deletions mod/execution/pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
}

Expand Down Expand Up @@ -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
}

Expand All @@ -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()
Expand All @@ -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 {
Expand All @@ -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
}

Expand Down Expand Up @@ -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,
) {
Expand Down

0 comments on commit 589d2bf

Please sign in to comment.