Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/rpcdaemon/cli/httpcfg/http_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,8 @@ type HttpCfg struct {

RpcTxSyncDefaultTimeout time.Duration // Default timeout for eth_sendRawTransactionSync
RpcTxSyncMaxTimeout time.Duration // Maximum timeout for eth_sendRawTransactionSync

// EIP-8161: SSZ-REST Engine API Transport
SszRestEnabled bool // Enable SSZ-REST Engine API server alongside JSON-RPC
SszRestPort int // Port for the SSZ-REST Engine API server (default: AuthRpcPort + 1)
}
10 changes: 10 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,16 @@ var (
Value: "",
}

SszRestEnabledFlag = cli.BoolFlag{
Name: "authrpc.ssz-rest",
Usage: "Enable the SSZ-REST Engine API transport (EIP-8161) alongside JSON-RPC",
}
SszRestPortFlag = cli.UintFlag{
Name: "authrpc.ssz-rest-port",
Usage: "HTTP port for the SSZ-REST Engine API server (default: authrpc.port + 1)",
Value: 0,
}

HttpCompressionFlag = cli.BoolFlag{
Name: "http.compression",
Usage: "Enable compression over HTTP-RPC. Use --http.compression=false to disable it",
Expand Down
16 changes: 16 additions & 0 deletions execution/engineapi/engine_api_jsonrpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,22 @@ func (c *JsonRpcClient) GetClientVersionV1(ctx context.Context, callerVersion *e
}, c.backOff(ctx))
}

func (c *JsonRpcClient) GetClientCommunicationChannelsV1(ctx context.Context) ([]enginetypes.CommunicationChannel, error) {
return backoff.RetryWithData(func() ([]enginetypes.CommunicationChannel, error) {
var result []enginetypes.CommunicationChannel
err := c.rpcClient.CallContext(ctx, &result, "engine_getClientCommunicationChannelsV1")
if err != nil {
return nil, c.maybeMakePermanent(err)
}
return result, nil
}, c.backOff(ctx))
}

func (c *JsonRpcClient) ExchangeCapabilitiesV2(fromCl []string) *enginetypes.ExchangeCapabilitiesV2Response {
// JSON-RPC client doesn't implement V2 directly; the server-side handles this.
return nil
}

func (c *JsonRpcClient) backOff(ctx context.Context) backoff.BackOff {
var backOff backoff.BackOff
backOff = backoff.NewConstantBackOff(c.retryBackOff)
Expand Down
49 changes: 49 additions & 0 deletions execution/engineapi/engine_api_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ var ourCapabilities = []string{
"engine_getBlobsV1",
"engine_getBlobsV2",
"engine_getBlobsV3",
"engine_getClientCommunicationChannelsV1",
"engine_exchangeCapabilitiesV2",
}

// Returns the most recent version of the payload(for the payloadID) at the time of receiving the call
Expand Down Expand Up @@ -247,6 +249,46 @@ func (e *EngineServer) ExchangeCapabilities(fromCl []string) []string {
return ourCapabilities
}

// ExchangeCapabilitiesV2 extends ExchangeCapabilities with supportedProtocols (EIP-8160).
func (e *EngineServer) ExchangeCapabilitiesV2(fromCl []string) *engine_types.ExchangeCapabilitiesV2Response {
capabilities := e.ExchangeCapabilities(fromCl)
return &engine_types.ExchangeCapabilitiesV2Response{
Capabilities: capabilities,
SupportedProtocols: e.getSupportedProtocols(),
}
}

// getSupportedProtocols returns the list of communication protocols supported by the EL.
func (e *EngineServer) getSupportedProtocols() []engine_types.CommunicationChannel {
addr := "localhost"
port := 8551
if e.httpConfig != nil {
if e.httpConfig.AuthRpcHTTPListenAddress != "" {
addr = e.httpConfig.AuthRpcHTTPListenAddress
}
if e.httpConfig.AuthRpcPort != 0 {
port = e.httpConfig.AuthRpcPort
}
}

channels := []engine_types.CommunicationChannel{
{
Protocol: "json_rpc",
URL: fmt.Sprintf("%s:%d", addr, port),
},
}

// EIP-8161: Advertise the SSZ-REST channel if the server is running
if e.httpConfig != nil && e.httpConfig.SszRestEnabled && e.sszRestPort > 0 {
channels = append(channels, engine_types.CommunicationChannel{
Protocol: "ssz_rest",
URL: fmt.Sprintf("http://%s:%d", addr, e.sszRestPort),
})
}

return channels
}

func (e *EngineServer) GetBlobsV1(ctx context.Context, blobHashes []common.Hash) ([]*engine_types.BlobAndProofV1, error) {
e.logger.Debug("[GetBlobsV1] Received Request", "hashes", len(blobHashes))
resp, err := e.getBlobs(ctx, blobHashes, clparams.DenebVersion)
Expand Down Expand Up @@ -284,3 +326,10 @@ func (e *EngineServer) GetBlobsV3(ctx context.Context, blobHashes []common.Hash)
}
return nil, err
}

// GetClientCommunicationChannelsV1 returns the communication protocols and endpoints supported by the EL.
// Deprecated: Use ExchangeCapabilitiesV2 instead. Kept for backward compatibility.
func (e *EngineServer) GetClientCommunicationChannelsV1(ctx context.Context) ([]engine_types.CommunicationChannel, error) {
e.engineLogSpamer.RecordRequest()
return e.getSupportedProtocols(), nil
}
36 changes: 36 additions & 0 deletions execution/engineapi/engine_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ type EngineServer struct {
// TODO Remove this on next release
printPectraBanner bool
maxReorgDepth uint64
httpConfig *httpcfg.HttpCfg
sszRestPort int // EIP-8161: port the SSZ-REST server is listening on
}

func NewEngineServer(
Expand Down Expand Up @@ -140,6 +142,7 @@ func (e *EngineServer) Start(
return nil
})
}
e.httpConfig = httpConfig
base := jsonrpc.NewBaseApi(filters, stateCache, blockReader, httpConfig.WithDatadir, httpConfig.EvmCallTimeout, engineReader, httpConfig.Dirs, nil, httpConfig.RangeLimit)
ethImpl := jsonrpc.NewEthAPI(base, db, eth, e.txpool, mining, jsonrpc.NewEthApiConfig(httpConfig), e.logger)

Expand All @@ -164,6 +167,39 @@ func (e *EngineServer) Start(
}
return err
})

// EIP-8161: Start SSZ-REST Engine API server if enabled
if httpConfig.SszRestEnabled {
eg.Go(func() error {
defer e.logger.Debug("[EngineServer] SSZ-REST server goroutine terminated")
jwtSecret, err := cli.ObtainJWTSecret(httpConfig, e.logger)
if err != nil {
e.logger.Error("[EngineServer] failed to obtain JWT secret for SSZ-REST server", "err", err)
return err
}

addr := httpConfig.AuthRpcHTTPListenAddress
if addr == "" {
addr = "127.0.0.1"
}
port := httpConfig.SszRestPort
if port == 0 {
port = httpConfig.AuthRpcPort + 1
if httpConfig.AuthRpcPort == 0 {
port = 8552
}
}
e.sszRestPort = port

sszServer := NewSszRestServer(e, e.logger, jwtSecret, addr, port)
err = sszServer.Start(ctx)
if err != nil && !errors.Is(err, context.Canceled) {
e.logger.Error("[EngineServer] SSZ-REST server background goroutine failed", "err", err)
}
return err
})
}

return eg.Wait()
}

Expand Down
29 changes: 29 additions & 0 deletions execution/engineapi/engine_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,35 @@ func TestGetPayloadBodiesByHashV2(t *testing.T) {
req.Equal(hexutil.Bytes(balBytes), bodies[0].BlockAccessList)
}

func TestGetClientCommunicationChannelsV1(t *testing.T) {
mockSentry := execmoduletester.New(t, execmoduletester.WithTxPool(), execmoduletester.WithChainConfig(chain.AllProtocolChanges))
req := require.New(t)

executionRpc := direct.NewExecutionClientDirect(mockSentry.ExecModule)
maxReorgDepth := ethconfig.Defaults.MaxReorgDepth
engineServer := NewEngineServer(mockSentry.Log, mockSentry.ChainConfig, executionRpc, nil, false, false, true, nil, ethconfig.Defaults.FcuTimeout, maxReorgDepth)

ctx := context.Background()

// Before Start (no httpConfig set) — should return defaults
channels, err := engineServer.GetClientCommunicationChannelsV1(ctx)
req.NoError(err)
req.Len(channels, 1)
req.Equal("json_rpc", channels[0].Protocol)
req.Equal("localhost:8551", channels[0].URL)

// After setting httpConfig via Start-like initialization
engineServer.httpConfig = &httpcfg.HttpCfg{
AuthRpcHTTPListenAddress: "0.0.0.0",
AuthRpcPort: 9551,
}
channels, err = engineServer.GetClientCommunicationChannelsV1(ctx)
req.NoError(err)
req.Len(channels, 1)
req.Equal("json_rpc", channels[0].Protocol)
req.Equal("0.0.0.0:9551", channels[0].URL)
}

func TestGetPayloadBodiesByRangeV2(t *testing.T) {
mockSentry := execmoduletester.New(t, execmoduletester.WithTxPool(), execmoduletester.WithChainConfig(chain.AllProtocolChanges))
req := require.New(t)
Expand Down
Loading
Loading