diff --git a/cmd/beacond/defaults.go b/cmd/beacond/defaults.go index af7e394ce..8848ff098 100644 --- a/cmd/beacond/defaults.go +++ b/cmd/beacond/defaults.go @@ -57,20 +57,20 @@ func DefaultComponents() []any { components.ProvideShutDownService[*Logger], } c = append(c, - components.ProvideNodeAPIServer[*Logger, NodeAPIContext], + components.ProvideNodeAPIServer[*Logger], components.ProvideNodeAPIEngine, components.ProvideNodeAPIBackend, ) c = append(c, - components.ProvideNodeAPIHandlers[NodeAPIContext], - components.ProvideNodeAPIBeaconHandler[NodeAPIContext], - components.ProvideNodeAPIBuilderHandler[NodeAPIContext], - components.ProvideNodeAPIConfigHandler[NodeAPIContext], - components.ProvideNodeAPIDebugHandler[NodeAPIContext], - components.ProvideNodeAPIEventsHandler[NodeAPIContext], - components.ProvideNodeAPINodeHandler[NodeAPIContext], - components.ProvideNodeAPIProofHandler[NodeAPIContext], + components.ProvideNodeAPIHandlers, + components.ProvideNodeAPIBeaconHandler, + components.ProvideNodeAPIBuilderHandler, + components.ProvideNodeAPIConfigHandler, + components.ProvideNodeAPIDebugHandler, + components.ProvideNodeAPIEventsHandler, + components.ProvideNodeAPINodeHandler, + components.ProvideNodeAPIProofHandler, ) return c diff --git a/cmd/beacond/types.go b/cmd/beacond/types.go index ca58e8e27..7034cfd2f 100644 --- a/cmd/beacond/types.go +++ b/cmd/beacond/types.go @@ -74,7 +74,7 @@ type ( NodeAPIEngine = echo.Engine // NodeAPIServer is a type alias for the node API server. - NodeAPIServer = server.Server[NodeAPIContext] + NodeAPIServer = server.Server // ReportingService is a type alias for the reporting service. ReportingService = version.ReportingService @@ -136,7 +136,4 @@ type ( // NodeAPIBackend is a type alias for the node API backend. NodeAPIBackend = backend.Backend - - // NodeAPIContext is a type alias for the node API context. - NodeAPIContext = echo.Context ) diff --git a/node-api/engines/echo/engine.go b/node-api/engines/echo/engine.go index 47c51c5cf..0f240093f 100644 --- a/node-api/engines/echo/engine.go +++ b/node-api/engines/echo/engine.go @@ -59,10 +59,7 @@ func (e *Engine) Run(addr string) error { } // RegisterRoutes registers the given route set with the Echo engine. -func (e *Engine) RegisterRoutes( - hs *handlers.RouteSet[Context], - logger log.Logger, -) { +func (e *Engine) RegisterRoutes(hs *handlers.RouteSet, logger log.Logger) { e.logger = logger group := e.Group(hs.BasePath) for _, route := range hs.Routes { diff --git a/node-api/engines/echo/middleware.go b/node-api/engines/echo/middleware.go index b0641b34b..fc20c8fec 100644 --- a/node-api/engines/echo/middleware.go +++ b/node-api/engines/echo/middleware.go @@ -37,10 +37,8 @@ type ErrorResponse struct { // responseMiddleware is a middleware that converts errors to an HTTP status // code and response. -func responseMiddleware( - handler *handlers.Route[Context], -) echo.HandlerFunc { - return func(c Context) error { +func responseMiddleware(handler *handlers.Route) echo.HandlerFunc { + return func(c handlers.Context) error { data, err := handler.Handler(c) code, response := responseFromError(data, err) return c.JSON(code, response) diff --git a/node-api/engines/echo/types.go b/node-api/engines/echo/types.go deleted file mode 100644 index 3a78a4e3a..000000000 --- a/node-api/engines/echo/types.go +++ /dev/null @@ -1,27 +0,0 @@ -// SPDX-License-Identifier: BUSL-1.1 -// -// Copyright (C) 2025, Berachain Foundation. All rights reserved. -// Use of this software is governed by the Business Source License included -// in the LICENSE file of this repository and at www.mariadb.com/bsl11. -// -// ANY USE OF THE LICENSED WORK IN VIOLATION OF THIS LICENSE WILL AUTOMATICALLY -// TERMINATE YOUR RIGHTS UNDER THIS LICENSE FOR THE CURRENT AND ALL OTHER -// VERSIONS OF THE LICENSED WORK. -// -// THIS LICENSE DOES NOT GRANT YOU ANY RIGHT IN ANY TRADEMARK OR LOGO OF -// LICENSOR OR ITS AFFILIATES (PROVIDED THAT YOU MAY USE A TRADEMARK OR LOGO OF -// LICENSOR AS EXPRESSLY REQUIRED BY THIS LICENSE). -// -// TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON -// AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, -// EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF -// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND -// TITLE. - -package echo - -import "github.com/labstack/echo/v4" - -type ( - Context = echo.Context -) diff --git a/node-api/handlers/beacon/blobs.go b/node-api/handlers/beacon/blobs.go index 4d90d06c9..b934a4997 100644 --- a/node-api/handlers/beacon/blobs.go +++ b/node-api/handlers/beacon/blobs.go @@ -23,13 +23,14 @@ package beacon import ( "strconv" + "github.com/berachain/beacon-kit/node-api/handlers" apitypes "github.com/berachain/beacon-kit/node-api/handlers/beacon/types" "github.com/berachain/beacon-kit/node-api/handlers/utils" ) // GetBlobSidecars provides an implementation for the // "/eth/v1/beacon/blob_sidecars/:block_id" API endpoint. -func (h *Handler[ContextT]) GetBlobSidecars(c ContextT) (any, error) { +func (h *Handler) GetBlobSidecars(c handlers.Context) (any, error) { req, err := utils.BindAndValidate[apitypes.GetBlobSidecarsRequest]( c, h.Logger(), ) diff --git a/node-api/handlers/beacon/block.go b/node-api/handlers/beacon/block.go index b12db63b1..de5b9a771 100644 --- a/node-api/handlers/beacon/block.go +++ b/node-api/handlers/beacon/block.go @@ -21,11 +21,12 @@ package beacon import ( + "github.com/berachain/beacon-kit/node-api/handlers" beacontypes "github.com/berachain/beacon-kit/node-api/handlers/beacon/types" "github.com/berachain/beacon-kit/node-api/handlers/utils" ) -func (h *Handler[ContextT]) GetBlockRewards(c ContextT) (any, error) { +func (h *Handler) GetBlockRewards(c handlers.Context) (any, error) { req, err := utils.BindAndValidate[beacontypes.GetBlockRewardsRequest]( c, h.Logger(), ) diff --git a/node-api/handlers/beacon/genesis.go b/node-api/handlers/beacon/genesis.go index 9157cb466..7840000cf 100644 --- a/node-api/handlers/beacon/genesis.go +++ b/node-api/handlers/beacon/genesis.go @@ -21,12 +21,13 @@ package beacon import ( + "github.com/berachain/beacon-kit/node-api/handlers" beacontypes "github.com/berachain/beacon-kit/node-api/handlers/beacon/types" "github.com/berachain/beacon-kit/node-api/handlers/types" "github.com/berachain/beacon-kit/node-api/handlers/utils" ) -func (h *Handler[ContextT]) GetGenesis(_ ContextT) (any, error) { +func (h *Handler) GetGenesis(_ handlers.Context) (any, error) { genesisRoot, err := h.backend.GenesisValidatorsRoot(utils.Genesis) if err != nil { return nil, err diff --git a/node-api/handlers/beacon/handler.go b/node-api/handlers/beacon/handler.go index 6ae054348..8393e87fa 100644 --- a/node-api/handlers/beacon/handler.go +++ b/node-api/handlers/beacon/handler.go @@ -22,26 +22,19 @@ package beacon import ( "github.com/berachain/beacon-kit/node-api/handlers" - "github.com/berachain/beacon-kit/node-api/server/context" ) // Handler is the handler for the beacon API. -type Handler[ - ContextT context.Context, -] struct { - *handlers.BaseHandler[ContextT] +type Handler struct { + *handlers.BaseHandler backend Backend } // NewHandler creates a new handler for the beacon API. -func NewHandler[ - ContextT context.Context, -]( - backend Backend, -) *Handler[ContextT] { - h := &Handler[ContextT]{ +func NewHandler(backend Backend) *Handler { + h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[ContextT](""), + handlers.NewRouteSet(""), ), backend: backend, } diff --git a/node-api/handlers/beacon/header.go b/node-api/handlers/beacon/header.go index 8fc249cb5..76fbf55b0 100644 --- a/node-api/handlers/beacon/header.go +++ b/node-api/handlers/beacon/header.go @@ -21,11 +21,12 @@ package beacon import ( + "github.com/berachain/beacon-kit/node-api/handlers" beacontypes "github.com/berachain/beacon-kit/node-api/handlers/beacon/types" "github.com/berachain/beacon-kit/node-api/handlers/utils" ) -func (h *Handler[ContextT]) GetBlockHeaders(c ContextT) (any, error) { +func (h *Handler) GetBlockHeaders(c handlers.Context) (any, error) { req, err := utils.BindAndValidate[beacontypes.GetBlockHeadersRequest]( c, h.Logger(), ) @@ -54,7 +55,7 @@ func (h *Handler[ContextT]) GetBlockHeaders(c ContextT) (any, error) { }, nil } -func (h *Handler[ContextT]) GetBlockHeaderByID(c ContextT) (any, error) { +func (h *Handler) GetBlockHeaderByID(c handlers.Context) (any, error) { req, err := utils.BindAndValidate[beacontypes.GetBlockHeaderRequest]( c, h.Logger(), ) diff --git a/node-api/handlers/beacon/historical.go b/node-api/handlers/beacon/historical.go index 996fd7837..6a3277578 100644 --- a/node-api/handlers/beacon/historical.go +++ b/node-api/handlers/beacon/historical.go @@ -21,12 +21,13 @@ package beacon import ( + "github.com/berachain/beacon-kit/node-api/handlers" beacontypes "github.com/berachain/beacon-kit/node-api/handlers/beacon/types" "github.com/berachain/beacon-kit/node-api/handlers/types" "github.com/berachain/beacon-kit/node-api/handlers/utils" ) -func (h *Handler[ContextT]) GetStateRoot(c ContextT) (any, error) { +func (h *Handler) GetStateRoot(c handlers.Context) (any, error) { req, err := utils.BindAndValidate[beacontypes.GetStateRootRequest]( c, h.Logger(), ) @@ -51,7 +52,7 @@ func (h *Handler[ContextT]) GetStateRoot(c ContextT) (any, error) { }, nil } -func (h *Handler[ContextT]) GetStateFork(c ContextT) (any, error) { +func (h *Handler) GetStateFork(c handlers.Context) (any, error) { req, err := utils.BindAndValidate[beacontypes.GetStateForkRequest]( c, h.Logger(), ) diff --git a/node-api/handlers/beacon/randao.go b/node-api/handlers/beacon/randao.go index 513073b97..45413153a 100644 --- a/node-api/handlers/beacon/randao.go +++ b/node-api/handlers/beacon/randao.go @@ -21,12 +21,13 @@ package beacon import ( + "github.com/berachain/beacon-kit/node-api/handlers" beacontypes "github.com/berachain/beacon-kit/node-api/handlers/beacon/types" "github.com/berachain/beacon-kit/node-api/handlers/utils" "github.com/berachain/beacon-kit/primitives/constants" ) -func (h *Handler[ContextT]) GetRandao(c ContextT) (any, error) { +func (h *Handler) GetRandao(c handlers.Context) (any, error) { req, err := utils.BindAndValidate[beacontypes.GetRandaoRequest]( c, h.Logger(), diff --git a/node-api/handlers/beacon/routes.go b/node-api/handlers/beacon/routes.go index 6f90b9d55..af1193419 100644 --- a/node-api/handlers/beacon/routes.go +++ b/node-api/handlers/beacon/routes.go @@ -28,11 +28,11 @@ import ( ) //nolint:funlen // routes are long -func (h *Handler[ContextT]) RegisterRoutes( +func (h *Handler) RegisterRoutes( logger log.Logger, ) { h.SetLogger(logger) - h.BaseHandler.AddRoutes([]*handlers.Route[ContextT]{ + h.BaseHandler.AddRoutes([]*handlers.Route{ { Method: http.MethodGet, Path: "/eth/v1/beacon/genesis", diff --git a/node-api/handlers/beacon/validators.go b/node-api/handlers/beacon/validators.go index 6cf6f5596..f8dbb88fb 100644 --- a/node-api/handlers/beacon/validators.go +++ b/node-api/handlers/beacon/validators.go @@ -21,14 +21,13 @@ package beacon import ( + "github.com/berachain/beacon-kit/node-api/handlers" beacontypes "github.com/berachain/beacon-kit/node-api/handlers/beacon/types" "github.com/berachain/beacon-kit/node-api/handlers/types" "github.com/berachain/beacon-kit/node-api/handlers/utils" ) -func (h *Handler[ContextT]) GetStateValidators( - c ContextT, -) (any, error) { +func (h *Handler) GetStateValidators(c handlers.Context) (any, error) { req, err := utils.BindAndValidate[beacontypes.GetStateValidatorsRequest]( c, h.Logger(), ) @@ -61,9 +60,7 @@ func (h *Handler[ContextT]) GetStateValidators( }, nil } -func (h *Handler[ContextT]) PostStateValidators( - c ContextT, -) (any, error) { +func (h *Handler) PostStateValidators(c handlers.Context) (any, error) { req, err := utils.BindAndValidate[beacontypes.PostStateValidatorsRequest]( c, h.Logger(), ) @@ -93,9 +90,7 @@ func (h *Handler[ContextT]) PostStateValidators( }, nil } -func (h *Handler[ContextT]) GetStateValidator( - c ContextT, -) (any, error) { +func (h *Handler) GetStateValidator(c handlers.Context) (any, error) { req, err := utils.BindAndValidate[beacontypes.GetStateValidatorRequest]( c, h.Logger(), ) @@ -116,9 +111,7 @@ func (h *Handler[ContextT]) GetStateValidator( return validator, nil } -func (h *Handler[ContextT]) GetStateValidatorBalances( - c ContextT, -) (any, error) { +func (h *Handler) GetStateValidatorBalances(c handlers.Context) (any, error) { req, err := utils.BindAndValidate[beacontypes.GetValidatorBalancesRequest]( c, h.Logger(), ) @@ -143,9 +136,7 @@ func (h *Handler[ContextT]) GetStateValidatorBalances( }, nil } -func (h *Handler[ContextT]) PostStateValidatorBalances( - c ContextT, -) (any, error) { +func (h *Handler) PostStateValidatorBalances(c handlers.Context) (any, error) { req, err := utils.BindAndValidate[beacontypes.PostValidatorBalancesRequest]( c, h.Logger(), ) diff --git a/node-api/handlers/builder/handler.go b/node-api/handlers/builder/handler.go index 93c88d712..23f1d4e71 100644 --- a/node-api/handlers/builder/handler.go +++ b/node-api/handlers/builder/handler.go @@ -22,17 +22,16 @@ package builder import ( "github.com/berachain/beacon-kit/node-api/handlers" - "github.com/berachain/beacon-kit/node-api/server/context" ) -type Handler[ContextT context.Context] struct { - *handlers.BaseHandler[ContextT] +type Handler struct { + *handlers.BaseHandler } -func NewHandler[ContextT context.Context]() *Handler[ContextT] { - h := &Handler[ContextT]{ +func NewHandler() *Handler { + h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[ContextT](""), + handlers.NewRouteSet(""), ), } return h diff --git a/node-api/handlers/builder/routes.go b/node-api/handlers/builder/routes.go index f3c99a098..9364856d4 100644 --- a/node-api/handlers/builder/routes.go +++ b/node-api/handlers/builder/routes.go @@ -27,11 +27,9 @@ import ( "github.com/berachain/beacon-kit/node-api/handlers" ) -func (h *Handler[ContextT]) RegisterRoutes( - logger log.Logger, -) { +func (h *Handler) RegisterRoutes(logger log.Logger) { h.SetLogger(logger) - h.BaseHandler.AddRoutes([]*handlers.Route[ContextT]{ + h.BaseHandler.AddRoutes([]*handlers.Route{ { Method: http.MethodGet, Path: "/eth/v1/builder/states/:state_id/expected_withdrawals", diff --git a/node-api/handlers/config/handler.go b/node-api/handlers/config/handler.go index d21534cf3..2ab58b8ab 100644 --- a/node-api/handlers/config/handler.go +++ b/node-api/handlers/config/handler.go @@ -20,19 +20,16 @@ package config -import ( - "github.com/berachain/beacon-kit/node-api/handlers" - "github.com/berachain/beacon-kit/node-api/server/context" -) +import "github.com/berachain/beacon-kit/node-api/handlers" -type Handler[ContextT context.Context] struct { - *handlers.BaseHandler[ContextT] +type Handler struct { + *handlers.BaseHandler } -func NewHandler[ContextT context.Context]() *Handler[ContextT] { - h := &Handler[ContextT]{ +func NewHandler() *Handler { + h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[ContextT](""), + handlers.NewRouteSet(""), ), } return h diff --git a/node-api/handlers/config/routes.go b/node-api/handlers/config/routes.go index c5a631bbe..3e2481666 100644 --- a/node-api/handlers/config/routes.go +++ b/node-api/handlers/config/routes.go @@ -27,11 +27,9 @@ import ( "github.com/berachain/beacon-kit/node-api/handlers" ) -func (h *Handler[ContextT]) RegisterRoutes( - logger log.Logger, -) { +func (h *Handler) RegisterRoutes(logger log.Logger) { h.SetLogger(logger) - h.BaseHandler.AddRoutes([]*handlers.Route[ContextT]{ + h.BaseHandler.AddRoutes([]*handlers.Route{ { Method: http.MethodGet, Path: "/eth/v1/config/fork_schedule", diff --git a/node-api/handlers/debug/handler.go b/node-api/handlers/debug/handler.go index 58cb4756b..c6a2c8f6d 100644 --- a/node-api/handlers/debug/handler.go +++ b/node-api/handlers/debug/handler.go @@ -20,28 +20,19 @@ package debug -import ( - "github.com/berachain/beacon-kit/node-api/handlers" - "github.com/berachain/beacon-kit/node-api/server/context" -) +import "github.com/berachain/beacon-kit/node-api/handlers" // Handler is the handler for the beacon API. -type Handler[ - ContextT context.Context, -] struct { - *handlers.BaseHandler[ContextT] +type Handler struct { + *handlers.BaseHandler backend Backend } // NewHandler creates a new handler for the beacon API. -func NewHandler[ - ContextT context.Context, -]( - backend Backend, -) *Handler[ContextT] { - h := &Handler[ContextT]{ +func NewHandler(backend Backend) *Handler { + h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[ContextT](""), + handlers.NewRouteSet(""), ), backend: backend, } diff --git a/node-api/handlers/debug/routes.go b/node-api/handlers/debug/routes.go index b871efa70..ba23caf66 100644 --- a/node-api/handlers/debug/routes.go +++ b/node-api/handlers/debug/routes.go @@ -27,11 +27,9 @@ import ( "github.com/berachain/beacon-kit/node-api/handlers" ) -func (h *Handler[ContextT]) RegisterRoutes( - logger log.Logger, -) { +func (h *Handler) RegisterRoutes(logger log.Logger) { h.SetLogger(logger) - h.BaseHandler.AddRoutes([]*handlers.Route[ContextT]{ + h.BaseHandler.AddRoutes([]*handlers.Route{ { Method: http.MethodGet, Path: "/eth/v2/debug/beacon/states/:state_id", diff --git a/node-api/handlers/debug/state.go b/node-api/handlers/debug/state.go index f0ed161b7..9cb75577a 100644 --- a/node-api/handlers/debug/state.go +++ b/node-api/handlers/debug/state.go @@ -21,11 +21,12 @@ package debug import ( + "github.com/berachain/beacon-kit/node-api/handlers" beacontypes "github.com/berachain/beacon-kit/node-api/handlers/beacon/types" "github.com/berachain/beacon-kit/node-api/handlers/utils" ) -func (h *Handler[ContextT]) GetState(c ContextT) (any, error) { +func (h *Handler) GetState(c handlers.Context) (any, error) { req, err := utils.BindAndValidate[beacontypes.GetStateRequest]( c, h.Logger(), ) @@ -46,8 +47,8 @@ func (h *Handler[ContextT]) GetState(c ContextT) (any, error) { } return beacontypes.StateResponse{ // TODO: The version should be retrieved based on the slot - Version: "deneb", // stubbed - ExecutionOptimistic: false, // stubbed + Version: "deneb1", // stubbed + ExecutionOptimistic: false, // stubbed // TODO: We can set to finalized if this is less than the highest height Finalized: false, // stubbed Data: beaconState, diff --git a/node-api/handlers/events/handler.go b/node-api/handlers/events/handler.go index 7b27c4c04..ba1f2a5b1 100644 --- a/node-api/handlers/events/handler.go +++ b/node-api/handlers/events/handler.go @@ -20,19 +20,16 @@ package events -import ( - "github.com/berachain/beacon-kit/node-api/handlers" - "github.com/berachain/beacon-kit/node-api/server/context" -) +import "github.com/berachain/beacon-kit/node-api/handlers" -type Handler[ContextT context.Context] struct { - *handlers.BaseHandler[ContextT] +type Handler struct { + *handlers.BaseHandler } -func NewHandler[ContextT context.Context]() *Handler[ContextT] { - h := &Handler[ContextT]{ +func NewHandler() *Handler { + h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[ContextT](""), + handlers.NewRouteSet(""), ), } return h diff --git a/node-api/handlers/events/routes.go b/node-api/handlers/events/routes.go index def8b0538..e9f0f2382 100644 --- a/node-api/handlers/events/routes.go +++ b/node-api/handlers/events/routes.go @@ -27,11 +27,9 @@ import ( "github.com/berachain/beacon-kit/node-api/handlers" ) -func (h *Handler[ContextT]) RegisterRoutes( - logger log.Logger, -) { +func (h *Handler) RegisterRoutes(logger log.Logger) { h.SetLogger(logger) - h.BaseHandler.AddRoutes([]*handlers.Route[ContextT]{ + h.BaseHandler.AddRoutes([]*handlers.Route{ { Method: http.MethodGet, Path: "/eth/v1/events", diff --git a/node-api/handlers/handlers.go b/node-api/handlers/handlers.go index e21428542..48fd85f99 100644 --- a/node-api/handlers/handlers.go +++ b/node-api/handlers/handlers.go @@ -23,57 +23,56 @@ package handlers import ( "github.com/berachain/beacon-kit/errors" "github.com/berachain/beacon-kit/log" + "github.com/labstack/echo/v4" ) +type Context = echo.Context + // handlerFn enforces a signature for all handler functions. -type handlerFn[ContextT any] func(c ContextT) (any, error) +type handlerFn func(c Context) (any, error) // Handlers is an interface that all handlers must implement. -type Handlers[ContextT any] interface { +type Handlers interface { // RegisterRoutes is a method that registers the routes for the handler. RegisterRoutes(logger log.Logger) - RouteSet() *RouteSet[ContextT] + RouteSet() *RouteSet } // BaseHandler is a base handler for all handlers. It abstracts the route set // and logger from the handler. -type BaseHandler[ContextT any] struct { - routes *RouteSet[ContextT] +type BaseHandler struct { + routes *RouteSet logger log.Logger } // NewBaseHandler initializes a new base handler with the given routes and // logger. -func NewBaseHandler[ContextT any]( - routes *RouteSet[ContextT], -) *BaseHandler[ContextT] { - return &BaseHandler[ContextT]{ +func NewBaseHandler(routes *RouteSet) *BaseHandler { + return &BaseHandler{ routes: routes, } } // NotImplemented is a placeholder for the beacon API. -func (b *BaseHandler[ContextT]) NotImplemented(ContextT) (any, error) { +func (b *BaseHandler) NotImplemented(Context) (any, error) { return nil, errors.New("not implemented") } // RouteSet returns the route set for the base handler. -func (b *BaseHandler[ContextT]) RouteSet() *RouteSet[ContextT] { +func (b *BaseHandler) RouteSet() *RouteSet { return b.routes } // Logger is used to access the logger for the base handler. -func (b *BaseHandler[ContextT]) Logger() log.Logger { +func (b *BaseHandler) Logger() log.Logger { return b.logger } -func (b *BaseHandler[ContextT]) SetLogger(logger log.Logger) { +func (b *BaseHandler) SetLogger(logger log.Logger) { b.logger = logger } // AddRoutes adds the given slice of routes to the base handler. -func (b *BaseHandler[ContextT]) AddRoutes( - routes []*Route[ContextT], -) { +func (b *BaseHandler) AddRoutes(routes []*Route) { b.routes.Routes = append(b.routes.Routes, routes...) } diff --git a/node-api/handlers/node/handler.go b/node-api/handlers/node/handler.go index f5b330a27..e64d8c84e 100644 --- a/node-api/handlers/node/handler.go +++ b/node-api/handlers/node/handler.go @@ -20,19 +20,16 @@ package node -import ( - "github.com/berachain/beacon-kit/node-api/handlers" - "github.com/berachain/beacon-kit/node-api/server/context" -) +import "github.com/berachain/beacon-kit/node-api/handlers" -type Handler[ContextT context.Context] struct { - *handlers.BaseHandler[ContextT] +type Handler struct { + *handlers.BaseHandler } -func NewHandler[ContextT context.Context]() *Handler[ContextT] { - h := &Handler[ContextT]{ +func NewHandler() *Handler { + h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[ContextT](""), + handlers.NewRouteSet(""), ), } return h diff --git a/node-api/handlers/node/placeholders.go b/node-api/handlers/node/placeholders.go index 5d68a9fd6..edf0e0014 100644 --- a/node-api/handlers/node/placeholders.go +++ b/node-api/handlers/node/placeholders.go @@ -20,10 +20,12 @@ package node +import "github.com/berachain/beacon-kit/node-api/handlers" + // Syncing is a placeholder so that beacon API clients don't break. // // TODO: Implement with real data. -func (h *Handler[ContextT]) Syncing(ContextT) (any, error) { +func (h *Handler) Syncing(handlers.Context) (any, error) { type SyncingResponse struct { Data struct { HeadSlot string `json:"head_slot"` @@ -47,7 +49,7 @@ func (h *Handler[ContextT]) Syncing(ContextT) (any, error) { // Version is a placeholder so that beacon API clients don't break. // // TODO: Implement with real data. -func (h *Handler[ContextT]) Version(ContextT) (any, error) { +func (h *Handler) Version(handlers.Context) (any, error) { type VersionResponse struct { Data struct { Version string `json:"version"` @@ -55,7 +57,7 @@ func (h *Handler[ContextT]) Version(ContextT) (any, error) { } response := VersionResponse{} - response.Data.Version = "1.0.0" + response.Data.Version = "1.1.0" return response, nil } diff --git a/node-api/handlers/node/routes.go b/node-api/handlers/node/routes.go index 15d8ec892..419fca4b3 100644 --- a/node-api/handlers/node/routes.go +++ b/node-api/handlers/node/routes.go @@ -27,11 +27,9 @@ import ( "github.com/berachain/beacon-kit/node-api/handlers" ) -func (h *Handler[ContextT]) RegisterRoutes( - logger log.Logger, -) { +func (h *Handler) RegisterRoutes(logger log.Logger) { h.SetLogger(logger) - h.BaseHandler.AddRoutes([]*handlers.Route[ContextT]{ + h.BaseHandler.AddRoutes([]*handlers.Route{ { Method: http.MethodGet, Path: "/eth/v1/node/identity", diff --git a/node-api/handlers/proof/block_proposer.go b/node-api/handlers/proof/block_proposer.go index 56d75c492..8a68e3abe 100644 --- a/node-api/handlers/proof/block_proposer.go +++ b/node-api/handlers/proof/block_proposer.go @@ -21,6 +21,7 @@ package proof import ( + "github.com/berachain/beacon-kit/node-api/handlers" "github.com/berachain/beacon-kit/node-api/handlers/proof/merkle" "github.com/berachain/beacon-kit/node-api/handlers/proof/types" "github.com/berachain/beacon-kit/node-api/handlers/utils" @@ -29,7 +30,7 @@ import ( // GetBlockProposer returns the block proposer pubkey for the given timestamp // 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[ContextT]) GetBlockProposer(c ContextT) (any, error) { +func (h *Handler) GetBlockProposer(c handlers.Context) (any, error) { params, err := utils.BindAndValidate[types.BlockProposerRequest]( c, h.Logger(), ) diff --git a/node-api/handlers/proof/execution_fee_recipient.go b/node-api/handlers/proof/execution_fee_recipient.go index 31c300e7a..2c7fbf01d 100644 --- a/node-api/handlers/proof/execution_fee_recipient.go +++ b/node-api/handlers/proof/execution_fee_recipient.go @@ -21,6 +21,7 @@ package proof import ( + "github.com/berachain/beacon-kit/node-api/handlers" "github.com/berachain/beacon-kit/node-api/handlers/proof/merkle" "github.com/berachain/beacon-kit/node-api/handlers/proof/types" "github.com/berachain/beacon-kit/node-api/handlers/utils" @@ -29,7 +30,7 @@ import ( // GetExecutionFeeRecipient returns the fee recipient from the latest execution // payload header for the given timestamp id, along with the proof that can be // verified against the beacon block root. -func (h *Handler[ContextT]) GetExecutionFeeRecipient(c ContextT) (any, error) { +func (h *Handler) GetExecutionFeeRecipient(c handlers.Context) (any, error) { params, err := utils.BindAndValidate[types.ExecutionFeeRecipientRequest]( c, h.Logger(), ) diff --git a/node-api/handlers/proof/execution_number.go b/node-api/handlers/proof/execution_number.go index afe8b1f03..e9e6fea36 100644 --- a/node-api/handlers/proof/execution_number.go +++ b/node-api/handlers/proof/execution_number.go @@ -21,6 +21,7 @@ package proof import ( + "github.com/berachain/beacon-kit/node-api/handlers" "github.com/berachain/beacon-kit/node-api/handlers/proof/merkle" "github.com/berachain/beacon-kit/node-api/handlers/proof/types" "github.com/berachain/beacon-kit/node-api/handlers/utils" @@ -29,7 +30,7 @@ import ( // GetExecutionNumber returns the block number from the latest execution // payload header for the given timestamp id, along with the proof that can be // verified against the beacon block root. -func (h *Handler[ContextT]) GetExecutionNumber(c ContextT) (any, error) { +func (h *Handler) GetExecutionNumber(c handlers.Context) (any, error) { params, err := utils.BindAndValidate[types.ExecutionNumberRequest]( c, h.Logger(), ) diff --git a/node-api/handlers/proof/handler.go b/node-api/handlers/proof/handler.go index 120272f91..1a86120ae 100644 --- a/node-api/handlers/proof/handler.go +++ b/node-api/handlers/proof/handler.go @@ -24,28 +24,21 @@ 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/utils" - "github.com/berachain/beacon-kit/node-api/server/context" "github.com/berachain/beacon-kit/primitives/math" statedb "github.com/berachain/beacon-kit/state-transition/core/state" ) // Handler is the handler for the proof API. -type Handler[ - ContextT context.Context, -] struct { - *handlers.BaseHandler[ContextT] +type Handler struct { + *handlers.BaseHandler backend Backend } // NewHandler creates a new handler for the proof API. -func NewHandler[ - ContextT context.Context, -]( - backend Backend, -) *Handler[ContextT] { - h := &Handler[ContextT]{ +func NewHandler(backend Backend) *Handler { + h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[ContextT](""), + handlers.NewRouteSet(""), ), backend: backend, } @@ -54,7 +47,7 @@ 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[_]) resolveTimestampID(timestampID string) ( +func (h *Handler) resolveTimestampID(timestampID string) ( math.Slot, *statedb.StateDB, *ctypes.BeaconBlockHeader, error, ) { var ( diff --git a/node-api/handlers/proof/routes.go b/node-api/handlers/proof/routes.go index b26012a90..15ebd540c 100644 --- a/node-api/handlers/proof/routes.go +++ b/node-api/handlers/proof/routes.go @@ -27,9 +27,9 @@ import ( "github.com/berachain/beacon-kit/node-api/handlers" ) -func (h *Handler[ContextT]) RegisterRoutes(logger log.Logger) { +func (h *Handler) RegisterRoutes(logger log.Logger) { h.SetLogger(logger) - h.BaseHandler.AddRoutes([]*handlers.Route[ContextT]{ + h.BaseHandler.AddRoutes([]*handlers.Route{ { Method: http.MethodGet, Path: "bkit/v1/proof/block_proposer/:timestamp_id", diff --git a/node-api/handlers/routes.go b/node-api/handlers/routes.go index 20617f0bb..4e95198b9 100644 --- a/node-api/handlers/routes.go +++ b/node-api/handlers/routes.go @@ -25,17 +25,17 @@ import ( ) // Route is a route for the node API. -type Route[ContextT any] struct { +type Route struct { Method string Path string - Handler handlerFn[ContextT] + Handler handlerFn } // DecorateWithLogs adds logging to the route's handler function as soon as // a request is received and when a response is ready. -func (r *Route[ContextT]) DecorateWithLogs(logger log.Logger) { +func (r *Route) DecorateWithLogs(logger log.Logger) { handler := r.Handler - r.Handler = func(ctx ContextT) (any, error) { + r.Handler = func(ctx Context) (any, error) { logger.Info("received request", "method", r.Method, "path", r.Path) res, err := handler(ctx) if err != nil { @@ -47,16 +47,14 @@ func (r *Route[ContextT]) DecorateWithLogs(logger log.Logger) { } // RouteSet is a set of routes for the node API. -type RouteSet[ContextT any] struct { +type RouteSet struct { BasePath string - Routes []*Route[ContextT] + Routes []*Route } // NewRouteSet creates a new route set. -func NewRouteSet[ContextT any]( - basePath string, routes ...*Route[ContextT], -) *RouteSet[ContextT] { - return &RouteSet[ContextT]{ +func NewRouteSet(basePath string, routes ...*Route) *RouteSet { + return &RouteSet{ BasePath: basePath, Routes: routes, } diff --git a/node-api/server/server.go b/node-api/server/server.go index a31b9d327..b23bc8262 100644 --- a/node-api/server/server.go +++ b/node-api/server/server.go @@ -26,14 +26,11 @@ import ( "github.com/berachain/beacon-kit/log" "github.com/berachain/beacon-kit/log/noop" "github.com/berachain/beacon-kit/node-api/handlers" - apicontext "github.com/berachain/beacon-kit/node-api/server/context" ) // Server is the API Server service. -type Server[ - ContextT apicontext.Context, -] struct { - engine Engine[ContextT] +type Server struct { + engine Engine config Config logger log.Logger } @@ -41,14 +38,12 @@ type Server[ // New initializes a new API Server with the given config, engine, and logger. // It will inject a noop logger into the API handlers and engine if logging is // disabled. -func New[ - ContextT apicontext.Context, -]( +func New( config Config, - engine Engine[ContextT], + engine Engine, logger log.Logger, - handlers ...handlers.Handlers[ContextT], -) *Server[ContextT] { + handlers ...handlers.Handlers, +) *Server { apiLogger := logger if !config.Logging { apiLogger = noop.NewLogger[log.Logger]() @@ -57,7 +52,7 @@ func New[ handler.RegisterRoutes(apiLogger) engine.RegisterRoutes(handler.RouteSet(), apiLogger) } - return &Server[ContextT]{ + return &Server{ engine: engine, config: config, logger: logger, @@ -65,7 +60,7 @@ func New[ } // Start starts the API Server at the configured address. -func (s *Server[_]) Start(ctx context.Context) error { +func (s *Server) Start(ctx context.Context) error { if !s.config.Enabled { return nil } @@ -73,7 +68,7 @@ func (s *Server[_]) Start(ctx context.Context) error { return nil } -func (s *Server[_]) start(ctx context.Context) { +func (s *Server) start(ctx context.Context) { errCh := make(chan error) go func() { errCh <- s.engine.Run(s.config.Address) @@ -88,11 +83,11 @@ func (s *Server[_]) start(ctx context.Context) { } } -func (s *Server[_]) Stop() error { +func (s *Server) Stop() error { return nil } // Name returns the name of the API server service. -func (s *Server[_]) Name() string { +func (s *Server) Name() string { return "node-api-server" } diff --git a/node-api/server/types.go b/node-api/server/types.go index 82ca1c182..284856cae 100644 --- a/node-api/server/types.go +++ b/node-api/server/types.go @@ -23,11 +23,10 @@ package server import ( "github.com/berachain/beacon-kit/log" "github.com/berachain/beacon-kit/node-api/handlers" - "github.com/berachain/beacon-kit/node-api/server/context" ) // Engine is a generic interface for an API engine. -type Engine[ContextT context.Context] interface { +type Engine interface { Run(addr string) error - RegisterRoutes(*handlers.RouteSet[ContextT], log.Logger) + RegisterRoutes(*handlers.RouteSet, log.Logger) } diff --git a/node-core/components/api.go b/node-core/components/api.go index f8d55e4a8..3b6ed6564 100644 --- a/node-core/components/api.go +++ b/node-core/components/api.go @@ -57,25 +57,26 @@ func ProvideNodeAPIBackend( type NodeAPIServerInput[ LoggerT log.AdvancedLogger[LoggerT], - NodeAPIContextT NodeAPIContext, ] struct { depinject.In - Engine NodeAPIEngine[NodeAPIContextT] + Engine NodeAPIEngine Config *config.Config - Handlers []handlers.Handlers[NodeAPIContextT] + Handlers []handlers.Handlers Logger LoggerT } func ProvideNodeAPIServer[ LoggerT log.AdvancedLogger[LoggerT], - NodeAPIContextT NodeAPIContext, ]( - in NodeAPIServerInput[LoggerT, NodeAPIContextT], -) *server.Server[NodeAPIContextT] { - in.Logger.AddKeyValColor("service", "node-api-server", - log.Blue) - return server.New[NodeAPIContextT]( + in NodeAPIServerInput[LoggerT], +) *server.Server { + in.Logger.AddKeyValColor( + "service", + "node-api-server", + log.Blue, + ) + return server.New( in.Config.NodeAPI, in.Engine, in.Logger.With("service", "node-api-server"), diff --git a/node-core/components/api_handlers.go b/node-core/components/api_handlers.go index 83581a284..63e71bd39 100644 --- a/node-core/components/api_handlers.go +++ b/node-core/components/api_handlers.go @@ -32,25 +32,19 @@ import ( proofapi "github.com/berachain/beacon-kit/node-api/handlers/proof" ) -type NodeAPIHandlersInput[ - NodeAPIContextT NodeAPIContext, -] struct { +type NodeAPIHandlersInput struct { depinject.In - BeaconAPIHandler *beaconapi.Handler[NodeAPIContextT] - BuilderAPIHandler *builderapi.Handler[NodeAPIContextT] - ConfigAPIHandler *configapi.Handler[NodeAPIContextT] - DebugAPIHandler *debugapi.Handler[NodeAPIContextT] - EventsAPIHandler *eventsapi.Handler[NodeAPIContextT] - NodeAPIHandler *nodeapi.Handler[NodeAPIContextT] - ProofAPIHandler *proofapi.Handler[NodeAPIContextT] + BeaconAPIHandler *beaconapi.Handler + BuilderAPIHandler *builderapi.Handler + ConfigAPIHandler *configapi.Handler + DebugAPIHandler *debugapi.Handler + EventsAPIHandler *eventsapi.Handler + NodeAPIHandler *nodeapi.Handler + ProofAPIHandler *proofapi.Handler } -func ProvideNodeAPIHandlers[ - NodeAPIContextT NodeAPIContext, -]( - in NodeAPIHandlersInput[NodeAPIContextT], -) []handlers.Handlers[NodeAPIContextT] { - return []handlers.Handlers[NodeAPIContextT]{ +func ProvideNodeAPIHandlers(in NodeAPIHandlersInput) []handlers.Handlers { + return []handlers.Handlers{ in.BeaconAPIHandler, in.BuilderAPIHandler, in.ConfigAPIHandler, @@ -61,44 +55,30 @@ func ProvideNodeAPIHandlers[ } } -func ProvideNodeAPIBeaconHandler[ - NodeAPIContextT NodeAPIContext, -](b NodeAPIBackend) *beaconapi.Handler[NodeAPIContextT] { - return beaconapi.NewHandler[NodeAPIContextT](b) +func ProvideNodeAPIBeaconHandler(b NodeAPIBackend) *beaconapi.Handler { + return beaconapi.NewHandler(b) } -func ProvideNodeAPIBuilderHandler[ - NodeAPIContextT NodeAPIContext, -]() *builderapi.Handler[NodeAPIContextT] { - return builderapi.NewHandler[NodeAPIContextT]() +func ProvideNodeAPIBuilderHandler() *builderapi.Handler { + return builderapi.NewHandler() } -func ProvideNodeAPIConfigHandler[ - NodeAPIContextT NodeAPIContext, -]() *configapi.Handler[NodeAPIContextT] { - return configapi.NewHandler[NodeAPIContextT]() +func ProvideNodeAPIConfigHandler() *configapi.Handler { + return configapi.NewHandler() } -func ProvideNodeAPIDebugHandler[ - NodeAPIContextT NodeAPIContext, -](b NodeAPIBackend) *debugapi.Handler[NodeAPIContextT] { - return debugapi.NewHandler[NodeAPIContextT](b) +func ProvideNodeAPIDebugHandler(b NodeAPIBackend) *debugapi.Handler { + return debugapi.NewHandler(b) } -func ProvideNodeAPIEventsHandler[ - NodeAPIContextT NodeAPIContext, -]() *eventsapi.Handler[NodeAPIContextT] { - return eventsapi.NewHandler[NodeAPIContextT]() +func ProvideNodeAPIEventsHandler() *eventsapi.Handler { + return eventsapi.NewHandler() } -func ProvideNodeAPINodeHandler[ - NodeAPIContextT NodeAPIContext, -]() *nodeapi.Handler[NodeAPIContextT] { - return nodeapi.NewHandler[NodeAPIContextT]() +func ProvideNodeAPINodeHandler() *nodeapi.Handler { + return nodeapi.NewHandler() } -func ProvideNodeAPIProofHandler[ - NodeAPIContextT NodeAPIContext, -](b NodeAPIBackend) *proofapi.Handler[NodeAPIContextT] { - return proofapi.NewHandler[NodeAPIContextT](b) +func ProvideNodeAPIProofHandler(b NodeAPIBackend) *proofapi.Handler { + return proofapi.NewHandler(b) } diff --git a/node-core/components/interfaces.go b/node-core/components/interfaces.go index 9c780b1b2..5bea54fd6 100644 --- a/node-core/components/interfaces.go +++ b/node-core/components/interfaces.go @@ -733,9 +733,9 @@ type ( } // Engine is a generic interface for an API engine. - NodeAPIEngine[ContextT NodeAPIContext] interface { + NodeAPIEngine interface { Run(addr string) error - RegisterRoutes(*handlers.RouteSet[ContextT], log.Logger) + RegisterRoutes(*handlers.RouteSet, log.Logger) } NodeAPIBackend interface { diff --git a/node-core/components/service_registry.go b/node-core/components/service_registry.go index fb25f8bbf..db74a8b92 100644 --- a/node-core/components/service_registry.go +++ b/node-core/components/service_registry.go @@ -27,7 +27,6 @@ import ( cometbft "github.com/berachain/beacon-kit/consensus/cometbft/service" "github.com/berachain/beacon-kit/execution/client" "github.com/berachain/beacon-kit/log" - "github.com/berachain/beacon-kit/node-api/engines/echo" "github.com/berachain/beacon-kit/node-api/server" "github.com/berachain/beacon-kit/node-core/components/metrics" service "github.com/berachain/beacon-kit/node-core/services/registry" @@ -44,7 +43,7 @@ type ServiceRegistryInput[ ChainService *blockchain.Service EngineClient *client.EngineClient Logger LoggerT - NodeAPIServer *server.Server[echo.Context] + NodeAPIServer *server.Server ReportingService *version.ReportingService TelemetrySink *metrics.TelemetrySink TelemetryService *telemetry.Service