mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 13:28:01 -05:00
Add Endpoint to Return Current Chain Config Parameters (#4595)
* add patch and endpoint * formatting * Merge branch 'master' into chain-config-endpoint * Merge branch 'master' into chain-config-endpoint * include beacon config * config params * Merge branch 'chain-config-endpoint' of github.com:prysmaticlabs/prysm into chain-config-endpoint * include tests * resolve confs * use patch * Merge branch 'master' into chain-config-endpoint * passing tests * Merge branch 'chain-config-endpoint' of github.com:prysmaticlabs/prysm into chain-config-endpoint * Merge branch 'master' into chain-config-endpoint * Merge branch 'master' into chain-config-endpoint * Merge refs/heads/master into chain-config-endpoint
This commit is contained in:
@@ -1261,7 +1261,7 @@ go_repository(
|
||||
|
||||
go_repository(
|
||||
name = "com_github_prysmaticlabs_ethereumapis",
|
||||
commit = "e1e8777cb75e9dd568c1a8e096b0497bfe37d631",
|
||||
commit = "c2c488463094ba91ed5d8f147a0abbabb1220d10",
|
||||
importpath = "github.com/prysmaticlabs/ethereumapis",
|
||||
patch_args = ["-p1"],
|
||||
patches = [
|
||||
|
||||
@@ -48,6 +48,7 @@ go_test(
|
||||
"attestations_test.go",
|
||||
"blocks_test.go",
|
||||
"committees_test.go",
|
||||
"config_test.go",
|
||||
"validators_test.go",
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
|
||||
@@ -2,14 +2,24 @@ package beacon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
ptypes "github.com/gogo/protobuf/types"
|
||||
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
)
|
||||
|
||||
// GetBeaconConfig returns the configuration of the beacon chain as understood by this node.
|
||||
// GetBeaconConfig retrieves the current configuration parameters of the beacon chain.
|
||||
func (bs *Server) GetBeaconConfig(ctx context.Context, _ *ptypes.Empty) (*ethpb.BeaconConfig, error) {
|
||||
return nil, status.Error(codes.Internal, "not implemented")
|
||||
conf := params.BeaconConfig()
|
||||
val := reflect.ValueOf(conf).Elem()
|
||||
numFields := val.Type().NumField()
|
||||
res := make(map[string]string, numFields)
|
||||
for i := 0; i < numFields; i++ {
|
||||
res[val.Type().Field(i).Name] = fmt.Sprintf("%v", val.Field(i).Interface())
|
||||
}
|
||||
return ðpb.BeaconConfig{
|
||||
Config: res,
|
||||
}, nil
|
||||
}
|
||||
|
||||
37
beacon-chain/rpc/beacon/config_test.go
Normal file
37
beacon-chain/rpc/beacon/config_test.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package beacon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
ptypes "github.com/gogo/protobuf/types"
|
||||
dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
||||
"github.com/prysmaticlabs/prysm/shared/params"
|
||||
)
|
||||
|
||||
func TestServer_GetBeaconConfig(t *testing.T) {
|
||||
db := dbTest.SetupDB(t)
|
||||
defer dbTest.TeardownDB(t, db)
|
||||
|
||||
ctx := context.Background()
|
||||
bs := &Server{}
|
||||
res, err := bs.GetBeaconConfig(ctx, &ptypes.Empty{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
conf := params.BeaconConfig()
|
||||
numFields := reflect.TypeOf(conf).Elem().NumField()
|
||||
|
||||
// Check if the result has the same number of items as our config struct.
|
||||
if len(res.Config) != numFields {
|
||||
t.Errorf("Expected %d items in config result, got %d", numFields, len(res.Config))
|
||||
}
|
||||
want := fmt.Sprintf("%d", conf.Eth1FollowDistance)
|
||||
|
||||
// Check that an element is properly populated from the config.
|
||||
if res.Config["Eth1FollowDistance"] != want {
|
||||
t.Errorf("Wanted %s for eth1 follow distance, received %s", want, res.Config["Eth1FollowDistance"])
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
diff --git a/eth/v1alpha1/BUILD.bazel b/eth/v1alpha1/BUILD.bazel
|
||||
index da955b2..981daa5 100644
|
||||
index c0fbe31..ae4ff87 100644
|
||||
--- a/eth/v1alpha1/BUILD.bazel
|
||||
+++ b/eth/v1alpha1/BUILD.bazel
|
||||
@@ -10,15 +10,14 @@ proto_library(
|
||||
@@ -25,7 +25,6 @@ proto_library(
|
||||
"beacon_chain.proto",
|
||||
"node.proto",
|
||||
"validator.proto",
|
||||
@@ -10,16 +10,15 @@ index da955b2..981daa5 100644
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
- "@grpc_ecosystem_grpc_gateway//protoc-gen-swagger/options:options_proto",
|
||||
"@com_google_protobuf//:empty_proto",
|
||||
@@ -33,6 +32,7 @@ proto_library(
|
||||
"@com_google_protobuf//:any_proto",
|
||||
"@com_google_protobuf//:timestamp_proto",
|
||||
"@go_googleapis//google/api:annotations_proto",
|
||||
+ "@gogo_special_proto//github.com/gogo/protobuf/gogoproto",
|
||||
"@grpc_ecosystem_grpc_gateway//protoc-gen-swagger/options:options_proto",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -40,12 +39,30 @@ load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
|
||||
@@ -48,11 +48,30 @@ java_proto_library(
|
||||
|
||||
go_proto_library(
|
||||
name = "go_proto",
|
||||
@@ -29,7 +28,6 @@ index da955b2..981daa5 100644
|
||||
proto = ":proto",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
- "@grpc_ecosystem_grpc_gateway//protoc-gen-swagger/options:options_go_proto",
|
||||
+ "@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
+ "@go_googleapis//google/api:annotations_go_proto",
|
||||
+ ],
|
||||
@@ -50,38 +48,8 @@ index da955b2..981daa5 100644
|
||||
+ "@com_github_golang_protobuf//ptypes/empty:go_default_library",
|
||||
+ "@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||
"@go_googleapis//google/api:annotations_go_proto",
|
||||
"@grpc_ecosystem_grpc_gateway//protoc-gen-swagger/options:options_go_proto",
|
||||
],
|
||||
)
|
||||
@@ -56,29 +73,3 @@ go_library(
|
||||
importpath = "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1",
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
-
|
||||
-##############################################################################
|
||||
-# OpenAPI (Swagger) V2
|
||||
-##############################################################################
|
||||
-load("@grpc_ecosystem_grpc_gateway//protoc-gen-swagger:defs.bzl", "protoc_gen_swagger")
|
||||
-
|
||||
-protoc_gen_swagger(
|
||||
- name = "swagger",
|
||||
- proto = ":proto",
|
||||
- visibility = ["//visibility:public"],
|
||||
- single_output = True,
|
||||
- json_names_for_fields = True,
|
||||
-)
|
||||
-
|
||||
-# Genrule for template subsitution.
|
||||
-# See documentation in //tools/replacer.
|
||||
-genrule(
|
||||
- name = "generated_swagger_proto",
|
||||
- srcs = [
|
||||
- "swagger.proto", # A go template compatibile file.
|
||||
- "swagger_description.md", # Replacement for description.
|
||||
- ],
|
||||
- outs = ["swagger_generated.proto"],
|
||||
- cmd = "$(location //tools/replacer) $(location swagger.proto) description=$(location swagger_description.md) > $(@)",
|
||||
- tools = ["//tools/replacer"],
|
||||
-)
|
||||
diff --git a/eth/v1alpha1/attestation.proto b/eth/v1alpha1/attestation.proto
|
||||
index b177b76..28b4b46 100644
|
||||
--- a/eth/v1alpha1/attestation.proto
|
||||
@@ -294,7 +262,7 @@ index 2ce5c34..4cbb276 100644
|
||||
+ bytes signature = 3 [(gogoproto.moretags) = "ssz-size:\"96\""];
|
||||
}
|
||||
diff --git a/eth/v1alpha1/beacon_chain.proto b/eth/v1alpha1/beacon_chain.proto
|
||||
index f060b0d..10bd8d0 100644
|
||||
index 111b867..183bc28 100644
|
||||
--- a/eth/v1alpha1/beacon_chain.proto
|
||||
+++ b/eth/v1alpha1/beacon_chain.proto
|
||||
@@ -15,6 +15,7 @@ syntax = "proto3";
|
||||
|
||||
Reference in New Issue
Block a user