move to beacon/engine

pull/29039/head
itsdevbear 9 months ago
parent 60504f7316
commit 2732319758
  1. 50
      beacon/engine/client/client.go
  2. 28
      beacon/engine/client/client_test.go
  3. 2
      beacon/engine/client/types.go

@ -14,8 +14,8 @@
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
// Package engineclient provides an RPC client for engine API required functionc. // Package client provides an RPC client for engine API required functionc.
package engineclient package client
import ( import (
"context" "context"
@ -28,22 +28,22 @@ import (
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
) )
// Client is a wrapper around rpc.Client that implements geth-specific functionality. // Engine is a wrapper around ethclient.Client that implements geth-specific functionality.
// //
// If you want to use the standardized Ethereum RPC functionality, use ethclient.Client instead. // If you want to use the standardized Ethereum RPC functionality, use ethclient.Engine instead.
type Client struct { type Engine struct {
*ethclient.Client *ethclient.Client
} }
// New creates a client that uses the given RPC client. // New creates a client that uses the given RPC client.
func New(c *ethclient.Client) *Client { func New(c *ethclient.Client) *Engine {
return &Client{c} return &Engine{c}
} }
// ExchangeTransitionConfigurationV1 calls the engine_exchangeTransitionConfigurationV1 // ExchangeTransitionConfigurationV1 calls the engine_exchangeTransitionConfigurationV1
// method via JSON-RPC. This is not really needed anymore, since we are post merge, // method via JSON-RPC. This is not really needed anymore, since we are post merge,
// but it is still here for reference / completeness sake. // but it is still here for reference / completeness sake.
func (c *Client) ExchangeTransitionConfigurationV1( func (c *Engine) ExchangeTransitionConfigurationV1(
ctx context.Context, ctx context.Context,
config engine.TransitionConfigurationV1, config engine.TransitionConfigurationV1,
) (*engine.TransitionConfigurationV1, error) { ) (*engine.TransitionConfigurationV1, error) {
@ -57,7 +57,7 @@ func (c *Client) ExchangeTransitionConfigurationV1(
} }
// ExchangeCapabilities calls the engine_exchangeCapabilities method via JSON-RPC. // ExchangeCapabilities calls the engine_exchangeCapabilities method via JSON-RPC.
func (c *Client) ExchangeCapabilities( func (c *Engine) ExchangeCapabilities(
ctx context.Context, ctx context.Context,
capabilities []string, capabilities []string,
) ([]string, error) { ) ([]string, error) {
@ -71,7 +71,7 @@ func (c *Client) ExchangeCapabilities(
} }
// GetClientVersionV1 calls the engine_getClientVersionV1 method via JSON-RPC. // GetClientVersionV1 calls the engine_getClientVersionV1 method via JSON-RPC.
func (c *Client) GetClientVersionV1(ctx context.Context) ([]engine.ClientVersionV1, error) { func (c *Engine) GetClientVersionV1(ctx context.Context) ([]engine.ClientVersionV1, error) {
result := make([]engine.ClientVersionV1, 0) result := make([]engine.ClientVersionV1, 0)
if err := c.Client.Client().CallContext( if err := c.Client.Client().CallContext(
ctx, &result, "engine_getClientVersionV1", nil, ctx, &result, "engine_getClientVersionV1", nil,
@ -82,7 +82,7 @@ func (c *Client) GetClientVersionV1(ctx context.Context) ([]engine.ClientVersion
} }
// NewPayloadV3 calls the engine_newPayloadV3 method via JSON-RPC. // NewPayloadV3 calls the engine_newPayloadV3 method via JSON-RPC.
func (c *Client) NewPayloadV3( func (c *Engine) NewPayloadV3(
ctx context.Context, payload *engine.ExecutionPayloadEnvelope, ctx context.Context, payload *engine.ExecutionPayloadEnvelope,
versionedHashes common.Hash, parentBlockRoot common.Hash, versionedHashes common.Hash, parentBlockRoot common.Hash,
) (*engine.PayloadStatusV1, error) { ) (*engine.PayloadStatusV1, error) {
@ -90,21 +90,21 @@ func (c *Client) NewPayloadV3(
} }
// NewPayloadV2 calls the engine_newPayloadV2 method via JSON-RPC. // NewPayloadV2 calls the engine_newPayloadV2 method via JSON-RPC.
func (c *Client) NewPayloadV2( func (c *Engine) NewPayloadV2(
ctx context.Context, payload *engine.ExecutionPayloadEnvelope, ctx context.Context, payload *engine.ExecutionPayloadEnvelope,
) (*engine.PayloadStatusV1, error) { ) (*engine.PayloadStatusV1, error) {
return c.newPayload(ctx, ShanghaiV2, payload) return c.newPayload(ctx, ShanghaiV2, payload)
} }
// NewPayloadV1 calls the engine_newPayloadV1 method via JSON-RPC. // NewPayloadV1 calls the engine_newPayloadV1 method via JSON-RPC.
func (c *Client) NewPayloadV1( func (c *Engine) NewPayloadV1(
ctx context.Context, payload *engine.ExecutionPayloadEnvelope, ctx context.Context, payload *engine.ExecutionPayloadEnvelope,
) (*engine.PayloadStatusV1, error) { ) (*engine.PayloadStatusV1, error) {
return c.newPayload(ctx, ParisV1, payload) return c.newPayload(ctx, ParisV1, payload)
} }
// newPayload is a helper function that can call an arbitrary version of the newPayload method. // newPayload is a helper function that can call an arbitrary version of the newPayload method.
func (c *Client) newPayload( func (c *Engine) newPayload(
ctx context.Context, version APIVersion, payload *engine.ExecutionPayloadEnvelope, ctx context.Context, version APIVersion, payload *engine.ExecutionPayloadEnvelope,
) (*engine.PayloadStatusV1, error) { ) (*engine.PayloadStatusV1, error) {
result := &engine.PayloadStatusV1{} result := &engine.PayloadStatusV1{}
@ -117,7 +117,7 @@ func (c *Client) newPayload(
} }
// newPayloadWithArgs is a helper function that can call an arbitrary version of the newPayload method. // newPayloadWithArgs is a helper function that can call an arbitrary version of the newPayload method.
func (c *Client) newPayloadWithArgs( func (c *Engine) newPayloadWithArgs(
ctx context.Context, version APIVersion, payload *engine.ExecutionPayloadEnvelope, args ...any, ctx context.Context, version APIVersion, payload *engine.ExecutionPayloadEnvelope, args ...any,
) (*engine.PayloadStatusV1, error) { ) (*engine.PayloadStatusV1, error) {
result := &engine.PayloadStatusV1{} result := &engine.PayloadStatusV1{}
@ -130,21 +130,21 @@ func (c *Client) newPayloadWithArgs(
} }
// ForkchoiceUpdatedV1 calls the engine_forkchoiceUpdatedV1 method via JSON-RPC. // ForkchoiceUpdatedV1 calls the engine_forkchoiceUpdatedV1 method via JSON-RPC.
func (c *Client) ForkchoiceUpdatedV1( func (c *Engine) ForkchoiceUpdatedV1(
ctx context.Context, state *engine.ForkchoiceStateV1, attrs *engine.PayloadAttributes, ctx context.Context, state *engine.ForkchoiceStateV1, attrs *engine.PayloadAttributes,
) (*ForkchoiceUpdatedResponse, error) { ) (*ForkchoiceUpdatedResponse, error) {
return c.forkchoiceUpdated(ctx, ParisV1, state, attrs) return c.forkchoiceUpdated(ctx, ParisV1, state, attrs)
} }
// ForkchoiceUpdatedV2 calls the engine_forkchoiceUpdatedV2 method via JSON-RPC. // ForkchoiceUpdatedV2 calls the engine_forkchoiceUpdatedV2 method via JSON-RPC.
func (c *Client) ForkchoiceUpdatedV2( func (c *Engine) ForkchoiceUpdatedV2(
ctx context.Context, state *engine.ForkchoiceStateV1, attrs *engine.PayloadAttributes, ctx context.Context, state *engine.ForkchoiceStateV1, attrs *engine.PayloadAttributes,
) (*ForkchoiceUpdatedResponse, error) { ) (*ForkchoiceUpdatedResponse, error) {
return c.forkchoiceUpdated(ctx, ShanghaiV2, state, attrs) return c.forkchoiceUpdated(ctx, ShanghaiV2, state, attrs)
} }
// ForkchoiceUpdatedV3 calls the engine_forkchoiceUpdatedV3 method via JSON-RPC. // ForkchoiceUpdatedV3 calls the engine_forkchoiceUpdatedV3 method via JSON-RPC.
func (c *Client) ForkchoiceUpdatedV3( func (c *Engine) ForkchoiceUpdatedV3(
ctx context.Context, state *engine.ForkchoiceStateV1, attrs *engine.PayloadAttributes, ctx context.Context, state *engine.ForkchoiceStateV1, attrs *engine.PayloadAttributes,
) (*ForkchoiceUpdatedResponse, error) { ) (*ForkchoiceUpdatedResponse, error) {
return c.forkchoiceUpdated(ctx, CancunV3, state, attrs) return c.forkchoiceUpdated(ctx, CancunV3, state, attrs)
@ -152,7 +152,7 @@ func (c *Client) ForkchoiceUpdatedV3(
// forkchoiceUpdateCall is a helper function to call to any version of the forkchoiceUpdated // forkchoiceUpdateCall is a helper function to call to any version of the forkchoiceUpdated
// method. // method.
func (c *Client) forkchoiceUpdated( func (c *Engine) forkchoiceUpdated(
ctx context.Context, version APIVersion, state *engine.ForkchoiceStateV1, attrs any, ctx context.Context, version APIVersion, state *engine.ForkchoiceStateV1, attrs any,
) (*ForkchoiceUpdatedResponse, error) { ) (*ForkchoiceUpdatedResponse, error) {
result := &ForkchoiceUpdatedResponse{} result := &ForkchoiceUpdatedResponse{}
@ -173,28 +173,28 @@ func (c *Client) forkchoiceUpdated(
} }
// GetPayloadV3 calls the engine_getPayloadV3 method via JSON-RPC. // GetPayloadV3 calls the engine_getPayloadV3 method via JSON-RPC.
func (c *Client) GetPayloadV1( func (c *Engine) GetPayloadV1(
ctx context.Context, payloadID *engine.PayloadID, ctx context.Context, payloadID *engine.PayloadID,
) (*engine.ExecutionPayloadEnvelope, error) { ) (*engine.ExecutionPayloadEnvelope, error) {
return c.getPayload(ctx, ParisV1, payloadID) return c.getPayload(ctx, ParisV1, payloadID)
} }
// GetPayloadV2 calls the engine_getPayloadV3 method via JSON-RPC. // GetPayloadV2 calls the engine_getPayloadV3 method via JSON-RPC.
func (c *Client) GetPayloadV2( func (c *Engine) GetPayloadV2(
ctx context.Context, payloadID *engine.PayloadID, ctx context.Context, payloadID *engine.PayloadID,
) (*engine.ExecutionPayloadEnvelope, error) { ) (*engine.ExecutionPayloadEnvelope, error) {
return c.getPayload(ctx, ShanghaiV2, payloadID) return c.getPayload(ctx, ShanghaiV2, payloadID)
} }
// GetPayloadV3 calls the engine_getPayloadV3 method via JSON-RPC. // GetPayloadV3 calls the engine_getPayloadV3 method via JSON-RPC.
func (c *Client) GetPayloadV3( func (c *Engine) GetPayloadV3(
ctx context.Context, payloadID *engine.PayloadID, ctx context.Context, payloadID *engine.PayloadID,
) (*engine.ExecutionPayloadEnvelope, error) { ) (*engine.ExecutionPayloadEnvelope, error) {
return c.getPayload(ctx, CancunV3, payloadID) return c.getPayload(ctx, CancunV3, payloadID)
} }
// getPayload is a helper function that can call an arbitrary version of the getPayload method. // getPayload is a helper function that can call an arbitrary version of the getPayload method.
func (c *Client) getPayload(ctx context.Context, version APIVersion, payloadID *engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) { func (c *Engine) getPayload(ctx context.Context, version APIVersion, payloadID *engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
result := &engine.ExecutionPayloadEnvelope{} result := &engine.ExecutionPayloadEnvelope{}
if err := c.Client.Client().CallContext( if err := c.Client.Client().CallContext(
ctx, result, fmt.Sprintf("engine_getPayloadV%d", version), payloadID, ctx, result, fmt.Sprintf("engine_getPayloadV%d", version), payloadID,
@ -205,7 +205,7 @@ func (c *Client) getPayload(ctx context.Context, version APIVersion, payloadID *
} }
// GetPayloadBodiesByHashV1 calls the engine_getPayloadBodiesByHashV1 method via JSON-RPC. // GetPayloadBodiesByHashV1 calls the engine_getPayloadBodiesByHashV1 method via JSON-RPC.
func (c *Client) GetPayloadBodiesByHashV1( func (c *Engine) GetPayloadBodiesByHashV1(
ctx context.Context, ctx context.Context,
hashes []common.Hash, hashes []common.Hash,
) ([]*engine.ExecutionPayloadBodyV1, error) { ) ([]*engine.ExecutionPayloadBodyV1, error) {
@ -219,7 +219,7 @@ func (c *Client) GetPayloadBodiesByHashV1(
} }
// GetPayloadBodiesByRangeV1 calls the engine_getPayloadBodiesByRangeV1 method via JSON-RPC. // GetPayloadBodiesByRangeV1 calls the engine_getPayloadBodiesByRangeV1 method via JSON-RPC.
func (c *Client) GetPayloadBodiesByRangeV1( func (c *Engine) GetPayloadBodiesByRangeV1(
ctx context.Context, start, count hexutil.Uint64, ctx context.Context, start, count hexutil.Uint64,
) ([]*engine.ExecutionPayloadBodyV1, error) { ) ([]*engine.ExecutionPayloadBodyV1, error) {
result := make([]*engine.ExecutionPayloadBodyV1, 0) result := make([]*engine.ExecutionPayloadBodyV1, 0)

@ -1,4 +1,4 @@
package engineclient package client
import ( import (
"context" "context"
@ -160,7 +160,7 @@ func TestEngineClient(t *testing.T) {
t.Run(name, tt.test) t.Run(name, tt.test)
} }
} }
func testExchangeCapabilities(t *testing.T, chain []*types.Block, client *Client) { func testExchangeCapabilities(t *testing.T, chain []*types.Block, client *Engine) {
expected := catalyst.Caps expected := catalyst.Caps
capabilities := []string{"random", "ignored", "strings"} capabilities := []string{"random", "ignored", "strings"}
actual, err := client.ExchangeCapabilities(context.Background(), capabilities) actual, err := client.ExchangeCapabilities(context.Background(), capabilities)
@ -172,7 +172,7 @@ func testExchangeCapabilities(t *testing.T, chain []*types.Block, client *Client
} }
} }
func testGetClientV1(t *testing.T, chain []*types.Block, client *Client) { func testGetClientV1(t *testing.T, chain []*types.Block, client *Engine) {
actual, err := client.GetClientVersionV1(context.Background()) actual, err := client.GetClientVersionV1(context.Background())
if err != nil { if err != nil {
t.Fatalf("GetClientVersionV1 failed: %v", err) t.Fatalf("GetClientVersionV1 failed: %v", err)
@ -182,7 +182,7 @@ func testGetClientV1(t *testing.T, chain []*types.Block, client *Client) {
} }
} }
func testGetPayloadBodiesByHashV1(t *testing.T, chain []*types.Block, client *Client) { func testGetPayloadBodiesByHashV1(t *testing.T, chain []*types.Block, client *Engine) {
actual, err := client.GetPayloadBodiesByHashV1(context.Background(), []common.Hash{chain[2].Hash()}) actual, err := client.GetPayloadBodiesByHashV1(context.Background(), []common.Hash{chain[2].Hash()})
if err != nil { if err != nil {
t.Fatalf("GetPayloadBodiesByHashV1 failed: %v", err) t.Fatalf("GetPayloadBodiesByHashV1 failed: %v", err)
@ -204,7 +204,7 @@ func testGetPayloadBodiesByHashV1(t *testing.T, chain []*types.Block, client *Cl
} }
} }
func testGetPayloadBodiesByRangeV1(t *testing.T, chain []*types.Block, client *Client) { func testGetPayloadBodiesByRangeV1(t *testing.T, chain []*types.Block, client *Engine) {
actual, err := client.GetPayloadBodiesByRangeV1(context.Background(), hexutil.Uint64(chain[2].NumberU64()), hexutil.Uint64(1)) actual, err := client.GetPayloadBodiesByRangeV1(context.Background(), hexutil.Uint64(chain[2].NumberU64()), hexutil.Uint64(1))
if err != nil { if err != nil {
t.Fatalf("GetPayloadBodiesByRangeV1 failed: %v", err) t.Fatalf("GetPayloadBodiesByRangeV1 failed: %v", err)
@ -225,7 +225,7 @@ func testGetPayloadBodiesByRangeV1(t *testing.T, chain []*types.Block, client *C
} }
} }
func testNewPayloadV1(t *testing.T, chain []*types.Block, client *Client) { func testNewPayloadV1(t *testing.T, chain []*types.Block, client *Engine) {
ctx := context.Background() ctx := context.Background()
// Create a mock payload // Create a mock payload
@ -241,7 +241,7 @@ func testNewPayloadV1(t *testing.T, chain []*types.Block, client *Client) {
} }
} }
func testNewPayloadV2(t *testing.T, chain []*types.Block, client *Client) { func testNewPayloadV2(t *testing.T, chain []*types.Block, client *Engine) {
ctx := context.Background() ctx := context.Background()
// Create a mock payload // Create a mock payload
@ -257,7 +257,7 @@ func testNewPayloadV2(t *testing.T, chain []*types.Block, client *Client) {
} }
} }
func testNewPayloadV3(t *testing.T, chain []*types.Block, client *Client) { func testNewPayloadV3(t *testing.T, chain []*types.Block, client *Engine) {
ctx := context.Background() ctx := context.Background()
// Create a mock payload // Create a mock payload
@ -297,7 +297,7 @@ func createMockPayload(parent *types.Block) *engine.ExecutionPayloadEnvelope {
}} }}
} }
func testForkchoiceUpdatedV1(t *testing.T, chain []*types.Block, client *Client) { func testForkchoiceUpdatedV1(t *testing.T, chain []*types.Block, client *Engine) {
// Call ForkchoiceUpdatedV2 // Call ForkchoiceUpdatedV2
resp, err := client.ForkchoiceUpdatedV1(context.Background(), &engine.ForkchoiceStateV1{ resp, err := client.ForkchoiceUpdatedV1(context.Background(), &engine.ForkchoiceStateV1{
HeadBlockHash: common.Hash{}, HeadBlockHash: common.Hash{},
@ -314,7 +314,7 @@ func testForkchoiceUpdatedV1(t *testing.T, chain []*types.Block, client *Client)
} }
} }
func testForkchoiceUpdatedV2(t *testing.T, chain []*types.Block, client *Client) { func testForkchoiceUpdatedV2(t *testing.T, chain []*types.Block, client *Engine) {
// Call ForkchoiceUpdatedV2 // Call ForkchoiceUpdatedV2
resp, err := client.ForkchoiceUpdatedV2(context.Background(), &engine.ForkchoiceStateV1{ resp, err := client.ForkchoiceUpdatedV2(context.Background(), &engine.ForkchoiceStateV1{
HeadBlockHash: common.Hash{}, HeadBlockHash: common.Hash{},
@ -331,7 +331,7 @@ func testForkchoiceUpdatedV2(t *testing.T, chain []*types.Block, client *Client)
} }
} }
func testForkchoiceUpdatedV3(t *testing.T, chain []*types.Block, client *Client) { func testForkchoiceUpdatedV3(t *testing.T, chain []*types.Block, client *Engine) {
// Call ForkchoiceUpdatedV3 // Call ForkchoiceUpdatedV3
resp, err := client.ForkchoiceUpdatedV3(context.Background(), &engine.ForkchoiceStateV1{ resp, err := client.ForkchoiceUpdatedV3(context.Background(), &engine.ForkchoiceStateV1{
HeadBlockHash: common.Hash{}, HeadBlockHash: common.Hash{},
@ -348,7 +348,7 @@ func testForkchoiceUpdatedV3(t *testing.T, chain []*types.Block, client *Client)
} }
} }
func testGetPayloadV3(t *testing.T, chain []*types.Block, client *Client) { func testGetPayloadV3(t *testing.T, chain []*types.Block, client *Engine) {
payloadID := engine.PayloadID{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08} // Example PayloadID, adjust as necessary payloadID := engine.PayloadID{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08} // Example PayloadID, adjust as necessary
_, err := client.GetPayloadV3(context.Background(), &payloadID) _, err := client.GetPayloadV3(context.Background(), &payloadID)
if err.Error() != "Unsupported fork" { if err.Error() != "Unsupported fork" {
@ -356,7 +356,7 @@ func testGetPayloadV3(t *testing.T, chain []*types.Block, client *Client) {
} }
} }
func testGetPayloadV2(t *testing.T, chain []*types.Block, client *Client) { func testGetPayloadV2(t *testing.T, chain []*types.Block, client *Engine) {
payloadID := engine.PayloadID{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08} // Example PayloadID, adjust as necessary payloadID := engine.PayloadID{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08} // Example PayloadID, adjust as necessary
_, err := client.GetPayloadV2(context.Background(), &payloadID) _, err := client.GetPayloadV2(context.Background(), &payloadID)
if err.Error() != "Unknown payload" { if err.Error() != "Unknown payload" {
@ -364,7 +364,7 @@ func testGetPayloadV2(t *testing.T, chain []*types.Block, client *Client) {
} }
} }
func testGetPayloadV1(t *testing.T, chain []*types.Block, client *Client) { func testGetPayloadV1(t *testing.T, chain []*types.Block, client *Engine) {
payloadID := engine.PayloadID{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08} // Example PayloadID, adjust as necessary payloadID := engine.PayloadID{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08} // Example PayloadID, adjust as necessary
_, err := client.GetPayloadV1(context.Background(), &payloadID) _, err := client.GetPayloadV1(context.Background(), &payloadID)
if err.Error() != "Unknown payload" { if err.Error() != "Unknown payload" {

@ -1,4 +1,4 @@
package engineclient package client
import ( import (
"github.com/ethereum/go-ethereum/beacon/engine" "github.com/ethereum/go-ethereum/beacon/engine"
Loading…
Cancel
Save