From 2e33595187fa8d2a4e808868f2942efc7f6c1ac9 Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Thu, 30 Apr 2020 20:47:10 -0500 Subject: [PATCH] Implement GetBeaconState Endpoint (#5668) * implement get beacon state * gaz * Merge branch 'master' into implement-debug-state * passing tests * enable with featureconfig * struct oder * Update beacon-chain/rpc/beacon/state.go * Merge refs/heads/master into implement-debug-state * lint resolve * Merge branch 'implement-debug-state' of github.com:prysmaticlabs/prysm into implement-debug-state * tested at runtime * fix build * Merge branch 'master' into implement-debug-state * Merge refs/heads/master into implement-debug-state * Merge refs/heads/master into implement-debug-state * Merge refs/heads/master into implement-debug-state * Merge refs/heads/master into implement-debug-state * Merge refs/heads/master into implement-debug-state * build and fmt * conf * Merge refs/heads/master into implement-debug-state * Merge refs/heads/master into implement-debug-state * Merge refs/heads/master into implement-debug-state * Merge refs/heads/master into implement-debug-state * Merge refs/heads/master into implement-debug-state --- beacon-chain/flags/base.go | 5 + beacon-chain/gateway/BUILD.bazel | 1 + beacon-chain/gateway/gateway.go | 56 ++++--- beacon-chain/gateway/server/main.go | 18 ++- beacon-chain/main.go | 1 + beacon-chain/node/node.go | 64 ++++---- beacon-chain/rpc/BUILD.bazel | 1 + beacon-chain/rpc/beacon/BUILD.bazel | 4 + beacon-chain/rpc/beacon/state.go | 39 +++++ beacon-chain/rpc/beacon/state_test.go | 80 ++++++++++ beacon-chain/rpc/service.go | 216 +++++++++++++------------- beacon-chain/usage.go | 1 + proto/beacon/rpc/v1/debug.proto | 3 - 13 files changed, 328 insertions(+), 161 deletions(-) create mode 100644 beacon-chain/rpc/beacon/state.go create mode 100644 beacon-chain/rpc/beacon/state_test.go diff --git a/beacon-chain/flags/base.go b/beacon-chain/flags/base.go index 6470cf9b3946..e4ef7e547abf 100644 --- a/beacon-chain/flags/base.go +++ b/beacon-chain/flags/base.go @@ -124,4 +124,9 @@ var ( Usage: "The amount of blocks the local peer is bounded to request and respond to in a batch.", Value: 64, } + // EnableDebugRPCEndpoints as /v1/beacon/state. + EnableDebugRPCEndpoints = &cli.BoolFlag{ + Name: "enable-debug-rpc-endpoints", + Usage: "Enables the debug rpc service, containing utility endpoints such as /eth/v1alpha1/beacon/state. Requires --new-state-mgmt", + } ) diff --git a/beacon-chain/gateway/BUILD.bazel b/beacon-chain/gateway/BUILD.bazel index edd85218bd23..130d6aa9c8d6 100644 --- a/beacon-chain/gateway/BUILD.bazel +++ b/beacon-chain/gateway/BUILD.bazel @@ -16,6 +16,7 @@ go_library( ], deps = [ "//shared:go_default_library", + "//proto/beacon/rpc/v1:go_grpc_gateway_library", "@com_github_prysmaticlabs_ethereumapis//eth/v1alpha1:go_grpc_gateway_library", "@com_github_rs_cors//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", diff --git a/beacon-chain/gateway/gateway.go b/beacon-chain/gateway/gateway.go index b1282ced9152..dcef54cd43c4 100644 --- a/beacon-chain/gateway/gateway.go +++ b/beacon-chain/gateway/gateway.go @@ -11,6 +11,7 @@ import ( gwruntime "github.com/grpc-ecosystem/grpc-gateway/runtime" ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1_gateway" + pbrpc "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1_gateway" "github.com/prysmaticlabs/prysm/shared" "google.golang.org/grpc" "google.golang.org/grpc/connectivity" @@ -21,16 +22,16 @@ var _ = shared.Service(&Gateway{}) // Gateway is the gRPC gateway to serve HTTP JSON traffic as a proxy and forward // it to the beacon-chain gRPC server. type Gateway struct { - conn *grpc.ClientConn - ctx context.Context - cancel context.CancelFunc - gatewayAddr string - remoteAddr string - server *http.Server - mux *http.ServeMux - allowedOrigins []string - - startFailure error + conn *grpc.ClientConn + ctx context.Context + cancel context.CancelFunc + gatewayAddr string + remoteAddr string + server *http.Server + mux *http.ServeMux + allowedOrigins []string + startFailure error + enableDebugRPCEndpoints bool } // Start the gateway service. This serves the HTTP JSON traffic on the specified @@ -50,12 +51,21 @@ func (g *Gateway) Start() { g.conn = conn - gwmux := gwruntime.NewServeMux(gwruntime.WithMarshalerOption(gwruntime.MIMEWildcard, &gwruntime.JSONPb{OrigName: false, EmitDefaults: true})) - for _, f := range []func(context.Context, *gwruntime.ServeMux, *grpc.ClientConn) error{ + gwmux := gwruntime.NewServeMux( + gwruntime.WithMarshalerOption( + gwruntime.MIMEWildcard, + &gwruntime.JSONPb{OrigName: false, EmitDefaults: true}, + ), + ) + handlers := []func(context.Context, *gwruntime.ServeMux, *grpc.ClientConn) error{ ethpb.RegisterNodeHandler, ethpb.RegisterBeaconChainHandler, ethpb.RegisterBeaconNodeValidatorHandler, - } { + } + if g.enableDebugRPCEndpoints { + handlers = append(handlers, pbrpc.RegisterDebugHandler) + } + for _, f := range handlers { if err := f(ctx, gwmux, conn); err != nil { log.WithError(err).Error("Failed to start gateway") g.startFailure = err @@ -108,17 +118,25 @@ func (g *Gateway) Stop() error { // New returns a new gateway server which translates HTTP into gRPC. // Accepts a context and optional http.ServeMux. -func New(ctx context.Context, remoteAddress, gatewayAddress string, mux *http.ServeMux, allowedOrigins []string) *Gateway { +func New( + ctx context.Context, + remoteAddress, + gatewayAddress string, + mux *http.ServeMux, + allowedOrigins []string, + enableDebugRPCEndpoints bool, +) *Gateway { if mux == nil { mux = http.NewServeMux() } return &Gateway{ - remoteAddr: remoteAddress, - gatewayAddr: gatewayAddress, - ctx: ctx, - mux: mux, - allowedOrigins: allowedOrigins, + remoteAddr: remoteAddress, + gatewayAddr: gatewayAddress, + ctx: ctx, + mux: mux, + allowedOrigins: allowedOrigins, + enableDebugRPCEndpoints: enableDebugRPCEndpoints, } } diff --git a/beacon-chain/gateway/server/main.go b/beacon-chain/gateway/server/main.go index 6cb37fa0e449..8174aa2c84b2 100644 --- a/beacon-chain/gateway/server/main.go +++ b/beacon-chain/gateway/server/main.go @@ -16,10 +16,11 @@ import ( ) var ( - beaconRPC = flag.String("beacon-rpc", "localhost:4000", "Beacon chain gRPC endpoint") - port = flag.Int("port", 8000, "Port to serve on") - debug = flag.Bool("debug", false, "Enable debug logging") - allowedOrigins = flag.String("corsdomain", "", "A comma separated list of CORS domains to allow") + beaconRPC = flag.String("beacon-rpc", "localhost:4000", "Beacon chain gRPC endpoint") + port = flag.Int("port", 8000, "Port to serve on") + debug = flag.Bool("debug", false, "Enable debug logging") + allowedOrigins = flag.String("corsdomain", "", "A comma separated list of CORS domains to allow") + enableDebugRPCEndpoints = flag.Bool("enable-debug-rpc-endpoints", false, "Enable debug rpc endpoints such as /eth/v1alpha1/beacon/state") ) func init() { @@ -35,7 +36,14 @@ func main() { } mux := http.NewServeMux() - gw := gateway.New(context.Background(), *beaconRPC, fmt.Sprintf("0.0.0.0:%d", *port), mux, strings.Split(*allowedOrigins, ",")) + gw := gateway.New( + context.Background(), + *beaconRPC, + fmt.Sprintf("0.0.0.0:%d", *port), + mux, + strings.Split(*allowedOrigins, ","), + *enableDebugRPCEndpoints, + ) mux.HandleFunc("/swagger/", gateway.SwaggerServer()) mux.HandleFunc("/healthz", healthzServer(gw)) gw.Start() diff --git a/beacon-chain/main.go b/beacon-chain/main.go index 0b09c753c066..bf4cde9efd71 100644 --- a/beacon-chain/main.go +++ b/beacon-chain/main.go @@ -50,6 +50,7 @@ var appFlags = []cli.Flag{ flags.ArchiveBlocksFlag, flags.ArchiveAttestationsFlag, flags.SlotsPerArchivedPoint, + flags.EnableDebugRPCEndpoints, cmd.BootstrapNode, cmd.NoDiscovery, cmd.StaticPeers, diff --git a/beacon-chain/node/node.go b/beacon-chain/node/node.go index 52710ccc4e23..acfa3a42f9ce 100644 --- a/beacon-chain/node/node.go +++ b/beacon-chain/node/node.go @@ -538,38 +538,40 @@ func (b *BeaconNode) registerRPCService() error { slasherCert := b.cliCtx.String(flags.SlasherCertFlag.Name) slasherProvider := b.cliCtx.String(flags.SlasherProviderFlag.Name) mockEth1DataVotes := b.cliCtx.Bool(flags.InteropMockEth1DataVotesFlag.Name) + enableDebugRPCEndpoints := b.cliCtx.Bool(flags.EnableDebugRPCEndpoints.Name) p2pService := b.fetchP2P() rpcService := rpc.NewService(b.ctx, &rpc.Config{ - Host: host, - Port: port, - CertFlag: cert, - KeyFlag: key, - BeaconDB: b.db, - Broadcaster: p2pService, - PeersFetcher: p2pService, - HeadFetcher: chainService, - ForkFetcher: chainService, - FinalizationFetcher: chainService, - ParticipationFetcher: chainService, - BlockReceiver: chainService, - AttestationReceiver: chainService, - GenesisTimeFetcher: chainService, - GenesisFetcher: chainService, - AttestationsPool: b.attestationPool, - ExitPool: b.exitPool, - SlashingsPool: b.slashingsPool, - POWChainService: web3Service, - ChainStartFetcher: chainStartFetcher, - MockEth1Votes: mockEth1DataVotes, - SyncService: syncService, - DepositFetcher: depositFetcher, - PendingDepositFetcher: b.depositCache, - BlockNotifier: b, - StateNotifier: b, - OperationNotifier: b, - SlasherCert: slasherCert, - SlasherProvider: slasherProvider, - StateGen: b.stateGen, + Host: host, + Port: port, + CertFlag: cert, + KeyFlag: key, + BeaconDB: b.db, + Broadcaster: p2pService, + PeersFetcher: p2pService, + HeadFetcher: chainService, + ForkFetcher: chainService, + FinalizationFetcher: chainService, + ParticipationFetcher: chainService, + BlockReceiver: chainService, + AttestationReceiver: chainService, + GenesisTimeFetcher: chainService, + GenesisFetcher: chainService, + AttestationsPool: b.attestationPool, + ExitPool: b.exitPool, + SlashingsPool: b.slashingsPool, + POWChainService: web3Service, + ChainStartFetcher: chainStartFetcher, + MockEth1Votes: mockEth1DataVotes, + SyncService: syncService, + DepositFetcher: depositFetcher, + PendingDepositFetcher: b.depositCache, + BlockNotifier: b, + StateNotifier: b, + OperationNotifier: b, + SlasherCert: slasherCert, + SlasherProvider: slasherProvider, + StateGen: b.stateGen, + EnableDebugRPCEndpoints: enableDebugRPCEndpoints, }) return b.services.RegisterService(rpcService) @@ -610,6 +612,7 @@ func (b *BeaconNode) registerGRPCGateway() error { selfAddress := fmt.Sprintf("127.0.0.1:%d", b.cliCtx.Int(flags.RPCPort.Name)) gatewayAddress := fmt.Sprintf("0.0.0.0:%d", gatewayPort) allowedOrigins := strings.Split(b.cliCtx.String(flags.GPRCGatewayCorsDomain.Name), ",") + enableDebugRPCEndpoints := b.cliCtx.Bool(flags.EnableDebugRPCEndpoints.Name) return b.services.RegisterService( gateway.New( b.ctx, @@ -617,6 +620,7 @@ func (b *BeaconNode) registerGRPCGateway() error { gatewayAddress, nil, /*optional mux*/ allowedOrigins, + enableDebugRPCEndpoints, ), ) } diff --git a/beacon-chain/rpc/BUILD.bazel b/beacon-chain/rpc/BUILD.bazel index a2e535554e96..36f47201313c 100644 --- a/beacon-chain/rpc/BUILD.bazel +++ b/beacon-chain/rpc/BUILD.bazel @@ -24,6 +24,7 @@ go_library( "//beacon-chain/state/stategen:go_default_library", "//beacon-chain/sync:go_default_library", "//proto/beacon/p2p/v1:go_default_library", + "//proto/beacon/rpc/v1:go_default_library", "//proto/slashing:go_default_library", "//shared/featureconfig:go_default_library", "//shared/params:go_default_library", diff --git a/beacon-chain/rpc/beacon/BUILD.bazel b/beacon-chain/rpc/beacon/BUILD.bazel index 387259b17cfa..ffc24663bdc6 100644 --- a/beacon-chain/rpc/beacon/BUILD.bazel +++ b/beacon-chain/rpc/beacon/BUILD.bazel @@ -10,6 +10,7 @@ go_library( "config.go", "server.go", "slashings.go", + "state.go", "validators.go", "validators_stream.go", ], @@ -37,6 +38,7 @@ go_library( "//beacon-chain/state/stategen:go_default_library", "//beacon-chain/state/stateutil:go_default_library", "//proto/beacon/p2p/v1:go_default_library", + "//proto/beacon/rpc/v1:go_default_library", "//shared/attestationutil:go_default_library", "//shared/bytesutil:go_default_library", "//shared/event:go_default_library", @@ -67,6 +69,7 @@ go_test( "committees_test.go", "config_test.go", "slashings_test.go", + "state_test.go", "validators_stream_test.go", "validators_test.go", ], @@ -92,6 +95,7 @@ go_test( "//beacon-chain/state:go_default_library", "//beacon-chain/state/stategen:go_default_library", "//proto/beacon/p2p/v1:go_default_library", + "//proto/beacon/rpc/v1:go_default_library", "//shared/attestationutil:go_default_library", "//shared/bytesutil:go_default_library", "//shared/featureconfig:go_default_library", diff --git a/beacon-chain/rpc/beacon/state.go b/beacon-chain/rpc/beacon/state.go new file mode 100644 index 000000000000..7b32c1de9095 --- /dev/null +++ b/beacon-chain/rpc/beacon/state.go @@ -0,0 +1,39 @@ +package beacon + +import ( + "context" + + pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" + pbrpc "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1" + "github.com/prysmaticlabs/prysm/shared/bytesutil" + "github.com/prysmaticlabs/prysm/shared/featureconfig" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +// GetBeaconState retrieves a beacon state +// from the beacon node by either a slot or block root. +func (bs *Server) GetBeaconState( + ctx context.Context, + req *pbrpc.BeaconStateRequest, +) (*pbp2p.BeaconState, error) { + if !featureconfig.Get().NewStateMgmt { + return nil, status.Error(codes.FailedPrecondition, "requires --enable-new-state-mgmt to function") + } + switch q := req.QueryFilter.(type) { + case *pbrpc.BeaconStateRequest_Slot: + st, err := bs.StateGen.StateBySlot(ctx, q.Slot) + if err != nil { + return nil, status.Errorf(codes.Internal, "could not compute state by slot: %v", err) + } + return st.CloneInnerState(), nil + case *pbrpc.BeaconStateRequest_BlockRoot: + st, err := bs.StateGen.StateByRoot(ctx, bytesutil.ToBytes32(q.BlockRoot)) + if err != nil { + return nil, status.Errorf(codes.Internal, "could not compute state by block root: %v", err) + } + return st.CloneInnerState(), nil + default: + return nil, status.Error(codes.InvalidArgument, "need to specify either a block root or slot to request state") + } +} diff --git a/beacon-chain/rpc/beacon/state_test.go b/beacon-chain/rpc/beacon/state_test.go new file mode 100644 index 000000000000..5484ea256edf --- /dev/null +++ b/beacon-chain/rpc/beacon/state_test.go @@ -0,0 +1,80 @@ +package beacon + +import ( + "context" + "testing" + + "github.com/gogo/protobuf/proto" + ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1" + "github.com/prysmaticlabs/go-ssz" + "github.com/prysmaticlabs/prysm/beacon-chain/cache" + dbTest "github.com/prysmaticlabs/prysm/beacon-chain/db/testing" + "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" + pbrpc "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1" + "github.com/prysmaticlabs/prysm/shared/featureconfig" + "github.com/prysmaticlabs/prysm/shared/testutil" +) + +func TestServer_GetBeaconState(t *testing.T) { + resetCfg := featureconfig.InitWithReset(&featureconfig.Flags{NewStateMgmt: true}) + defer resetCfg() + + db := dbTest.SetupDB(t) + defer dbTest.TeardownDB(t, db) + + ctx := context.Background() + st := testutil.NewBeaconState() + slot := uint64(100) + if err := st.SetSlot(slot); err != nil { + t.Fatal(err) + } + b := ðpb.SignedBeaconBlock{Block: ðpb.BeaconBlock{ + Slot: slot, + }} + if err := db.SaveBlock(ctx, b); err != nil { + t.Fatal(err) + } + gRoot, err := ssz.HashTreeRoot(b.Block) + if err != nil { + t.Fatal(err) + } + gen := stategen.New(db, cache.NewStateSummaryCache()) + if err := gen.SaveState(ctx, gRoot, st); err != nil { + t.Fatal(err) + } + if err := db.SaveState(ctx, st, gRoot); err != nil { + t.Fatal(err) + } + bs := &Server{ + BeaconDB: db, + StateGen: gen, + } + if _, err := bs.GetBeaconState(ctx, &pbrpc.BeaconStateRequest{}); err == nil { + t.Errorf("Expected error without a query filter, received nil") + } + req := &pbrpc.BeaconStateRequest{ + QueryFilter: &pbrpc.BeaconStateRequest_BlockRoot{ + BlockRoot: gRoot[:], + }, + } + res, err := bs.GetBeaconState(ctx, req) + if err != nil { + t.Fatal(err) + } + wanted := st.CloneInnerState() + if !proto.Equal(wanted, res) { + t.Errorf("Wanted %v, received %v", wanted, res) + } + req = &pbrpc.BeaconStateRequest{ + QueryFilter: &pbrpc.BeaconStateRequest_Slot{ + Slot: slot, + }, + } + res, err = bs.GetBeaconState(ctx, req) + if err != nil { + t.Fatal(err) + } + if !proto.Equal(wanted, res) { + t.Errorf("Wanted %v, received %v", wanted, res) + } +} diff --git a/beacon-chain/rpc/service.go b/beacon-chain/rpc/service.go index b5644a72a530..d97f4ab6f973 100644 --- a/beacon-chain/rpc/service.go +++ b/beacon-chain/rpc/service.go @@ -32,6 +32,7 @@ import ( "github.com/prysmaticlabs/prysm/beacon-chain/state/stategen" "github.com/prysmaticlabs/prysm/beacon-chain/sync" pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1" + pbrpc "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1" slashpb "github.com/prysmaticlabs/prysm/proto/slashing" "github.com/prysmaticlabs/prysm/shared/featureconfig" "github.com/prysmaticlabs/prysm/shared/params" @@ -52,80 +53,82 @@ func init() { // Service defining an RPC server for a beacon node. type Service struct { - ctx context.Context - cancel context.CancelFunc - beaconDB db.HeadAccessDatabase - headFetcher blockchain.HeadFetcher - forkFetcher blockchain.ForkFetcher - finalizationFetcher blockchain.FinalizationFetcher - participationFetcher blockchain.ParticipationFetcher - genesisTimeFetcher blockchain.TimeFetcher - genesisFetcher blockchain.GenesisFetcher - attestationReceiver blockchain.AttestationReceiver - blockReceiver blockchain.BlockReceiver - powChainService powchain.Chain - chainStartFetcher powchain.ChainStartFetcher - mockEth1Votes bool - attestationsPool attestations.Pool - exitPool *voluntaryexits.Pool - slashingsPool *slashings.Pool - syncService sync.Checker - host string - port string - listener net.Listener - withCert string - withKey string - grpcServer *grpc.Server - canonicalStateChan chan *pbp2p.BeaconState - incomingAttestation chan *ethpb.Attestation - credentialError error - p2p p2p.Broadcaster - peersFetcher p2p.PeersProvider - depositFetcher depositcache.DepositFetcher - pendingDepositFetcher depositcache.PendingDepositsFetcher - stateNotifier statefeed.Notifier - blockNotifier blockfeed.Notifier - operationNotifier opfeed.Notifier - slasherConn *grpc.ClientConn - slasherProvider string - slasherCert string - slasherCredentialError error - slasherClient slashpb.SlasherClient - stateGen *stategen.State + ctx context.Context + cancel context.CancelFunc + beaconDB db.HeadAccessDatabase + headFetcher blockchain.HeadFetcher + forkFetcher blockchain.ForkFetcher + finalizationFetcher blockchain.FinalizationFetcher + participationFetcher blockchain.ParticipationFetcher + genesisTimeFetcher blockchain.TimeFetcher + genesisFetcher blockchain.GenesisFetcher + attestationReceiver blockchain.AttestationReceiver + blockReceiver blockchain.BlockReceiver + powChainService powchain.Chain + chainStartFetcher powchain.ChainStartFetcher + mockEth1Votes bool + enableDebugRPCEndpoints bool + attestationsPool attestations.Pool + exitPool *voluntaryexits.Pool + slashingsPool *slashings.Pool + syncService sync.Checker + host string + port string + listener net.Listener + withCert string + withKey string + grpcServer *grpc.Server + canonicalStateChan chan *pbp2p.BeaconState + incomingAttestation chan *ethpb.Attestation + credentialError error + p2p p2p.Broadcaster + peersFetcher p2p.PeersProvider + depositFetcher depositcache.DepositFetcher + pendingDepositFetcher depositcache.PendingDepositsFetcher + stateNotifier statefeed.Notifier + blockNotifier blockfeed.Notifier + operationNotifier opfeed.Notifier + slasherConn *grpc.ClientConn + slasherProvider string + slasherCert string + slasherCredentialError error + slasherClient slashpb.SlasherClient + stateGen *stategen.State } // Config options for the beacon node RPC server. type Config struct { - Host string - Port string - CertFlag string - KeyFlag string - BeaconDB db.HeadAccessDatabase - HeadFetcher blockchain.HeadFetcher - ForkFetcher blockchain.ForkFetcher - FinalizationFetcher blockchain.FinalizationFetcher - ParticipationFetcher blockchain.ParticipationFetcher - AttestationReceiver blockchain.AttestationReceiver - BlockReceiver blockchain.BlockReceiver - POWChainService powchain.Chain - ChainStartFetcher powchain.ChainStartFetcher - GenesisTimeFetcher blockchain.TimeFetcher - GenesisFetcher blockchain.GenesisFetcher - MockEth1Votes bool - AttestationsPool attestations.Pool - ExitPool *voluntaryexits.Pool - SlashingsPool *slashings.Pool - SyncService sync.Checker - Broadcaster p2p.Broadcaster - PeersFetcher p2p.PeersProvider - DepositFetcher depositcache.DepositFetcher - PendingDepositFetcher depositcache.PendingDepositsFetcher - SlasherProvider string - SlasherCert string - StateNotifier statefeed.Notifier - BlockNotifier blockfeed.Notifier - OperationNotifier opfeed.Notifier - StateGen *stategen.State + Host string + Port string + CertFlag string + KeyFlag string + BeaconDB db.HeadAccessDatabase + HeadFetcher blockchain.HeadFetcher + ForkFetcher blockchain.ForkFetcher + FinalizationFetcher blockchain.FinalizationFetcher + ParticipationFetcher blockchain.ParticipationFetcher + AttestationReceiver blockchain.AttestationReceiver + BlockReceiver blockchain.BlockReceiver + POWChainService powchain.Chain + ChainStartFetcher powchain.ChainStartFetcher + GenesisTimeFetcher blockchain.TimeFetcher + GenesisFetcher blockchain.GenesisFetcher + EnableDebugRPCEndpoints bool + MockEth1Votes bool + AttestationsPool attestations.Pool + ExitPool *voluntaryexits.Pool + SlashingsPool *slashings.Pool + SyncService sync.Checker + Broadcaster p2p.Broadcaster + PeersFetcher p2p.PeersProvider + DepositFetcher depositcache.DepositFetcher + PendingDepositFetcher depositcache.PendingDepositsFetcher + SlasherProvider string + SlasherCert string + StateNotifier statefeed.Notifier + BlockNotifier blockfeed.Notifier + OperationNotifier opfeed.Notifier + StateGen *stategen.State } // NewService instantiates a new RPC service instance that will @@ -133,40 +136,41 @@ type Config struct { func NewService(ctx context.Context, cfg *Config) *Service { ctx, cancel := context.WithCancel(ctx) return &Service{ - ctx: ctx, - cancel: cancel, - beaconDB: cfg.BeaconDB, - headFetcher: cfg.HeadFetcher, - forkFetcher: cfg.ForkFetcher, - finalizationFetcher: cfg.FinalizationFetcher, - participationFetcher: cfg.ParticipationFetcher, - genesisTimeFetcher: cfg.GenesisTimeFetcher, - genesisFetcher: cfg.GenesisFetcher, - attestationReceiver: cfg.AttestationReceiver, - blockReceiver: cfg.BlockReceiver, - p2p: cfg.Broadcaster, - peersFetcher: cfg.PeersFetcher, - powChainService: cfg.POWChainService, - chainStartFetcher: cfg.ChainStartFetcher, - mockEth1Votes: cfg.MockEth1Votes, - attestationsPool: cfg.AttestationsPool, - exitPool: cfg.ExitPool, - slashingsPool: cfg.SlashingsPool, - syncService: cfg.SyncService, - host: cfg.Host, - port: cfg.Port, - withCert: cfg.CertFlag, - withKey: cfg.KeyFlag, - depositFetcher: cfg.DepositFetcher, - pendingDepositFetcher: cfg.PendingDepositFetcher, - canonicalStateChan: make(chan *pbp2p.BeaconState, params.BeaconConfig().DefaultBufferSize), - incomingAttestation: make(chan *ethpb.Attestation, params.BeaconConfig().DefaultBufferSize), - stateNotifier: cfg.StateNotifier, - blockNotifier: cfg.BlockNotifier, - operationNotifier: cfg.OperationNotifier, - slasherProvider: cfg.SlasherProvider, - slasherCert: cfg.SlasherCert, - stateGen: cfg.StateGen, + ctx: ctx, + cancel: cancel, + beaconDB: cfg.BeaconDB, + headFetcher: cfg.HeadFetcher, + forkFetcher: cfg.ForkFetcher, + finalizationFetcher: cfg.FinalizationFetcher, + participationFetcher: cfg.ParticipationFetcher, + genesisTimeFetcher: cfg.GenesisTimeFetcher, + genesisFetcher: cfg.GenesisFetcher, + attestationReceiver: cfg.AttestationReceiver, + blockReceiver: cfg.BlockReceiver, + p2p: cfg.Broadcaster, + peersFetcher: cfg.PeersFetcher, + powChainService: cfg.POWChainService, + chainStartFetcher: cfg.ChainStartFetcher, + mockEth1Votes: cfg.MockEth1Votes, + attestationsPool: cfg.AttestationsPool, + exitPool: cfg.ExitPool, + slashingsPool: cfg.SlashingsPool, + syncService: cfg.SyncService, + host: cfg.Host, + port: cfg.Port, + withCert: cfg.CertFlag, + withKey: cfg.KeyFlag, + depositFetcher: cfg.DepositFetcher, + pendingDepositFetcher: cfg.PendingDepositFetcher, + canonicalStateChan: make(chan *pbp2p.BeaconState, params.BeaconConfig().DefaultBufferSize), + incomingAttestation: make(chan *ethpb.Attestation, params.BeaconConfig().DefaultBufferSize), + stateNotifier: cfg.StateNotifier, + blockNotifier: cfg.BlockNotifier, + operationNotifier: cfg.OperationNotifier, + slasherProvider: cfg.SlasherProvider, + slasherCert: cfg.SlasherCert, + stateGen: cfg.StateGen, + enableDebugRPCEndpoints: cfg.EnableDebugRPCEndpoints, } } @@ -270,6 +274,10 @@ func (s *Service) Start() { } ethpb.RegisterNodeServer(s.grpcServer, nodeServer) ethpb.RegisterBeaconChainServer(s.grpcServer, beaconChainServer) + if s.enableDebugRPCEndpoints { + log.Info("Enabled debug RPC endpoints") + pbrpc.RegisterDebugServer(s.grpcServer, beaconChainServer) + } ethpb.RegisterBeaconNodeValidatorServer(s.grpcServer, validatorServer) // Register reflection service on gRPC server. diff --git a/beacon-chain/usage.go b/beacon-chain/usage.go index 916fc5405cf9..33473af8b22a 100644 --- a/beacon-chain/usage.go +++ b/beacon-chain/usage.go @@ -94,6 +94,7 @@ var appHelpFlagGroups = []flagGroup{ flags.SlotsPerArchivedPoint, flags.DisableDiscv5, flags.BlockBatchLimit, + flags.EnableDebugRPCEndpoints, }, }, { diff --git a/proto/beacon/rpc/v1/debug.proto b/proto/beacon/rpc/v1/debug.proto index cf4b037b285e..289468f1d154 100644 --- a/proto/beacon/rpc/v1/debug.proto +++ b/proto/beacon/rpc/v1/debug.proto @@ -26,8 +26,5 @@ message BeaconStateRequest { // The block root corresponding to a desired beacon state. bytes block_root = 2; - - // The state root corresponding to a desired beacon state. - bytes state_root = 3; } } \ No newline at end of file