Skip to content

Commit

Permalink
Update dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Dec 7, 2023
1 parent 353ed95 commit cbccdf7
Show file tree
Hide file tree
Showing 20 changed files with 395 additions and 189 deletions.
8 changes: 5 additions & 3 deletions clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
eth2client "github.com/attestantio/go-eth2-client"
httpclient "github.com/attestantio/go-eth2-client/http"
multiclient "github.com/attestantio/go-eth2-client/multi"
"github.com/attestantio/vouch/services/metrics"
"github.com/attestantio/vouch/util"
"github.com/pkg/errors"
)
Expand All @@ -32,7 +33,7 @@ var (
)

// fetchClient fetches a client service, instantiating it if required.
func fetchClient(ctx context.Context, address string) (eth2client.Service, error) {
func fetchClient(ctx context.Context, monitor metrics.Service, address string) (eth2client.Service, error) {
if address == "" {
return nil, errors.New("no address supplied for client")
}
Expand All @@ -45,6 +46,7 @@ func fetchClient(ctx context.Context, address string) (eth2client.Service, error
var err error
client, err = httpclient.New(ctx,
httpclient.WithLogLevel(util.LogLevel(fmt.Sprintf("eth2client.%s", address))),
httpclient.WithMonitor(monitor),
httpclient.WithTimeout(util.Timeout(fmt.Sprintf("eth2client.%s", address))),
httpclient.WithAddress(address),
httpclient.WithExtraHeaders(map[string]string{
Expand All @@ -63,7 +65,7 @@ func fetchClient(ctx context.Context, address string) (eth2client.Service, error
}

// fetchMulticlient fetches a multiclient service, instantiating it if required.
func fetchMultiClient(ctx context.Context, addresses []string) (eth2client.Service, error) {
func fetchMultiClient(ctx context.Context, monitor metrics.Service, addresses []string) (eth2client.Service, error) {
if len(addresses) == 0 {
return nil, errors.New("no addresses supplied for multiclient")
}
Expand All @@ -78,7 +80,7 @@ func fetchMultiClient(ctx context.Context, addresses []string) (eth2client.Servi
// Fetch or create the individual clients.
clients := make([]eth2client.Service, 0, len(addresses))
for _, address := range addresses {
client, err := fetchClient(ctx, address)
client, err := fetchClient(ctx, monitor, address)
if err != nil {
log.Error().Err(err).Str("address", address).Msg("Cannot access client for multiclient; dropping from list")
continue
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ go 1.20

require (
github.com/attestantio/go-block-relay v0.2.0
github.com/attestantio/go-builder-client v0.4.1
github.com/attestantio/go-eth2-client v0.19.5
github.com/attestantio/go-builder-client v0.4.2
github.com/attestantio/go-eth2-client v0.19.7
github.com/aws/aws-sdk-go v1.46.4
github.com/holiman/uint256 v1.2.3
github.com/mitchellh/go-homedir v1.1.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAE
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
github.com/attestantio/go-block-relay v0.2.0 h1:RiIDW6nLAfTYsD7bQ4W3MJVDlTIifyDUsHQvm5HWF3k=
github.com/attestantio/go-block-relay v0.2.0/go.mod h1:6pjIGKOdIwP1AF0+TFF9kBVS1CueHec5sLSZX4U9XBg=
github.com/attestantio/go-builder-client v0.4.1 h1:1F4JVW9ElebH8cVhxs3jFSaWHy4NXGCePdUM7em/fLs=
github.com/attestantio/go-builder-client v0.4.1/go.mod h1:3u2Y8lHSPFaNJSRG1QFQsh11w+x7+5SLBNM6ajbqyxU=
github.com/attestantio/go-eth2-client v0.19.5 h1:4V+vhXsCYji5jWrlONbr03GV7qoLRdzq96dLgXaqmek=
github.com/attestantio/go-eth2-client v0.19.5/go.mod h1:mZve1kV9Ctj0I1HH9gdg+MnI8lZ+Cb2EktEtOYrBlsM=
github.com/attestantio/go-builder-client v0.4.2 h1:EycfAFqQV+ooc2z6hmTsbuH4TCLknr0aO0nHLHLMpJM=
github.com/attestantio/go-builder-client v0.4.2/go.mod h1:e02i/WO4fjs3/u9oIZEjiC8CK1Qyxy4cpiMMGKx4VqQ=
github.com/attestantio/go-eth2-client v0.19.7 h1:1cX2rYz9tMZGhXTCe5Ax3C9fmHx1igih21+MU1eO5ls=
github.com/attestantio/go-eth2-client v0.19.7/go.mod h1:mZve1kV9Ctj0I1HH9gdg+MnI8lZ+Cb2EktEtOYrBlsM=
github.com/aws/aws-sdk-go v1.44.81/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
github.com/aws/aws-sdk-go v1.46.4 h1:48tKgtm9VMPkb6y7HuYlsfhQmoIRAsTEXTsWLVlty4M=
github.com/aws/aws-sdk-go v1.46.4/go.mod h1:aVsgQcEevwlmQ7qHE9I3h+dtQgpqhFB+i8Phjh7fkwI=
Expand Down
77 changes: 46 additions & 31 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func main2() int {
}

logModules()
log.Info().Str("version", ReleaseVersion).Msg("Starting vouch")
log.Info().Str("version", ReleaseVersion).Str("commit_hash", util.CommitHash()).Msg("Starting vouch")

initProfiling()

Expand Down Expand Up @@ -277,14 +277,14 @@ func initProfiling() {
}
}

func startClient(ctx context.Context) (eth2client.Service, error) {
func startClient(ctx context.Context, monitor metrics.Service) (eth2client.Service, error) {
log.Trace().Msg("Starting consensus client service")
var consensusClient eth2client.Service
var err error
if len(viper.GetStringSlice("beacon-node-addresses")) > 0 {
consensusClient, err = fetchMultiClient(ctx, viper.GetStringSlice("beacon-node-addresses"))
consensusClient, err = fetchMultiClient(ctx, monitor, viper.GetStringSlice("beacon-node-addresses"))
} else {
consensusClient, err = fetchClient(ctx, viper.GetString("beacon-node-address"))
consensusClient, err = fetchClient(ctx, monitor, viper.GetString("beacon-node-address"))
}
if err != nil {
return nil, err
Expand Down Expand Up @@ -392,7 +392,7 @@ func startServices(ctx context.Context,
default:
eventsBeaconNodeAddresses = util.BeaconNodeAddresses("strategies.attestationdata")
}
eventsConsensusClient, err := fetchMultiClient(ctx, eventsBeaconNodeAddresses)
eventsConsensusClient, err := fetchMultiClient(ctx, monitor, eventsBeaconNodeAddresses)
if err != nil {
return nil, nil, errors.Wrap(err, "failed to fetch multiclient for controller")
}
Expand Down Expand Up @@ -442,7 +442,14 @@ func startBasicServices(ctx context.Context,
metrics.Service,
error,
) {
eth2Client, err := startClient(ctx)
// Initialise monitor without chainTime service and server for now, so the
// client can provide metrics.
monitor, err := startMonitor(ctx, nil, false)
if err != nil {
return nil, nil, nil, errors.Wrap(err, "failed to start metrics service")
}

eth2Client, err := startClient(ctx, monitor)
if err != nil {
return nil, nil, nil, err
}
Expand All @@ -457,7 +464,8 @@ func startBasicServices(ctx context.Context,
}

log.Trace().Msg("Starting metrics service")
monitor, err := startMonitor(ctx, chainTime)
// Reinitialise monitor with chainTime service and an operational server.
monitor, err = startMonitor(ctx, chainTime, true)
if err != nil {
return nil, nil, nil, errors.Wrap(err, "failed to start metrics service")
}
Expand Down Expand Up @@ -830,15 +838,22 @@ func initMajordomo(ctx context.Context) (majordomo.Service, error) {
}

// startMonitor starts the relevant metrics monitor given user input.
func startMonitor(ctx context.Context, chainTime chaintime.Service) (metrics.Service, error) {
func startMonitor(ctx context.Context,
chainTime chaintime.Service,
createServer bool,
) (
metrics.Service,
error,
) {
log.Trace().Msg("Starting metrics service")
var monitor metrics.Service
if viper.Get("metrics.prometheus.listen-address") != "" {
if viper.Get("metrics.prometheus.listen-address") != nil {
var err error
monitor, err = prometheusmetrics.New(ctx,
prometheusmetrics.WithLogLevel(util.LogLevel("metrics.prometheus")),
prometheusmetrics.WithAddress(viper.GetString("metrics.prometheus.listen-address")),
prometheusmetrics.WithChainTime(chainTime),
prometheusmetrics.WithCreateServer(createServer),
)
if err != nil {
return nil, errors.Wrap(err, "failed to start prometheus metrics service")
Expand Down Expand Up @@ -1047,7 +1062,7 @@ func selectAttestationDataProvider(ctx context.Context,
log.Info().Msg("Starting best attestation data strategy")
attestationDataProviders := make(map[string]eth2client.AttestationDataProvider)
for _, address := range util.BeaconNodeAddresses("strategies.attestationdata.best") {
client, err := fetchClient(ctx, address)
client, err := fetchClient(ctx, monitor, address)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %s for attestation data strategy", address))
}
Expand All @@ -1069,7 +1084,7 @@ func selectAttestationDataProvider(ctx context.Context,
log.Info().Msg("Starting first attestation data strategy")
attestationDataProviders := make(map[string]eth2client.AttestationDataProvider)
for _, address := range util.BeaconNodeAddresses("strategies.attestationdata.first") {
client, err := fetchClient(ctx, address)
client, err := fetchClient(ctx, monitor, address)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %s for attestation data strategy", address))
}
Expand Down Expand Up @@ -1107,7 +1122,7 @@ func selectAggregateAttestationProvider(ctx context.Context,
log.Info().Msg("Starting best aggregate attestation strategy")
aggregateAttestationProviders := make(map[string]eth2client.AggregateAttestationProvider)
for _, address := range util.BeaconNodeAddresses("strategies.aggregateattestation.best") {
client, err := fetchClient(ctx, address)
client, err := fetchClient(ctx, monitor, address)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %s for aggregate attestation strategy", address))
}
Expand All @@ -1127,7 +1142,7 @@ func selectAggregateAttestationProvider(ctx context.Context,
log.Info().Msg("Starting first aggregate attestation strategy")
aggregateAttestationProviders := make(map[string]eth2client.AggregateAttestationProvider)
for _, address := range util.BeaconNodeAddresses("strategies.aggregateattestation.first") {
client, err := fetchClient(ctx, address)
client, err := fetchClient(ctx, monitor, address)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %s for aggregate attestation strategy", address))
}
Expand Down Expand Up @@ -1164,7 +1179,7 @@ func selectProposalProvider(ctx context.Context,
log.Info().Msg("Starting best beacon block proposal strategy")
proposalProviders := make(map[string]eth2client.ProposalProvider)
for _, address := range util.BeaconNodeAddresses("strategies.beaconblockproposal.best") {
client, err := fetchClient(ctx, address)
client, err := fetchClient(ctx, monitor, address)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %s for beacon block proposal strategy", address))
}
Expand All @@ -1190,7 +1205,7 @@ func selectProposalProvider(ctx context.Context,
log.Info().Msg("Starting first beacon block proposal strategy")
proposalProviders := make(map[string]eth2client.ProposalProvider)
for _, address := range util.BeaconNodeAddresses("strategies.beaconblockproposal.first") {
client, err := fetchClient(ctx, address)
client, err := fetchClient(ctx, monitor, address)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %s for beacon block proposal strategy", address))
}
Expand Down Expand Up @@ -1227,7 +1242,7 @@ func selectBlindedProposalProvider(ctx context.Context,
log.Info().Msg("Starting best blinded beacon block proposal strategy")
blindedProposalProviders := make(map[string]eth2client.BlindedProposalProvider)
for _, address := range util.BeaconNodeAddresses("strategies.blindedbeaconblockproposal.best") {
client, err := fetchClient(ctx, address)
client, err := fetchClient(ctx, monitor, address)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %s for blinded beacon block proposal strategy", address))
}
Expand All @@ -1252,7 +1267,7 @@ func selectBlindedProposalProvider(ctx context.Context,
log.Info().Msg("Starting first blinded beacon block proposal strategy")
blindedProposalProviders := make(map[string]eth2client.BlindedProposalProvider)
for _, address := range util.BeaconNodeAddresses("strategies.blindedbeaconblockproposal.first") {
client, err := fetchClient(ctx, address)
client, err := fetchClient(ctx, monitor, address)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %s for blinded beacon block proposal strategy", address))
}
Expand Down Expand Up @@ -1288,7 +1303,7 @@ func selectSyncCommitteeContributionProvider(ctx context.Context,
log.Info().Msg("Starting best sync committee contribution strategy")
syncCommitteeContributionProviders := make(map[string]eth2client.SyncCommitteeContributionProvider)
for _, address := range util.BeaconNodeAddresses("strategies.synccommitteecontribution.best") {
client, err := fetchClient(ctx, address)
client, err := fetchClient(ctx, monitor, address)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %s for sync committee contribution strategy", address))
}
Expand All @@ -1308,7 +1323,7 @@ func selectSyncCommitteeContributionProvider(ctx context.Context,
log.Info().Msg("Starting first sync committee contribution strategy")
syncCommitteeContributionProviders := make(map[string]eth2client.SyncCommitteeContributionProvider)
for _, address := range util.BeaconNodeAddresses("strategies.synccommitteecontribution.first") {
client, err := fetchClient(ctx, address)
client, err := fetchClient(ctx, monitor, address)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %s for sync committee contribution strategy", address))
}
Expand Down Expand Up @@ -1344,7 +1359,7 @@ func selectBeaconBlockRootProvider(ctx context.Context,
log.Info().Msg("Starting majority beacon block root strategy")
beaconBlockRootProviders := make(map[string]eth2client.BeaconBlockRootProvider)
for _, address := range util.BeaconNodeAddresses("strategies.beaconblockroot.majority") {
client, err := fetchClient(ctx, address)
client, err := fetchClient(ctx, monitor, address)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %s for beacon block root strategy", address))
}
Expand All @@ -1366,7 +1381,7 @@ func selectBeaconBlockRootProvider(ctx context.Context,
log.Info().Msg("Starting first beacon block root strategy")
beaconBlockRootProviders := make(map[string]eth2client.BeaconBlockRootProvider)
for _, address := range util.BeaconNodeAddresses("strategies.beaconblockroot.first") {
client, err := fetchClient(ctx, address)
client, err := fetchClient(ctx, monitor, address)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %s for beacon block root strategy", address))
}
Expand Down Expand Up @@ -1428,7 +1443,7 @@ func startMultinodeSubmitter(ctx context.Context,
) {
aggregateAttestationSubmitters := make(map[string]eth2client.AggregateAttestationsSubmitter)
for _, address := range util.BeaconNodeAddresses("submitter.aggregateattestation.multinode") {
client, err := fetchClient(ctx, address)
client, err := fetchClient(ctx, monitor, address)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %s for aggregate attestation submitter strategy", address))
}
Expand All @@ -1437,7 +1452,7 @@ func startMultinodeSubmitter(ctx context.Context,

attestationsSubmitters := make(map[string]eth2client.AttestationsSubmitter)
for _, address := range util.BeaconNodeAddresses("submitter.attestation.multinode") {
client, err := fetchClient(ctx, address)
client, err := fetchClient(ctx, monitor, address)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %s for attestation submitter strategy", address))
}
Expand All @@ -1446,7 +1461,7 @@ func startMultinodeSubmitter(ctx context.Context,

proposalSubmitters := make(map[string]eth2client.ProposalSubmitter)
for _, address := range util.BeaconNodeAddresses("submitter.proposal.multinode") {
client, err := fetchClient(ctx, address)
client, err := fetchClient(ctx, monitor, address)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %s for proposal submitter strategy", address))
}
Expand All @@ -1455,7 +1470,7 @@ func startMultinodeSubmitter(ctx context.Context,

beaconCommitteeSubscriptionsSubmitters := make(map[string]eth2client.BeaconCommitteeSubscriptionsSubmitter)
for _, address := range util.BeaconNodeAddresses("submitter.beaconcommitteesubscription.multinode") {
client, err := fetchClient(ctx, address)
client, err := fetchClient(ctx, monitor, address)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %s for beacon committee subscription submitter strategy", address))
}
Expand All @@ -1464,7 +1479,7 @@ func startMultinodeSubmitter(ctx context.Context,

proposalPreparationSubmitters := make(map[string]eth2client.ProposalPreparationsSubmitter)
for _, address := range util.BeaconNodeAddresses("submitter.proposalpreparation.multinode") {
client, err := fetchClient(ctx, address)
client, err := fetchClient(ctx, monitor, address)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %s for proposal preparation submitter strategy", address))
}
Expand All @@ -1473,7 +1488,7 @@ func startMultinodeSubmitter(ctx context.Context,

syncCommitteeContributionsSubmitters := make(map[string]eth2client.SyncCommitteeContributionsSubmitter)
for _, address := range util.BeaconNodeAddresses("submitter.synccommitteecontribution.multinode") {
client, err := fetchClient(ctx, address)
client, err := fetchClient(ctx, monitor, address)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %s for sync committee contribution submitter strategy", address))
}
Expand All @@ -1482,7 +1497,7 @@ func startMultinodeSubmitter(ctx context.Context,

syncCommitteeMessagesSubmitters := make(map[string]eth2client.SyncCommitteeMessagesSubmitter)
for _, address := range util.BeaconNodeAddresses("submitter.synccommitteemessage.multinode") {
client, err := fetchClient(ctx, address)
client, err := fetchClient(ctx, monitor, address)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %s for sync committee message submitter strategy", address))
}
Expand All @@ -1491,7 +1506,7 @@ func startMultinodeSubmitter(ctx context.Context,

syncCommitteeSubscriptionsSubmitters := make(map[string]eth2client.SyncCommitteeSubscriptionsSubmitter)
for _, address := range util.BeaconNodeAddresses("submitter.synccommitteesubscription.multinode") {
client, err := fetchClient(ctx, address)
client, err := fetchClient(ctx, monitor, address)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %s for sync committee subscription submitter strategy", address))
}
Expand Down Expand Up @@ -1596,7 +1611,7 @@ func startBlockRelay(ctx context.Context,
secondaryValidatorRegistrationsSubmitters := make([]eth2client.ValidatorRegistrationsSubmitter, 0, len(bestBeaconNodeAddresses)+len(firstBeaconNodeAddresses))
clients := make(map[string]struct{})
for _, address := range bestBeaconNodeAddresses {
client, err := fetchClient(ctx, address)
client, err := fetchClient(ctx, monitor, address)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %s for blinded beacon block proposal strategy", address))
}
Expand All @@ -1605,7 +1620,7 @@ func startBlockRelay(ctx context.Context,
}
for _, address := range firstBeaconNodeAddresses {
if _, exists := clients[address]; !exists {
client, err := fetchClient(ctx, address)
client, err := fetchClient(ctx, monitor, address)
if err != nil {
return nil, errors.Wrap(err, fmt.Sprintf("failed to fetch client %s for blinded beacon block proposal strategy", address))
}
Expand Down
Loading

0 comments on commit cbccdf7

Please sign in to comment.