From 9ee3e129d00cd183fbd143090fba5c0d8d326eca Mon Sep 17 00:00:00 2001 From: aBear Date: Mon, 9 Dec 2024 19:53:08 -0500 Subject: [PATCH] some more clenaup --- node-api/handlers/proof/backend.go | 9 +++++---- node-api/handlers/proof/block_proposer.go | 4 ++-- .../handlers/proof/execution_fee_recipient.go | 4 ++-- node-api/handlers/proof/execution_number.go | 4 ++-- node-api/handlers/proof/handler.go | 17 ++++++++--------- node-api/handlers/proof/merkle/beacon_state.go | 6 +++--- .../proof/merkle/block_proposer_index.go | 8 ++++---- .../proof/merkle/block_proposer_pubkey.go | 6 +++--- .../proof/merkle/execution_fee_recipient.go | 5 +++-- .../handlers/proof/merkle/execution_number.go | 5 +++-- node-api/handlers/proof/routes.go | 2 +- node-api/handlers/proof/types/response.go | 13 +++++++------ node-api/handlers/proof/types/types.go | 10 ---------- node-core/components/api_handlers.go | 5 ++--- 14 files changed, 45 insertions(+), 53 deletions(-) diff --git a/node-api/handlers/proof/backend.go b/node-api/handlers/proof/backend.go index 31567335ec..8d468aba64 100644 --- a/node-api/handlers/proof/backend.go +++ b/node-api/handlers/proof/backend.go @@ -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 { diff --git a/node-api/handlers/proof/block_proposer.go b/node-api/handlers/proof/block_proposer.go index fdd6322712..6ad294ca84 100644 --- a/node-api/handlers/proof/block_proposer.go +++ b/node-api/handlers/proof/block_proposer.go @@ -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(), @@ -72,7 +72,7 @@ func (h *Handler[ return nil, err } - return types.BlockProposerResponse[BeaconBlockHeaderT]{ + return types.BlockProposerResponse{ BeaconBlockHeader: blockHeader, BeaconBlockRoot: beaconBlockRoot, ValidatorPubkey: proposerValidator.GetPubkey(), diff --git a/node-api/handlers/proof/execution_fee_recipient.go b/node-api/handlers/proof/execution_fee_recipient.go index c0cb366f49..fa2934469c 100644 --- a/node-api/handlers/proof/execution_fee_recipient.go +++ b/node-api/handlers/proof/execution_fee_recipient.go @@ -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(), @@ -61,7 +61,7 @@ func (h *Handler[ return nil, err } - return types.ExecutionFeeRecipientResponse[BeaconBlockHeaderT]{ + return types.ExecutionFeeRecipientResponse{ BeaconBlockHeader: blockHeader, BeaconBlockRoot: beaconBlockRoot, ExecutionFeeRecipient: leph.GetFeeRecipient(), diff --git a/node-api/handlers/proof/execution_number.go b/node-api/handlers/proof/execution_number.go index 29d2e76cba..109d88faf6 100644 --- a/node-api/handlers/proof/execution_number.go +++ b/node-api/handlers/proof/execution_number.go @@ -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(), @@ -61,7 +61,7 @@ func (h *Handler[ return nil, err } - return types.ExecutionNumberResponse[BeaconBlockHeaderT]{ + return types.ExecutionNumberResponse{ BeaconBlockHeader: blockHeader, BeaconBlockRoot: beaconBlockRoot, ExecutionNumber: leph.GetNumber(), diff --git a/node-api/handlers/proof/handler.go b/node-api/handlers/proof/handler.go index 34a1b71590..88e752dd4b 100644 --- a/node-api/handlers/proof/handler.go +++ b/node-api/handlers/proof/handler.go @@ -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" @@ -30,7 +31,6 @@ import ( // Handler is the handler for the proof API. type Handler[ - BeaconBlockHeaderT types.BeaconBlockHeader, BeaconStateT types.BeaconState[ BeaconStateMarshallableT, ExecutionPayloadHeaderT, ValidatorT, ], @@ -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, ], @@ -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( @@ -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) diff --git a/node-api/handlers/proof/merkle/beacon_state.go b/node-api/handlers/proof/merkle/beacon_state.go index c3e63e5b86..0cdf5ef36b 100644 --- a/node-api/handlers/proof/merkle/beacon_state.go +++ b/node-api/handlers/proof/merkle/beacon_state.go @@ -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" ) @@ -30,7 +30,7 @@ import ( // 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 { @@ -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( diff --git a/node-api/handlers/proof/merkle/block_proposer_index.go b/node-api/handlers/proof/merkle/block_proposer_index.go index 2abeb0f026..043bd3a648 100644 --- a/node-api/handlers/proof/merkle/block_proposer_index.go +++ b/node-api/handlers/proof/merkle/block_proposer_index.go @@ -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" ) @@ -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 @@ -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( diff --git a/node-api/handlers/proof/merkle/block_proposer_pubkey.go b/node-api/handlers/proof/merkle/block_proposer_pubkey.go index d5e336b78e..69784831b6 100644 --- a/node-api/handlers/proof/merkle/block_proposer_pubkey.go +++ b/node-api/handlers/proof/merkle/block_proposer_pubkey.go @@ -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" @@ -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, ], @@ -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, diff --git a/node-api/handlers/proof/merkle/execution_fee_recipient.go b/node-api/handlers/proof/merkle/execution_fee_recipient.go index 25b6224074..4d5af56aac 100644 --- a/node-api/handlers/proof/merkle/execution_fee_recipient.go +++ b/node-api/handlers/proof/merkle/execution_fee_recipient.go @@ -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" @@ -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, @@ -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) { diff --git a/node-api/handlers/proof/merkle/execution_number.go b/node-api/handlers/proof/merkle/execution_number.go index 635682a7eb..bcbf9659c8 100644 --- a/node-api/handlers/proof/merkle/execution_number.go +++ b/node-api/handlers/proof/merkle/execution_number.go @@ -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" @@ -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, @@ -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) { diff --git a/node-api/handlers/proof/routes.go b/node-api/handlers/proof/routes.go index b542babc47..ef79b5845a 100644 --- a/node-api/handlers/proof/routes.go +++ b/node-api/handlers/proof/routes.go @@ -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]{ diff --git a/node-api/handlers/proof/types/response.go b/node-api/handlers/proof/types/response.go index 257b136f2f..812ace8f40 100644 --- a/node-api/handlers/proof/types/response.go +++ b/node-api/handlers/proof/types/response.go @@ -21,6 +21,7 @@ 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" @@ -28,10 +29,10 @@ import ( // 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"` @@ -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"` @@ -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"` diff --git a/node-api/handlers/proof/types/types.go b/node-api/handlers/proof/types/types.go index a6dcd71751..fbb31e0631 100644 --- a/node-api/handlers/proof/types/types.go +++ b/node-api/handlers/proof/types/types.go @@ -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, diff --git a/node-core/components/api_handlers.go b/node-core/components/api_handlers.go index 1319271e38..2be79c16c0 100644 --- a/node-core/components/api_handlers.go +++ b/node-core/components/api_handlers.go @@ -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, ] } @@ -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,