mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 13:28:01 -05:00
Remove Execution Client Fallback and Make Providing an Execution Client Required (#10921)
* Starting * Done * Fix more tests * Fix test * Fix test * fix up * building * requirement * gaz * builds * rem deadcode * fix * fix up * removed checked method * Update service_test.go Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: Nishant Das <nishdas93@gmail.com>
This commit is contained in:
@@ -106,7 +106,7 @@ func setupBeaconChain(t *testing.T, beaconDB db.Database) *Service {
|
||||
web3Service, err = execution.NewService(
|
||||
ctx,
|
||||
execution.WithDatabase(beaconDB),
|
||||
execution.WithHttpEndpoints([]string{endpoint}),
|
||||
execution.WithHttpEndpoint(endpoint),
|
||||
execution.WithDepositContractAddress(common.Address{}),
|
||||
)
|
||||
require.NoError(t, err, "Unable to set up web3 service")
|
||||
|
||||
@@ -115,7 +115,6 @@ go_test(
|
||||
"//crypto/bls:go_default_library",
|
||||
"//encoding/bytesutil:go_default_library",
|
||||
"//monitoring/clientstats:go_default_library",
|
||||
"//network:go_default_library",
|
||||
"//network/authorization:go_default_library",
|
||||
"//proto/engine/v1:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
|
||||
@@ -36,7 +36,7 @@ func TestLatestMainchainInfo_OK(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDepositContractAddress(testAcc.ContractAddr),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
@@ -79,7 +79,7 @@ func TestBlockHashByHeight_ReturnsHash(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
require.NoError(t, err, "unable to setup web3 ETH1.0 chain service")
|
||||
@@ -111,7 +111,7 @@ func TestBlockHashByHeight_ReturnsError_WhenNoEth1Client(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
require.NoError(t, err, "unable to setup web3 ETH1.0 chain service")
|
||||
@@ -132,7 +132,7 @@ func TestBlockExists_ValidHash(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
require.NoError(t, err, "unable to setup web3 ETH1.0 chain service")
|
||||
@@ -168,7 +168,7 @@ func TestBlockExists_InvalidHash(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
require.NoError(t, err, "unable to setup web3 ETH1.0 chain service")
|
||||
@@ -187,7 +187,7 @@ func TestBlockExists_UsesCachedBlockInfo(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
require.NoError(t, err, "unable to setup web3 ETH1.0 chain service")
|
||||
@@ -217,7 +217,7 @@ func TestService_BlockNumberByTimestamp(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
@@ -249,7 +249,7 @@ func TestService_BlockNumberByTimestampLessTargetTime(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
@@ -287,7 +287,7 @@ func TestService_BlockNumberByTimestampMoreTargetTime(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
@@ -323,7 +323,7 @@ func TestService_BlockTimeByHeight_ReturnsError_WhenNoEth1Client(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
require.NoError(t, err, "unable to setup web3 ETH1.0 chain service")
|
||||
|
||||
@@ -59,7 +59,7 @@ func TestProcessDeposit_OK(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
require.NoError(t, err, "Unable to setup web3 ETH1.0 chain service")
|
||||
@@ -88,7 +88,7 @@ func TestProcessDeposit_InvalidMerkleBranch(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
require.NoError(t, err, "unable to setup web3 ETH1.0 chain service")
|
||||
@@ -119,7 +119,7 @@ func TestProcessDeposit_InvalidPublicKey(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
require.NoError(t, err, "unable to setup web3 ETH1.0 chain service")
|
||||
@@ -161,7 +161,7 @@ func TestProcessDeposit_InvalidSignature(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
require.NoError(t, err, "unable to setup web3 ETH1.0 chain service")
|
||||
@@ -203,7 +203,7 @@ func TestProcessDeposit_UnableToVerify(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
require.NoError(t, err, "unable to setup web3 ETH1.0 chain service")
|
||||
@@ -241,7 +241,7 @@ func TestProcessDeposit_IncompleteDeposit(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
require.NoError(t, err, "unable to setup web3 ETH1.0 chain service")
|
||||
@@ -310,7 +310,7 @@ func TestProcessDeposit_AllDepositedSuccessfully(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
require.NoError(t, err, "unable to setup web3 ETH1.0 chain service")
|
||||
|
||||
@@ -40,7 +40,7 @@ func TestProcessDepositLog_OK(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDepositContractAddress(testAcc.ContractAddr),
|
||||
WithDatabase(beaconDB),
|
||||
WithDepositCache(depositCache),
|
||||
@@ -109,7 +109,7 @@ func TestProcessDepositLog_InsertsPendingDeposit(t *testing.T) {
|
||||
})
|
||||
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDepositContractAddress(testAcc.ContractAddr),
|
||||
WithDatabase(beaconDB),
|
||||
WithDepositCache(depositCache),
|
||||
@@ -170,7 +170,7 @@ func TestUnpackDepositLogData_OK(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDepositContractAddress(testAcc.ContractAddr),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
@@ -225,7 +225,7 @@ func TestProcessETH2GenesisLog_8DuplicatePubkeys(t *testing.T) {
|
||||
})
|
||||
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDepositContractAddress(testAcc.ContractAddr),
|
||||
WithDatabase(beaconDB),
|
||||
WithDepositCache(depositCache),
|
||||
@@ -300,7 +300,7 @@ func TestProcessETH2GenesisLog(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDepositContractAddress(testAcc.ContractAddr),
|
||||
WithDatabase(beaconDB),
|
||||
WithDepositCache(depositCache),
|
||||
@@ -392,7 +392,7 @@ func TestProcessETH2GenesisLog_CorrectNumOfDeposits(t *testing.T) {
|
||||
})
|
||||
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDepositContractAddress(testAcc.ContractAddr),
|
||||
WithDatabase(kvStore),
|
||||
WithDepositCache(depositCache),
|
||||
@@ -490,7 +490,7 @@ func TestProcessETH2GenesisLog_LargePeriodOfNoLogs(t *testing.T) {
|
||||
})
|
||||
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDepositContractAddress(testAcc.ContractAddr),
|
||||
WithDatabase(kvStore),
|
||||
WithDepositCache(depositCache),
|
||||
@@ -602,7 +602,7 @@ func newPowchainService(t *testing.T, eth1Backend *mock.TestAccount, beaconDB db
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDepositContractAddress(eth1Backend.ContractAddr),
|
||||
WithDatabase(beaconDB),
|
||||
WithDepositCache(depositCache),
|
||||
|
||||
@@ -7,55 +7,31 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/db"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state/stategen"
|
||||
"github.com/prysmaticlabs/prysm/v3/network"
|
||||
"github.com/prysmaticlabs/prysm/v3/network/authorization"
|
||||
)
|
||||
|
||||
type Option func(s *Service) error
|
||||
|
||||
// WithHttpEndpoints deduplicates and parses http endpoints for the execution chain service to use,
|
||||
// and sets the "current" endpoint that will be used first.
|
||||
func WithHttpEndpoints(endpointStrings []string) Option {
|
||||
// WithHttpEndpoint parse http endpoint for the powchain service to use.
|
||||
func WithHttpEndpoint(endpointString string) Option {
|
||||
return func(s *Service) error {
|
||||
stringEndpoints := dedupEndpoints(endpointStrings)
|
||||
endpoints := make([]network.Endpoint, len(stringEndpoints))
|
||||
for i, e := range stringEndpoints {
|
||||
endpoints[i] = HttpEndpoint(e)
|
||||
}
|
||||
// Select first http endpoint in the provided list.
|
||||
var currEndpoint network.Endpoint
|
||||
if len(endpointStrings) > 0 {
|
||||
currEndpoint = endpoints[0]
|
||||
}
|
||||
s.cfg.httpEndpoints = endpoints
|
||||
s.cfg.currHttpEndpoint = currEndpoint
|
||||
s.cfg.currHttpEndpoint = HttpEndpoint(endpointString)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithHttpEndpointsAndJWTSecret for authenticating the execution node JSON-RPC endpoint.
|
||||
func WithHttpEndpointsAndJWTSecret(endpointStrings []string, secret []byte) Option {
|
||||
// WithHttpEndpointAndJWTSecret for authenticating the execution node JSON-RPC endpoint.
|
||||
func WithHttpEndpointAndJWTSecret(endpointString string, secret []byte) Option {
|
||||
return func(s *Service) error {
|
||||
if len(secret) == 0 {
|
||||
return nil
|
||||
}
|
||||
stringEndpoints := dedupEndpoints(endpointStrings)
|
||||
endpoints := make([]network.Endpoint, len(stringEndpoints))
|
||||
// Overwrite authorization type for all endpoints to be of a bearer
|
||||
// type.
|
||||
for i, e := range stringEndpoints {
|
||||
hEndpoint := HttpEndpoint(e)
|
||||
hEndpoint.Auth.Method = authorization.Bearer
|
||||
hEndpoint.Auth.Value = string(secret)
|
||||
endpoints[i] = hEndpoint
|
||||
}
|
||||
// Select first http endpoint in the provided list.
|
||||
var currEndpoint network.Endpoint
|
||||
if len(endpointStrings) > 0 {
|
||||
currEndpoint = endpoints[0]
|
||||
}
|
||||
s.cfg.httpEndpoints = endpoints
|
||||
s.cfg.currHttpEndpoint = currEndpoint
|
||||
// Overwrite authorization type for all endpoints to be of a bearer type.
|
||||
hEndpoint := HttpEndpoint(endpointString)
|
||||
hEndpoint.Auth.Method = authorization.Bearer
|
||||
hEndpoint.Auth.Value = string(secret)
|
||||
|
||||
s.cfg.currHttpEndpoint = hEndpoint
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,9 @@ type BeaconNodeStatsUpdater interface {
|
||||
}
|
||||
|
||||
type PowchainCollector struct {
|
||||
SyncEth1Connected *prometheus.Desc
|
||||
SyncEth1FallbackConnected *prometheus.Desc
|
||||
SyncEth1FallbackConfigured *prometheus.Desc // true if flag specified: --fallback-web3provider
|
||||
updateChan chan clientstats.BeaconNodeStats
|
||||
latestStats clientstats.BeaconNodeStats
|
||||
SyncEth1Connected *prometheus.Desc
|
||||
updateChan chan clientstats.BeaconNodeStats
|
||||
latestStats clientstats.BeaconNodeStats
|
||||
sync.Mutex
|
||||
ctx context.Context
|
||||
finishChan chan struct{}
|
||||
@@ -38,8 +36,6 @@ func (pc *PowchainCollector) Update(update clientstats.BeaconNodeStats) {
|
||||
// prometheus.Collector interface.
|
||||
func (pc *PowchainCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
ch <- pc.SyncEth1Connected
|
||||
ch <- pc.SyncEth1FallbackConfigured
|
||||
ch <- pc.SyncEth1FallbackConnected
|
||||
}
|
||||
|
||||
// Collect is invoked by the prometheus collection loop.
|
||||
@@ -54,26 +50,6 @@ func (pc *PowchainCollector) Describe(ch chan<- *prometheus.Desc) {
|
||||
func (pc *PowchainCollector) Collect(ch chan<- prometheus.Metric) {
|
||||
bs := pc.getLatestStats()
|
||||
|
||||
var syncEth1FallbackConfigured float64 = 0
|
||||
if bs.SyncEth1FallbackConfigured {
|
||||
syncEth1FallbackConfigured = 1
|
||||
}
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
pc.SyncEth1FallbackConfigured,
|
||||
prometheus.GaugeValue,
|
||||
syncEth1FallbackConfigured,
|
||||
)
|
||||
|
||||
var syncEth1FallbackConnected float64 = 0
|
||||
if bs.SyncEth1FallbackConnected {
|
||||
syncEth1FallbackConnected = 1
|
||||
}
|
||||
ch <- prometheus.MustNewConstMetric(
|
||||
pc.SyncEth1FallbackConnected,
|
||||
prometheus.GaugeValue,
|
||||
syncEth1FallbackConnected,
|
||||
)
|
||||
|
||||
var syncEth1Connected float64 = 0
|
||||
if bs.SyncEth1Connected {
|
||||
syncEth1Connected = 1
|
||||
@@ -120,18 +96,6 @@ func NewPowchainCollector(ctx context.Context) (*PowchainCollector, error) {
|
||||
namespace := "powchain"
|
||||
updateChan := make(chan clientstats.BeaconNodeStats, 2)
|
||||
c := &PowchainCollector{
|
||||
SyncEth1FallbackConfigured: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "", "sync_eth1_fallback_configured"),
|
||||
"Boolean recording whether a fallback eth1 endpoint was configured: 0=false, 1=true.",
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
SyncEth1FallbackConnected: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "", "sync_eth1_fallback_connected"),
|
||||
"Boolean indicating whether a fallback eth1 endpoint is currently connected: 0=false, 1=true.",
|
||||
nil,
|
||||
nil,
|
||||
),
|
||||
SyncEth1Connected: prometheus.NewDesc(
|
||||
prometheus.BuildFQName(namespace, "", "sync_eth1_connected"),
|
||||
"Boolean indicating whether an eth1 endpoint is currently connected: 0=false, 1=true.",
|
||||
|
||||
@@ -65,8 +65,7 @@ func (s *Service) pollConnectionStatus(ctx context.Context) {
|
||||
currClient := s.rpcClient
|
||||
if err := s.setupExecutionClientConnections(ctx, s.cfg.currHttpEndpoint); err != nil {
|
||||
errorLogger(err, "Could not connect to execution client endpoint")
|
||||
s.runError = err
|
||||
s.fallbackToNextEndpoint()
|
||||
s.retryExecutionClientConnection(ctx, err)
|
||||
continue
|
||||
}
|
||||
// Close previous client, if connection was successful.
|
||||
@@ -101,52 +100,6 @@ func (s *Service) retryExecutionClientConnection(ctx context.Context, err error)
|
||||
s.runError = nil
|
||||
}
|
||||
|
||||
// This performs a health check on our primary endpoint, and if it
|
||||
// is ready to serve we connect to it again. This method is only
|
||||
// relevant if we are on our backup endpoint.
|
||||
func (s *Service) checkDefaultEndpoint(ctx context.Context) {
|
||||
primaryEndpoint := s.cfg.httpEndpoints[0]
|
||||
// Return early if we are running on our primary
|
||||
// endpoint.
|
||||
if s.cfg.currHttpEndpoint.Equals(primaryEndpoint) {
|
||||
return
|
||||
}
|
||||
|
||||
currClient := s.rpcClient
|
||||
if err := s.setupExecutionClientConnections(ctx, primaryEndpoint); err != nil {
|
||||
log.WithError(err).Debug("Primary endpoint not ready")
|
||||
return
|
||||
}
|
||||
// Close previous client, if connection was successful.
|
||||
if currClient != nil {
|
||||
currClient.Close()
|
||||
}
|
||||
s.updateCurrHttpEndpoint(primaryEndpoint)
|
||||
}
|
||||
|
||||
// This is an inefficient way to search for the next endpoint, but given N is
|
||||
// expected to be small, it is fine to search this way.
|
||||
func (s *Service) fallbackToNextEndpoint() {
|
||||
currEndpoint := s.cfg.currHttpEndpoint
|
||||
currIndex := 0
|
||||
totalEndpoints := len(s.cfg.httpEndpoints)
|
||||
|
||||
for i, endpoint := range s.cfg.httpEndpoints {
|
||||
if endpoint.Equals(currEndpoint) {
|
||||
currIndex = i
|
||||
break
|
||||
}
|
||||
}
|
||||
nextIndex := currIndex + 1
|
||||
if nextIndex >= totalEndpoints {
|
||||
nextIndex = 0
|
||||
}
|
||||
s.updateCurrHttpEndpoint(s.cfg.httpEndpoints[nextIndex])
|
||||
if nextIndex != currIndex {
|
||||
log.Infof("Falling back to alternative endpoint: %s", logs.MaskCredentialsLogging(s.cfg.currHttpEndpoint.Url))
|
||||
}
|
||||
}
|
||||
|
||||
// Initializes an RPC connection with authentication headers.
|
||||
func (s *Service) newRPCClientWithAuth(ctx context.Context, endpoint network.Endpoint) (*gethRPC.Client, error) {
|
||||
// Need to handle ipc and http
|
||||
|
||||
@@ -17,7 +17,6 @@ import (
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
gethTypes "github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/ethclient"
|
||||
gethRPC "github.com/ethereum/go-ethereum/rpc"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
@@ -84,11 +83,9 @@ type ChainStartFetcher interface {
|
||||
// ChainInfoFetcher retrieves information about eth1 metadata at the Ethereum consensus genesis time.
|
||||
type ChainInfoFetcher interface {
|
||||
GenesisExecutionChainInfo() (uint64, *big.Int)
|
||||
IsConnectedToETH1() bool
|
||||
CurrentETH1Endpoint() string
|
||||
CurrentETH1ConnectionError() error
|
||||
ETH1Endpoints() []string
|
||||
ETH1ConnectionErrors() []error
|
||||
ExecutionClientConnected() bool
|
||||
ExecutionClientEndpoint() string
|
||||
ExecutionClientConnectionErr() error
|
||||
}
|
||||
|
||||
// POWBlockFetcher defines a struct that can retrieve mainchain blocks.
|
||||
@@ -130,7 +127,6 @@ type config struct {
|
||||
stateGen *stategen.State
|
||||
eth1HeaderReqLimit uint64
|
||||
beaconNodeStatsUpdater BeaconNodeStatsUpdater
|
||||
httpEndpoints []network.Endpoint
|
||||
currHttpEndpoint network.Endpoint
|
||||
finalizedStateAtStartup state.BeaconState
|
||||
}
|
||||
@@ -297,17 +293,25 @@ func (s *Service) Status() error {
|
||||
return s.runError
|
||||
}
|
||||
|
||||
// ExecutionClientConnected checks whether are connected via RPC.
|
||||
func (s *Service) ExecutionClientConnected() bool {
|
||||
return s.connectedETH1
|
||||
}
|
||||
|
||||
// ExecutionClientEndpoint returns the URL of the current, connected execution client.
|
||||
func (s *Service) ExecutionClientEndpoint() string {
|
||||
return s.cfg.currHttpEndpoint.Url
|
||||
}
|
||||
|
||||
// ExecutionClientConnectionErr returns the error (if any) of the current connection.
|
||||
func (s *Service) ExecutionClientConnectionErr() error {
|
||||
return s.runError
|
||||
}
|
||||
|
||||
func (s *Service) updateBeaconNodeStats() {
|
||||
bs := clientstats.BeaconNodeStats{}
|
||||
if len(s.cfg.httpEndpoints) > 1 {
|
||||
bs.SyncEth1FallbackConfigured = true
|
||||
}
|
||||
if s.IsConnectedToETH1() {
|
||||
if s.primaryConnected() {
|
||||
bs.SyncEth1Connected = true
|
||||
} else {
|
||||
bs.SyncEth1FallbackConnected = true
|
||||
}
|
||||
if s.ExecutionClientConnected() {
|
||||
bs.SyncEth1Connected = true
|
||||
}
|
||||
s.cfg.beaconNodeStatsUpdater.Update(bs)
|
||||
}
|
||||
@@ -322,51 +326,6 @@ func (s *Service) updateConnectedETH1(state bool) {
|
||||
s.updateBeaconNodeStats()
|
||||
}
|
||||
|
||||
// IsConnectedToETH1 checks if the beacon node is connected to a ETH1 Node.
|
||||
func (s *Service) IsConnectedToETH1() bool {
|
||||
return s.connectedETH1
|
||||
}
|
||||
|
||||
// CurrentETH1Endpoint returns the URL of the current ETH1 endpoint.
|
||||
func (s *Service) CurrentETH1Endpoint() string {
|
||||
return s.cfg.currHttpEndpoint.Url
|
||||
}
|
||||
|
||||
// CurrentETH1ConnectionError returns the error (if any) of the current connection.
|
||||
func (s *Service) CurrentETH1ConnectionError() error {
|
||||
return s.runError
|
||||
}
|
||||
|
||||
// ETH1Endpoints returns the slice of HTTP endpoint URLs (default is 0th element).
|
||||
func (s *Service) ETH1Endpoints() []string {
|
||||
var eps []string
|
||||
for _, ep := range s.cfg.httpEndpoints {
|
||||
eps = append(eps, ep.Url)
|
||||
}
|
||||
return eps
|
||||
}
|
||||
|
||||
// ETH1ConnectionErrors returns a slice of errors for each HTTP endpoint. An error
|
||||
// of nil means the connection was successful.
|
||||
func (s *Service) ETH1ConnectionErrors() []error {
|
||||
var errs []error
|
||||
for _, ep := range s.cfg.httpEndpoints {
|
||||
client, err := s.newRPCClientWithAuth(s.ctx, ep)
|
||||
if err != nil {
|
||||
client.Close()
|
||||
errs = append(errs, err)
|
||||
continue
|
||||
}
|
||||
if err := ensureCorrectExecutionChain(s.ctx, ethclient.NewClient(client)); err != nil {
|
||||
client.Close()
|
||||
errs = append(errs, err)
|
||||
continue
|
||||
}
|
||||
client.Close()
|
||||
}
|
||||
return errs
|
||||
}
|
||||
|
||||
// refers to the latest eth1 block which follows the condition: eth1_timestamp +
|
||||
// SECONDS_PER_ETH1_BLOCK * ETH1_FOLLOW_DISTANCE <= current_unix_time
|
||||
func (s *Service) followedBlockHeight(ctx context.Context) (uint64, error) {
|
||||
@@ -656,7 +615,6 @@ func (s *Service) run(done <-chan struct{}) {
|
||||
}
|
||||
s.processBlockHeader(head)
|
||||
s.handleETH1FollowDistance()
|
||||
s.checkDefaultEndpoint(s.ctx)
|
||||
case <-chainstartTicker.C:
|
||||
if s.chainStartData.Chainstarted {
|
||||
chainstartTicker.Stop()
|
||||
@@ -888,7 +846,3 @@ func eth1HeadIsBehind(timestamp uint64) bool {
|
||||
// check that web3 client is syncing
|
||||
return time.Unix(int64(timestamp), 0).Before(timeout) // lint:ignore uintcast -- timestamp will not exceed int64 in your lifetime.
|
||||
}
|
||||
|
||||
func (s *Service) primaryConnected() bool {
|
||||
return s.cfg.currHttpEndpoint.Equals(s.cfg.httpEndpoints[0])
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/v3/contracts/deposit/mock"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/v3/monitoring/clientstats"
|
||||
"github.com/prysmaticlabs/prysm/v3/network"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
@@ -143,7 +142,7 @@ func TestStart_OK(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDepositContractAddress(testAcc.ContractAddr),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
@@ -172,7 +171,7 @@ func TestStart_NoHttpEndpointDefinedFails_WithoutChainStarted(t *testing.T) {
|
||||
testAcc, err := mock.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
_, err = NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{""}),
|
||||
WithHttpEndpoint(""),
|
||||
WithDepositContractAddress(testAcc.ContractAddr),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
@@ -191,7 +190,7 @@ func TestStop_OK(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDepositContractAddress(testAcc.ContractAddr),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
@@ -221,7 +220,7 @@ func TestService_Eth1Synced(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDepositContractAddress(testAcc.ContractAddr),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
@@ -247,7 +246,7 @@ func TestFollowBlock_OK(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDepositContractAddress(testAcc.ContractAddr),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
@@ -325,7 +324,7 @@ func TestHandlePanic_OK(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
require.NoError(t, err, "unable to setup web3 ETH1.0 chain service")
|
||||
@@ -362,7 +361,7 @@ func TestLogTillGenesis_OK(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDepositContractAddress(testAcc.ContractAddr),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
@@ -501,7 +500,7 @@ func TestNewService_EarliestVotingBlock(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
web3Service, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDepositContractAddress(testAcc.ContractAddr),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
@@ -557,14 +556,14 @@ func TestNewService_Eth1HeaderRequLimit(t *testing.T) {
|
||||
server.Stop()
|
||||
})
|
||||
s1, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDepositContractAddress(testAcc.ContractAddr),
|
||||
WithDatabase(beaconDB),
|
||||
)
|
||||
require.NoError(t, err, "unable to setup web3 ETH1.0 chain service")
|
||||
assert.Equal(t, defaultEth1HeaderReqLimit, s1.cfg.eth1HeaderReqLimit, "default eth1 header request limit not set")
|
||||
s2, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDepositContractAddress(testAcc.ContractAddr),
|
||||
WithDatabase(beaconDB),
|
||||
WithEth1HeaderRequestLimit(uint64(150)),
|
||||
@@ -583,60 +582,6 @@ func (mbs *mockBSUpdater) Update(bs clientstats.BeaconNodeStats) {
|
||||
|
||||
var _ BeaconNodeStatsUpdater = &mockBSUpdater{}
|
||||
|
||||
func TestServiceFallbackCorrectly(t *testing.T) {
|
||||
testAcc, err := mock.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
beaconDB := dbutil.SetupDB(t)
|
||||
|
||||
server, firstEndpoint, err := mockExecution.SetupRPCServer()
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
server.Stop()
|
||||
})
|
||||
server2, secondEndpoint, err := mockExecution.SetupRPCServer()
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
server2.Stop()
|
||||
})
|
||||
server3, thirdEndpoint, err := mockExecution.SetupRPCServer()
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
server3.Stop()
|
||||
})
|
||||
|
||||
mbs := &mockBSUpdater{}
|
||||
s1, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{firstEndpoint}),
|
||||
WithDepositContractAddress(testAcc.ContractAddr),
|
||||
WithDatabase(beaconDB),
|
||||
WithBeaconNodeStatsUpdater(mbs),
|
||||
)
|
||||
require.NoError(t, err)
|
||||
s1.cfg.beaconNodeStatsUpdater = mbs
|
||||
|
||||
assert.Equal(t, firstEndpoint, s1.cfg.currHttpEndpoint.Url, "Unexpected http endpoint")
|
||||
|
||||
// Stay at the first endpoint.
|
||||
s1.fallbackToNextEndpoint()
|
||||
assert.Equal(t, firstEndpoint, s1.cfg.currHttpEndpoint.Url, "Unexpected http endpoint")
|
||||
assert.Equal(t, false, mbs.lastBS.SyncEth1FallbackConfigured, "SyncEth1FallbackConfigured in clientstats update should be false when only 1 endpoint is configured")
|
||||
|
||||
s1.cfg.httpEndpoints = append(s1.cfg.httpEndpoints, network.Endpoint{Url: secondEndpoint})
|
||||
|
||||
s1.fallbackToNextEndpoint()
|
||||
assert.Equal(t, secondEndpoint, s1.cfg.currHttpEndpoint.Url, "Unexpected http endpoint")
|
||||
assert.Equal(t, true, mbs.lastBS.SyncEth1FallbackConfigured, "SyncEth1FallbackConfigured in clientstats update should be true when > 1 endpoint is configured")
|
||||
|
||||
s1.cfg.httpEndpoints = append(s1.cfg.httpEndpoints, network.Endpoint{Url: thirdEndpoint})
|
||||
|
||||
s1.fallbackToNextEndpoint()
|
||||
assert.Equal(t, thirdEndpoint, s1.cfg.currHttpEndpoint.Url, "Unexpected http endpoint")
|
||||
|
||||
// Rollover correctly back to the first endpoint
|
||||
s1.fallbackToNextEndpoint()
|
||||
assert.Equal(t, firstEndpoint, s1.cfg.currHttpEndpoint.Url, "Unexpected http endpoint")
|
||||
}
|
||||
|
||||
func TestDedupEndpoints(t *testing.T) {
|
||||
assert.DeepEqual(t, []string{"A"}, dedupEndpoints([]string{"A"}), "did not dedup correctly")
|
||||
assert.DeepEqual(t, []string{"A", "B"}, dedupEndpoints([]string{"A", "B"}), "did not dedup correctly")
|
||||
@@ -667,7 +612,7 @@ func TestService_EnsureConsistentPowchainData(t *testing.T) {
|
||||
srv.Stop()
|
||||
})
|
||||
s1, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDatabase(beaconDB),
|
||||
WithDepositCache(cache),
|
||||
)
|
||||
@@ -697,7 +642,7 @@ func TestService_InitializeCorrectly(t *testing.T) {
|
||||
srv.Stop()
|
||||
})
|
||||
s1, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDatabase(beaconDB),
|
||||
WithDepositCache(cache),
|
||||
)
|
||||
@@ -726,7 +671,7 @@ func TestService_EnsureValidPowchainData(t *testing.T) {
|
||||
srv.Stop()
|
||||
})
|
||||
s1, err := NewService(context.Background(),
|
||||
WithHttpEndpoints([]string{endpoint}),
|
||||
WithHttpEndpoint(endpoint),
|
||||
WithDatabase(beaconDB),
|
||||
WithDepositCache(cache),
|
||||
)
|
||||
@@ -822,12 +767,7 @@ func TestETH1Endpoints(t *testing.T) {
|
||||
t.Cleanup(func() {
|
||||
server.Stop()
|
||||
})
|
||||
server, secondEndpoint, err := mockExecution.SetupRPCServer()
|
||||
require.NoError(t, err)
|
||||
t.Cleanup(func() {
|
||||
server.Stop()
|
||||
})
|
||||
endpoints := []string{firstEndpoint, secondEndpoint}
|
||||
endpoints := []string{firstEndpoint}
|
||||
|
||||
testAcc, err := mock.Setup()
|
||||
require.NoError(t, err, "Unable to set up simulated backend")
|
||||
@@ -835,7 +775,7 @@ func TestETH1Endpoints(t *testing.T) {
|
||||
|
||||
mbs := &mockBSUpdater{}
|
||||
s1, err := NewService(context.Background(),
|
||||
WithHttpEndpoints(endpoints),
|
||||
WithHttpEndpoint(endpoints[0]),
|
||||
WithDepositContractAddress(testAcc.ContractAddr),
|
||||
WithDatabase(beaconDB),
|
||||
WithBeaconNodeStatsUpdater(mbs),
|
||||
@@ -844,10 +784,7 @@ func TestETH1Endpoints(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Check default endpoint is set to current.
|
||||
assert.Equal(t, firstEndpoint, s1.CurrentETH1Endpoint(), "Unexpected http endpoint")
|
||||
|
||||
// Check endpoints are all present.
|
||||
assert.DeepSSZEqual(t, endpoints, s1.ETH1Endpoints(), "Unexpected http endpoint slice")
|
||||
assert.Equal(t, firstEndpoint, s1.ExecutionClientEndpoint(), "Unexpected http endpoint")
|
||||
}
|
||||
|
||||
func TestService_CacheBlockHeaders(t *testing.T) {
|
||||
|
||||
@@ -118,16 +118,15 @@ func (*Chain) ClearPreGenesisData() {
|
||||
// no-op
|
||||
}
|
||||
|
||||
// IsConnectedToETH1 --
|
||||
func (*Chain) IsConnectedToETH1() bool {
|
||||
func (*Chain) ExecutionClientConnected() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (m *Chain) CurrentETH1Endpoint() string {
|
||||
func (m *Chain) ExecutionClientEndpoint() string {
|
||||
return m.CurrEndpoint
|
||||
}
|
||||
|
||||
func (m *Chain) CurrentETH1ConnectionError() error {
|
||||
func (m *Chain) ExecutionClientConnectionErr() error {
|
||||
return m.CurrError
|
||||
}
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ func TestClearDB(t *testing.T) {
|
||||
|
||||
context := cli.NewContext(&app, set, nil)
|
||||
_, err = New(context, WithExecutionChainOptions([]execution.Option{
|
||||
execution.WithHttpEndpoints([]string{endpoint}),
|
||||
execution.WithHttpEndpoint(endpoint),
|
||||
}))
|
||||
require.NoError(t, err)
|
||||
|
||||
|
||||
@@ -223,26 +223,15 @@ func (ns *Server) ListPeers(ctx context.Context, _ *empty.Empty) (*ethpb.Peers,
|
||||
|
||||
// GetETH1ConnectionStatus gets data about the ETH1 endpoints.
|
||||
func (ns *Server) GetETH1ConnectionStatus(_ context.Context, _ *empty.Empty) (*ethpb.ETH1ConnectionStatus, error) {
|
||||
var errStrs []string
|
||||
var currErrString string
|
||||
errs := ns.POWChainInfoFetcher.ETH1ConnectionErrors()
|
||||
// Extract string version of the errors.
|
||||
for _, err := range errs {
|
||||
if err == nil {
|
||||
errStrs = append(errStrs, "")
|
||||
} else {
|
||||
errStrs = append(errStrs, err.Error())
|
||||
}
|
||||
}
|
||||
curErr := ns.POWChainInfoFetcher.CurrentETH1ConnectionError()
|
||||
if curErr != nil {
|
||||
currErrString = curErr.Error()
|
||||
var currErr string
|
||||
err := ns.POWChainInfoFetcher.ExecutionClientConnectionErr()
|
||||
if err != nil {
|
||||
currErr = err.Error()
|
||||
}
|
||||
return ðpb.ETH1ConnectionStatus{
|
||||
CurrentAddress: ns.POWChainInfoFetcher.CurrentETH1Endpoint(),
|
||||
CurrentConnectionError: currErrString,
|
||||
Addresses: ns.POWChainInfoFetcher.ETH1Endpoints(),
|
||||
ConnectionErrors: errStrs,
|
||||
CurrentAddress: ns.POWChainInfoFetcher.ExecutionClientEndpoint(),
|
||||
CurrentConnectionError: currErr,
|
||||
Addresses: []string{ns.POWChainInfoFetcher.ExecutionClientEndpoint()},
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package node
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -152,14 +152,12 @@ func TestNodeServer_ListPeers(t *testing.T) {
|
||||
|
||||
func TestNodeServer_GetETH1ConnectionStatus(t *testing.T) {
|
||||
server := grpc.NewServer()
|
||||
eps := []string{"foo", "bar"}
|
||||
errs := []error{fmt.Errorf("error 1"), fmt.Errorf("error 2"), nil}
|
||||
errStrs := []string{"error 1", "error 2", ""}
|
||||
ep := "foo"
|
||||
err := errors.New("error1")
|
||||
errStr := "error1"
|
||||
mockFetcher := &testutil.MockExecutionChainInfoFetcher{
|
||||
CurrEndpoint: eps[0],
|
||||
CurrError: errs[0],
|
||||
Endpoints: eps,
|
||||
Errors: errs,
|
||||
CurrEndpoint: ep,
|
||||
CurrError: err,
|
||||
}
|
||||
ns := &Server{
|
||||
POWChainInfoFetcher: mockFetcher,
|
||||
@@ -169,8 +167,6 @@ func TestNodeServer_GetETH1ConnectionStatus(t *testing.T) {
|
||||
|
||||
res, err := ns.GetETH1ConnectionStatus(context.Background(), &emptypb.Empty{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, eps[0], res.CurrentAddress)
|
||||
assert.Equal(t, errStrs[0], res.CurrentConnectionError)
|
||||
assert.DeepSSZEqual(t, eps, res.Addresses)
|
||||
assert.DeepSSZEqual(t, errStrs, res.ConnectionErrors)
|
||||
assert.Equal(t, ep, res.CurrentAddress)
|
||||
assert.Equal(t, errStr, res.CurrentConnectionError)
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ func (vs *Server) deposits(
|
||||
return []*ethpb.Deposit{}, nil
|
||||
}
|
||||
|
||||
if !vs.Eth1InfoFetcher.IsConnectedToETH1() {
|
||||
if !vs.Eth1InfoFetcher.ExecutionClientConnected() {
|
||||
log.Warn("not connected to eth1 node, skip pending deposit insertion")
|
||||
return []*ethpb.Deposit{}, nil
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ func (vs *Server) eth1DataMajorityVote(ctx context.Context, beaconState state.Be
|
||||
if vs.MockEth1Votes {
|
||||
return vs.mockETH1DataVote(ctx, slot)
|
||||
}
|
||||
if !vs.Eth1InfoFetcher.IsConnectedToETH1() {
|
||||
if !vs.Eth1InfoFetcher.ExecutionClientConnected() {
|
||||
return vs.randomETH1DataVote(ctx)
|
||||
}
|
||||
eth1DataNotification = false
|
||||
|
||||
@@ -300,7 +300,7 @@ func (vs *Server) validatorStatus(
|
||||
// Unknown status means the validator has not been put into the state yet.
|
||||
case ethpb.ValidatorStatus_UNKNOWN_STATUS:
|
||||
// If no connection to ETH1, the deposit block number or position in queue cannot be determined.
|
||||
if !vs.Eth1InfoFetcher.IsConnectedToETH1() {
|
||||
if !vs.Eth1InfoFetcher.ExecutionClientConnected() {
|
||||
log.Warn("Not connected to ETH1. Cannot determine validator ETH1 deposit block number")
|
||||
return resp, nonExistentIndex
|
||||
}
|
||||
|
||||
@@ -8,30 +8,20 @@ import (
|
||||
type MockExecutionChainInfoFetcher struct {
|
||||
CurrEndpoint string
|
||||
CurrError error
|
||||
Endpoints []string
|
||||
Errors []error
|
||||
}
|
||||
|
||||
func (*MockExecutionChainInfoFetcher) GenesisExecutionChainInfo() (uint64, *big.Int) {
|
||||
return uint64(0), &big.Int{}
|
||||
}
|
||||
|
||||
func (*MockExecutionChainInfoFetcher) IsConnectedToETH1() bool {
|
||||
func (*MockExecutionChainInfoFetcher) ExecutionClientConnected() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (m *MockExecutionChainInfoFetcher) CurrentETH1Endpoint() string {
|
||||
func (m *MockExecutionChainInfoFetcher) ExecutionClientEndpoint() string {
|
||||
return m.CurrEndpoint
|
||||
}
|
||||
|
||||
func (m *MockExecutionChainInfoFetcher) CurrentETH1ConnectionError() error {
|
||||
func (m *MockExecutionChainInfoFetcher) ExecutionClientConnectionErr() error {
|
||||
return m.CurrError
|
||||
}
|
||||
|
||||
func (m *MockExecutionChainInfoFetcher) ETH1Endpoints() []string {
|
||||
return m.Endpoints
|
||||
}
|
||||
|
||||
func (m *MockExecutionChainInfoFetcher) ETH1ConnectionErrors() []error {
|
||||
return m.Errors
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ go_library(
|
||||
"//cmd/beacon-chain/flags:go_default_library",
|
||||
"//io/file:go_default_library",
|
||||
"@com_github_pkg_errors//:go_default_library",
|
||||
"@com_github_sirupsen_logrus//:go_default_library",
|
||||
"@com_github_urfave_cli_v2//:go_default_library",
|
||||
],
|
||||
)
|
||||
@@ -28,7 +27,6 @@ go_test(
|
||||
"//io/file:go_default_library",
|
||||
"//testing/assert:go_default_library",
|
||||
"//testing/require:go_default_library",
|
||||
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
|
||||
"@com_github_urfave_cli_v2//:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
@@ -9,25 +9,25 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/execution"
|
||||
"github.com/prysmaticlabs/prysm/v3/cmd/beacon-chain/flags"
|
||||
"github.com/prysmaticlabs/prysm/v3/io/file"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
var log = logrus.WithField("prefix", "cmd-execution-chain")
|
||||
|
||||
// FlagOptions for execution service flag configurations.
|
||||
func FlagOptions(c *cli.Context) ([]execution.Option, error) {
|
||||
endpoints := parseExecutionChainEndpoint(c)
|
||||
endpoint, err := parseExecutionChainEndpoint(c)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
jwtSecret, err := parseJWTSecretFromFile(c)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not read JWT secret file for authenticating execution API")
|
||||
}
|
||||
opts := []execution.Option{
|
||||
execution.WithHttpEndpoints(endpoints),
|
||||
execution.WithHttpEndpoint(endpoint),
|
||||
execution.WithEth1HeaderRequestLimit(c.Uint64(flags.Eth1HeaderReqLimit.Name)),
|
||||
}
|
||||
if len(jwtSecret) > 0 {
|
||||
opts = append(opts, execution.WithHttpEndpointsAndJWTSecret(endpoints, jwtSecret))
|
||||
opts = append(opts, execution.WithHttpEndpointAndJWTSecret(endpoint, jwtSecret))
|
||||
}
|
||||
return opts, nil
|
||||
}
|
||||
@@ -63,15 +63,15 @@ func parseJWTSecretFromFile(c *cli.Context) ([]byte, error) {
|
||||
return secret, nil
|
||||
}
|
||||
|
||||
func parseExecutionChainEndpoint(c *cli.Context) []string {
|
||||
if c.String(flags.ExecutionEngineEndpoint.Name) == "" && len(c.StringSlice(flags.FallbackWeb3ProviderFlag.Name)) == 0 {
|
||||
log.Error(
|
||||
"No execution engine specified to run with the beacon node. " +
|
||||
"You must specified an execution client in order to participate. Visit " +
|
||||
"https://docs.prylabs.network/docs/prysm-usage/setup-eth1 for more information",
|
||||
func parseExecutionChainEndpoint(c *cli.Context) (string, error) {
|
||||
if c.String(flags.ExecutionEngineEndpoint.Name) == "" {
|
||||
return "", fmt.Errorf(
|
||||
"you need to specify %s to provide a connection endpoint to an Ethereum execution client "+
|
||||
"for your Prysm beacon node. This is a requirement for running a node. You can read more about "+
|
||||
"how to configure this execution client connection in our docs here "+
|
||||
"https://docs.prylabs.network/docs/install/install-with-script",
|
||||
flags.ExecutionEngineEndpoint.Name,
|
||||
)
|
||||
}
|
||||
endpoints := []string{c.String(flags.ExecutionEngineEndpoint.Name)}
|
||||
endpoints = append(endpoints, c.StringSlice(flags.FallbackWeb3ProviderFlag.Name)...)
|
||||
return endpoints
|
||||
return c.String(flags.ExecutionEngineEndpoint.Name), nil
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/v3/io/file"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
logTest "github.com/sirupsen/logrus/hooks/test"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
@@ -19,16 +18,11 @@ func TestExecutionchainCmd(t *testing.T) {
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.String(flags.ExecutionEngineEndpoint.Name, "primary", "")
|
||||
fallback := cli.StringSlice{}
|
||||
err := fallback.Set("fallback1")
|
||||
require.NoError(t, err)
|
||||
err = fallback.Set("fallback2")
|
||||
require.NoError(t, err)
|
||||
set.Var(&fallback, flags.FallbackWeb3ProviderFlag.Name, "")
|
||||
ctx := cli.NewContext(&app, set, nil)
|
||||
|
||||
endpoints := parseExecutionChainEndpoint(ctx)
|
||||
assert.DeepEqual(t, []string{"primary", "fallback1", "fallback2"}, endpoints)
|
||||
endpoints, err := parseExecutionChainEndpoint(ctx)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "primary", endpoints)
|
||||
}
|
||||
|
||||
func Test_parseJWTSecretFromFile(t *testing.T) {
|
||||
@@ -98,13 +92,10 @@ func Test_parseJWTSecretFromFile(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestPowchainPreregistration_EmptyWeb3Provider(t *testing.T) {
|
||||
hook := logTest.NewGlobal()
|
||||
app := cli.App{}
|
||||
set := flag.NewFlagSet("test", 0)
|
||||
set.String(flags.ExecutionEngineEndpoint.Name, "", "")
|
||||
fallback := cli.StringSlice{}
|
||||
set.Var(&fallback, flags.FallbackWeb3ProviderFlag.Name, "")
|
||||
ctx := cli.NewContext(&app, set, nil)
|
||||
parseExecutionChainEndpoint(ctx)
|
||||
assert.LogsContain(t, hook, "No execution engine specified to run with the beacon node. You must specified an execution client in order to participate")
|
||||
_, err := parseExecutionChainEndpoint(ctx)
|
||||
assert.ErrorContains(t, "you need to specify", err)
|
||||
}
|
||||
|
||||
@@ -44,11 +44,6 @@ var (
|
||||
"This is not required if using an IPC connection.",
|
||||
Value: "",
|
||||
}
|
||||
// FallbackWeb3ProviderFlag provides a fallback endpoint to an ETH 1.0 RPC.
|
||||
FallbackWeb3ProviderFlag = &cli.StringSliceFlag{
|
||||
Name: "fallback-web3provider",
|
||||
Usage: "A mainchain web3 provider string http endpoint. This is our fallback web3 provider, this flag may be used multiple times.",
|
||||
}
|
||||
// DepositContractFlag defines a flag for the deposit contract address.
|
||||
DepositContractFlag = &cli.StringFlag{
|
||||
Name: "deposit-contract",
|
||||
|
||||
@@ -39,7 +39,6 @@ var appFlags = []cli.Flag{
|
||||
flags.DepositContractFlag,
|
||||
flags.ExecutionEngineEndpoint,
|
||||
flags.ExecutionJWTSecretFlag,
|
||||
flags.FallbackWeb3ProviderFlag,
|
||||
flags.RPCHost,
|
||||
flags.RPCPort,
|
||||
flags.CertFlag,
|
||||
@@ -189,9 +188,6 @@ func main() {
|
||||
if err := cmd.ExpandSingleEndpointIfFile(ctx, flags.ExecutionEngineEndpoint); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := cmd.ExpandWeb3EndpointsIfFile(ctx, flags.FallbackWeb3ProviderFlag); err != nil {
|
||||
return err
|
||||
}
|
||||
if ctx.IsSet(flags.SetGCPercent.Name) {
|
||||
runtimeDebug.SetGCPercent(ctx.Int(flags.SetGCPercent.Name))
|
||||
}
|
||||
|
||||
@@ -110,7 +110,6 @@ var appHelpFlagGroups = []flagGroup{
|
||||
flags.GPRCGatewayCorsDomain,
|
||||
flags.ExecutionEngineEndpoint,
|
||||
flags.ExecutionJWTSecretFlag,
|
||||
flags.FallbackWeb3ProviderFlag,
|
||||
flags.SetGCPercent,
|
||||
flags.SlotsPerArchivedPoint,
|
||||
flags.DisableDiscv5,
|
||||
|
||||
@@ -236,28 +236,6 @@ func populateBeaconNodeStats(pf metricMap) BeaconNodeStats {
|
||||
}
|
||||
}
|
||||
|
||||
f, err = pf.getFamily("powchain_sync_eth1_fallback_configured")
|
||||
if err != nil {
|
||||
log.WithError(err).Debug("Failed to get powchain_sync_eth1_fallback_configured")
|
||||
} else {
|
||||
m = f.Metric[0]
|
||||
bs.SyncEth1FallbackConfigured = false
|
||||
if int64(m.Gauge.GetValue()) == 1 {
|
||||
bs.SyncEth1FallbackConfigured = true
|
||||
}
|
||||
}
|
||||
|
||||
f, err = pf.getFamily("powchain_sync_eth1_fallback_connected")
|
||||
if err != nil {
|
||||
log.WithError(err).Debug("Failed to get powchain_sync_eth1_fallback_connected")
|
||||
} else {
|
||||
m = f.Metric[0]
|
||||
bs.SyncEth1FallbackConnected = false
|
||||
if int64(m.Gauge.GetValue()) == 1 {
|
||||
bs.SyncEth1FallbackConnected = true
|
||||
}
|
||||
}
|
||||
|
||||
return bs
|
||||
}
|
||||
|
||||
|
||||
@@ -55,8 +55,6 @@ func TestBeaconNodeScraper(t *testing.T) {
|
||||
require.Equal(t, int64(7365341184), bs.DiskBeaconchainBytesTotal)
|
||||
require.Equal(t, int64(37), bs.NetworkPeersConnected)
|
||||
require.Equal(t, true, bs.SyncEth1Connected)
|
||||
require.Equal(t, true, bs.SyncEth1FallbackConfigured)
|
||||
require.Equal(t, true, bs.SyncEth1FallbackConnected)
|
||||
}
|
||||
|
||||
// helper function to wrap up all the scrape logic so tests can focus on data cases and assertions
|
||||
@@ -85,21 +83,7 @@ func TestInvertEth1Metrics(t *testing.T) {
|
||||
key: "SyncEth1Connected",
|
||||
body: strings.Replace(prometheusTestBody, "powchain_sync_eth1_connected 1", "powchain_sync_eth1_connected 0", 1),
|
||||
test: func(bs *BeaconNodeStats) bool {
|
||||
return bs.SyncEth1Connected == false && bs.SyncEth1FallbackConfigured == true && bs.SyncEth1FallbackConnected == true
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "SyncEth1FallbackConfigured",
|
||||
body: strings.Replace(prometheusTestBody, "powchain_sync_eth1_fallback_configured 1", "powchain_sync_eth1_fallback_configured 0", 1),
|
||||
test: func(bs *BeaconNodeStats) bool {
|
||||
return bs.SyncEth1Connected == true && bs.SyncEth1FallbackConfigured == false && bs.SyncEth1FallbackConnected == true
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "SyncEth1FallbackConnected",
|
||||
body: strings.Replace(prometheusTestBody, "powchain_sync_eth1_fallback_connected 1", "powchain_sync_eth1_fallback_connected 0", 1),
|
||||
test: func(bs *BeaconNodeStats) bool {
|
||||
return bs.SyncEth1Connected == true && bs.SyncEth1FallbackConfigured == true && bs.SyncEth1FallbackConnected == false
|
||||
return bs.SyncEth1Connected == false
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -49,12 +49,10 @@ type CommonStats struct {
|
||||
// to be present with their zero-value when not supported by a client.
|
||||
type BeaconNodeStats struct {
|
||||
// TODO(#8850): add support for this after slasher refactor is merged
|
||||
SlasherActive bool `json:"slasher_active"`
|
||||
SyncEth1FallbackConfigured bool `json:"sync_eth1_fallback_configured"`
|
||||
SyncEth1FallbackConnected bool `json:"sync_eth1_fallback_connected"`
|
||||
SyncEth1Connected bool `json:"sync_eth1_connected"`
|
||||
SyncEth2Synced bool `json:"sync_eth2_synced"`
|
||||
DiskBeaconchainBytesTotal int64 `json:"disk_beaconchain_bytes_total"`
|
||||
SlasherActive bool `json:"slasher_active"`
|
||||
SyncEth1Connected bool `json:"sync_eth1_connected"`
|
||||
SyncEth2Synced bool `json:"sync_eth2_synced"`
|
||||
DiskBeaconchainBytesTotal int64 `json:"disk_beaconchain_bytes_total"`
|
||||
// N/A -- would require significant network code changes at this time
|
||||
NetworkLibp2pBytesTotalReceive int64 `json:"network_libp2p_bytes_total_receive"`
|
||||
// N/A -- would require significant network code changes at this time
|
||||
|
||||
Reference in New Issue
Block a user