diff --git a/beacon-chain/rpc/BUILD.bazel b/beacon-chain/rpc/BUILD.bazel index 0c233eba64..1c7813d31a 100644 --- a/beacon-chain/rpc/BUILD.bazel +++ b/beacon-chain/rpc/BUILD.bazel @@ -87,6 +87,7 @@ go_test( "//beacon-chain/execution/testing:go_default_library", "//beacon-chain/startup:go_default_library", "//beacon-chain/sync/initial-sync/testing:go_default_library", + "//config/features:go_default_library", "//testing/assert:go_default_library", "//testing/require:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", diff --git a/beacon-chain/rpc/endpoints.go b/beacon-chain/rpc/endpoints.go index 0b3add8626..1607ef5919 100644 --- a/beacon-chain/rpc/endpoints.go +++ b/beacon-chain/rpc/endpoints.go @@ -22,6 +22,7 @@ import ( validatorv1alpha1 "github.com/OffchainLabs/prysm/v6/beacon-chain/rpc/prysm/v1alpha1/validator" validatorprysm "github.com/OffchainLabs/prysm/v6/beacon-chain/rpc/prysm/validator" "github.com/OffchainLabs/prysm/v6/beacon-chain/state/stategen" + "github.com/OffchainLabs/prysm/v6/config/features" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" ) @@ -95,14 +96,19 @@ func (s *Service) endpoints( endpoints = append(endpoints, s.nodeEndpoints()...) endpoints = append(endpoints, s.beaconEndpoints(ch, stater, blocker, validatorServer, coreService)...) endpoints = append(endpoints, s.configEndpoints()...) - endpoints = append(endpoints, s.lightClientEndpoints(blocker, stater)...) endpoints = append(endpoints, s.eventsEndpoints()...) endpoints = append(endpoints, s.prysmBeaconEndpoints(ch, stater, coreService)...) endpoints = append(endpoints, s.prysmNodeEndpoints()...) endpoints = append(endpoints, s.prysmValidatorEndpoints(stater, coreService)...) + + if features.Get().EnableLightClient { + endpoints = append(endpoints, s.lightClientEndpoints(blocker, stater)...) + } + if enableDebug { endpoints = append(endpoints, s.debugEndpoints(stater)...) } + return endpoints } diff --git a/beacon-chain/rpc/endpoints_test.go b/beacon-chain/rpc/endpoints_test.go index 6b3aab4289..cf6487e0be 100644 --- a/beacon-chain/rpc/endpoints_test.go +++ b/beacon-chain/rpc/endpoints_test.go @@ -6,6 +6,7 @@ import ( "slices" "testing" + "github.com/OffchainLabs/prysm/v6/config/features" "github.com/OffchainLabs/prysm/v6/testing/assert" ) @@ -139,27 +140,56 @@ func Test_endpoints(t *testing.T) { "/prysm/v1/validators/{state_id}/active_set_changes": {http.MethodGet}, } - s := &Service{cfg: &Config{}} - - endpoints := s.endpoints(true, nil, nil, nil, nil, nil, nil) - actualRoutes := make(map[string][]string, len(endpoints)) - for _, e := range endpoints { - if _, ok := actualRoutes[e.template]; ok { - actualRoutes[e.template] = append(actualRoutes[e.template], e.methods...) - } else { - actualRoutes[e.template] = e.methods - } - } - expectedRoutes := make(map[string][]string) - for _, m := range []map[string][]string{ - beaconRoutes, builderRoutes, configRoutes, debugRoutes, eventsRoutes, - nodeRoutes, validatorRoutes, rewardsRoutes, lightClientRoutes, blobRoutes, - prysmValidatorRoutes, prysmNodeRoutes, prysmBeaconRoutes, - } { - maps.Copy(expectedRoutes, m) + testCases := []struct { + name string + flag *features.Flags + additionalExpectedRoutes []map[string][]string + }{ + { + name: "no flags", + }, + { + name: "light client enabled", + flag: &features.Flags{ + EnableLightClient: true, + }, + additionalExpectedRoutes: []map[string][]string{ + lightClientRoutes, + }, + }, } - assert.Equal(t, true, maps.EqualFunc(expectedRoutes, actualRoutes, func(actualMethods []string, expectedMethods []string) bool { - return slices.Equal(expectedMethods, actualMethods) - })) + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + resetFn := features.InitWithReset(tc.flag) + defer resetFn() + + s := &Service{cfg: &Config{}} + + endpoints := s.endpoints(true, nil, nil, nil, nil, nil, nil) + actualRoutes := make(map[string][]string, len(endpoints)) + for _, e := range endpoints { + if _, ok := actualRoutes[e.template]; ok { + actualRoutes[e.template] = append(actualRoutes[e.template], e.methods...) + } else { + actualRoutes[e.template] = e.methods + } + } + expectedRoutes := make(map[string][]string) + for _, m := range []map[string][]string{ + beaconRoutes, builderRoutes, configRoutes, debugRoutes, eventsRoutes, + nodeRoutes, validatorRoutes, rewardsRoutes, blobRoutes, + prysmValidatorRoutes, prysmNodeRoutes, prysmBeaconRoutes, + } { + maps.Copy(expectedRoutes, m) + } + for _, m := range tc.additionalExpectedRoutes { + maps.Copy(expectedRoutes, m) + } + + assert.Equal(t, true, maps.EqualFunc(expectedRoutes, actualRoutes, func(actualMethods []string, expectedMethods []string) bool { + return slices.Equal(expectedMethods, actualMethods) + })) + }) + } } diff --git a/beacon-chain/rpc/eth/light-client/BUILD.bazel b/beacon-chain/rpc/eth/light-client/BUILD.bazel index bde907b915..643abd1bf0 100644 --- a/beacon-chain/rpc/eth/light-client/BUILD.bazel +++ b/beacon-chain/rpc/eth/light-client/BUILD.bazel @@ -17,7 +17,6 @@ go_library( "//beacon-chain/db:go_default_library", "//beacon-chain/rpc/eth/shared:go_default_library", "//beacon-chain/rpc/lookup:go_default_library", - "//config/features:go_default_library", "//config/params:go_default_library", "//encoding/bytesutil:go_default_library", "//monitoring/tracing/trace:go_default_library", @@ -44,7 +43,6 @@ go_test( "//beacon-chain/core/light-client:go_default_library", "//beacon-chain/db/testing:go_default_library", "//beacon-chain/state:go_default_library", - "//config/features:go_default_library", "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//consensus-types/interfaces:go_default_library", diff --git a/beacon-chain/rpc/eth/light-client/handlers.go b/beacon-chain/rpc/eth/light-client/handlers.go index 93586819a5..428a03f7d5 100644 --- a/beacon-chain/rpc/eth/light-client/handlers.go +++ b/beacon-chain/rpc/eth/light-client/handlers.go @@ -8,7 +8,6 @@ import ( "github.com/OffchainLabs/prysm/v6/api/server/structs" "github.com/OffchainLabs/prysm/v6/beacon-chain/core/signing" "github.com/OffchainLabs/prysm/v6/beacon-chain/rpc/eth/shared" - "github.com/OffchainLabs/prysm/v6/config/features" "github.com/OffchainLabs/prysm/v6/config/params" "github.com/OffchainLabs/prysm/v6/encoding/bytesutil" "github.com/OffchainLabs/prysm/v6/monitoring/tracing/trace" @@ -22,11 +21,6 @@ import ( // GetLightClientBootstrap - implements https://github.com/ethereum/beacon-APIs/blob/263f4ed6c263c967f13279c7a9f5629b51c5fc55/apis/beacon/light_client/bootstrap.yaml func (s *Server) GetLightClientBootstrap(w http.ResponseWriter, req *http.Request) { - if !features.Get().EnableLightClient { - httputil.HandleError(w, "Light client feature flag is not enabled", http.StatusNotFound) - return - } - // Prepare ctx, span := trace.StartSpan(req.Context(), "beacon.GetLightClientBootstrap") defer span.End() @@ -74,11 +68,6 @@ func (s *Server) GetLightClientBootstrap(w http.ResponseWriter, req *http.Reques // GetLightClientUpdatesByRange - implements https://github.com/ethereum/beacon-APIs/blob/263f4ed6c263c967f13279c7a9f5629b51c5fc55/apis/beacon/light_client/updates.yaml func (s *Server) GetLightClientUpdatesByRange(w http.ResponseWriter, req *http.Request) { - if !features.Get().EnableLightClient { - httputil.HandleError(w, "Light client feature flag is not enabled", http.StatusNotFound) - return - } - ctx, span := trace.StartSpan(req.Context(), "beacon.GetLightClientUpdatesByRange") defer span.End() @@ -187,11 +176,6 @@ func (s *Server) GetLightClientUpdatesByRange(w http.ResponseWriter, req *http.R // GetLightClientFinalityUpdate - implements https://github.com/ethereum/beacon-APIs/blob/263f4ed6c263c967f13279c7a9f5629b51c5fc55/apis/beacon/light_client/finality_update.yaml func (s *Server) GetLightClientFinalityUpdate(w http.ResponseWriter, req *http.Request) { - if !features.Get().EnableLightClient { - httputil.HandleError(w, "Light client feature flag is not enabled", http.StatusNotFound) - return - } - _, span := trace.StartSpan(req.Context(), "beacon.GetLightClientFinalityUpdate") defer span.End() @@ -225,11 +209,6 @@ func (s *Server) GetLightClientFinalityUpdate(w http.ResponseWriter, req *http.R // GetLightClientOptimisticUpdate - implements https://github.com/ethereum/beacon-APIs/blob/263f4ed6c263c967f13279c7a9f5629b51c5fc55/apis/beacon/light_client/optimistic_update.yaml func (s *Server) GetLightClientOptimisticUpdate(w http.ResponseWriter, req *http.Request) { - if !features.Get().EnableLightClient { - httputil.HandleError(w, "Light client feature flag is not enabled", http.StatusNotFound) - return - } - _, span := trace.StartSpan(req.Context(), "beacon.GetLightClientOptimisticUpdate") defer span.End() diff --git a/beacon-chain/rpc/eth/light-client/handlers_test.go b/beacon-chain/rpc/eth/light-client/handlers_test.go index 7d82ba0693..e390ff0194 100644 --- a/beacon-chain/rpc/eth/light-client/handlers_test.go +++ b/beacon-chain/rpc/eth/light-client/handlers_test.go @@ -17,7 +17,6 @@ import ( lightclient "github.com/OffchainLabs/prysm/v6/beacon-chain/core/light-client" dbtesting "github.com/OffchainLabs/prysm/v6/beacon-chain/db/testing" "github.com/OffchainLabs/prysm/v6/beacon-chain/state" - "github.com/OffchainLabs/prysm/v6/config/features" fieldparams "github.com/OffchainLabs/prysm/v6/config/fieldparams" "github.com/OffchainLabs/prysm/v6/config/params" "github.com/OffchainLabs/prysm/v6/consensus-types/interfaces" @@ -34,11 +33,6 @@ import ( ) func TestLightClientHandler_GetLightClientBootstrap(t *testing.T) { - resetFn := features.InitWithReset(&features.Flags{ - EnableLightClient: true, - }) - defer resetFn() - params.SetupTestConfigCleanup(t) cfg := params.BeaconConfig() cfg.AltairForkEpoch = 0 @@ -454,11 +448,6 @@ func TestLightClientHandler_GetLightClientBootstrap(t *testing.T) { } func TestLightClientHandler_GetLightClientByRange(t *testing.T) { - resetFn := features.InitWithReset(&features.Flags{ - EnableLightClient: true, - }) - defer resetFn() - helpers.ClearCache() ctx := context.Background() @@ -1501,10 +1490,6 @@ func TestLightClientHandler_GetLightClientByRange(t *testing.T) { } func TestLightClientHandler_GetLightClientFinalityUpdate(t *testing.T) { - resetFn := features.InitWithReset(&features.Flags{ - EnableLightClient: true, - }) - defer resetFn() helpers.ClearCache() t.Run("no update", func(t *testing.T) { @@ -1589,10 +1574,6 @@ func TestLightClientHandler_GetLightClientFinalityUpdate(t *testing.T) { } func TestLightClientHandler_GetLightClientOptimisticUpdate(t *testing.T) { - resetFn := features.InitWithReset(&features.Flags{ - EnableLightClient: true, - }) - defer resetFn() helpers.ClearCache() t.Run("no update", func(t *testing.T) { diff --git a/changelog/bastin_lc-rpc-endpoint-flag.md b/changelog/bastin_lc-rpc-endpoint-flag.md new file mode 100644 index 0000000000..9b18d7543e --- /dev/null +++ b/changelog/bastin_lc-rpc-endpoint-flag.md @@ -0,0 +1,3 @@ +### Ignored + +- Put the light client beacon api endpoints behind a flag \ No newline at end of file