From 3f8af83af1991dc15c42b4b7e6ea98d6ba335a3c Mon Sep 17 00:00:00 2001 From: aBear Date: Fri, 31 Jan 2025 21:45:52 -0500 Subject: [PATCH 01/13] dropped ctx from provide node api handlers --- cmd/beacond/defaults.go | 2 +- node-core/components/api_handlers.go | 27 +++++++++++---------------- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/cmd/beacond/defaults.go b/cmd/beacond/defaults.go index af7e394cee..37648b817f 100644 --- a/cmd/beacond/defaults.go +++ b/cmd/beacond/defaults.go @@ -63,7 +63,7 @@ func DefaultComponents() []any { ) c = append(c, - components.ProvideNodeAPIHandlers[NodeAPIContext], + components.ProvideNodeAPIHandlers, components.ProvideNodeAPIBeaconHandler[NodeAPIContext], components.ProvideNodeAPIBuilderHandler[NodeAPIContext], components.ProvideNodeAPIConfigHandler[NodeAPIContext], diff --git a/node-core/components/api_handlers.go b/node-core/components/api_handlers.go index 83581a2843..af0e33906a 100644 --- a/node-core/components/api_handlers.go +++ b/node-core/components/api_handlers.go @@ -22,6 +22,7 @@ package components import ( "cosmossdk.io/depinject" + "github.com/berachain/beacon-kit/node-api/engines/echo" "github.com/berachain/beacon-kit/node-api/handlers" beaconapi "github.com/berachain/beacon-kit/node-api/handlers/beacon" builderapi "github.com/berachain/beacon-kit/node-api/handlers/builder" @@ -32,25 +33,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[echo.Context] + BuilderAPIHandler *builderapi.Handler[echo.Context] + ConfigAPIHandler *configapi.Handler[echo.Context] + DebugAPIHandler *debugapi.Handler[echo.Context] + EventsAPIHandler *eventsapi.Handler[echo.Context] + NodeAPIHandler *nodeapi.Handler[echo.Context] + ProofAPIHandler *proofapi.Handler[echo.Context] } -func ProvideNodeAPIHandlers[ - NodeAPIContextT NodeAPIContext, -]( - in NodeAPIHandlersInput[NodeAPIContextT], -) []handlers.Handlers[NodeAPIContextT] { - return []handlers.Handlers[NodeAPIContextT]{ +func ProvideNodeAPIHandlers(in NodeAPIHandlersInput) []handlers.Handlers[echo.Context] { + return []handlers.Handlers[echo.Context]{ in.BeaconAPIHandler, in.BuilderAPIHandler, in.ConfigAPIHandler, From d2bb7d1ae2f1f04ff10905407c3bfbf1508102e1 Mon Sep 17 00:00:00 2001 From: aBear Date: Fri, 31 Jan 2025 21:54:37 -0500 Subject: [PATCH 02/13] dropped ctx from provide node api beaconHandler --- cmd/beacond/defaults.go | 2 +- node-api/handlers/beacon/blobs.go | 3 ++- node-api/handlers/beacon/block.go | 3 ++- node-api/handlers/beacon/genesis.go | 3 ++- node-api/handlers/beacon/handler.go | 18 ++++++------------ node-api/handlers/beacon/header.go | 5 +++-- node-api/handlers/beacon/historical.go | 5 +++-- node-api/handlers/beacon/randao.go | 3 ++- node-api/handlers/beacon/routes.go | 5 +++-- node-api/handlers/beacon/validators.go | 21 ++++++--------------- node-core/components/api_handlers.go | 8 +++----- 11 files changed, 33 insertions(+), 43 deletions(-) diff --git a/cmd/beacond/defaults.go b/cmd/beacond/defaults.go index 37648b817f..a197f891f6 100644 --- a/cmd/beacond/defaults.go +++ b/cmd/beacond/defaults.go @@ -64,7 +64,7 @@ func DefaultComponents() []any { c = append(c, components.ProvideNodeAPIHandlers, - components.ProvideNodeAPIBeaconHandler[NodeAPIContext], + components.ProvideNodeAPIBeaconHandler, components.ProvideNodeAPIBuilderHandler[NodeAPIContext], components.ProvideNodeAPIConfigHandler[NodeAPIContext], components.ProvideNodeAPIDebugHandler[NodeAPIContext], diff --git a/node-api/handlers/beacon/blobs.go b/node-api/handlers/beacon/blobs.go index 4d90d06c93..4290cb2913 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/engines/echo" 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 echo.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 b12db63b1a..024b155532 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/engines/echo" 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 echo.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 9157cb466b..b7400eb6e8 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/engines/echo" 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(_ echo.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 6ae054348f..2ddfc90869 100644 --- a/node-api/handlers/beacon/handler.go +++ b/node-api/handlers/beacon/handler.go @@ -21,27 +21,21 @@ package beacon import ( + "github.com/berachain/beacon-kit/node-api/engines/echo" "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[echo.Context] 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[echo.Context](""), ), backend: backend, } diff --git a/node-api/handlers/beacon/header.go b/node-api/handlers/beacon/header.go index 8fc249cb5c..eb0210de59 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/engines/echo" 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 echo.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 echo.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 996fd78372..2fea98d09e 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/engines/echo" 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 echo.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 echo.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 513073b971..0e00e4345f 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/engines/echo" 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 echo.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 6f90b9d553..247123fea4 100644 --- a/node-api/handlers/beacon/routes.go +++ b/node-api/handlers/beacon/routes.go @@ -24,15 +24,16 @@ import ( "net/http" "github.com/berachain/beacon-kit/log" + "github.com/berachain/beacon-kit/node-api/engines/echo" "github.com/berachain/beacon-kit/node-api/handlers" ) //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[echo.Context]{ { 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 6cf6f5596b..135c314054 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/engines/echo" 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 echo.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 echo.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 echo.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 echo.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 echo.Context) (any, error) { req, err := utils.BindAndValidate[beacontypes.PostValidatorBalancesRequest]( c, h.Logger(), ) diff --git a/node-core/components/api_handlers.go b/node-core/components/api_handlers.go index af0e33906a..a819485ff6 100644 --- a/node-core/components/api_handlers.go +++ b/node-core/components/api_handlers.go @@ -35,7 +35,7 @@ import ( type NodeAPIHandlersInput struct { depinject.In - BeaconAPIHandler *beaconapi.Handler[echo.Context] + BeaconAPIHandler *beaconapi.Handler BuilderAPIHandler *builderapi.Handler[echo.Context] ConfigAPIHandler *configapi.Handler[echo.Context] DebugAPIHandler *debugapi.Handler[echo.Context] @@ -56,10 +56,8 @@ func ProvideNodeAPIHandlers(in NodeAPIHandlersInput) []handlers.Handlers[echo.Co } } -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[ From df8e2c203e5e1074470bd506bb71d0c889a0aed4 Mon Sep 17 00:00:00 2001 From: aBear Date: Fri, 31 Jan 2025 21:58:16 -0500 Subject: [PATCH 03/13] dropped ctx from provide node api builder handler --- cmd/beacond/defaults.go | 2 +- node-api/handlers/builder/handler.go | 12 ++++++------ node-api/handlers/builder/routes.go | 7 +++---- node-core/components/api_handlers.go | 8 +++----- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/cmd/beacond/defaults.go b/cmd/beacond/defaults.go index a197f891f6..06b14df4bc 100644 --- a/cmd/beacond/defaults.go +++ b/cmd/beacond/defaults.go @@ -65,7 +65,7 @@ func DefaultComponents() []any { c = append(c, components.ProvideNodeAPIHandlers, components.ProvideNodeAPIBeaconHandler, - components.ProvideNodeAPIBuilderHandler[NodeAPIContext], + components.ProvideNodeAPIBuilderHandler, components.ProvideNodeAPIConfigHandler[NodeAPIContext], components.ProvideNodeAPIDebugHandler[NodeAPIContext], components.ProvideNodeAPIEventsHandler[NodeAPIContext], diff --git a/node-api/handlers/builder/handler.go b/node-api/handlers/builder/handler.go index 93c88d7124..96c596c2d2 100644 --- a/node-api/handlers/builder/handler.go +++ b/node-api/handlers/builder/handler.go @@ -21,18 +21,18 @@ package builder import ( + "github.com/berachain/beacon-kit/node-api/engines/echo" "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[echo.Context] } -func NewHandler[ContextT context.Context]() *Handler[ContextT] { - h := &Handler[ContextT]{ +func NewHandler() *Handler { + h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[ContextT](""), + handlers.NewRouteSet[echo.Context](""), ), } return h diff --git a/node-api/handlers/builder/routes.go b/node-api/handlers/builder/routes.go index f3c99a0987..81fc5bb240 100644 --- a/node-api/handlers/builder/routes.go +++ b/node-api/handlers/builder/routes.go @@ -24,14 +24,13 @@ import ( "net/http" "github.com/berachain/beacon-kit/log" + "github.com/berachain/beacon-kit/node-api/engines/echo" "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[echo.Context]{ { Method: http.MethodGet, Path: "/eth/v1/builder/states/:state_id/expected_withdrawals", diff --git a/node-core/components/api_handlers.go b/node-core/components/api_handlers.go index a819485ff6..6d9cee5d00 100644 --- a/node-core/components/api_handlers.go +++ b/node-core/components/api_handlers.go @@ -36,7 +36,7 @@ import ( type NodeAPIHandlersInput struct { depinject.In BeaconAPIHandler *beaconapi.Handler - BuilderAPIHandler *builderapi.Handler[echo.Context] + BuilderAPIHandler *builderapi.Handler ConfigAPIHandler *configapi.Handler[echo.Context] DebugAPIHandler *debugapi.Handler[echo.Context] EventsAPIHandler *eventsapi.Handler[echo.Context] @@ -60,10 +60,8 @@ 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[ From 4d3bd1d13637e6e14f1a0980dea267eaa183a164 Mon Sep 17 00:00:00 2001 From: aBear Date: Fri, 31 Jan 2025 22:01:06 -0500 Subject: [PATCH 04/13] dropped ctx from provide node api config handler --- cmd/beacond/defaults.go | 2 +- node-api/handlers/config/handler.go | 12 ++++++------ node-api/handlers/config/routes.go | 7 +++---- node-core/components/api_handlers.go | 8 +++----- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/cmd/beacond/defaults.go b/cmd/beacond/defaults.go index 06b14df4bc..a6c7346702 100644 --- a/cmd/beacond/defaults.go +++ b/cmd/beacond/defaults.go @@ -66,7 +66,7 @@ func DefaultComponents() []any { components.ProvideNodeAPIHandlers, components.ProvideNodeAPIBeaconHandler, components.ProvideNodeAPIBuilderHandler, - components.ProvideNodeAPIConfigHandler[NodeAPIContext], + components.ProvideNodeAPIConfigHandler, components.ProvideNodeAPIDebugHandler[NodeAPIContext], components.ProvideNodeAPIEventsHandler[NodeAPIContext], components.ProvideNodeAPINodeHandler[NodeAPIContext], diff --git a/node-api/handlers/config/handler.go b/node-api/handlers/config/handler.go index d21534cf30..448e9572b3 100644 --- a/node-api/handlers/config/handler.go +++ b/node-api/handlers/config/handler.go @@ -21,18 +21,18 @@ package config import ( + "github.com/berachain/beacon-kit/node-api/engines/echo" "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[echo.Context] } -func NewHandler[ContextT context.Context]() *Handler[ContextT] { - h := &Handler[ContextT]{ +func NewHandler() *Handler { + h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[ContextT](""), + handlers.NewRouteSet[echo.Context](""), ), } return h diff --git a/node-api/handlers/config/routes.go b/node-api/handlers/config/routes.go index c5a631bbe0..f391ad16d6 100644 --- a/node-api/handlers/config/routes.go +++ b/node-api/handlers/config/routes.go @@ -24,14 +24,13 @@ import ( "net/http" "github.com/berachain/beacon-kit/log" + "github.com/berachain/beacon-kit/node-api/engines/echo" "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[echo.Context]{ { Method: http.MethodGet, Path: "/eth/v1/config/fork_schedule", diff --git a/node-core/components/api_handlers.go b/node-core/components/api_handlers.go index 6d9cee5d00..a292e14025 100644 --- a/node-core/components/api_handlers.go +++ b/node-core/components/api_handlers.go @@ -37,7 +37,7 @@ type NodeAPIHandlersInput struct { depinject.In BeaconAPIHandler *beaconapi.Handler BuilderAPIHandler *builderapi.Handler - ConfigAPIHandler *configapi.Handler[echo.Context] + ConfigAPIHandler *configapi.Handler DebugAPIHandler *debugapi.Handler[echo.Context] EventsAPIHandler *eventsapi.Handler[echo.Context] NodeAPIHandler *nodeapi.Handler[echo.Context] @@ -64,10 +64,8 @@ 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[ From 5c8773ff352bbb1f3142ddd3ec67e3f89c97f23f Mon Sep 17 00:00:00 2001 From: aBear Date: Fri, 31 Jan 2025 22:04:55 -0500 Subject: [PATCH 05/13] dropped ctx from provide debug api handler --- cmd/beacond/defaults.go | 2 +- node-api/handlers/debug/handler.go | 18 ++++++------------ node-api/handlers/debug/routes.go | 7 +++---- node-api/handlers/debug/state.go | 7 ++++--- node-core/components/api_handlers.go | 8 +++----- 5 files changed, 17 insertions(+), 25 deletions(-) diff --git a/cmd/beacond/defaults.go b/cmd/beacond/defaults.go index a6c7346702..6dc3edcc8a 100644 --- a/cmd/beacond/defaults.go +++ b/cmd/beacond/defaults.go @@ -67,7 +67,7 @@ func DefaultComponents() []any { components.ProvideNodeAPIBeaconHandler, components.ProvideNodeAPIBuilderHandler, components.ProvideNodeAPIConfigHandler, - components.ProvideNodeAPIDebugHandler[NodeAPIContext], + components.ProvideNodeAPIDebugHandler, components.ProvideNodeAPIEventsHandler[NodeAPIContext], components.ProvideNodeAPINodeHandler[NodeAPIContext], components.ProvideNodeAPIProofHandler[NodeAPIContext], diff --git a/node-api/handlers/debug/handler.go b/node-api/handlers/debug/handler.go index 58cb4756ba..43029a9f65 100644 --- a/node-api/handlers/debug/handler.go +++ b/node-api/handlers/debug/handler.go @@ -21,27 +21,21 @@ package debug import ( + "github.com/berachain/beacon-kit/node-api/engines/echo" "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[echo.Context] 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[echo.Context](""), ), backend: backend, } diff --git a/node-api/handlers/debug/routes.go b/node-api/handlers/debug/routes.go index b871efa703..253ee7c042 100644 --- a/node-api/handlers/debug/routes.go +++ b/node-api/handlers/debug/routes.go @@ -24,14 +24,13 @@ import ( "net/http" "github.com/berachain/beacon-kit/log" + "github.com/berachain/beacon-kit/node-api/engines/echo" "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[echo.Context]{ { 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 f0ed161b72..668170c59f 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/engines/echo" 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 echo.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-core/components/api_handlers.go b/node-core/components/api_handlers.go index a292e14025..6ce82db129 100644 --- a/node-core/components/api_handlers.go +++ b/node-core/components/api_handlers.go @@ -38,7 +38,7 @@ type NodeAPIHandlersInput struct { BeaconAPIHandler *beaconapi.Handler BuilderAPIHandler *builderapi.Handler ConfigAPIHandler *configapi.Handler - DebugAPIHandler *debugapi.Handler[echo.Context] + DebugAPIHandler *debugapi.Handler EventsAPIHandler *eventsapi.Handler[echo.Context] NodeAPIHandler *nodeapi.Handler[echo.Context] ProofAPIHandler *proofapi.Handler[echo.Context] @@ -68,10 +68,8 @@ 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[ From 523163c315878ec45434bd5ef40b3873c4c2d205 Mon Sep 17 00:00:00 2001 From: aBear Date: Fri, 31 Jan 2025 22:08:59 -0500 Subject: [PATCH 06/13] dropped ctx from provide node api events handler --- cmd/beacond/defaults.go | 2 +- node-api/handlers/events/handler.go | 12 ++++++------ node-api/handlers/events/routes.go | 7 +++---- node-core/components/api_handlers.go | 8 +++----- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/cmd/beacond/defaults.go b/cmd/beacond/defaults.go index 6dc3edcc8a..169bacf521 100644 --- a/cmd/beacond/defaults.go +++ b/cmd/beacond/defaults.go @@ -68,7 +68,7 @@ func DefaultComponents() []any { components.ProvideNodeAPIBuilderHandler, components.ProvideNodeAPIConfigHandler, components.ProvideNodeAPIDebugHandler, - components.ProvideNodeAPIEventsHandler[NodeAPIContext], + components.ProvideNodeAPIEventsHandler, components.ProvideNodeAPINodeHandler[NodeAPIContext], components.ProvideNodeAPIProofHandler[NodeAPIContext], ) diff --git a/node-api/handlers/events/handler.go b/node-api/handlers/events/handler.go index 7b27c4c043..d61beea92c 100644 --- a/node-api/handlers/events/handler.go +++ b/node-api/handlers/events/handler.go @@ -21,18 +21,18 @@ package events import ( + "github.com/berachain/beacon-kit/node-api/engines/echo" "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[echo.Context] } -func NewHandler[ContextT context.Context]() *Handler[ContextT] { - h := &Handler[ContextT]{ +func NewHandler() *Handler { + h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[ContextT](""), + handlers.NewRouteSet[echo.Context](""), ), } return h diff --git a/node-api/handlers/events/routes.go b/node-api/handlers/events/routes.go index def8b0538c..5f7b3105c5 100644 --- a/node-api/handlers/events/routes.go +++ b/node-api/handlers/events/routes.go @@ -24,14 +24,13 @@ import ( "net/http" "github.com/berachain/beacon-kit/log" + "github.com/berachain/beacon-kit/node-api/engines/echo" "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[echo.Context]{ { Method: http.MethodGet, Path: "/eth/v1/events", diff --git a/node-core/components/api_handlers.go b/node-core/components/api_handlers.go index 6ce82db129..68ff112324 100644 --- a/node-core/components/api_handlers.go +++ b/node-core/components/api_handlers.go @@ -39,7 +39,7 @@ type NodeAPIHandlersInput struct { BuilderAPIHandler *builderapi.Handler ConfigAPIHandler *configapi.Handler DebugAPIHandler *debugapi.Handler - EventsAPIHandler *eventsapi.Handler[echo.Context] + EventsAPIHandler *eventsapi.Handler NodeAPIHandler *nodeapi.Handler[echo.Context] ProofAPIHandler *proofapi.Handler[echo.Context] } @@ -72,10 +72,8 @@ 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[ From a706246434877b33aac02de0aa7757ec59df3918 Mon Sep 17 00:00:00 2001 From: aBear Date: Fri, 31 Jan 2025 22:11:50 -0500 Subject: [PATCH 07/13] dropped ctx from provide node api handler --- cmd/beacond/defaults.go | 2 +- node-api/handlers/node/handler.go | 12 ++++++------ node-api/handlers/node/placeholders.go | 8 +++++--- node-api/handlers/node/routes.go | 7 +++---- node-core/components/api_handlers.go | 8 +++----- 5 files changed, 18 insertions(+), 19 deletions(-) diff --git a/cmd/beacond/defaults.go b/cmd/beacond/defaults.go index 169bacf521..90fbe8702d 100644 --- a/cmd/beacond/defaults.go +++ b/cmd/beacond/defaults.go @@ -69,7 +69,7 @@ func DefaultComponents() []any { components.ProvideNodeAPIConfigHandler, components.ProvideNodeAPIDebugHandler, components.ProvideNodeAPIEventsHandler, - components.ProvideNodeAPINodeHandler[NodeAPIContext], + components.ProvideNodeAPINodeHandler, components.ProvideNodeAPIProofHandler[NodeAPIContext], ) diff --git a/node-api/handlers/node/handler.go b/node-api/handlers/node/handler.go index f5b330a27e..9caf16560b 100644 --- a/node-api/handlers/node/handler.go +++ b/node-api/handlers/node/handler.go @@ -21,18 +21,18 @@ package node import ( + "github.com/berachain/beacon-kit/node-api/engines/echo" "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[echo.Context] } -func NewHandler[ContextT context.Context]() *Handler[ContextT] { - h := &Handler[ContextT]{ +func NewHandler() *Handler { + h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[ContextT](""), + handlers.NewRouteSet[echo.Context](""), ), } return h diff --git a/node-api/handlers/node/placeholders.go b/node-api/handlers/node/placeholders.go index 5d68a9fd6e..ffc2809ac6 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/engines/echo" + // 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(echo.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(echo.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 15d8ec8921..4cacd088b2 100644 --- a/node-api/handlers/node/routes.go +++ b/node-api/handlers/node/routes.go @@ -24,14 +24,13 @@ import ( "net/http" "github.com/berachain/beacon-kit/log" + "github.com/berachain/beacon-kit/node-api/engines/echo" "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[echo.Context]{ { Method: http.MethodGet, Path: "/eth/v1/node/identity", diff --git a/node-core/components/api_handlers.go b/node-core/components/api_handlers.go index 68ff112324..3711ba2f58 100644 --- a/node-core/components/api_handlers.go +++ b/node-core/components/api_handlers.go @@ -40,7 +40,7 @@ type NodeAPIHandlersInput struct { ConfigAPIHandler *configapi.Handler DebugAPIHandler *debugapi.Handler EventsAPIHandler *eventsapi.Handler - NodeAPIHandler *nodeapi.Handler[echo.Context] + NodeAPIHandler *nodeapi.Handler ProofAPIHandler *proofapi.Handler[echo.Context] } @@ -76,10 +76,8 @@ 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[ From 3626d323111bd120b887d753378dd9e4a278323e Mon Sep 17 00:00:00 2001 From: aBear Date: Fri, 31 Jan 2025 22:15:38 -0500 Subject: [PATCH 08/13] dropped ctx from provide node api proof handler --- cmd/beacond/defaults.go | 2 +- node-api/handlers/proof/block_proposer.go | 3 ++- .../handlers/proof/execution_fee_recipient.go | 3 ++- node-api/handlers/proof/execution_number.go | 3 ++- node-api/handlers/proof/handler.go | 20 +++++++------------ node-api/handlers/proof/routes.go | 5 +++-- node-core/components/api_handlers.go | 8 +++----- 7 files changed, 20 insertions(+), 24 deletions(-) diff --git a/cmd/beacond/defaults.go b/cmd/beacond/defaults.go index 90fbe8702d..e9c2b410be 100644 --- a/cmd/beacond/defaults.go +++ b/cmd/beacond/defaults.go @@ -70,7 +70,7 @@ func DefaultComponents() []any { components.ProvideNodeAPIDebugHandler, components.ProvideNodeAPIEventsHandler, components.ProvideNodeAPINodeHandler, - components.ProvideNodeAPIProofHandler[NodeAPIContext], + components.ProvideNodeAPIProofHandler, ) return c diff --git a/node-api/handlers/proof/block_proposer.go b/node-api/handlers/proof/block_proposer.go index 56d75c4925..993e2894eb 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/engines/echo" "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 echo.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 31c300e7ac..bd788476b0 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/engines/echo" "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 echo.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 afe8b1f039..93cc4b7702 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/engines/echo" "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 echo.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 120272f91a..a662359aa3 100644 --- a/node-api/handlers/proof/handler.go +++ b/node-api/handlers/proof/handler.go @@ -22,30 +22,24 @@ package proof import ( ctypes "github.com/berachain/beacon-kit/consensus-types/types" + "github.com/berachain/beacon-kit/node-api/engines/echo" "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[echo.Context] 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[echo.Context](""), ), backend: backend, } @@ -54,7 +48,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 b26012a904..c501698791 100644 --- a/node-api/handlers/proof/routes.go +++ b/node-api/handlers/proof/routes.go @@ -24,12 +24,13 @@ import ( "net/http" "github.com/berachain/beacon-kit/log" + "github.com/berachain/beacon-kit/node-api/engines/echo" "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[echo.Context]{ { Method: http.MethodGet, Path: "bkit/v1/proof/block_proposer/:timestamp_id", diff --git a/node-core/components/api_handlers.go b/node-core/components/api_handlers.go index 3711ba2f58..c7921099d2 100644 --- a/node-core/components/api_handlers.go +++ b/node-core/components/api_handlers.go @@ -41,7 +41,7 @@ type NodeAPIHandlersInput struct { DebugAPIHandler *debugapi.Handler EventsAPIHandler *eventsapi.Handler NodeAPIHandler *nodeapi.Handler - ProofAPIHandler *proofapi.Handler[echo.Context] + ProofAPIHandler *proofapi.Handler } func ProvideNodeAPIHandlers(in NodeAPIHandlersInput) []handlers.Handlers[echo.Context] { @@ -80,8 +80,6 @@ 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) } From 5cf537c70196ef670d55891c369480ed9af11d7f Mon Sep 17 00:00:00 2001 From: aBear Date: Fri, 31 Jan 2025 22:17:49 -0500 Subject: [PATCH 09/13] dropped ctx from provide node api server --- cmd/beacond/defaults.go | 2 +- node-core/components/api.go | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/cmd/beacond/defaults.go b/cmd/beacond/defaults.go index e9c2b410be..8848ff098c 100644 --- a/cmd/beacond/defaults.go +++ b/cmd/beacond/defaults.go @@ -57,7 +57,7 @@ func DefaultComponents() []any { components.ProvideShutDownService[*Logger], } c = append(c, - components.ProvideNodeAPIServer[*Logger, NodeAPIContext], + components.ProvideNodeAPIServer[*Logger], components.ProvideNodeAPIEngine, components.ProvideNodeAPIBackend, ) diff --git a/node-core/components/api.go b/node-core/components/api.go index f8d55e4a86..7f11771d01 100644 --- a/node-core/components/api.go +++ b/node-core/components/api.go @@ -57,25 +57,23 @@ func ProvideNodeAPIBackend( type NodeAPIServerInput[ LoggerT log.AdvancedLogger[LoggerT], - NodeAPIContextT NodeAPIContext, ] struct { depinject.In - Engine NodeAPIEngine[NodeAPIContextT] + Engine NodeAPIEngine[echo.Context] Config *config.Config - Handlers []handlers.Handlers[NodeAPIContextT] + Handlers []handlers.Handlers[echo.Context] Logger LoggerT } func ProvideNodeAPIServer[ LoggerT log.AdvancedLogger[LoggerT], - NodeAPIContextT NodeAPIContext, ]( - in NodeAPIServerInput[LoggerT, NodeAPIContextT], -) *server.Server[NodeAPIContextT] { + in NodeAPIServerInput[LoggerT], +) *server.Server[echo.Context] { in.Logger.AddKeyValColor("service", "node-api-server", log.Blue) - return server.New[NodeAPIContextT]( + return server.New[echo.Context]( in.Config.NodeAPI, in.Engine, in.Logger.With("service", "node-api-server"), From 635801e08c6f6e949b578a7cdc8377172c0afc63 Mon Sep 17 00:00:00 2001 From: aBear Date: Fri, 31 Jan 2025 22:23:27 -0500 Subject: [PATCH 10/13] dropped ctx from server.Server --- cmd/beacond/types.go | 5 +---- node-api/server/server.go | 28 ++++++++++-------------- node-core/components/api.go | 11 ++++++---- node-core/components/service_registry.go | 3 +-- 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/cmd/beacond/types.go b/cmd/beacond/types.go index ca58e8e272..7034cfd2f4 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/server/server.go b/node-api/server/server.go index a31b9d3275..797cbb6364 100644 --- a/node-api/server/server.go +++ b/node-api/server/server.go @@ -25,15 +25,13 @@ import ( "github.com/berachain/beacon-kit/log" "github.com/berachain/beacon-kit/log/noop" + "github.com/berachain/beacon-kit/node-api/engines/echo" "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[echo.Context] config Config logger log.Logger } @@ -41,14 +39,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[echo.Context], logger log.Logger, - handlers ...handlers.Handlers[ContextT], -) *Server[ContextT] { + handlers ...handlers.Handlers[echo.Context], +) *Server { apiLogger := logger if !config.Logging { apiLogger = noop.NewLogger[log.Logger]() @@ -57,7 +53,7 @@ func New[ handler.RegisterRoutes(apiLogger) engine.RegisterRoutes(handler.RouteSet(), apiLogger) } - return &Server[ContextT]{ + return &Server{ engine: engine, config: config, logger: logger, @@ -65,7 +61,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 +69,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 +84,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-core/components/api.go b/node-core/components/api.go index 7f11771d01..c336d845d8 100644 --- a/node-core/components/api.go +++ b/node-core/components/api.go @@ -70,10 +70,13 @@ func ProvideNodeAPIServer[ LoggerT log.AdvancedLogger[LoggerT], ]( in NodeAPIServerInput[LoggerT], -) *server.Server[echo.Context] { - in.Logger.AddKeyValColor("service", "node-api-server", - log.Blue) - return server.New[echo.Context]( +) *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/service_registry.go b/node-core/components/service_registry.go index fb25f8bbf9..db74a8b925 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 From 7ade486aacd2bfad3d9c9f80f4f07a3182d810d5 Mon Sep 17 00:00:00 2001 From: aBear Date: Fri, 31 Jan 2025 22:39:33 -0500 Subject: [PATCH 11/13] moved echo.Context to handlers package --- node-api/engines/echo/engine.go | 2 +- node-api/engines/echo/middleware.go | 4 +-- node-api/engines/echo/types.go | 27 ------------------- node-api/handlers/beacon/blobs.go | 4 +-- node-api/handlers/beacon/block.go | 4 +-- node-api/handlers/beacon/genesis.go | 4 +-- node-api/handlers/beacon/handler.go | 5 ++-- node-api/handlers/beacon/header.go | 6 ++--- node-api/handlers/beacon/historical.go | 6 ++--- node-api/handlers/beacon/randao.go | 4 +-- node-api/handlers/beacon/routes.go | 3 +-- node-api/handlers/beacon/validators.go | 12 ++++----- node-api/handlers/builder/handler.go | 5 ++-- node-api/handlers/builder/routes.go | 3 +-- node-api/handlers/config/handler.go | 9 +++---- node-api/handlers/config/routes.go | 3 +-- node-api/handlers/debug/handler.go | 9 +++---- node-api/handlers/debug/routes.go | 3 +-- node-api/handlers/debug/state.go | 4 +-- node-api/handlers/events/handler.go | 9 +++---- node-api/handlers/events/routes.go | 3 +-- node-api/handlers/handlers.go | 3 +++ node-api/handlers/node/handler.go | 9 +++---- node-api/handlers/node/placeholders.go | 6 ++--- node-api/handlers/node/routes.go | 3 +-- 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 | 5 ++-- node-api/handlers/proof/routes.go | 3 +-- node-api/server/server.go | 7 +++-- node-core/components/api.go | 4 +-- node-core/components/api_handlers.go | 5 ++-- 33 files changed, 69 insertions(+), 117 deletions(-) delete mode 100644 node-api/engines/echo/types.go diff --git a/node-api/engines/echo/engine.go b/node-api/engines/echo/engine.go index 47c51c5cf2..17c1d2091d 100644 --- a/node-api/engines/echo/engine.go +++ b/node-api/engines/echo/engine.go @@ -60,7 +60,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], + hs *handlers.RouteSet[handlers.Context], logger log.Logger, ) { e.logger = logger diff --git a/node-api/engines/echo/middleware.go b/node-api/engines/echo/middleware.go index b0641b34b0..81b9c22780 100644 --- a/node-api/engines/echo/middleware.go +++ b/node-api/engines/echo/middleware.go @@ -38,9 +38,9 @@ type ErrorResponse struct { // responseMiddleware is a middleware that converts errors to an HTTP status // code and response. func responseMiddleware( - handler *handlers.Route[Context], + handler *handlers.Route[handlers.Context], ) echo.HandlerFunc { - return func(c Context) error { + 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 3a78a4e3af..0000000000 --- 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 4290cb2913..b934a49979 100644 --- a/node-api/handlers/beacon/blobs.go +++ b/node-api/handlers/beacon/blobs.go @@ -23,14 +23,14 @@ package beacon import ( "strconv" - "github.com/berachain/beacon-kit/node-api/engines/echo" + "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) GetBlobSidecars(c echo.Context) (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 024b155532..de5b9a7715 100644 --- a/node-api/handlers/beacon/block.go +++ b/node-api/handlers/beacon/block.go @@ -21,12 +21,12 @@ package beacon import ( - "github.com/berachain/beacon-kit/node-api/engines/echo" + "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) GetBlockRewards(c echo.Context) (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 b7400eb6e8..7840000cfa 100644 --- a/node-api/handlers/beacon/genesis.go +++ b/node-api/handlers/beacon/genesis.go @@ -21,13 +21,13 @@ package beacon import ( - "github.com/berachain/beacon-kit/node-api/engines/echo" + "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) GetGenesis(_ echo.Context) (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 2ddfc90869..e23d909a57 100644 --- a/node-api/handlers/beacon/handler.go +++ b/node-api/handlers/beacon/handler.go @@ -21,13 +21,12 @@ package beacon import ( - "github.com/berachain/beacon-kit/node-api/engines/echo" "github.com/berachain/beacon-kit/node-api/handlers" ) // Handler is the handler for the beacon API. type Handler struct { - *handlers.BaseHandler[echo.Context] + *handlers.BaseHandler[handlers.Context] backend Backend } @@ -35,7 +34,7 @@ type Handler struct { func NewHandler(backend Backend) *Handler { h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[echo.Context](""), + handlers.NewRouteSet[handlers.Context](""), ), backend: backend, } diff --git a/node-api/handlers/beacon/header.go b/node-api/handlers/beacon/header.go index eb0210de59..76fbf55b06 100644 --- a/node-api/handlers/beacon/header.go +++ b/node-api/handlers/beacon/header.go @@ -21,12 +21,12 @@ package beacon import ( - "github.com/berachain/beacon-kit/node-api/engines/echo" + "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) GetBlockHeaders(c echo.Context) (any, error) { +func (h *Handler) GetBlockHeaders(c handlers.Context) (any, error) { req, err := utils.BindAndValidate[beacontypes.GetBlockHeadersRequest]( c, h.Logger(), ) @@ -55,7 +55,7 @@ func (h *Handler) GetBlockHeaders(c echo.Context) (any, error) { }, nil } -func (h *Handler) GetBlockHeaderByID(c echo.Context) (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 2fea98d09e..6a32775788 100644 --- a/node-api/handlers/beacon/historical.go +++ b/node-api/handlers/beacon/historical.go @@ -21,13 +21,13 @@ package beacon import ( - "github.com/berachain/beacon-kit/node-api/engines/echo" + "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) GetStateRoot(c echo.Context) (any, error) { +func (h *Handler) GetStateRoot(c handlers.Context) (any, error) { req, err := utils.BindAndValidate[beacontypes.GetStateRootRequest]( c, h.Logger(), ) @@ -52,7 +52,7 @@ func (h *Handler) GetStateRoot(c echo.Context) (any, error) { }, nil } -func (h *Handler) GetStateFork(c echo.Context) (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 0e00e4345f..45413153a3 100644 --- a/node-api/handlers/beacon/randao.go +++ b/node-api/handlers/beacon/randao.go @@ -21,13 +21,13 @@ package beacon import ( - "github.com/berachain/beacon-kit/node-api/engines/echo" + "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) GetRandao(c echo.Context) (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 247123fea4..2e49e7b05e 100644 --- a/node-api/handlers/beacon/routes.go +++ b/node-api/handlers/beacon/routes.go @@ -24,7 +24,6 @@ import ( "net/http" "github.com/berachain/beacon-kit/log" - "github.com/berachain/beacon-kit/node-api/engines/echo" "github.com/berachain/beacon-kit/node-api/handlers" ) @@ -33,7 +32,7 @@ func (h *Handler) RegisterRoutes( logger log.Logger, ) { h.SetLogger(logger) - h.BaseHandler.AddRoutes([]*handlers.Route[echo.Context]{ + h.BaseHandler.AddRoutes([]*handlers.Route[handlers.Context]{ { 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 135c314054..f8dbb88fb2 100644 --- a/node-api/handlers/beacon/validators.go +++ b/node-api/handlers/beacon/validators.go @@ -21,13 +21,13 @@ package beacon import ( - "github.com/berachain/beacon-kit/node-api/engines/echo" + "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) GetStateValidators(c echo.Context) (any, error) { +func (h *Handler) GetStateValidators(c handlers.Context) (any, error) { req, err := utils.BindAndValidate[beacontypes.GetStateValidatorsRequest]( c, h.Logger(), ) @@ -60,7 +60,7 @@ func (h *Handler) GetStateValidators(c echo.Context) (any, error) { }, nil } -func (h *Handler) PostStateValidators(c echo.Context) (any, error) { +func (h *Handler) PostStateValidators(c handlers.Context) (any, error) { req, err := utils.BindAndValidate[beacontypes.PostStateValidatorsRequest]( c, h.Logger(), ) @@ -90,7 +90,7 @@ func (h *Handler) PostStateValidators(c echo.Context) (any, error) { }, nil } -func (h *Handler) GetStateValidator(c echo.Context) (any, error) { +func (h *Handler) GetStateValidator(c handlers.Context) (any, error) { req, err := utils.BindAndValidate[beacontypes.GetStateValidatorRequest]( c, h.Logger(), ) @@ -111,7 +111,7 @@ func (h *Handler) GetStateValidator(c echo.Context) (any, error) { return validator, nil } -func (h *Handler) GetStateValidatorBalances(c echo.Context) (any, error) { +func (h *Handler) GetStateValidatorBalances(c handlers.Context) (any, error) { req, err := utils.BindAndValidate[beacontypes.GetValidatorBalancesRequest]( c, h.Logger(), ) @@ -136,7 +136,7 @@ func (h *Handler) GetStateValidatorBalances(c echo.Context) (any, error) { }, nil } -func (h *Handler) PostStateValidatorBalances(c echo.Context) (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 96c596c2d2..7d04c09782 100644 --- a/node-api/handlers/builder/handler.go +++ b/node-api/handlers/builder/handler.go @@ -21,18 +21,17 @@ package builder import ( - "github.com/berachain/beacon-kit/node-api/engines/echo" "github.com/berachain/beacon-kit/node-api/handlers" ) type Handler struct { - *handlers.BaseHandler[echo.Context] + *handlers.BaseHandler[handlers.Context] } func NewHandler() *Handler { h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[echo.Context](""), + handlers.NewRouteSet[handlers.Context](""), ), } return h diff --git a/node-api/handlers/builder/routes.go b/node-api/handlers/builder/routes.go index 81fc5bb240..989b5a4dd0 100644 --- a/node-api/handlers/builder/routes.go +++ b/node-api/handlers/builder/routes.go @@ -24,13 +24,12 @@ import ( "net/http" "github.com/berachain/beacon-kit/log" - "github.com/berachain/beacon-kit/node-api/engines/echo" "github.com/berachain/beacon-kit/node-api/handlers" ) func (h *Handler) RegisterRoutes(logger log.Logger) { h.SetLogger(logger) - h.BaseHandler.AddRoutes([]*handlers.Route[echo.Context]{ + h.BaseHandler.AddRoutes([]*handlers.Route[handlers.Context]{ { 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 448e9572b3..a117815146 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/engines/echo" - "github.com/berachain/beacon-kit/node-api/handlers" -) +import "github.com/berachain/beacon-kit/node-api/handlers" type Handler struct { - *handlers.BaseHandler[echo.Context] + *handlers.BaseHandler[handlers.Context] } func NewHandler() *Handler { h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[echo.Context](""), + handlers.NewRouteSet[handlers.Context](""), ), } return h diff --git a/node-api/handlers/config/routes.go b/node-api/handlers/config/routes.go index f391ad16d6..fe8070fce6 100644 --- a/node-api/handlers/config/routes.go +++ b/node-api/handlers/config/routes.go @@ -24,13 +24,12 @@ import ( "net/http" "github.com/berachain/beacon-kit/log" - "github.com/berachain/beacon-kit/node-api/engines/echo" "github.com/berachain/beacon-kit/node-api/handlers" ) func (h *Handler) RegisterRoutes(logger log.Logger) { h.SetLogger(logger) - h.BaseHandler.AddRoutes([]*handlers.Route[echo.Context]{ + h.BaseHandler.AddRoutes([]*handlers.Route[handlers.Context]{ { 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 43029a9f65..4f7393870e 100644 --- a/node-api/handlers/debug/handler.go +++ b/node-api/handlers/debug/handler.go @@ -20,14 +20,11 @@ package debug -import ( - "github.com/berachain/beacon-kit/node-api/engines/echo" - "github.com/berachain/beacon-kit/node-api/handlers" -) +import "github.com/berachain/beacon-kit/node-api/handlers" // Handler is the handler for the beacon API. type Handler struct { - *handlers.BaseHandler[echo.Context] + *handlers.BaseHandler[handlers.Context] backend Backend } @@ -35,7 +32,7 @@ type Handler struct { func NewHandler(backend Backend) *Handler { h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[echo.Context](""), + handlers.NewRouteSet[handlers.Context](""), ), backend: backend, } diff --git a/node-api/handlers/debug/routes.go b/node-api/handlers/debug/routes.go index 253ee7c042..712c9ec2e9 100644 --- a/node-api/handlers/debug/routes.go +++ b/node-api/handlers/debug/routes.go @@ -24,13 +24,12 @@ import ( "net/http" "github.com/berachain/beacon-kit/log" - "github.com/berachain/beacon-kit/node-api/engines/echo" "github.com/berachain/beacon-kit/node-api/handlers" ) func (h *Handler) RegisterRoutes(logger log.Logger) { h.SetLogger(logger) - h.BaseHandler.AddRoutes([]*handlers.Route[echo.Context]{ + h.BaseHandler.AddRoutes([]*handlers.Route[handlers.Context]{ { 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 668170c59f..9cb75577ae 100644 --- a/node-api/handlers/debug/state.go +++ b/node-api/handlers/debug/state.go @@ -21,12 +21,12 @@ package debug import ( - "github.com/berachain/beacon-kit/node-api/engines/echo" + "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) GetState(c echo.Context) (any, error) { +func (h *Handler) GetState(c handlers.Context) (any, error) { req, err := utils.BindAndValidate[beacontypes.GetStateRequest]( c, h.Logger(), ) diff --git a/node-api/handlers/events/handler.go b/node-api/handlers/events/handler.go index d61beea92c..402ed7ef31 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/engines/echo" - "github.com/berachain/beacon-kit/node-api/handlers" -) +import "github.com/berachain/beacon-kit/node-api/handlers" type Handler struct { - *handlers.BaseHandler[echo.Context] + *handlers.BaseHandler[handlers.Context] } func NewHandler() *Handler { h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[echo.Context](""), + handlers.NewRouteSet[handlers.Context](""), ), } return h diff --git a/node-api/handlers/events/routes.go b/node-api/handlers/events/routes.go index 5f7b3105c5..d8ede565db 100644 --- a/node-api/handlers/events/routes.go +++ b/node-api/handlers/events/routes.go @@ -24,13 +24,12 @@ import ( "net/http" "github.com/berachain/beacon-kit/log" - "github.com/berachain/beacon-kit/node-api/engines/echo" "github.com/berachain/beacon-kit/node-api/handlers" ) func (h *Handler) RegisterRoutes(logger log.Logger) { h.SetLogger(logger) - h.BaseHandler.AddRoutes([]*handlers.Route[echo.Context]{ + h.BaseHandler.AddRoutes([]*handlers.Route[handlers.Context]{ { Method: http.MethodGet, Path: "/eth/v1/events", diff --git a/node-api/handlers/handlers.go b/node-api/handlers/handlers.go index e21428542d..ebc8247f7a 100644 --- a/node-api/handlers/handlers.go +++ b/node-api/handlers/handlers.go @@ -23,8 +23,11 @@ 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) diff --git a/node-api/handlers/node/handler.go b/node-api/handlers/node/handler.go index 9caf16560b..cb93075f39 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/engines/echo" - "github.com/berachain/beacon-kit/node-api/handlers" -) +import "github.com/berachain/beacon-kit/node-api/handlers" type Handler struct { - *handlers.BaseHandler[echo.Context] + *handlers.BaseHandler[handlers.Context] } func NewHandler() *Handler { h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[echo.Context](""), + handlers.NewRouteSet[handlers.Context](""), ), } return h diff --git a/node-api/handlers/node/placeholders.go b/node-api/handlers/node/placeholders.go index ffc2809ac6..edf0e0014b 100644 --- a/node-api/handlers/node/placeholders.go +++ b/node-api/handlers/node/placeholders.go @@ -20,12 +20,12 @@ package node -import "github.com/berachain/beacon-kit/node-api/engines/echo" +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) Syncing(echo.Context) (any, error) { +func (h *Handler) Syncing(handlers.Context) (any, error) { type SyncingResponse struct { Data struct { HeadSlot string `json:"head_slot"` @@ -49,7 +49,7 @@ func (h *Handler) Syncing(echo.Context) (any, error) { // Version is a placeholder so that beacon API clients don't break. // // TODO: Implement with real data. -func (h *Handler) Version(echo.Context) (any, error) { +func (h *Handler) Version(handlers.Context) (any, error) { type VersionResponse struct { Data struct { Version string `json:"version"` diff --git a/node-api/handlers/node/routes.go b/node-api/handlers/node/routes.go index 4cacd088b2..79273f9ea0 100644 --- a/node-api/handlers/node/routes.go +++ b/node-api/handlers/node/routes.go @@ -24,13 +24,12 @@ import ( "net/http" "github.com/berachain/beacon-kit/log" - "github.com/berachain/beacon-kit/node-api/engines/echo" "github.com/berachain/beacon-kit/node-api/handlers" ) func (h *Handler) RegisterRoutes(logger log.Logger) { h.SetLogger(logger) - h.BaseHandler.AddRoutes([]*handlers.Route[echo.Context]{ + h.BaseHandler.AddRoutes([]*handlers.Route[handlers.Context]{ { 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 993e2894eb..8a68e3abe6 100644 --- a/node-api/handlers/proof/block_proposer.go +++ b/node-api/handlers/proof/block_proposer.go @@ -21,7 +21,7 @@ package proof import ( - "github.com/berachain/beacon-kit/node-api/engines/echo" + "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" @@ -30,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) GetBlockProposer(c echo.Context) (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 bd788476b0..2c7fbf01d7 100644 --- a/node-api/handlers/proof/execution_fee_recipient.go +++ b/node-api/handlers/proof/execution_fee_recipient.go @@ -21,7 +21,7 @@ package proof import ( - "github.com/berachain/beacon-kit/node-api/engines/echo" + "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" @@ -30,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) GetExecutionFeeRecipient(c echo.Context) (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 93cc4b7702..e9e6fea36c 100644 --- a/node-api/handlers/proof/execution_number.go +++ b/node-api/handlers/proof/execution_number.go @@ -21,7 +21,7 @@ package proof import ( - "github.com/berachain/beacon-kit/node-api/engines/echo" + "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" @@ -30,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) GetExecutionNumber(c echo.Context) (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 a662359aa3..14ceec3928 100644 --- a/node-api/handlers/proof/handler.go +++ b/node-api/handlers/proof/handler.go @@ -22,7 +22,6 @@ package proof import ( ctypes "github.com/berachain/beacon-kit/consensus-types/types" - "github.com/berachain/beacon-kit/node-api/engines/echo" "github.com/berachain/beacon-kit/node-api/handlers" "github.com/berachain/beacon-kit/node-api/handlers/utils" "github.com/berachain/beacon-kit/primitives/math" @@ -31,7 +30,7 @@ import ( // Handler is the handler for the proof API. type Handler struct { - *handlers.BaseHandler[echo.Context] + *handlers.BaseHandler[handlers.Context] backend Backend } @@ -39,7 +38,7 @@ type Handler struct { func NewHandler(backend Backend) *Handler { h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[echo.Context](""), + handlers.NewRouteSet[handlers.Context](""), ), backend: backend, } diff --git a/node-api/handlers/proof/routes.go b/node-api/handlers/proof/routes.go index c501698791..0649375a67 100644 --- a/node-api/handlers/proof/routes.go +++ b/node-api/handlers/proof/routes.go @@ -24,13 +24,12 @@ import ( "net/http" "github.com/berachain/beacon-kit/log" - "github.com/berachain/beacon-kit/node-api/engines/echo" "github.com/berachain/beacon-kit/node-api/handlers" ) func (h *Handler) RegisterRoutes(logger log.Logger) { h.SetLogger(logger) - h.BaseHandler.AddRoutes([]*handlers.Route[echo.Context]{ + h.BaseHandler.AddRoutes([]*handlers.Route[handlers.Context]{ { Method: http.MethodGet, Path: "bkit/v1/proof/block_proposer/:timestamp_id", diff --git a/node-api/server/server.go b/node-api/server/server.go index 797cbb6364..c33b7129fa 100644 --- a/node-api/server/server.go +++ b/node-api/server/server.go @@ -25,13 +25,12 @@ import ( "github.com/berachain/beacon-kit/log" "github.com/berachain/beacon-kit/log/noop" - "github.com/berachain/beacon-kit/node-api/engines/echo" "github.com/berachain/beacon-kit/node-api/handlers" ) // Server is the API Server service. type Server struct { - engine Engine[echo.Context] + engine Engine[handlers.Context] config Config logger log.Logger } @@ -41,9 +40,9 @@ type Server struct { // disabled. func New( config Config, - engine Engine[echo.Context], + engine Engine[handlers.Context], logger log.Logger, - handlers ...handlers.Handlers[echo.Context], + handlers ...handlers.Handlers[handlers.Context], ) *Server { apiLogger := logger if !config.Logging { diff --git a/node-core/components/api.go b/node-core/components/api.go index c336d845d8..33ef2197a0 100644 --- a/node-core/components/api.go +++ b/node-core/components/api.go @@ -60,9 +60,9 @@ type NodeAPIServerInput[ ] struct { depinject.In - Engine NodeAPIEngine[echo.Context] + Engine NodeAPIEngine[handlers.Context] Config *config.Config - Handlers []handlers.Handlers[echo.Context] + Handlers []handlers.Handlers[handlers.Context] Logger LoggerT } diff --git a/node-core/components/api_handlers.go b/node-core/components/api_handlers.go index c7921099d2..1b88ed0dfb 100644 --- a/node-core/components/api_handlers.go +++ b/node-core/components/api_handlers.go @@ -22,7 +22,6 @@ package components import ( "cosmossdk.io/depinject" - "github.com/berachain/beacon-kit/node-api/engines/echo" "github.com/berachain/beacon-kit/node-api/handlers" beaconapi "github.com/berachain/beacon-kit/node-api/handlers/beacon" builderapi "github.com/berachain/beacon-kit/node-api/handlers/builder" @@ -44,8 +43,8 @@ type NodeAPIHandlersInput struct { ProofAPIHandler *proofapi.Handler } -func ProvideNodeAPIHandlers(in NodeAPIHandlersInput) []handlers.Handlers[echo.Context] { - return []handlers.Handlers[echo.Context]{ +func ProvideNodeAPIHandlers(in NodeAPIHandlersInput) []handlers.Handlers[handlers.Context] { + return []handlers.Handlers[handlers.Context]{ in.BeaconAPIHandler, in.BuilderAPIHandler, in.ConfigAPIHandler, From f91e75e6830971b066b20a64ea0dccc93c9675b0 Mon Sep 17 00:00:00 2001 From: aBear Date: Fri, 31 Jan 2025 22:46:49 -0500 Subject: [PATCH 12/13] simplified handlers.Context Signed-off-by: aBear --- node-api/engines/echo/engine.go | 5 +---- node-api/engines/echo/middleware.go | 4 +--- node-api/handlers/beacon/handler.go | 4 ++-- node-api/handlers/beacon/routes.go | 2 +- node-api/handlers/builder/handler.go | 4 ++-- node-api/handlers/builder/routes.go | 2 +- node-api/handlers/config/handler.go | 4 ++-- node-api/handlers/config/routes.go | 2 +- node-api/handlers/debug/handler.go | 4 ++-- node-api/handlers/debug/routes.go | 2 +- node-api/handlers/events/handler.go | 4 ++-- node-api/handlers/events/routes.go | 2 +- node-api/handlers/handlers.go | 28 ++++++++++++---------------- node-api/handlers/node/handler.go | 4 ++-- node-api/handlers/node/routes.go | 2 +- node-api/handlers/proof/handler.go | 4 ++-- node-api/handlers/proof/routes.go | 2 +- node-api/handlers/routes.go | 18 ++++++++---------- node-api/server/server.go | 2 +- node-api/server/types.go | 2 +- node-core/components/api.go | 2 +- node-core/components/api_handlers.go | 4 ++-- node-core/components/interfaces.go | 2 +- 23 files changed, 49 insertions(+), 60 deletions(-) diff --git a/node-api/engines/echo/engine.go b/node-api/engines/echo/engine.go index 17c1d2091d..0f240093ff 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[handlers.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 81b9c22780..fc20c8fec2 100644 --- a/node-api/engines/echo/middleware.go +++ b/node-api/engines/echo/middleware.go @@ -37,9 +37,7 @@ type ErrorResponse struct { // responseMiddleware is a middleware that converts errors to an HTTP status // code and response. -func responseMiddleware( - handler *handlers.Route[handlers.Context], -) echo.HandlerFunc { +func responseMiddleware(handler *handlers.Route) echo.HandlerFunc { return func(c handlers.Context) error { data, err := handler.Handler(c) code, response := responseFromError(data, err) diff --git a/node-api/handlers/beacon/handler.go b/node-api/handlers/beacon/handler.go index e23d909a57..8393e87fa3 100644 --- a/node-api/handlers/beacon/handler.go +++ b/node-api/handlers/beacon/handler.go @@ -26,7 +26,7 @@ import ( // Handler is the handler for the beacon API. type Handler struct { - *handlers.BaseHandler[handlers.Context] + *handlers.BaseHandler backend Backend } @@ -34,7 +34,7 @@ type Handler struct { func NewHandler(backend Backend) *Handler { h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[handlers.Context](""), + handlers.NewRouteSet(""), ), backend: backend, } diff --git a/node-api/handlers/beacon/routes.go b/node-api/handlers/beacon/routes.go index 2e49e7b05e..af11934197 100644 --- a/node-api/handlers/beacon/routes.go +++ b/node-api/handlers/beacon/routes.go @@ -32,7 +32,7 @@ func (h *Handler) RegisterRoutes( logger log.Logger, ) { h.SetLogger(logger) - h.BaseHandler.AddRoutes([]*handlers.Route[handlers.Context]{ + h.BaseHandler.AddRoutes([]*handlers.Route{ { Method: http.MethodGet, Path: "/eth/v1/beacon/genesis", diff --git a/node-api/handlers/builder/handler.go b/node-api/handlers/builder/handler.go index 7d04c09782..23f1d4e71f 100644 --- a/node-api/handlers/builder/handler.go +++ b/node-api/handlers/builder/handler.go @@ -25,13 +25,13 @@ import ( ) type Handler struct { - *handlers.BaseHandler[handlers.Context] + *handlers.BaseHandler } func NewHandler() *Handler { h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[handlers.Context](""), + handlers.NewRouteSet(""), ), } return h diff --git a/node-api/handlers/builder/routes.go b/node-api/handlers/builder/routes.go index 989b5a4dd0..9364856d47 100644 --- a/node-api/handlers/builder/routes.go +++ b/node-api/handlers/builder/routes.go @@ -29,7 +29,7 @@ import ( func (h *Handler) RegisterRoutes(logger log.Logger) { h.SetLogger(logger) - h.BaseHandler.AddRoutes([]*handlers.Route[handlers.Context]{ + 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 a117815146..2ab58b8ab0 100644 --- a/node-api/handlers/config/handler.go +++ b/node-api/handlers/config/handler.go @@ -23,13 +23,13 @@ package config import "github.com/berachain/beacon-kit/node-api/handlers" type Handler struct { - *handlers.BaseHandler[handlers.Context] + *handlers.BaseHandler } func NewHandler() *Handler { h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[handlers.Context](""), + handlers.NewRouteSet(""), ), } return h diff --git a/node-api/handlers/config/routes.go b/node-api/handlers/config/routes.go index fe8070fce6..3e24816668 100644 --- a/node-api/handlers/config/routes.go +++ b/node-api/handlers/config/routes.go @@ -29,7 +29,7 @@ import ( func (h *Handler) RegisterRoutes(logger log.Logger) { h.SetLogger(logger) - h.BaseHandler.AddRoutes([]*handlers.Route[handlers.Context]{ + 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 4f7393870e..c6a2c8f6d1 100644 --- a/node-api/handlers/debug/handler.go +++ b/node-api/handlers/debug/handler.go @@ -24,7 +24,7 @@ import "github.com/berachain/beacon-kit/node-api/handlers" // Handler is the handler for the beacon API. type Handler struct { - *handlers.BaseHandler[handlers.Context] + *handlers.BaseHandler backend Backend } @@ -32,7 +32,7 @@ type Handler struct { func NewHandler(backend Backend) *Handler { h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[handlers.Context](""), + handlers.NewRouteSet(""), ), backend: backend, } diff --git a/node-api/handlers/debug/routes.go b/node-api/handlers/debug/routes.go index 712c9ec2e9..ba23caf66f 100644 --- a/node-api/handlers/debug/routes.go +++ b/node-api/handlers/debug/routes.go @@ -29,7 +29,7 @@ import ( func (h *Handler) RegisterRoutes(logger log.Logger) { h.SetLogger(logger) - h.BaseHandler.AddRoutes([]*handlers.Route[handlers.Context]{ + h.BaseHandler.AddRoutes([]*handlers.Route{ { Method: http.MethodGet, Path: "/eth/v2/debug/beacon/states/:state_id", diff --git a/node-api/handlers/events/handler.go b/node-api/handlers/events/handler.go index 402ed7ef31..ba1f2a5b18 100644 --- a/node-api/handlers/events/handler.go +++ b/node-api/handlers/events/handler.go @@ -23,13 +23,13 @@ package events import "github.com/berachain/beacon-kit/node-api/handlers" type Handler struct { - *handlers.BaseHandler[handlers.Context] + *handlers.BaseHandler } func NewHandler() *Handler { h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[handlers.Context](""), + handlers.NewRouteSet(""), ), } return h diff --git a/node-api/handlers/events/routes.go b/node-api/handlers/events/routes.go index d8ede565db..e9f0f2382a 100644 --- a/node-api/handlers/events/routes.go +++ b/node-api/handlers/events/routes.go @@ -29,7 +29,7 @@ import ( func (h *Handler) RegisterRoutes(logger log.Logger) { h.SetLogger(logger) - h.BaseHandler.AddRoutes([]*handlers.Route[handlers.Context]{ + 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 ebc8247f7a..48fd85f99b 100644 --- a/node-api/handlers/handlers.go +++ b/node-api/handlers/handlers.go @@ -29,54 +29,50 @@ import ( 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 cb93075f39..e64d8c84ed 100644 --- a/node-api/handlers/node/handler.go +++ b/node-api/handlers/node/handler.go @@ -23,13 +23,13 @@ package node import "github.com/berachain/beacon-kit/node-api/handlers" type Handler struct { - *handlers.BaseHandler[handlers.Context] + *handlers.BaseHandler } func NewHandler() *Handler { h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[handlers.Context](""), + handlers.NewRouteSet(""), ), } return h diff --git a/node-api/handlers/node/routes.go b/node-api/handlers/node/routes.go index 79273f9ea0..419fca4b36 100644 --- a/node-api/handlers/node/routes.go +++ b/node-api/handlers/node/routes.go @@ -29,7 +29,7 @@ import ( func (h *Handler) RegisterRoutes(logger log.Logger) { h.SetLogger(logger) - h.BaseHandler.AddRoutes([]*handlers.Route[handlers.Context]{ + h.BaseHandler.AddRoutes([]*handlers.Route{ { Method: http.MethodGet, Path: "/eth/v1/node/identity", diff --git a/node-api/handlers/proof/handler.go b/node-api/handlers/proof/handler.go index 14ceec3928..1a86120aec 100644 --- a/node-api/handlers/proof/handler.go +++ b/node-api/handlers/proof/handler.go @@ -30,7 +30,7 @@ import ( // Handler is the handler for the proof API. type Handler struct { - *handlers.BaseHandler[handlers.Context] + *handlers.BaseHandler backend Backend } @@ -38,7 +38,7 @@ type Handler struct { func NewHandler(backend Backend) *Handler { h := &Handler{ BaseHandler: handlers.NewBaseHandler( - handlers.NewRouteSet[handlers.Context](""), + handlers.NewRouteSet(""), ), backend: backend, } diff --git a/node-api/handlers/proof/routes.go b/node-api/handlers/proof/routes.go index 0649375a67..15ebd540cd 100644 --- a/node-api/handlers/proof/routes.go +++ b/node-api/handlers/proof/routes.go @@ -29,7 +29,7 @@ import ( func (h *Handler) RegisterRoutes(logger log.Logger) { h.SetLogger(logger) - h.BaseHandler.AddRoutes([]*handlers.Route[handlers.Context]{ + 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 20617f0bbb..4e95198b9c 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 c33b7129fa..7b6cd1f658 100644 --- a/node-api/server/server.go +++ b/node-api/server/server.go @@ -42,7 +42,7 @@ func New( config Config, engine Engine[handlers.Context], logger log.Logger, - handlers ...handlers.Handlers[handlers.Context], + handlers ...handlers.Handlers, ) *Server { apiLogger := logger if !config.Logging { diff --git a/node-api/server/types.go b/node-api/server/types.go index 82ca1c1828..4d42d32923 100644 --- a/node-api/server/types.go +++ b/node-api/server/types.go @@ -29,5 +29,5 @@ import ( // Engine is a generic interface for an API engine. type Engine[ContextT context.Context] 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 33ef2197a0..26cb617139 100644 --- a/node-core/components/api.go +++ b/node-core/components/api.go @@ -62,7 +62,7 @@ type NodeAPIServerInput[ Engine NodeAPIEngine[handlers.Context] Config *config.Config - Handlers []handlers.Handlers[handlers.Context] + Handlers []handlers.Handlers Logger LoggerT } diff --git a/node-core/components/api_handlers.go b/node-core/components/api_handlers.go index 1b88ed0dfb..63e71bd390 100644 --- a/node-core/components/api_handlers.go +++ b/node-core/components/api_handlers.go @@ -43,8 +43,8 @@ type NodeAPIHandlersInput struct { ProofAPIHandler *proofapi.Handler } -func ProvideNodeAPIHandlers(in NodeAPIHandlersInput) []handlers.Handlers[handlers.Context] { - return []handlers.Handlers[handlers.Context]{ +func ProvideNodeAPIHandlers(in NodeAPIHandlersInput) []handlers.Handlers { + return []handlers.Handlers{ in.BeaconAPIHandler, in.BuilderAPIHandler, in.ConfigAPIHandler, diff --git a/node-core/components/interfaces.go b/node-core/components/interfaces.go index 9c780b1b2c..00902bb15b 100644 --- a/node-core/components/interfaces.go +++ b/node-core/components/interfaces.go @@ -735,7 +735,7 @@ type ( // Engine is a generic interface for an API engine. NodeAPIEngine[ContextT NodeAPIContext] interface { Run(addr string) error - RegisterRoutes(*handlers.RouteSet[ContextT], log.Logger) + RegisterRoutes(*handlers.RouteSet, log.Logger) } NodeAPIBackend interface { From 7bedccce536dc09f6d34f28f7156ae34eb8c1714 Mon Sep 17 00:00:00 2001 From: aBear Date: Fri, 31 Jan 2025 23:02:46 -0500 Subject: [PATCH 13/13] some more cleanup --- node-api/server/server.go | 4 ++-- node-api/server/types.go | 3 +-- node-core/components/api.go | 2 +- node-core/components/interfaces.go | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/node-api/server/server.go b/node-api/server/server.go index 7b6cd1f658..b23bc82625 100644 --- a/node-api/server/server.go +++ b/node-api/server/server.go @@ -30,7 +30,7 @@ import ( // Server is the API Server service. type Server struct { - engine Engine[handlers.Context] + engine Engine config Config logger log.Logger } @@ -40,7 +40,7 @@ type Server struct { // disabled. func New( config Config, - engine Engine[handlers.Context], + engine Engine, logger log.Logger, handlers ...handlers.Handlers, ) *Server { diff --git a/node-api/server/types.go b/node-api/server/types.go index 4d42d32923..284856caea 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, log.Logger) } diff --git a/node-core/components/api.go b/node-core/components/api.go index 26cb617139..3b6ed65647 100644 --- a/node-core/components/api.go +++ b/node-core/components/api.go @@ -60,7 +60,7 @@ type NodeAPIServerInput[ ] struct { depinject.In - Engine NodeAPIEngine[handlers.Context] + Engine NodeAPIEngine Config *config.Config Handlers []handlers.Handlers Logger LoggerT diff --git a/node-core/components/interfaces.go b/node-core/components/interfaces.go index 00902bb15b..5bea54fd6b 100644 --- a/node-core/components/interfaces.go +++ b/node-core/components/interfaces.go @@ -733,7 +733,7 @@ type ( } // Engine is a generic interface for an API engine. - NodeAPIEngine[ContextT NodeAPIContext] interface { + NodeAPIEngine interface { Run(addr string) error RegisterRoutes(*handlers.RouteSet, log.Logger) }