Skip to content

Commit

Permalink
Merge pull request #27 from ethpandaops/feat/raw-block
Browse files Browse the repository at this point in the history
feat(beacon): add raw block
  • Loading branch information
Savid authored Mar 27, 2024
2 parents 29cbd9b + 10f186c commit 624f4c9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/beacon/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ 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)
RawDebugBeaconState(ctx context.Context, stateID string, contentType string) ([]byte, error)
DepositSnapshot(ctx context.Context) (*types.DepositSnapshot, error)
}
Expand Down Expand Up @@ -210,6 +211,16 @@ func (c *consensusClient) RawDebugBeaconState(ctx context.Context, stateID strin
return data, nil
}

// RawBlock returns the block in the requested format.
func (c *consensusClient) RawBlock(ctx context.Context, stateID string, contentType string) ([]byte, error) {
data, err := c.getRaw(ctx, fmt.Sprintf("/eth/v2/beacon/blocks/%s", stateID), 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
2 changes: 2 additions & 0 deletions pkg/beacon/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ type Node interface {
// Fetchers - these are not cached and will always fetch from the node.
// FetchBlock fetches the block for the given state id.
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)
// FetchBeaconState fetches the beacon state for the given state id.
FetchBeaconState(ctx context.Context, stateID string) (*spec.VersionedBeaconState, error)
// FetchBeaconStateRoot fetches the state root 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 @@ -67,6 +67,10 @@ func (n *node) FetchBlock(ctx context.Context, stateID string) (*spec.VersionedS
return n.getBlock(ctx, stateID)
}

func (n *node) FetchRawBlock(ctx context.Context, stateID string, contentType string) ([]byte, error) {
return n.api.RawBlock(ctx, stateID, contentType)
}

func (n *node) FetchBeaconState(ctx context.Context, stateID string) (*spec.VersionedBeaconState, error) {
provider, isProvider := n.client.(eth2client.BeaconStateProvider)
if !isProvider {
Expand Down

0 comments on commit 624f4c9

Please sign in to comment.