Skip to content

Commit

Permalink
some more clenaup
Browse files Browse the repository at this point in the history
  • Loading branch information
abi87 committed Dec 10, 2024
1 parent eeb90db commit 9ee3e12
Show file tree
Hide file tree
Showing 14 changed files with 45 additions and 53 deletions.
9 changes: 5 additions & 4 deletions node-api/handlers/proof/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@
package proof

import (
ctypes "github.com/berachain/beacon-kit/consensus-types/types"
"github.com/berachain/beacon-kit/primitives/math"
)

// Backend is the interface for backend of the proof API.
type Backend[BeaconBlockHeaderT, BeaconStateT, ValidatorT any] interface {
BlockBackend[BeaconBlockHeaderT]
type Backend[BeaconStateT, ValidatorT any] interface {
BlockBackend
StateBackend[BeaconStateT]
GetParentSlotByTimestamp(timestamp math.U64) (math.Slot, error)
}

type BlockBackend[BeaconBlockHeaderT any] interface {
BlockHeaderAtSlot(slot math.Slot) (BeaconBlockHeaderT, error)
type BlockBackend interface {
BlockHeaderAtSlot(slot math.Slot) (*ctypes.BeaconBlockHeader, error)
}

type StateBackend[BeaconStateT any] interface {
Expand Down
4 changes: 2 additions & 2 deletions node-api/handlers/proof/block_proposer.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
// id along with a merkle proof that can be verified against the beacon block
// root. It also returns the merkle proof of the proposer index.
func (h *Handler[
BeaconBlockHeaderT, _, _, ContextT, _, _,
_, _, ContextT, _, _,
]) GetBlockProposer(c ContextT) (any, error) {
params, err := utils.BindAndValidate[types.BlockProposerRequest](
c, h.Logger(),
Expand Down Expand Up @@ -72,7 +72,7 @@ func (h *Handler[
return nil, err
}

return types.BlockProposerResponse[BeaconBlockHeaderT]{
return types.BlockProposerResponse{
BeaconBlockHeader: blockHeader,
BeaconBlockRoot: beaconBlockRoot,
ValidatorPubkey: proposerValidator.GetPubkey(),
Expand Down
4 changes: 2 additions & 2 deletions node-api/handlers/proof/execution_fee_recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
// payload header for the given timestamp id, along with the proof that can be
// verified against the beacon block root.
func (h *Handler[
BeaconBlockHeaderT, _, _, ContextT, _, _,
_, _, ContextT, _, _,
]) GetExecutionFeeRecipient(c ContextT) (any, error) {
params, err := utils.BindAndValidate[types.ExecutionFeeRecipientRequest](
c, h.Logger(),
Expand Down Expand Up @@ -61,7 +61,7 @@ func (h *Handler[
return nil, err
}

return types.ExecutionFeeRecipientResponse[BeaconBlockHeaderT]{
return types.ExecutionFeeRecipientResponse{
BeaconBlockHeader: blockHeader,
BeaconBlockRoot: beaconBlockRoot,
ExecutionFeeRecipient: leph.GetFeeRecipient(),
Expand Down
4 changes: 2 additions & 2 deletions node-api/handlers/proof/execution_number.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
// payload header for the given timestamp id, along with the proof that can be
// verified against the beacon block root.
func (h *Handler[
BeaconBlockHeaderT, _, _, ContextT, _, _,
_, _, ContextT, _, _,
]) GetExecutionNumber(c ContextT) (any, error) {
params, err := utils.BindAndValidate[types.ExecutionNumberRequest](
c, h.Logger(),
Expand Down Expand Up @@ -61,7 +61,7 @@ func (h *Handler[
return nil, err
}

return types.ExecutionNumberResponse[BeaconBlockHeaderT]{
return types.ExecutionNumberResponse{
BeaconBlockHeader: blockHeader,
BeaconBlockRoot: beaconBlockRoot,
ExecutionNumber: leph.GetNumber(),
Expand Down
17 changes: 8 additions & 9 deletions node-api/handlers/proof/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package proof

import (
ctypes "github.com/berachain/beacon-kit/consensus-types/types"
"github.com/berachain/beacon-kit/node-api/handlers"
"github.com/berachain/beacon-kit/node-api/handlers/proof/types"
"github.com/berachain/beacon-kit/node-api/handlers/utils"
Expand All @@ -30,7 +31,6 @@ import (

// Handler is the handler for the proof API.
type Handler[
BeaconBlockHeaderT types.BeaconBlockHeader,
BeaconStateT types.BeaconState[
BeaconStateMarshallableT, ExecutionPayloadHeaderT, ValidatorT,
],
Expand All @@ -40,12 +40,11 @@ type Handler[
ValidatorT types.Validator,
] struct {
*handlers.BaseHandler[ContextT]
backend Backend[BeaconBlockHeaderT, BeaconStateT, ValidatorT]
backend Backend[BeaconStateT, ValidatorT]
}

// NewHandler creates a new handler for the proof API.
func NewHandler[
BeaconBlockHeaderT types.BeaconBlockHeader,
BeaconStateT types.BeaconState[
BeaconStateMarshallableT, ExecutionPayloadHeaderT, ValidatorT,
],
Expand All @@ -54,13 +53,13 @@ func NewHandler[
ExecutionPayloadHeaderT types.ExecutionPayloadHeader,
ValidatorT types.Validator,
](
backend Backend[BeaconBlockHeaderT, BeaconStateT, ValidatorT],
backend Backend[BeaconStateT, ValidatorT],
) *Handler[
BeaconBlockHeaderT, BeaconStateT, BeaconStateMarshallableT,
BeaconStateT, BeaconStateMarshallableT,
ContextT, ExecutionPayloadHeaderT, ValidatorT,
] {
h := &Handler[
BeaconBlockHeaderT, BeaconStateT, BeaconStateMarshallableT,
BeaconStateT, BeaconStateMarshallableT,
ContextT, ExecutionPayloadHeaderT, ValidatorT,
]{
BaseHandler: handlers.NewBaseHandler(
Expand All @@ -74,13 +73,13 @@ func NewHandler[
// Get the slot from the given input of timestamp id, beacon state, and beacon
// block header for the resolved slot.
func (h *Handler[
BeaconBlockHeaderT, BeaconStateT, _, _, _, _,
BeaconStateT, _, _, _, _,
]) resolveTimestampID(timestampID string) (
math.Slot, BeaconStateT, BeaconBlockHeaderT, error,
math.Slot, BeaconStateT, *ctypes.BeaconBlockHeader, error,
) {
var (
beaconState BeaconStateT
blockHeader BeaconBlockHeaderT
blockHeader *ctypes.BeaconBlockHeader
)

slot, err := utils.ParentSlotFromTimestampID(timestampID, h.backend)
Expand Down
6 changes: 3 additions & 3 deletions node-api/handlers/proof/merkle/beacon_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
package merkle

import (
ctypes "github.com/berachain/beacon-kit/consensus-types/types"
"github.com/berachain/beacon-kit/errors"
"github.com/berachain/beacon-kit/node-api/handlers/proof/types"
"github.com/berachain/beacon-kit/primitives/common"
"github.com/berachain/beacon-kit/primitives/encoding/ssz/merkle"
)

// ProveBeaconStateInBlock generates a proof for the beacon state in the
// beacon block. It uses the fastssz library to generate the proof.
func ProveBeaconStateInBlock(
bbh types.BeaconBlockHeader, verifyProof bool,
bbh *ctypes.BeaconBlockHeader, verifyProof bool,
) ([]common.Root, error) {
blockProofTree, err := bbh.GetTree()
if err != nil {
Expand Down Expand Up @@ -62,7 +62,7 @@ func ProveBeaconStateInBlock(
//
// TODO: verifying the proof is not absolutely necessary.
func verifyBeaconStateInBlock(
bbh types.BeaconBlockHeader, proof []common.Root, leaf common.Root,
bbh *ctypes.BeaconBlockHeader, proof []common.Root, leaf common.Root,
) error {
beaconRoot := bbh.HashTreeRoot()
if beaconRootVerified, err := merkle.VerifyProof(
Expand Down
8 changes: 4 additions & 4 deletions node-api/handlers/proof/merkle/block_proposer_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
package merkle

import (
ctypes "github.com/berachain/beacon-kit/consensus-types/types"
"github.com/berachain/beacon-kit/errors"
"github.com/berachain/beacon-kit/node-api/handlers/proof/types"
"github.com/berachain/beacon-kit/primitives/common"
"github.com/berachain/beacon-kit/primitives/encoding/ssz/merkle"
)
Expand All @@ -32,8 +32,8 @@ import (
// sanity check. Returns the proof along with the beacon block root. It uses
// the fastssz library to generate the proof.
func ProveProposerIndexInBlock[
BeaconBlockHeaderT types.BeaconBlockHeader,
](bbh BeaconBlockHeaderT) ([]common.Root, common.Root, error) {
BeaconBlockHeaderT *ctypes.BeaconBlockHeader,
](bbh *ctypes.BeaconBlockHeader) ([]common.Root, common.Root, error) {
blockProofTree, err := bbh.GetTree()
if err != nil {
return nil, common.Root{}, err
Expand Down Expand Up @@ -65,7 +65,7 @@ func ProveProposerIndexInBlock[
//
// TODO: verifying the proof is not absolutely necessary.
func verifyProposerIndexInBlock(
bbh types.BeaconBlockHeader, proof []common.Root, leaf common.Root,
bbh *ctypes.BeaconBlockHeader, proof []common.Root, leaf common.Root,
) (common.Root, error) {
beaconRoot := bbh.HashTreeRoot()
if beaconRootVerified, err := merkle.VerifyProof(
Expand Down
6 changes: 3 additions & 3 deletions node-api/handlers/proof/merkle/block_proposer_pubkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package merkle

import (
ctypes "github.com/berachain/beacon-kit/consensus-types/types"
"github.com/berachain/beacon-kit/errors"
"github.com/berachain/beacon-kit/node-api/handlers/proof/types"
"github.com/berachain/beacon-kit/primitives/common"
Expand All @@ -33,12 +34,11 @@ import (
// sanity check. Returns the proof along with the beacon block root. It uses
// the fastssz library to generate the proof.
func ProveProposerPubkeyInBlock[
BeaconBlockHeaderT types.BeaconBlockHeader,
BeaconStateMarshallableT types.BeaconStateMarshallable,
ExecutionPayloadHeaderT types.ExecutionPayloadHeader,
ValidatorT any,
](
bbh BeaconBlockHeaderT,
bbh *ctypes.BeaconBlockHeader,
bs types.BeaconState[
BeaconStateMarshallableT, ExecutionPayloadHeaderT, ValidatorT,
],
Expand Down Expand Up @@ -112,7 +112,7 @@ func ProveProposerPubkeyInState[
//
// TODO: verifying the proof is not absolutely necessary.
func verifyProposerInBlock(
bbh types.BeaconBlockHeader,
bbh *ctypes.BeaconBlockHeader,
valOffset math.U64,
proof []common.Root,
leaf common.Root,
Expand Down
5 changes: 3 additions & 2 deletions node-api/handlers/proof/merkle/execution_fee_recipient.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package merkle

import (
ctypes "github.com/berachain/beacon-kit/consensus-types/types"
"github.com/berachain/beacon-kit/errors"
"github.com/berachain/beacon-kit/node-api/handlers/proof/types"
"github.com/berachain/beacon-kit/primitives/common"
Expand All @@ -34,7 +35,7 @@ import (
// along with the beacon block root. It uses the fastssz library to generate the
// proof.
func ProveExecutionFeeRecipientInBlock[
BeaconBlockHeaderT types.BeaconBlockHeader,
BeaconBlockHeaderT *ctypes.BeaconBlockHeader,
BeaconStateMarshallableT types.BeaconStateMarshallable,
ExecutionPayloadHeaderT types.ExecutionPayloadHeader,
ValidatorT any,
Expand Down Expand Up @@ -111,7 +112,7 @@ func ProveExecutionFeeRecipientInState[
//
// TODO: verifying the proof is not absolutely necessary.
func verifyExecutionFeeRecipientInBlock(
bbh types.BeaconBlockHeader,
bbh *ctypes.BeaconBlockHeader,
proof []common.Root,
leaf common.Root,
) (common.Root, error) {
Expand Down
5 changes: 3 additions & 2 deletions node-api/handlers/proof/merkle/execution_number.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
package merkle

import (
ctypes "github.com/berachain/beacon-kit/consensus-types/types"
"github.com/berachain/beacon-kit/errors"
"github.com/berachain/beacon-kit/node-api/handlers/proof/types"
"github.com/berachain/beacon-kit/primitives/common"
Expand All @@ -34,7 +35,7 @@ import (
// along with the beacon block root. It uses the fastssz library to generate the
// proof.
func ProveExecutionNumberInBlock[
BeaconBlockHeaderT types.BeaconBlockHeader,
BeaconBlockHeaderT *ctypes.BeaconBlockHeader,
BeaconStateMarshallableT types.BeaconStateMarshallable,
ExecutionPayloadHeaderT types.ExecutionPayloadHeader,
ValidatorT any,
Expand Down Expand Up @@ -107,7 +108,7 @@ func ProveExecutionNumberInState[
//
// TODO: verifying the proof is not absolutely necessary.
func verifyExecutionNumberInBlock(
bbh types.BeaconBlockHeader,
bbh *ctypes.BeaconBlockHeader,
proof []common.Root,
leaf common.Root,
) (common.Root, error) {
Expand Down
2 changes: 1 addition & 1 deletion node-api/handlers/proof/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
)

func (
h *Handler[_, _, _, ContextT, _, _],
h *Handler[_, _, ContextT, _, _],
) RegisterRoutes(logger log.Logger) {
h.SetLogger(logger)
h.BaseHandler.AddRoutes([]*handlers.Route[ContextT]{
Expand Down
13 changes: 7 additions & 6 deletions node-api/handlers/proof/types/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@
package types

import (
ctypes "github.com/berachain/beacon-kit/consensus-types/types"
"github.com/berachain/beacon-kit/primitives/common"
"github.com/berachain/beacon-kit/primitives/crypto"
"github.com/berachain/beacon-kit/primitives/math"
)

// BlockProposerResponse is the response for the
// `/proof/block_proposer/{timestamp_id}` endpoint.
type BlockProposerResponse[BeaconBlockHeaderT any] struct {
type BlockProposerResponse struct {
// BeaconBlockHeader is the block header of which the hash tree root is the
// beacon block root to verify against.
BeaconBlockHeader BeaconBlockHeaderT `json:"beacon_block_header"`
BeaconBlockHeader *ctypes.BeaconBlockHeader `json:"beacon_block_header"`

// BeaconBlockRoot is the beacon block root for this slot.
BeaconBlockRoot common.Root `json:"beacon_block_root"`
Expand All @@ -52,10 +53,10 @@ type BlockProposerResponse[BeaconBlockHeaderT any] struct {

// ExecutionNumberResponse is the response for the
// `/proof/execution_number/{timestamp_id}` endpoint.
type ExecutionNumberResponse[BeaconBlockHeaderT any] struct {
type ExecutionNumberResponse struct {
// BeaconBlockHeader is the block header of which the hash tree root is the
// beacon block root to verify against.
BeaconBlockHeader BeaconBlockHeaderT `json:"beacon_block_header"`
BeaconBlockHeader *ctypes.BeaconBlockHeader `json:"beacon_block_header"`

// BeaconBlockRoot is the beacon block root for this slot.
BeaconBlockRoot common.Root `json:"beacon_block_root"`
Expand All @@ -70,10 +71,10 @@ type ExecutionNumberResponse[BeaconBlockHeaderT any] struct {

// ExecutionFeeRecipientResponse is the response for the
// `/proof/execution_fee_recipient/{timestamp_id}` endpoint.
type ExecutionFeeRecipientResponse[BeaconBlockHeaderT any] struct {
type ExecutionFeeRecipientResponse struct {
// BeaconBlockHeader is the block header of which the hash tree root is the
// beacon block root to verify against.
BeaconBlockHeader BeaconBlockHeaderT `json:"beacon_block_header"`
BeaconBlockHeader *ctypes.BeaconBlockHeader `json:"beacon_block_header"`

// BeaconBlockRoot is the beacon block root for this slot.
BeaconBlockRoot common.Root `json:"beacon_block_root"`
Expand Down
10 changes: 0 additions & 10 deletions node-api/handlers/proof/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,11 @@ package types

import (
"github.com/berachain/beacon-kit/primitives/common"
"github.com/berachain/beacon-kit/primitives/constraints"
"github.com/berachain/beacon-kit/primitives/crypto"
"github.com/berachain/beacon-kit/primitives/math"
fastssz "github.com/ferranbt/fastssz"
)

// BeaconBlockHeader is the interface for a beacon block header.
type BeaconBlockHeader interface {
constraints.SSZRootable
// GetTree is kept for FastSSZ compatibility.
GetTree() (*fastssz.Node, error)
// GetProposerIndex returns the proposer index.
GetProposerIndex() math.ValidatorIndex
}

// BeaconState is the interface for a beacon state.
type BeaconState[
BeaconStateMarshallableT, ExecutionPayloadHeaderT, ValidatorT any,
Expand Down
5 changes: 2 additions & 3 deletions node-core/components/api_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type NodeAPIHandlersInput[
EventsAPIHandler *eventsapi.Handler[NodeAPIContextT]
NodeAPIHandler *nodeapi.Handler[NodeAPIContextT]
ProofAPIHandler *proofapi.Handler[
*ctypes.BeaconBlockHeader, BeaconStateT, BeaconStateMarshallableT,
BeaconStateT, BeaconStateMarshallableT,
NodeAPIContextT, ExecutionPayloadHeaderT, *Validator,
]
}
Expand Down Expand Up @@ -168,11 +168,10 @@ func ProvideNodeAPIProofHandler[
NodeT,
*Validator,
]) *proofapi.Handler[
*ctypes.BeaconBlockHeader, BeaconStateT, BeaconStateMarshallableT,
BeaconStateT, BeaconStateMarshallableT,
NodeAPIContextT, ExecutionPayloadHeaderT, *Validator,
] {
return proofapi.NewHandler[
*ctypes.BeaconBlockHeader,
BeaconStateT,
BeaconStateMarshallableT,
NodeAPIContextT,
Expand Down

0 comments on commit 9ee3e12

Please sign in to comment.