mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Use a single rest handler (#13446)
This commit is contained in:
@@ -3,6 +3,7 @@ package accounts
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -10,6 +11,7 @@ import (
|
|||||||
grpcutil "github.com/prysmaticlabs/prysm/v4/api/grpc"
|
grpcutil "github.com/prysmaticlabs/prysm/v4/api/grpc"
|
||||||
"github.com/prysmaticlabs/prysm/v4/crypto/bls"
|
"github.com/prysmaticlabs/prysm/v4/crypto/bls"
|
||||||
"github.com/prysmaticlabs/prysm/v4/validator/accounts/wallet"
|
"github.com/prysmaticlabs/prysm/v4/validator/accounts/wallet"
|
||||||
|
beaconApi "github.com/prysmaticlabs/prysm/v4/validator/client/beacon-api"
|
||||||
iface "github.com/prysmaticlabs/prysm/v4/validator/client/iface"
|
iface "github.com/prysmaticlabs/prysm/v4/validator/client/iface"
|
||||||
nodeClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/node-client-factory"
|
nodeClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/node-client-factory"
|
||||||
validatorClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/validator-client-factory"
|
validatorClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/validator-client-factory"
|
||||||
@@ -80,14 +82,18 @@ func (acm *CLIManager) prepareBeaconClients(ctx context.Context) (*iface.Validat
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, errors.Wrapf(err, "could not dial endpoint %s", acm.beaconRPCProvider)
|
return nil, nil, errors.Wrapf(err, "could not dial endpoint %s", acm.beaconRPCProvider)
|
||||||
}
|
}
|
||||||
|
|
||||||
conn := validatorHelpers.NewNodeConnection(
|
conn := validatorHelpers.NewNodeConnection(
|
||||||
grpcConn,
|
grpcConn,
|
||||||
acm.beaconApiEndpoint,
|
acm.beaconApiEndpoint,
|
||||||
acm.beaconApiTimeout,
|
acm.beaconApiTimeout,
|
||||||
)
|
)
|
||||||
|
|
||||||
validatorClient := validatorClientFactory.NewValidatorClient(conn)
|
restHandler := &beaconApi.BeaconApiJsonRestHandler{
|
||||||
nodeClient := nodeClientFactory.NewNodeClient(conn)
|
HttpClient: http.Client{Timeout: acm.beaconApiTimeout},
|
||||||
|
Host: acm.beaconApiEndpoint,
|
||||||
|
}
|
||||||
|
validatorClient := validatorClientFactory.NewValidatorClient(conn, restHandler)
|
||||||
|
nodeClient := nodeClientFactory.NewNodeClient(conn, restHandler)
|
||||||
|
|
||||||
return &validatorClient, &nodeClient, nil
|
return &validatorClient, &nodeClient, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,8 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/golang/protobuf/ptypes/empty"
|
"github.com/golang/protobuf/ptypes/empty"
|
||||||
@@ -357,12 +355,7 @@ func (c beaconApiBeaconChainClient) GetValidatorParticipation(ctx context.Contex
|
|||||||
panic("beaconApiBeaconChainClient.GetValidatorParticipation is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.")
|
panic("beaconApiBeaconChainClient.GetValidatorParticipation is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiBeaconChainClientWithFallback.")
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBeaconApiBeaconChainClientWithFallback(host string, timeout time.Duration, fallbackClient iface.BeaconChainClient) iface.BeaconChainClient {
|
func NewBeaconApiBeaconChainClientWithFallback(jsonRestHandler JsonRestHandler, fallbackClient iface.BeaconChainClient) iface.BeaconChainClient {
|
||||||
jsonRestHandler := beaconApiJsonRestHandler{
|
|
||||||
httpClient: http.Client{Timeout: timeout},
|
|
||||||
host: host,
|
|
||||||
}
|
|
||||||
|
|
||||||
return &beaconApiBeaconChainClient{
|
return &beaconApiBeaconChainClient{
|
||||||
jsonRestHandler: jsonRestHandler,
|
jsonRestHandler: jsonRestHandler,
|
||||||
fallbackClient: fallbackClient,
|
fallbackClient: fallbackClient,
|
||||||
|
|||||||
@@ -2,9 +2,7 @@ package beacon_api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/golang/protobuf/ptypes/empty"
|
"github.com/golang/protobuf/ptypes/empty"
|
||||||
@@ -100,12 +98,7 @@ func (c *beaconApiNodeClient) ListPeers(ctx context.Context, in *empty.Empty) (*
|
|||||||
panic("beaconApiNodeClient.ListPeers is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiNodeClientWithFallback.")
|
panic("beaconApiNodeClient.ListPeers is not implemented. To use a fallback client, pass a fallback client as the last argument of NewBeaconApiNodeClientWithFallback.")
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNodeClientWithFallback(host string, timeout time.Duration, fallbackClient iface.NodeClient) iface.NodeClient {
|
func NewNodeClientWithFallback(jsonRestHandler JsonRestHandler, fallbackClient iface.NodeClient) iface.NodeClient {
|
||||||
jsonRestHandler := beaconApiJsonRestHandler{
|
|
||||||
httpClient: http.Client{Timeout: timeout},
|
|
||||||
host: host,
|
|
||||||
}
|
|
||||||
|
|
||||||
return &beaconApiNodeClient{
|
return &beaconApiNodeClient{
|
||||||
jsonRestHandler: jsonRestHandler,
|
jsonRestHandler: jsonRestHandler,
|
||||||
fallbackClient: fallbackClient,
|
fallbackClient: fallbackClient,
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package beacon_api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"net/http"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
@@ -23,12 +22,7 @@ type beaconApiValidatorClient struct {
|
|||||||
prysmBeaconChainCLient iface.PrysmBeaconChainClient
|
prysmBeaconChainCLient iface.PrysmBeaconChainClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBeaconApiValidatorClient(host string, timeout time.Duration) iface.ValidatorClient {
|
func NewBeaconApiValidatorClient(jsonRestHandler JsonRestHandler) iface.ValidatorClient {
|
||||||
jsonRestHandler := beaconApiJsonRestHandler{
|
|
||||||
httpClient: http.Client{Timeout: timeout},
|
|
||||||
host: host,
|
|
||||||
}
|
|
||||||
|
|
||||||
return &beaconApiValidatorClient{
|
return &beaconApiValidatorClient{
|
||||||
genesisProvider: beaconApiGenesisProvider{jsonRestHandler: jsonRestHandler},
|
genesisProvider: beaconApiGenesisProvider{jsonRestHandler: jsonRestHandler},
|
||||||
dutiesProvider: beaconApiDutiesProvider{jsonRestHandler: jsonRestHandler},
|
dutiesProvider: beaconApiDutiesProvider{jsonRestHandler: jsonRestHandler},
|
||||||
|
|||||||
@@ -13,29 +13,29 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type JsonRestHandler interface {
|
type JsonRestHandler interface {
|
||||||
Get(ctx context.Context, query string, resp interface{}) error
|
Get(ctx context.Context, endpoint string, resp interface{}) error
|
||||||
Post(ctx context.Context, endpoint string, headers map[string]string, data *bytes.Buffer, resp interface{}) error
|
Post(ctx context.Context, endpoint string, headers map[string]string, data *bytes.Buffer, resp interface{}) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type beaconApiJsonRestHandler struct {
|
type BeaconApiJsonRestHandler struct {
|
||||||
httpClient http.Client
|
HttpClient http.Client
|
||||||
host string
|
Host string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get sends a GET request and decodes the response body as a JSON object into the passed in object.
|
// Get sends a GET request and decodes the response body as a JSON object into the passed in object.
|
||||||
// If an HTTP error is returned, the body is decoded as a DefaultJsonError JSON object and returned as the first return value.
|
// If an HTTP error is returned, the body is decoded as a DefaultJsonError JSON object and returned as the first return value.
|
||||||
func (c beaconApiJsonRestHandler) Get(ctx context.Context, endpoint string, resp interface{}) error {
|
func (c BeaconApiJsonRestHandler) Get(ctx context.Context, endpoint string, resp interface{}) error {
|
||||||
if resp == nil {
|
if resp == nil {
|
||||||
return errors.New("resp is nil")
|
return errors.New("resp is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
url := c.host + endpoint
|
url := c.Host + endpoint
|
||||||
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "failed to create request for endpoint %s", url)
|
return errors.Wrapf(err, "failed to create request for endpoint %s", url)
|
||||||
}
|
}
|
||||||
|
|
||||||
httpResp, err := c.httpClient.Do(req)
|
httpResp, err := c.HttpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "failed to perform request for endpoint %s", url)
|
return errors.Wrapf(err, "failed to perform request for endpoint %s", url)
|
||||||
}
|
}
|
||||||
@@ -50,7 +50,7 @@ func (c beaconApiJsonRestHandler) Get(ctx context.Context, endpoint string, resp
|
|||||||
|
|
||||||
// Post sends a POST request and decodes the response body as a JSON object into the passed in object.
|
// Post sends a POST request and decodes the response body as a JSON object into the passed in object.
|
||||||
// If an HTTP error is returned, the body is decoded as a DefaultJsonError JSON object and returned as the first return value.
|
// If an HTTP error is returned, the body is decoded as a DefaultJsonError JSON object and returned as the first return value.
|
||||||
func (c beaconApiJsonRestHandler) Post(
|
func (c BeaconApiJsonRestHandler) Post(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
apiEndpoint string,
|
apiEndpoint string,
|
||||||
headers map[string]string,
|
headers map[string]string,
|
||||||
@@ -61,7 +61,7 @@ func (c beaconApiJsonRestHandler) Post(
|
|||||||
return errors.New("data is nil")
|
return errors.New("data is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
url := c.host + apiEndpoint
|
url := c.Host + apiEndpoint
|
||||||
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, data)
|
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "failed to create request for endpoint %s", url)
|
return errors.Wrapf(err, "failed to create request for endpoint %s", url)
|
||||||
@@ -72,7 +72,7 @@ func (c beaconApiJsonRestHandler) Post(
|
|||||||
}
|
}
|
||||||
req.Header.Set("Content-Type", api.JsonMediaType)
|
req.Header.Set("Content-Type", api.JsonMediaType)
|
||||||
|
|
||||||
httpResp, err := c.httpClient.Do(req)
|
httpResp, err := c.HttpClient.Do(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrapf(err, "failed to perform request for endpoint %s", url)
|
return errors.Wrapf(err, "failed to perform request for endpoint %s", url)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,9 +40,9 @@ func TestGet(t *testing.T) {
|
|||||||
server := httptest.NewServer(mux)
|
server := httptest.NewServer(mux)
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
|
||||||
jsonRestHandler := beaconApiJsonRestHandler{
|
jsonRestHandler := BeaconApiJsonRestHandler{
|
||||||
httpClient: http.Client{Timeout: time.Second * 5},
|
HttpClient: http.Client{Timeout: time.Second * 5},
|
||||||
host: server.URL,
|
Host: server.URL,
|
||||||
}
|
}
|
||||||
resp := &beacon.GetGenesisResponse{}
|
resp := &beacon.GetGenesisResponse{}
|
||||||
require.NoError(t, jsonRestHandler.Get(ctx, endpoint+"?arg1=abc&arg2=def", resp))
|
require.NoError(t, jsonRestHandler.Get(ctx, endpoint+"?arg1=abc&arg2=def", resp))
|
||||||
@@ -86,9 +86,9 @@ func TestPost(t *testing.T) {
|
|||||||
server := httptest.NewServer(mux)
|
server := httptest.NewServer(mux)
|
||||||
defer server.Close()
|
defer server.Close()
|
||||||
|
|
||||||
jsonRestHandler := beaconApiJsonRestHandler{
|
jsonRestHandler := BeaconApiJsonRestHandler{
|
||||||
httpClient: http.Client{Timeout: time.Second * 5},
|
HttpClient: http.Client{Timeout: time.Second * 5},
|
||||||
host: server.URL,
|
Host: server.URL,
|
||||||
}
|
}
|
||||||
resp := &beacon.GetGenesisResponse{}
|
resp := &beacon.GetGenesisResponse{}
|
||||||
require.NoError(t, jsonRestHandler.Post(ctx, endpoint, headers, bytes.NewBuffer(dataBytes), resp))
|
require.NoError(t, jsonRestHandler.Post(ctx, endpoint, headers, bytes.NewBuffer(dataBytes), resp))
|
||||||
|
|||||||
@@ -3,11 +3,9 @@ package beacon_api
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
|
||||||
neturl "net/url"
|
neturl "net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/prysm/validator"
|
"github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/prysm/validator"
|
||||||
@@ -16,12 +14,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// NewPrysmBeaconChainClient returns implementation of iface.PrysmBeaconChainClient.
|
// NewPrysmBeaconChainClient returns implementation of iface.PrysmBeaconChainClient.
|
||||||
func NewPrysmBeaconChainClient(host string, timeout time.Duration, nodeClient iface.NodeClient) iface.PrysmBeaconChainClient {
|
func NewPrysmBeaconChainClient(jsonRestHandler JsonRestHandler, nodeClient iface.NodeClient) iface.PrysmBeaconChainClient {
|
||||||
jsonRestHandler := beaconApiJsonRestHandler{
|
|
||||||
httpClient: http.Client{Timeout: timeout},
|
|
||||||
host: host,
|
|
||||||
}
|
|
||||||
|
|
||||||
return prysmBeaconChainClient{
|
return prysmBeaconChainClient{
|
||||||
jsonRestHandler: jsonRestHandler,
|
jsonRestHandler: jsonRestHandler,
|
||||||
nodeClient: nodeClient,
|
nodeClient: nodeClient,
|
||||||
|
|||||||
@@ -9,30 +9,18 @@ import (
|
|||||||
validatorHelpers "github.com/prysmaticlabs/prysm/v4/validator/helpers"
|
validatorHelpers "github.com/prysmaticlabs/prysm/v4/validator/helpers"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewBeaconChainClient(validatorConn validatorHelpers.NodeConnection) iface.BeaconChainClient {
|
func NewBeaconChainClient(validatorConn validatorHelpers.NodeConnection, jsonRestHandler beaconApi.JsonRestHandler) iface.BeaconChainClient {
|
||||||
grpcClient := grpcApi.NewGrpcBeaconChainClient(validatorConn.GetGrpcClientConn())
|
grpcClient := grpcApi.NewGrpcBeaconChainClient(validatorConn.GetGrpcClientConn())
|
||||||
featureFlags := features.Get()
|
if features.Get().EnableBeaconRESTApi {
|
||||||
|
return beaconApi.NewBeaconApiBeaconChainClientWithFallback(jsonRestHandler, grpcClient)
|
||||||
if featureFlags.EnableBeaconRESTApi {
|
|
||||||
return beaconApi.NewBeaconApiBeaconChainClientWithFallback(
|
|
||||||
validatorConn.GetBeaconApiUrl(),
|
|
||||||
validatorConn.GetBeaconApiTimeout(),
|
|
||||||
grpcClient,
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
return grpcClient
|
return grpcClient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPrysmBeaconClient(validatorConn validatorHelpers.NodeConnection) iface.PrysmBeaconChainClient {
|
func NewPrysmBeaconClient(validatorConn validatorHelpers.NodeConnection, jsonRestHandler beaconApi.JsonRestHandler) iface.PrysmBeaconChainClient {
|
||||||
featureFlags := features.Get()
|
if features.Get().EnableBeaconRESTApi {
|
||||||
|
return beaconApi.NewPrysmBeaconChainClient(jsonRestHandler, nodeClientFactory.NewNodeClient(validatorConn, jsonRestHandler))
|
||||||
if featureFlags.EnableBeaconRESTApi {
|
|
||||||
return beaconApi.NewPrysmBeaconChainClient(
|
|
||||||
validatorConn.GetBeaconApiUrl(),
|
|
||||||
validatorConn.GetBeaconApiTimeout(),
|
|
||||||
nodeClientFactory.NewNodeClient(validatorConn),
|
|
||||||
)
|
|
||||||
} else {
|
} else {
|
||||||
return grpcApi.NewGrpcPrysmBeaconChainClient(validatorConn.GetGrpcClientConn())
|
return grpcApi.NewGrpcPrysmBeaconChainClient(validatorConn.GetGrpcClientConn())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,12 +8,10 @@ import (
|
|||||||
validatorHelpers "github.com/prysmaticlabs/prysm/v4/validator/helpers"
|
validatorHelpers "github.com/prysmaticlabs/prysm/v4/validator/helpers"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewNodeClient(validatorConn validatorHelpers.NodeConnection) iface.NodeClient {
|
func NewNodeClient(validatorConn validatorHelpers.NodeConnection, jsonRestHandler beaconApi.JsonRestHandler) iface.NodeClient {
|
||||||
grpcClient := grpcApi.NewNodeClient(validatorConn.GetGrpcClientConn())
|
grpcClient := grpcApi.NewNodeClient(validatorConn.GetGrpcClientConn())
|
||||||
featureFlags := features.Get()
|
if features.Get().EnableBeaconRESTApi {
|
||||||
|
return beaconApi.NewNodeClientWithFallback(jsonRestHandler, grpcClient)
|
||||||
if featureFlags.EnableBeaconRESTApi {
|
|
||||||
return beaconApi.NewNodeClientWithFallback(validatorConn.GetBeaconApiUrl(), validatorConn.GetBeaconApiTimeout(), grpcClient)
|
|
||||||
} else {
|
} else {
|
||||||
return grpcClient
|
return grpcClient
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -20,6 +21,7 @@ import (
|
|||||||
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
|
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
|
||||||
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
||||||
"github.com/prysmaticlabs/prysm/v4/validator/accounts/wallet"
|
"github.com/prysmaticlabs/prysm/v4/validator/accounts/wallet"
|
||||||
|
beaconApi "github.com/prysmaticlabs/prysm/v4/validator/client/beacon-api"
|
||||||
beaconChainClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/beacon-chain-client-factory"
|
beaconChainClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/beacon-chain-client-factory"
|
||||||
"github.com/prysmaticlabs/prysm/v4/validator/client/iface"
|
"github.com/prysmaticlabs/prysm/v4/validator/client/iface"
|
||||||
nodeClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/node-client-factory"
|
nodeClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/node-client-factory"
|
||||||
@@ -189,15 +191,16 @@ func (v *ValidatorService) Start() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
validatorClient := validatorClientFactory.NewValidatorClient(v.conn)
|
restHandler := &beaconApi.BeaconApiJsonRestHandler{
|
||||||
beaconClient := beaconChainClientFactory.NewBeaconChainClient(v.conn)
|
HttpClient: http.Client{Timeout: v.conn.GetBeaconApiTimeout()},
|
||||||
prysmBeaconClient := beaconChainClientFactory.NewPrysmBeaconClient(v.conn)
|
Host: v.conn.GetBeaconApiUrl(),
|
||||||
|
}
|
||||||
|
|
||||||
valStruct := &validator{
|
valStruct := &validator{
|
||||||
db: v.db,
|
db: v.db,
|
||||||
validatorClient: validatorClient,
|
validatorClient: validatorClientFactory.NewValidatorClient(v.conn, restHandler),
|
||||||
beaconClient: beaconClient,
|
beaconClient: beaconChainClientFactory.NewBeaconChainClient(v.conn, restHandler),
|
||||||
node: nodeClientFactory.NewNodeClient(v.conn),
|
node: nodeClientFactory.NewNodeClient(v.conn, restHandler),
|
||||||
graffiti: v.graffiti,
|
graffiti: v.graffiti,
|
||||||
logValidatorBalances: v.logValidatorBalances,
|
logValidatorBalances: v.logValidatorBalances,
|
||||||
emitAccountMetrics: v.emitAccountMetrics,
|
emitAccountMetrics: v.emitAccountMetrics,
|
||||||
@@ -221,7 +224,7 @@ func (v *ValidatorService) Start() {
|
|||||||
Web3SignerConfig: v.Web3SignerConfig,
|
Web3SignerConfig: v.Web3SignerConfig,
|
||||||
proposerSettings: v.proposerSettings,
|
proposerSettings: v.proposerSettings,
|
||||||
walletInitializedChannel: make(chan *wallet.Wallet, 1),
|
walletInitializedChannel: make(chan *wallet.Wallet, 1),
|
||||||
prysmBeaconClient: prysmBeaconClient,
|
prysmBeaconClient: beaconChainClientFactory.NewPrysmBeaconClient(v.conn, restHandler),
|
||||||
validatorsRegBatchSize: v.validatorsRegBatchSize,
|
validatorsRegBatchSize: v.validatorsRegBatchSize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,11 +8,12 @@ import (
|
|||||||
validatorHelpers "github.com/prysmaticlabs/prysm/v4/validator/helpers"
|
validatorHelpers "github.com/prysmaticlabs/prysm/v4/validator/helpers"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewValidatorClient(validatorConn validatorHelpers.NodeConnection) iface.ValidatorClient {
|
func NewValidatorClient(
|
||||||
featureFlags := features.Get()
|
validatorConn validatorHelpers.NodeConnection,
|
||||||
|
jsonRestHandler beaconApi.JsonRestHandler,
|
||||||
if featureFlags.EnableBeaconRESTApi {
|
) iface.ValidatorClient {
|
||||||
return beaconApi.NewBeaconApiValidatorClient(validatorConn.GetBeaconApiUrl(), validatorConn.GetBeaconApiTimeout())
|
if features.Get().EnableBeaconRESTApi {
|
||||||
|
return beaconApi.NewBeaconApiValidatorClient(jsonRestHandler)
|
||||||
} else {
|
} else {
|
||||||
return grpcApi.NewGrpcValidatorClient(validatorConn.GetGrpcClientConn())
|
return grpcApi.NewGrpcValidatorClient(validatorConn.GetGrpcClientConn())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,6 +49,7 @@ go_library(
|
|||||||
"//validator/accounts/petnames:go_default_library",
|
"//validator/accounts/petnames:go_default_library",
|
||||||
"//validator/accounts/wallet:go_default_library",
|
"//validator/accounts/wallet:go_default_library",
|
||||||
"//validator/client:go_default_library",
|
"//validator/client:go_default_library",
|
||||||
|
"//validator/client/beacon-api:go_default_library",
|
||||||
"//validator/client/beacon-chain-client-factory:go_default_library",
|
"//validator/client/beacon-chain-client-factory:go_default_library",
|
||||||
"//validator/client/iface:go_default_library",
|
"//validator/client/iface:go_default_library",
|
||||||
"//validator/client/node-client-factory:go_default_library",
|
"//validator/client/node-client-factory:go_default_library",
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package rpc
|
package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
middleware "github.com/grpc-ecosystem/go-grpc-middleware"
|
middleware "github.com/grpc-ecosystem/go-grpc-middleware"
|
||||||
grpcretry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
|
grpcretry "github.com/grpc-ecosystem/go-grpc-middleware/retry"
|
||||||
grpcopentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing"
|
grpcopentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing"
|
||||||
@@ -9,6 +11,7 @@ import (
|
|||||||
grpcutil "github.com/prysmaticlabs/prysm/v4/api/grpc"
|
grpcutil "github.com/prysmaticlabs/prysm/v4/api/grpc"
|
||||||
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
||||||
"github.com/prysmaticlabs/prysm/v4/validator/client"
|
"github.com/prysmaticlabs/prysm/v4/validator/client"
|
||||||
|
beaconApi "github.com/prysmaticlabs/prysm/v4/validator/client/beacon-api"
|
||||||
beaconChainClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/beacon-chain-client-factory"
|
beaconChainClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/beacon-chain-client-factory"
|
||||||
nodeClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/node-client-factory"
|
nodeClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/node-client-factory"
|
||||||
validatorClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/validator-client-factory"
|
validatorClientFactory "github.com/prysmaticlabs/prysm/v4/validator/client/validator-client-factory"
|
||||||
@@ -51,8 +54,13 @@ func (s *Server) registerBeaconClient() error {
|
|||||||
s.beaconApiTimeout,
|
s.beaconApiTimeout,
|
||||||
)
|
)
|
||||||
|
|
||||||
s.beaconChainClient = beaconChainClientFactory.NewBeaconChainClient(conn)
|
restHandler := &beaconApi.BeaconApiJsonRestHandler{
|
||||||
s.beaconNodeClient = nodeClientFactory.NewNodeClient(conn)
|
HttpClient: http.Client{Timeout: s.beaconApiTimeout},
|
||||||
s.beaconNodeValidatorClient = validatorClientFactory.NewValidatorClient(conn)
|
Host: s.beaconApiEndpoint,
|
||||||
|
}
|
||||||
|
s.beaconChainClient = beaconChainClientFactory.NewBeaconChainClient(conn, restHandler)
|
||||||
|
s.beaconNodeClient = nodeClientFactory.NewNodeClient(conn, restHandler)
|
||||||
|
s.beaconNodeValidatorClient = validatorClientFactory.NewValidatorClient(conn, restHandler)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user