Skip to content
Merged
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
22 changes: 22 additions & 0 deletions pkg/beacon/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
Expand All @@ -13,12 +14,18 @@ import (
"github.com/sirupsen/logrus"
)

// ErrNotFound is returned when the node responds with HTTP 404 for the
// requested resource, e.g. an execution payload envelope that has not been
// revealed or a block that does not exist.
var ErrNotFound = errors.New("not found")

// ConsensusClient is an interface for executing RPC calls to the Ethereum node.
type ConsensusClient interface {
NodePeer(ctx context.Context, peerID string) (types.Peer, error)
NodePeers(ctx context.Context) (types.Peers, error)
NodePeerCount(ctx context.Context) (types.PeerCount, error)
RawBlock(ctx context.Context, stateID string, contentType string) ([]byte, error)
RawExecutionPayloadEnvelope(ctx context.Context, blockID string, contentType string) ([]byte, error)
RawDebugBeaconState(ctx context.Context, stateID string, contentType string) ([]byte, error)
DepositSnapshot(ctx context.Context) (*types.DepositSnapshot, error)
NodeIdentity(ctx context.Context) (*types.Identity, error)
Expand Down Expand Up @@ -152,6 +159,10 @@ func (c *consensusClient) getRaw(ctx context.Context, path string, contentType s
defer rsp.Body.Close()

if rsp.StatusCode != http.StatusOK {
if rsp.StatusCode == http.StatusNotFound {
return nil, fmt.Errorf("status code: %d: %w", rsp.StatusCode, ErrNotFound)
}

return nil, fmt.Errorf("status code: %d", rsp.StatusCode)
}

Expand Down Expand Up @@ -223,6 +234,17 @@ func (c *consensusClient) RawBlock(ctx context.Context, stateID string, contentT
return data, nil
}

// RawExecutionPayloadEnvelope returns the signed execution payload envelope
// for the given block id in the requested format (gloas onwards).
func (c *consensusClient) RawExecutionPayloadEnvelope(ctx context.Context, blockID string, contentType string) ([]byte, error) {
data, err := c.getRaw(ctx, fmt.Sprintf("/eth/v1/beacon/execution_payload_envelopes/%s", blockID), contentType)
if err != nil {
return nil, err
}

return data, nil
}

// DepositSnapshot returns the deposit snapshot in the requested format.
func (c *consensusClient) DepositSnapshot(ctx context.Context) (*types.DepositSnapshot, error) {
data, err := c.get(ctx, "/eth/v1/beacon/deposit_snapshot")
Expand Down
3 changes: 3 additions & 0 deletions pkg/beacon/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ type Node interface {
FetchBlock(ctx context.Context, stateID string) (*spec.VersionedSignedBeaconBlock, error)
// FetchRawBlock fetches the raw, unparsed block for the given state id.
FetchRawBlock(ctx context.Context, stateID string, contentType string) ([]byte, error)
// FetchRawExecutionPayloadEnvelope fetches the raw, unparsed signed execution
// payload envelope for the given block id (gloas onwards).
FetchRawExecutionPayloadEnvelope(ctx context.Context, blockID string, contentType string) ([]byte, error)
// FetchBlockRoot fetches the block root for the given state id.
FetchBlockRoot(ctx context.Context, stateID string) (*phase0.Root, error)
// FetchBeaconState fetches the beacon state for the given state id.
Expand Down
4 changes: 4 additions & 0 deletions pkg/beacon/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ func (n *node) FetchRawBlock(ctx context.Context, stateID string, contentType st
return n.api.RawBlock(ctx, stateID, contentType)
}

func (n *node) FetchRawExecutionPayloadEnvelope(ctx context.Context, blockID string, contentType string) ([]byte, error) {
return n.api.RawExecutionPayloadEnvelope(ctx, blockID, contentType)
}

func (n *node) FetchBlockRoot(ctx context.Context, stateID string) (*phase0.Root, error) {
return n.getBlockRoot(ctx, stateID)
}
Expand Down